comparison src/xterm.c @ 35367:68000d773920

(x_list_fonts): Allow scalable fonts if SIZE is < 0, In the cache, use a key containing the information if scalable fonts are included. (x_load_font): Adapt to change of keys in the font cache. (x_list_fonts): Ensure caching font information when called for a null frame, which is the case frequently when Emacs starts.
author Gerd Moellmann <gerd@gnu.org>
date Wed, 17 Jan 2001 15:46:19 +0000
parents 1f5511b1d5ea
children 2470cdee5ed8
comparison
equal deleted inserted replaced
35366:94a6afe6cbef 35367:68000d773920
12778 { 12778 {
12779 return (FRAME_X_FONT_TABLE (f) + font_idx); 12779 return (FRAME_X_FONT_TABLE (f) + font_idx);
12780 } 12780 }
12781 12781
12782 12782
12783 /* Return a list of names of available fonts matching PATTERN on frame 12783 /* Return a list of names of available fonts matching PATTERN on frame F.
12784 F. If SIZE is not 0, it is the size (maximum bound width) of fonts 12784
12785 to be listed. Frame F NULL means we have not yet created any 12785 If SIZE is > 0, it is the size (maximum bounds width) of fonts
12786 frame on X, and consult the first display in x_display_list. 12786 to be listed.
12787 MAXNAMES sets a limit on how many fonts to match. */ 12787
12788 SIZE < 0 means include scalable fonts.
12789
12790 Frame F null means we have not yet created any frame on X, and
12791 consult the first display in x_display_list. MAXNAMES sets a limit
12792 on how many fonts to match. */
12788 12793
12789 Lisp_Object 12794 Lisp_Object
12790 x_list_fonts (f, pattern, size, maxnames) 12795 x_list_fonts (f, pattern, size, maxnames)
12791 FRAME_PTR f; 12796 struct frame *f;
12792 Lisp_Object pattern; 12797 Lisp_Object pattern;
12793 int size; 12798 int size;
12794 int maxnames; 12799 int maxnames;
12795 { 12800 {
12796 Lisp_Object list = Qnil, patterns, newlist = Qnil, key = Qnil; 12801 Lisp_Object list = Qnil, patterns, newlist = Qnil, key = Qnil;
12797 Lisp_Object tem, second_best; 12802 Lisp_Object tem, second_best;
12798 Display *dpy = f != NULL ? FRAME_X_DISPLAY (f) : x_display_list->display; 12803 struct x_display_info *dpyinfo
12804 = f ? FRAME_X_DISPLAY_INFO (f) : x_display_list;
12805 Display *dpy = dpyinfo->display;
12799 int try_XLoadQueryFont = 0; 12806 int try_XLoadQueryFont = 0;
12800 int count; 12807 int count;
12808 int allow_scalable_fonts_p = 0;
12809
12810 if (size < 0)
12811 {
12812 allow_scalable_fonts_p = 1;
12813 size = 0;
12814 }
12801 12815
12802 patterns = Fassoc (pattern, Valternate_fontname_alist); 12816 patterns = Fassoc (pattern, Valternate_fontname_alist);
12803 if (NILP (patterns)) 12817 if (NILP (patterns))
12804 patterns = Fcons (pattern, Qnil); 12818 patterns = Fcons (pattern, Qnil);
12805 12819
12813 char **names = NULL; 12827 char **names = NULL;
12814 12828
12815 pattern = XCAR (patterns); 12829 pattern = XCAR (patterns);
12816 /* See if we cached the result for this particular query. 12830 /* See if we cached the result for this particular query.
12817 The cache is an alist of the form: 12831 The cache is an alist of the form:
12818 (((PATTERN . MAXNAMES) (FONTNAME . WIDTH) ...) ...) 12832 ((((PATTERN . MAXNAMES) . SCALABLE) (FONTNAME . WIDTH) ...) ...) */
12819 */ 12833 tem = XCDR (dpyinfo->name_list_element);
12820 if (f && (tem = XCDR (FRAME_X_DISPLAY_INFO (f)->name_list_element), 12834 key = Fcons (Fcons (pattern, make_number (maxnames)),
12821 key = Fcons (pattern, make_number (maxnames)), 12835 allow_scalable_fonts_p ? Qt : Qnil);
12822 !NILP (list = Fassoc (key, tem)))) 12836 list = Fassoc (key, tem);
12837 if (!NILP (list))
12823 { 12838 {
12824 list = Fcdr_safe (list); 12839 list = Fcdr_safe (list);
12825 /* We have a cashed list. Don't have to get the list again. */ 12840 /* We have a cashed list. Don't have to get the list again. */
12826 goto label_cached; 12841 goto label_cached;
12827 } 12842 }
12904 int width = 0; 12919 int width = 0;
12905 char *p = names[i]; 12920 char *p = names[i];
12906 int average_width = -1, dashes = 0; 12921 int average_width = -1, dashes = 0;
12907 12922
12908 /* Count the number of dashes in NAMES[I]. If there are 12923 /* Count the number of dashes in NAMES[I]. If there are
12909 14 dashes, and the field value following 12th dash 12924 14 dashes, and the field value following 12th dash
12910 (AVERAGE_WIDTH) is 0, this is a auto-scaled font which 12925 (AVERAGE_WIDTH) is 0, this is a auto-scaled font which
12911 is usually too ugly to be used for editing. Let's 12926 is usually too ugly to be used for editing. Let's
12912 ignore it. */ 12927 ignore it. */
12913 while (*p) 12928 while (*p)
12914 if (*p++ == '-') 12929 if (*p++ == '-')
12915 { 12930 {
12916 dashes++; 12931 dashes++;
12917 if (dashes == 7) /* PIXEL_SIZE field */ 12932 if (dashes == 7) /* PIXEL_SIZE field */
12918 width = atoi (p); 12933 width = atoi (p);
12919 else if (dashes == 12) /* AVERAGE_WIDTH field */ 12934 else if (dashes == 12) /* AVERAGE_WIDTH field */
12920 average_width = atoi (p); 12935 average_width = atoi (p);
12921 } 12936 }
12922 if (dashes < 14 || average_width != 0) 12937
12938 if (allow_scalable_fonts_p
12939 || dashes < 14 || average_width != 0)
12923 { 12940 {
12924 tem = build_string (names[i]); 12941 tem = build_string (names[i]);
12925 if (NILP (Fassoc (tem, list))) 12942 if (NILP (Fassoc (tem, list)))
12926 { 12943 {
12927 if (STRINGP (Vx_pixel_size_width_font_regexp) 12944 if (STRINGP (Vx_pixel_size_width_font_regexp)
12940 if (!try_XLoadQueryFont) 12957 if (!try_XLoadQueryFont)
12941 XFreeFontNames (names); 12958 XFreeFontNames (names);
12942 } 12959 }
12943 12960
12944 /* Now store the result in the cache. */ 12961 /* Now store the result in the cache. */
12945 if (f != NULL) 12962 XCDR (dpyinfo->name_list_element)
12946 XCDR (FRAME_X_DISPLAY_INFO (f)->name_list_element) 12963 = Fcons (Fcons (key, list), XCDR (dpyinfo->name_list_element));
12947 = Fcons (Fcons (key, list),
12948 XCDR (FRAME_X_DISPLAY_INFO (f)->name_list_element));
12949 12964
12950 label_cached: 12965 label_cached:
12951 if (NILP (list)) continue; /* Try the remaining alternatives. */ 12966 if (NILP (list)) continue; /* Try the remaining alternatives. */
12952 12967
12953 newlist = second_best = Qnil; 12968 newlist = second_best = Qnil;
12967 } 12982 }
12968 12983
12969 if (!INTEGERP (XCDR (tem))) 12984 if (!INTEGERP (XCDR (tem)))
12970 { 12985 {
12971 /* Since we have not yet known the size of this font, we 12986 /* Since we have not yet known the size of this font, we
12972 must try slow function call XLoadQueryFont. */ 12987 must try slow function call XLoadQueryFont. */
12973 XFontStruct *thisinfo; 12988 XFontStruct *thisinfo;
12974 12989
12975 BLOCK_INPUT; 12990 BLOCK_INPUT;
12976 count = x_catch_errors (dpy); 12991 count = x_catch_errors (dpy);
12977 thisinfo = XLoadQueryFont (dpy, 12992 thisinfo = XLoadQueryFont (dpy,
13259 /* We come here because of a bug of XListFonts mentioned at 13274 /* We come here because of a bug of XListFonts mentioned at
13260 the head of this block. Let's store this information in 13275 the head of this block. Let's store this information in
13261 the cache for x_list_fonts. */ 13276 the cache for x_list_fonts. */
13262 Lisp_Object lispy_name = build_string (fontname); 13277 Lisp_Object lispy_name = build_string (fontname);
13263 Lisp_Object lispy_full_name = build_string (fontp->full_name); 13278 Lisp_Object lispy_full_name = build_string (fontp->full_name);
13279 Lisp_Object key = Fcons (Fcons (lispy_name, make_number (256)),
13280 Qnil);
13264 13281
13265 XCDR (dpyinfo->name_list_element) 13282 XCDR (dpyinfo->name_list_element)
13266 = Fcons (Fcons (Fcons (lispy_name, make_number (256)), 13283 = Fcons (Fcons (key,
13267 Fcons (Fcons (lispy_full_name, 13284 Fcons (Fcons (lispy_full_name,
13268 make_number (fontp->size)), 13285 make_number (fontp->size)),
13269 Qnil)), 13286 Qnil)),
13270 XCDR (dpyinfo->name_list_element)); 13287 XCDR (dpyinfo->name_list_element));
13271 if (full_name) 13288 if (full_name)
13272 XCDR (dpyinfo->name_list_element) 13289 {
13273 = Fcons (Fcons (Fcons (lispy_full_name, make_number (256)), 13290 key = Fcons (Fcons (lispy_full_name, make_number (256)),
13274 Fcons (Fcons (lispy_full_name, 13291 Qnil);
13275 make_number (fontp->size)), 13292 XCDR (dpyinfo->name_list_element)
13276 Qnil)), 13293 = Fcons (Fcons (key,
13277 XCDR (dpyinfo->name_list_element)); 13294 Fcons (Fcons (lispy_full_name,
13295 make_number (fontp->size)),
13296 Qnil)),
13297 XCDR (dpyinfo->name_list_element));
13298 }
13278 } 13299 }
13279 13300
13280 /* The slot `encoding' specifies how to map a character 13301 /* The slot `encoding' specifies how to map a character
13281 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to 13302 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
13282 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or 13303 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or