aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJim Blandy1993-05-25 14:03:41 +0000
committerJim Blandy1993-05-25 14:03:41 +0000
commitea96210c357f58dfd5cbfa9cfd1247bfbe82c306 (patch)
tree43b543108f802e2d9378a604ff8b2d4c3b4fadc8
parent660ed6694bde223792ca217f96465662b9b33413 (diff)
downloademacs-ea96210c357f58dfd5cbfa9cfd1247bfbe82c306.tar.gz
emacs-ea96210c357f58dfd5cbfa9cfd1247bfbe82c306.zip
* xfns.c: Clear out the old face stuff.
(x_face_table, n_faces, x_set_face, x_set_glyph, Fx_set_face_font, Fx_set_face, Fx_get_face): Removed. (syms_of_xfns): Remove defsubr for Fx_set_face. Arrange for font names to get fully resolved - no wildcards. * xfns.c (x_set_frame_parameters): Store the value in the frame parameter alist before we call the setter function, so the setter function can touch up the value if it chooses. (x_set_foreground_color, x_set_background_color): Call recompute_basic_faces, so their GC's will reflect the changes. (x_new_font): Add extern declaration - this returns a Lisp_Object now, the fully resolved font name. (x_set_font): Accept the fully resolved name from x_new_font, and put it in the frame's parameter alist. Call recompute_basic_faces. * xterm.c (x_new_font): Return the fully resolved font name, Qnil (if no match), or Qt (match, but unacceptable metrics). * xterm.c (x_new_font): Don't call init_frame_faces. * xterm.h: New section for declarations for xfaces.c. (init_frame_faces, free_frame_faces, intern_face, face_name_id_number, same_size_fonts, recompute_basic_faces, compute_char_face, compute_glyph_face): Declare these here. * xfaces.c (same_size_fonts): We can now remove this extern declaration. * xfns.c (face_name_id_number): Likewise. * xterm.c (intern_face): Likewise. * xfns.c (Fx_list_fonts): Remember that FACE may not have a font specified. Don't specify 30000 as the maximum limit on the number of fontns returned - 2000 is more reasonable. Treat faces as structures specifying modifications to the frame's parameters, rather than things which need to specify a complete set of parameters by themselves. * xfaces.c (init_frame_faces): Don't set up the two frame display faces by querying the GC - just leave all their fields blank, and call recompute_basic_faces, letting build_face do the work of consulting the frame when necessary. (recompute_basic_faces): New function. (compute_base_faces): New function for obtaining the "identity" for compute_char_face and compute_glyph_face. (compute_char_face, compute_glyph_face): Call it, instead of copying FRAME_DEFAULT_FACE. * xfns.c (x_make_gc): No need to call init_frame_faces here.
-rw-r--r--src/xfns.c306
1 files changed, 30 insertions, 276 deletions
diff --git a/src/xfns.c b/src/xfns.c
index 369532b87ef..a4fb4f2b8e4 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -192,8 +192,6 @@ extern Lisp_Object Vwindow_system_version;
192/* Mouse map for clicks in windows. */ 192/* Mouse map for clicks in windows. */
193extern Lisp_Object Vglobal_mouse_map; 193extern Lisp_Object Vglobal_mouse_map;
194 194
195/* Points to table of defined typefaces. */
196struct face *x_face_table[MAX_FACES_AND_GLYPHS];
197 195
198/* Error if we are not connected to X. */ 196/* Error if we are not connected to X. */
199static void 197static void
@@ -355,14 +353,15 @@ x_set_frame_parameters (f, alist)
355 left = val; 353 left = val;
356 else 354 else
357 { 355 {
358 register Lisp_Object tem; 356 register Lisp_Object param_index = Fget (prop, Qx_frame_parameter);
359 tem = Fget (prop, Qx_frame_parameter); 357 register Lisp_Object old_value = get_frame_param (f, prop);
360 if (XTYPE (tem) == Lisp_Int 358
361 && XINT (tem) >= 0
362 && XINT (tem) < sizeof (x_frame_parms)/sizeof (x_frame_parms[0]))
363 (*x_frame_parms[XINT (tem)].setter)(f, val,
364 get_frame_param (f, prop));
365 store_frame_param (f, prop, val); 359 store_frame_param (f, prop, val);
360 if (XTYPE (param_index) == Lisp_Int
361 && XINT (param_index) >= 0
362 && (XINT (param_index)
363 < sizeof (x_frame_parms)/sizeof (x_frame_parms[0])))
364 (*x_frame_parms[XINT (param_index)].setter)(f, val, old_value);
366 } 365 }
367 } 366 }
368 367
@@ -493,6 +492,7 @@ x_set_foreground_color (f, arg, oldval)
493 f->display.x->foreground_pixel); 492 f->display.x->foreground_pixel);
494 UNBLOCK_INPUT; 493 UNBLOCK_INPUT;
495#endif /* HAVE_X11 */ 494#endif /* HAVE_X11 */
495 recompute_basic_faces (f);
496 if (FRAME_VISIBLE_P (f)) 496 if (FRAME_VISIBLE_P (f))
497 redraw_frame (f); 497 redraw_frame (f);
498 } 498 }
@@ -527,6 +527,8 @@ x_set_background_color (f, arg, oldval)
527#endif /* not HAVE_X11 */ 527#endif /* not HAVE_X11 */
528 UNBLOCK_INPUT; 528 UNBLOCK_INPUT;
529 529
530 recompute_basic_faces (f);
531
530 if (FRAME_VISIBLE_P (f)) 532 if (FRAME_VISIBLE_P (f))
531 redraw_frame (f); 533 redraw_frame (f);
532 } 534 }
@@ -799,25 +801,32 @@ x_set_icon_type (f, arg, oldval)
799 UNBLOCK_INPUT; 801 UNBLOCK_INPUT;
800} 802}
801 803
804extern Lisp_Object x_new_font ();
805
802void 806void
803x_set_font (f, arg, oldval) 807x_set_font (f, arg, oldval)
804 struct frame *f; 808 struct frame *f;
805 Lisp_Object arg, oldval; 809 Lisp_Object arg, oldval;
806{ 810{
807 unsigned char *name; 811 Lisp_Object result;
808 int result;
809 812
810 CHECK_STRING (arg, 1); 813 CHECK_STRING (arg, 1);
811 name = XSTRING (arg)->data;
812 814
813 BLOCK_INPUT; 815 BLOCK_INPUT;
814 result = x_new_font (f, name); 816 result = x_new_font (f, XSTRING (arg)->data);
815 UNBLOCK_INPUT; 817 UNBLOCK_INPUT;
816 818
817 if (result == 1) 819 if (EQ (result, Qnil))
818 error ("Font \"%s\" is not defined", name); 820 error ("Font \"%s\" is not defined", XSTRING (arg)->data);
819 if (result == 2) 821 else if (EQ (result, Qt))
820 error ("the characters of the given font have varying widths"); 822 error ("the characters of the given font have varying widths");
823 else if (STRINGP (result))
824 {
825 recompute_basic_faces (f);
826 store_frame_param (f, Qfont, result);
827 }
828 else
829 abort ();
821} 830}
822 831
823void 832void
@@ -1050,240 +1059,6 @@ x_set_vertical_scroll_bars (f, arg, oldval)
1050 } 1059 }
1051} 1060}
1052 1061
1053#ifdef HAVE_X11
1054int n_faces;
1055
1056#if 0
1057/* I believe this function is obsolete with respect to the new face display
1058 changes. */
1059x_set_face (scr, font, background, foreground, stipple)
1060 struct frame *scr;
1061 XFontStruct *font;
1062 unsigned long background, foreground;
1063 Pixmap stipple;
1064{
1065 XGCValues gc_values;
1066 GC temp_gc;
1067 unsigned long gc_mask;
1068 struct face *new_face;
1069 unsigned int width = 16;
1070 unsigned int height = 16;
1071
1072 if (n_faces == MAX_FACES_AND_GLYPHS)
1073 return 1;
1074
1075 /* Create the Graphics Context. */
1076 gc_values.font = font->fid;
1077 gc_values.foreground = foreground;
1078 gc_values.background = background;
1079 gc_values.line_width = 0;
1080 gc_mask = GCLineWidth | GCFont | GCForeground | GCBackground;
1081 if (stipple)
1082 {
1083 gc_values.stipple
1084 = XCreateBitmapFromData (x_current_display, ROOT_WINDOW,
1085 (char *) stipple, width, height);
1086 gc_mask |= GCStipple;
1087 }
1088
1089 temp_gc = XCreateGC (x_current_display, FRAME_X_WINDOW (scr),
1090 gc_mask, &gc_values);
1091 if (!temp_gc)
1092 return 1;
1093 new_face = (struct face *) xmalloc (sizeof (struct face));
1094 if (!new_face)
1095 {
1096 XFreeGC (x_current_display, temp_gc);
1097 return 1;
1098 }
1099
1100 new_face->font = font;
1101 new_face->foreground = foreground;
1102 new_face->background = background;
1103 new_face->face_gc = temp_gc;
1104 if (stipple)
1105 new_face->stipple = gc_values.stipple;
1106
1107 x_face_table[++n_faces] = new_face;
1108 return 1;
1109}
1110#endif
1111
1112x_set_glyph (scr, glyph)
1113{
1114}
1115
1116#if 0
1117DEFUN ("x-set-face-font", Fx_set_face_font, Sx_set_face_font, 4, 2, 0,
1118 "Specify face table entry FACE-CODE to be the font named by FONT,\n\
1119 in colors FOREGROUND and BACKGROUND.")
1120 (face_code, font_name, foreground, background)
1121 Lisp_Object face_code;
1122 Lisp_Object font_name;
1123 Lisp_Object foreground;
1124 Lisp_Object background;
1125{
1126 register struct face *fp; /* Current face info. */
1127 register int fn; /* Face number. */
1128 register FONT_TYPE *f; /* Font data structure. */
1129 unsigned char *newname;
1130 int fg, bg;
1131 GC temp_gc;
1132 XGCValues gc_values;
1133
1134 /* Need to do something about this. */
1135 Drawable drawable = FRAME_X_WINDOW (selected_frame);
1136
1137 CHECK_NUMBER (face_code, 1);
1138 CHECK_STRING (font_name, 2);
1139
1140 if (EQ (foreground, Qnil) || EQ (background, Qnil))
1141 {
1142 fg = selected_frame->display.x->foreground_pixel;
1143 bg = selected_frame->display.x->background_pixel;
1144 }
1145 else
1146 {
1147 CHECK_NUMBER (foreground, 0);
1148 CHECK_NUMBER (background, 1);
1149
1150 fg = x_decode_color (XINT (foreground), BLACK_PIX_DEFAULT);
1151 bg = x_decode_color (XINT (background), WHITE_PIX_DEFAULT);
1152 }
1153
1154 fn = XINT (face_code);
1155 if ((fn < 1) || (fn > 255))
1156 error ("Invalid face code, %d", fn);
1157
1158 newname = XSTRING (font_name)->data;
1159 BLOCK_INPUT;
1160 f = (*newname == 0 ? 0 : XGetFont (newname));
1161 UNBLOCK_INPUT;
1162 if (f == 0)
1163 error ("Font \"%s\" is not defined", newname);
1164
1165 fp = x_face_table[fn];
1166 if (fp == 0)
1167 {
1168 x_face_table[fn] = fp = (struct face *) xmalloc (sizeof (struct face));
1169 bzero (fp, sizeof (struct face));
1170 fp->face_type = x_pixmap;
1171 }
1172 else if (FACE_IS_FONT (fn))
1173 {
1174 BLOCK_INPUT;
1175 XFreeGC (FACE_FONT (fn));
1176 UNBLOCK_INPUT;
1177 }
1178 else if (FACE_IS_IMAGE (fn)) /* This should not happen... */
1179 {
1180 BLOCK_INPUT;
1181 XFreePixmap (x_current_display, FACE_IMAGE (fn));
1182 fp->face_type = x_font;
1183 UNBLOCK_INPUT;
1184 }
1185 else
1186 abort ();
1187
1188 fp->face_GLYPH.font_desc.font = f;
1189 gc_values.font = f->fid;
1190 gc_values.foreground = fg;
1191 gc_values.background = bg;
1192 fp->face_GLYPH.font_desc.face_gc = XCreateGC (x_current_display,
1193 drawable, GCFont | GCForeground
1194 | GCBackground, &gc_values);
1195 fp->face_GLYPH.font_desc.font_width = FONT_WIDTH (f);
1196 fp->face_GLYPH.font_desc.font_height = FONT_HEIGHT (f);
1197
1198 return face_code;
1199}
1200#endif
1201#else /* X10 */
1202DEFUN ("x-set-face", Fx_set_face, Sx_set_face, 4, 4, 0,
1203 "Specify face table entry FACE-CODE to be the font named by FONT,\n\
1204 in colors FOREGROUND and BACKGROUND.")
1205 (face_code, font_name, foreground, background)
1206 Lisp_Object face_code;
1207 Lisp_Object font_name;
1208 Lisp_Object foreground;
1209 Lisp_Object background;
1210{
1211 register struct face *fp; /* Current face info. */
1212 register int fn; /* Face number. */
1213 register FONT_TYPE *f; /* Font data structure. */
1214 unsigned char *newname;
1215
1216 CHECK_NUMBER (face_code, 1);
1217 CHECK_STRING (font_name, 2);
1218
1219 fn = XINT (face_code);
1220 if ((fn < 1) || (fn > 255))
1221 error ("Invalid face code, %d", fn);
1222
1223 /* Ask the server to find the specified font. */
1224 newname = XSTRING (font_name)->data;
1225 BLOCK_INPUT;
1226 f = (*newname == 0 ? 0 : XGetFont (newname));
1227 UNBLOCK_INPUT;
1228 if (f == 0)
1229 error ("Font \"%s\" is not defined", newname);
1230
1231 /* Get the face structure for face_code in the face table.
1232 Make sure it exists. */
1233 fp = x_face_table[fn];
1234 if (fp == 0)
1235 {
1236 x_face_table[fn] = fp = (struct face *) xmalloc (sizeof (struct face));
1237 bzero (fp, sizeof (struct face));
1238 }
1239
1240 /* If this face code already exists, get rid of the old font. */
1241 if (fp->font != 0 && fp->font != f)
1242 {
1243 BLOCK_INPUT;
1244 XLoseFont (fp->font);
1245 UNBLOCK_INPUT;
1246 }
1247
1248 /* Store the specified information in FP. */
1249 fp->fg = x_decode_color (foreground, BLACK_PIX_DEFAULT);
1250 fp->bg = x_decode_color (background, WHITE_PIX_DEFAULT);
1251 fp->font = f;
1252
1253 return face_code;
1254}
1255#endif /* X10 */
1256
1257#if 0
1258/* This is excluded because there is no painless way
1259 to get or to remember the name of the font. */
1260
1261DEFUN ("x-get-face", Fx_get_face, Sx_get_face, 1, 1, 0,
1262 "Get data defining face code FACE. FACE is an integer.\n\
1263The value is a list (FONT FG-COLOR BG-COLOR).")
1264 (face)
1265 Lisp_Object face;
1266{
1267 register struct face *fp; /* Current face info. */
1268 register int fn; /* Face number. */
1269
1270 CHECK_NUMBER (face, 1);
1271 fn = XINT (face);
1272 if ((fn < 1) || (fn > 255))
1273 error ("Invalid face code, %d", fn);
1274
1275 /* Make sure the face table exists and this face code is defined. */
1276 if (x_face_table == 0 || x_face_table[fn] == 0)
1277 return Qnil;
1278
1279 fp = x_face_table[fn];
1280
1281 return Fcons (build_string (fp->name),
1282 Fcons (make_number (fp->fg),
1283 Fcons (make_number (fp->bg), Qnil)));
1284}
1285#endif /* 0 */
1286
1287/* Subroutines of creating an X frame. */ 1062/* Subroutines of creating an X frame. */
1288 1063
1289#ifdef HAVE_X11 1064#ifdef HAVE_X11
@@ -1819,8 +1594,6 @@ x_make_gc (f)
1819 f->display.x->background_pixel, 1594 f->display.x->background_pixel,
1820 DefaultDepth (x_current_display, XDefaultScreen (x_current_display)))); 1595 DefaultDepth (x_current_display, XDefaultScreen (x_current_display))));
1821 1596
1822 init_frame_faces (f);
1823
1824 UNBLOCK_INPUT; 1597 UNBLOCK_INPUT;
1825} 1598}
1826#endif /* HAVE_X11 */ 1599#endif /* HAVE_X11 */
@@ -1925,6 +1698,7 @@ be shared by the new frame.")
1925 x_window (f); 1698 x_window (f);
1926 x_icon (f, parms); 1699 x_icon (f, parms);
1927 x_make_gc (f); 1700 x_make_gc (f);
1701 init_frame_faces (f);
1928 1702
1929 /* We need to do this after creating the X window, so that the 1703 /* We need to do this after creating the X window, so that the
1930 icon-creation functions can say whose icon they're describing. */ 1704 icon-creation functions can say whose icon they're describing. */
@@ -2325,23 +2099,6 @@ x_rubber_band (f, x, y, width, height, geo, str, hscroll, vscroll)
2325} 2099}
2326#endif /* not HAVE_X11 */ 2100#endif /* not HAVE_X11 */
2327 2101
2328extern int face_name_id_number ();
2329
2330/* Return non-zero if FONT1 and FONT2 have the same size bounding box.
2331 We assume that they're both character-cell fonts. */
2332int
2333same_size_fonts (font1, font2)
2334 XFontStruct *font1, *font2;
2335{
2336 XCharStruct *bounds1 = &font1->min_bounds;
2337 XCharStruct *bounds2 = &font2->min_bounds;
2338
2339 return (bounds1->width == bounds2->width
2340 && bounds1->ascent == bounds2->ascent
2341 && bounds1->descent == bounds2->descent);
2342}
2343
2344
2345DEFUN ("x-list-fonts", Fx_list_fonts, Sx_list_fonts, 1, 3, 0, 2102DEFUN ("x-list-fonts", Fx_list_fonts, Sx_list_fonts, 1, 3, 0,
2346 "Return a list of the names of available fonts matching PATTERN.\n\ 2103 "Return a list of the names of available fonts matching PATTERN.\n\
2347If optional arguments FACE and FRAME are specified, return only fonts\n\ 2104If optional arguments FACE and FRAME are specified, return only fonts\n\
@@ -2384,13 +2141,13 @@ fonts), even if they match PATTERN and FACE.")
2384 face_id = 0; 2141 face_id = 0;
2385 size_ref = FRAME_FACES (f) [face_id]->font; 2142 size_ref = FRAME_FACES (f) [face_id]->font;
2386 if (size_ref == (XFontStruct *) (~0)) 2143 if (size_ref == (XFontStruct *) (~0))
2387 size_ref = FRAME_DEFAULT_FACE (f)->font; 2144 size_ref = f->display.x->font;
2388 } 2145 }
2389 2146
2390 BLOCK_INPUT; 2147 BLOCK_INPUT;
2391 names = XListFontsWithInfo (x_current_display, 2148 names = XListFontsWithInfo (x_current_display,
2392 XSTRING (pattern)->data, 2149 XSTRING (pattern)->data,
2393 30000, /* maxnames */ 2150 2000, /* maxnames */
2394 &num_fonts, /* count_return */ 2151 &num_fonts, /* count_return */
2395 &info); /* info_return */ 2152 &info); /* info_return */
2396 UNBLOCK_INPUT; 2153 UNBLOCK_INPUT;
@@ -2402,10 +2159,8 @@ fonts), even if they match PATTERN and FACE.")
2402 list = Qnil; 2159 list = Qnil;
2403 tail = &list; 2160 tail = &list;
2404 for (i = 0; i < num_fonts; i++) 2161 for (i = 0; i < num_fonts; i++)
2405 /* Is this an acceptable font? */ 2162 if (! size_ref
2406 if (! info[i].per_char 2163 || same_size_fonts (&info[i], size_ref))
2407 && (! size_ref
2408 || same_size_fonts (&info[i], size_ref)))
2409 { 2164 {
2410 *tail = Fcons (build_string (names[i]), Qnil); 2165 *tail = Fcons (build_string (names[i]), Qnil);
2411 tail = &XCONS (*tail)->cdr; 2166 tail = &XCONS (*tail)->cdr;
@@ -3939,7 +3694,6 @@ unless you set the mouse color.");
3939 defsubr (&Sx_get_default); 3694 defsubr (&Sx_get_default);
3940 defsubr (&Sx_store_cut_buffer); 3695 defsubr (&Sx_store_cut_buffer);
3941 defsubr (&Sx_get_cut_buffer); 3696 defsubr (&Sx_get_cut_buffer);
3942 defsubr (&Sx_set_face);
3943#endif 3697#endif
3944 defsubr (&Sx_parse_geometry); 3698 defsubr (&Sx_parse_geometry);
3945 defsubr (&Sx_create_frame); 3699 defsubr (&Sx_create_frame);