comparison src/xfaces.c @ 31570:9eeff4863080

Remove conditional compilation on SCALABLE_FONTS. (Finternal_set_lisp_face_attribute): If frame is 0, set new frame defaults first.
author Gerd Moellmann <gerd@gnu.org>
date Tue, 12 Sep 2000 14:19:32 +0000
parents 7ba4ef0eac8d
children d69d99161d39
comparison
equal deleted inserted replaced
31569:8b6e9e1a553b 31570:9eeff4863080
177 The faces `default', `modeline' are considered `basic faces'. 177 The faces `default', `modeline' are considered `basic faces'.
178 When redisplay happens the first time for a newly created frame, 178 When redisplay happens the first time for a newly created frame,
179 basic faces are realized for CHARSET_ASCII. Frame parameters are 179 basic faces are realized for CHARSET_ASCII. Frame parameters are
180 used to fill in unspecified attributes of the default face. */ 180 used to fill in unspecified attributes of the default face. */
181 181
182 /* Define SCALABLE_FONTS to a non-zero value to enable scalable
183 font use. Define it to zero to disable scalable font use.
184
185 Use of too many or too large scalable fonts can crash XFree86
186 servers. That's why I've put the code dealing with scalable fonts
187 in #if's. */
188
189 #define SCALABLE_FONTS 1
190
191 #include <config.h> 182 #include <config.h>
192 #include <sys/types.h> 183 #include <sys/types.h>
193 #include <sys/stat.h> 184 #include <sys/stat.h>
194 #include "lisp.h" 185 #include "lisp.h"
195 #include "charset.h" 186 #include "charset.h"
196 #include "frame.h" 187 #include "frame.h"
197 188
198 #ifdef HAVE_WINDOW_SYSTEM 189 #ifdef HAVE_WINDOW_SYSTEM
199 #include "fontset.h" 190 #include "fontset.h"
200 #endif 191 #endif /* HAVE_WINDOW_SYSTEM */
192
201 #ifdef HAVE_X_WINDOWS 193 #ifdef HAVE_X_WINDOWS
202 #include "xterm.h" 194 #include "xterm.h"
203 #ifdef USE_MOTIF 195 #ifdef USE_MOTIF
204 #include <Xm/Xm.h> 196 #include <Xm/Xm.h>
205 #include <Xm/XmStrDefs.h> 197 #include <Xm/XmStrDefs.h>
206 #endif /* USE_MOTIF */ 198 #endif /* USE_MOTIF */
207 #endif 199 #endif /* HAVE_X_WINDOWS */
208 200
209 #ifdef MSDOS 201 #ifdef MSDOS
210 #include "dosfns.h" 202 #include "dosfns.h"
211 #endif 203 #endif
212 204
222 #define x_list_fonts w32_list_fonts 214 #define x_list_fonts w32_list_fonts
223 #define GCGraphicsExposures 0 215 #define GCGraphicsExposures 0
224 /* For historic reasons, FONT_WIDTH refers to average width on W32, 216 /* For historic reasons, FONT_WIDTH refers to average width on W32,
225 not maximum as on X. Redefine here. */ 217 not maximum as on X. Redefine here. */
226 #define FONT_WIDTH FONT_MAX_WIDTH 218 #define FONT_WIDTH FONT_MAX_WIDTH
227 #endif 219 #endif /* WINDOWSNT */
228 220
229 #include "buffer.h" 221 #include "buffer.h"
230 #include "dispextern.h" 222 #include "dispextern.h"
231 #include "blockinput.h" 223 #include "blockinput.h"
232 #include "window.h" 224 #include "window.h"
360 scalable fonts. A value of t means allow the use of any scalable 352 scalable fonts. A value of t means allow the use of any scalable
361 font. Otherwise, value must be a list of regular expressions. A 353 font. Otherwise, value must be a list of regular expressions. A
362 font may be scaled if its name matches a regular expression in the 354 font may be scaled if its name matches a regular expression in the
363 list. */ 355 list. */
364 356
365 #if SCALABLE_FONTS
366 Lisp_Object Vscalable_fonts_allowed; 357 Lisp_Object Vscalable_fonts_allowed;
367 #endif
368 358
369 /* Maximum number of fonts to consider in font_list. If not an 359 /* Maximum number of fonts to consider in font_list. If not an
370 integer > 0, DEFAULT_FONT_LIST_LIMIT is used instead. */ 360 integer > 0, DEFAULT_FONT_LIST_LIMIT is used instead. */
371 361
372 Lisp_Object Vfont_list_limit; 362 Lisp_Object Vfont_list_limit;
636 if (n % 5 != 0) 626 if (n % 5 != 0)
637 fputc ('\n', stderr); 627 fputc ('\n', stderr);
638 return Qnil; 628 return Qnil;
639 } 629 }
640 630
641
642 #endif /* DEBUG_X_COLORS */ 631 #endif /* DEBUG_X_COLORS */
632
643 633
644 /* Free colors used on frame F. PIXELS is an array of NPIXELS pixel 634 /* Free colors used on frame F. PIXELS is an array of NPIXELS pixel
645 color values. Interrupt input must be blocked when this function 635 color values. Interrupt input must be blocked when this function
646 is called. */ 636 is called. */
647 637
2249 2239
2250 /* Get the list of fonts matching PATTERN from the X server. */ 2240 /* Get the list of fonts matching PATTERN from the X server. */
2251 BLOCK_INPUT; 2241 BLOCK_INPUT;
2252 names = XListFonts (dpy, pattern, nfonts, &n); 2242 names = XListFonts (dpy, pattern, nfonts, &n);
2253 UNBLOCK_INPUT; 2243 UNBLOCK_INPUT;
2254 #endif 2244 #endif /* HAVE_X_WINDOWS */
2255 #ifdef WINDOWSNT 2245 #ifdef WINDOWSNT
2256 /* NTEMACS_TODO : currently this uses w32_list_fonts, but it may be 2246 /* NTEMACS_TODO : currently this uses w32_list_fonts, but it may be
2257 better to do it the other way around. */ 2247 better to do it the other way around. */
2258 Lisp_Object lfonts; 2248 Lisp_Object lfonts;
2259 Lisp_Object lpattern, tem; 2249 Lisp_Object lpattern, tem;
2281 for (i = 0; i < n; i++) 2271 for (i = 0; i < n; i++)
2282 { 2272 {
2283 names[i] = XSTRING (XCAR (tem))->data; 2273 names[i] = XSTRING (XCAR (tem))->data;
2284 tem = XCDR (tem); 2274 tem = XCDR (tem);
2285 } 2275 }
2286 #endif 2276 #endif /* WINDOWSNT */
2287 2277
2288 if (names) 2278 if (names)
2289 { 2279 {
2290 /* Make a copy of the font names we got from X, and 2280 /* Make a copy of the font names we got from X, and
2291 split them into fields. */ 2281 split them into fields. */
2297 /* Ignore fonts having a name that we can't parse. */ 2287 /* Ignore fonts having a name that we can't parse. */
2298 if (!split_font_name (f, fonts + j, 1)) 2288 if (!split_font_name (f, fonts + j, 1))
2299 xfree (fonts[j].name); 2289 xfree (fonts[j].name);
2300 else if (font_scalable_p (fonts + j)) 2290 else if (font_scalable_p (fonts + j))
2301 { 2291 {
2302 #if SCALABLE_FONTS
2303 if (!scalable_fonts_p 2292 if (!scalable_fonts_p
2304 || !may_use_scalable_font_p (fonts + j, names[i])) 2293 || !may_use_scalable_font_p (fonts + j, names[i]))
2305 xfree (fonts[j].name); 2294 xfree (fonts[j].name);
2306 else 2295 else
2307 ++j; 2296 ++j;
2308 #else /* !SCALABLE_FONTS */
2309 /* Always ignore scalable fonts. */
2310 xfree (fonts[j].name);
2311 #endif /* !SCALABLE_FONTS */
2312 } 2297 }
2313 else 2298 else
2314 ++j; 2299 ++j;
2315 } 2300 }
2316 2301
2413 nfonts = DEFAULT_FONT_LIST_LIMIT; 2398 nfonts = DEFAULT_FONT_LIST_LIMIT;
2414 if (INTEGERP (Vfont_list_limit) && XINT (Vfont_list_limit) > 0) 2399 if (INTEGERP (Vfont_list_limit) && XINT (Vfont_list_limit) > 0)
2415 nfonts = XFASTINT (Vfont_list_limit); 2400 nfonts = XFASTINT (Vfont_list_limit);
2416 2401
2417 *fonts = (struct font_name *) xmalloc (nfonts * sizeof **fonts); 2402 *fonts = (struct font_name *) xmalloc (nfonts * sizeof **fonts);
2418 #if SCALABLE_FONTS
2419 nfonts = x_face_list_fonts (f, pattern, *fonts, nfonts, 1, 1); 2403 nfonts = x_face_list_fonts (f, pattern, *fonts, nfonts, 1, 1);
2420 #else
2421 nfonts = x_face_list_fonts (f, pattern, *fonts, nfonts, 1, 0);
2422 #endif
2423 2404
2424 /* Sort the resulting array and return it in *FONTS. If no 2405 /* Sort the resulting array and return it in *FONTS. If no
2425 fonts were found, make sure to set *FONTS to null. */ 2406 fonts were found, make sure to set *FONTS to null. */
2426 if (nfonts) 2407 if (nfonts)
2427 sort_fonts (f, *fonts, nfonts, cmpfn); 2408 sort_fonts (f, *fonts, nfonts, cmpfn);
3062 3043
3063 LFACE_FONT (lface) = fontname; 3044 LFACE_FONT (lface) = fontname;
3064 3045
3065 return 1; 3046 return 1;
3066 } 3047 }
3048
3067 #endif /* HAVE_WINDOW_SYSTEM */ 3049 #endif /* HAVE_WINDOW_SYSTEM */
3068 3050
3069 3051
3070 /* Merges the face height FROM with the face height TO, and returns the 3052 /* Merges the face height FROM with the face height TO, and returns the
3071 merged height. If FROM is an invalid height, then INVALID is 3053 merged height. If FROM is an invalid height, then INVALID is
3642 /* If FRAME is 0, change face on all frames, and change the 3624 /* If FRAME is 0, change face on all frames, and change the
3643 default for new frames. */ 3625 default for new frames. */
3644 if (INTEGERP (frame) && XINT (frame) == 0) 3626 if (INTEGERP (frame) && XINT (frame) == 0)
3645 { 3627 {
3646 Lisp_Object tail; 3628 Lisp_Object tail;
3629 Finternal_set_lisp_face_attribute (face, attr, value, Qt);
3647 FOR_EACH_FRAME (tail, frame) 3630 FOR_EACH_FRAME (tail, frame)
3648 Finternal_set_lisp_face_attribute (face, attr, value, frame); 3631 Finternal_set_lisp_face_attribute (face, attr, value, frame);
3649 return Finternal_set_lisp_face_attribute (face, attr, value, Qt); 3632 return face;
3650 } 3633 }
3651 3634
3652 /* Set lface to the Lisp attribute vector of FACE. */ 3635 /* Set lface to the Lisp attribute vector of FACE. */
3653 if (EQ (frame, Qt)) 3636 if (EQ (frame, Qt))
3654 lface = lface_from_face_name (NULL, face, 1); 3637 lface = lface_from_face_name (NULL, face, 1);
3993 if (EQ (attr, QCforeground)) 3976 if (EQ (attr, QCforeground))
3994 param = Qscroll_bar_foreground; 3977 param = Qscroll_bar_foreground;
3995 else if (EQ (attr, QCbackground)) 3978 else if (EQ (attr, QCbackground))
3996 param = Qscroll_bar_background; 3979 param = Qscroll_bar_background;
3997 } 3980 }
3998 #endif 3981 #endif /* not WINDOWSNT */
3999 else if (EQ (face, Qborder)) 3982 else if (EQ (face, Qborder))
4000 { 3983 {
4001 /* Changing background color of `border' sets frame parameter 3984 /* Changing background color of `border' sets frame parameter
4002 `border-color'. */ 3985 `border-color'. */
4003 if (EQ (attr, QCbackground)) 3986 if (EQ (attr, QCbackground))
4143 CHECK_LIVE_FRAME (frame, 2); 4126 CHECK_LIVE_FRAME (frame, 2);
4144 BLOCK_INPUT; 4127 BLOCK_INPUT;
4145 value = display_x_get_resource (FRAME_X_DISPLAY_INFO (XFRAME (frame)), 4128 value = display_x_get_resource (FRAME_X_DISPLAY_INFO (XFRAME (frame)),
4146 resource, class, Qnil, Qnil); 4129 resource, class, Qnil, Qnil);
4147 UNBLOCK_INPUT; 4130 UNBLOCK_INPUT;
4148 #endif 4131 #endif /* not WINDOWSNT */
4149 return value; 4132 return value;
4150 } 4133 }
4151 4134
4152 4135
4153 /* Return resource string VALUE as a boolean value, i.e. nil, or t. 4136 /* Return resource string VALUE as a boolean value, i.e. nil, or t.
4333 XtApplyToWidgets (widget, xm_apply_resources, &res); 4316 XtApplyToWidgets (widget, xm_apply_resources, &res);
4334 if (fl) 4317 if (fl)
4335 XmFontListFree (fl); 4318 XmFontListFree (fl);
4336 } 4319 }
4337 } 4320 }
4338
4339 4321
4340 #endif /* USE_MOTIF */ 4322 #endif /* USE_MOTIF */
4341 4323
4342 #ifdef USE_LUCID 4324 #ifdef USE_LUCID
4343 4325
5546 5528
5547 return 0; 5529 return 0;
5548 } 5530 }
5549 5531
5550 5532
5551 #if SCALABLE_FONTS
5552
5553 /* Value is non-zero if FONT is an exact match for face attributes in 5533 /* Value is non-zero if FONT is an exact match for face attributes in
5554 SPECIFIED. SPECIFIED is an array of face attribute values in font 5534 SPECIFIED. SPECIFIED is an array of face attribute values in font
5555 sort order. */ 5535 sort order. */
5556 5536
5557 static int 5537 static int
5656 } 5636 }
5657 5637
5658 return 0; 5638 return 0;
5659 } 5639 }
5660 5640
5661 #endif /* SCALABLE_FONTS != 0 */
5662 5641
5663 5642
5664 /* Return the name of the best matching font for face attributes 5643 /* Return the name of the best matching font for face attributes
5665 ATTRS in the array of font_name structures FONTS which contains 5644 ATTRS in the array of font_name structures FONTS which contains
5666 NFONTS elements. Value is a font name which is allocated from 5645 NFONTS elements. Value is a font name which is allocated from
5698 specified[i] = face_numeric_slant (attrs[LFACE_SLANT_INDEX]); 5677 specified[i] = face_numeric_slant (attrs[LFACE_SLANT_INDEX]);
5699 else 5678 else
5700 abort (); 5679 abort ();
5701 } 5680 }
5702 5681
5703 #if SCALABLE_FONTS
5704
5705 /* Set to 1 */
5706 exact_p = 0; 5682 exact_p = 0;
5707 5683
5708 /* Start with the first non-scalable font in the list. */ 5684 /* Start with the first non-scalable font in the list. */
5709 for (i = 0; i < nfonts; ++i) 5685 for (i = 0; i < nfonts; ++i)
5710 if (!font_scalable_p (fonts + i)) 5686 if (!font_scalable_p (fonts + i))
5762 5738
5763 if (font_scalable_p (best)) 5739 if (font_scalable_p (best))
5764 font_name = build_scalable_font_name (f, best, pt); 5740 font_name = build_scalable_font_name (f, best, pt);
5765 else 5741 else
5766 font_name = build_font_name (best); 5742 font_name = build_font_name (best);
5767
5768 #else /* !SCALABLE_FONTS */
5769
5770 /* Find the best non-scalable font. */
5771 best = fonts;
5772
5773 for (i = 1; i < nfonts; ++i)
5774 {
5775 xassert (!font_scalable_p (fonts + i));
5776 if (better_font_p (specified, fonts + i, best, 1))
5777 best = fonts + i;
5778 }
5779
5780 font_name = build_font_name (best);
5781
5782 #endif /* !SCALABLE_FONTS */
5783 5743
5784 /* Free font_name structures. */ 5744 /* Free font_name structures. */
5785 free_font_names (fonts, nfonts); 5745 free_font_names (fonts, nfonts);
5786 5746
5787 return font_name; 5747 return font_name;
7069 7029
7070 DEFVAR_LISP ("tty-defined-color-alist", &Vtty_defined_color_alist, 7030 DEFVAR_LISP ("tty-defined-color-alist", &Vtty_defined_color_alist,
7071 "An alist of defined terminal colors and their RGB values."); 7031 "An alist of defined terminal colors and their RGB values.");
7072 Vtty_defined_color_alist = Qnil; 7032 Vtty_defined_color_alist = Qnil;
7073 7033
7074 #if SCALABLE_FONTS
7075
7076 DEFVAR_LISP ("scalable-fonts-allowed", &Vscalable_fonts_allowed, 7034 DEFVAR_LISP ("scalable-fonts-allowed", &Vscalable_fonts_allowed,
7077 "Allowed scalable fonts.\n\ 7035 "Allowed scalable fonts.\n\
7078 A value of nil means don't allow any scalable fonts.\n\ 7036 A value of nil means don't allow any scalable fonts.\n\
7079 A value of t means allow any scalable font.\n\ 7037 A value of t means allow any scalable font.\n\
7080 Otherwise, value must be a list of regular expressions. A font may be\n\ 7038 Otherwise, value must be a list of regular expressions. A font may be\n\
7084 by default limits the fonts available severely. */ 7042 by default limits the fonts available severely. */
7085 Vscalable_fonts_allowed = Qt; 7043 Vscalable_fonts_allowed = Qt;
7086 #else 7044 #else
7087 Vscalable_fonts_allowed = Qnil; 7045 Vscalable_fonts_allowed = Qnil;
7088 #endif 7046 #endif
7089 #endif /* SCALABLE_FONTS */
7090 7047
7091 #ifdef HAVE_WINDOW_SYSTEM 7048 #ifdef HAVE_WINDOW_SYSTEM
7092 defsubr (&Sbitmap_spec_p); 7049 defsubr (&Sbitmap_spec_p);
7093 defsubr (&Sx_list_fonts); 7050 defsubr (&Sx_list_fonts);
7094 defsubr (&Sinternal_face_x_get_resource); 7051 defsubr (&Sinternal_face_x_get_resource);