428
|
1 /* Generic Objects and Functions.
|
|
2 Copyright (C) 1995 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1995 Board of Trustees, University of Illinois.
|
2527
|
4 Copyright (C) 1995, 1996, 2002, 2004 Ben Wing.
|
428
|
5
|
|
6 This file is part of XEmacs.
|
|
7
|
|
8 XEmacs is free software; you can redistribute it and/or modify it
|
|
9 under the terms of the GNU General Public License as published by the
|
|
10 Free Software Foundation; either version 2, or (at your option) any
|
|
11 later version.
|
|
12
|
|
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
16 for more details.
|
|
17
|
|
18 You should have received a copy of the GNU General Public License
|
|
19 along with XEmacs; see the file COPYING. If not, write to
|
|
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
21 Boston, MA 02111-1307, USA. */
|
|
22
|
|
23 /* Synched up with: Not in FSF. */
|
|
24
|
|
25 #include <config.h>
|
|
26 #include "lisp.h"
|
|
27
|
771
|
28 #include "buffer.h"
|
872
|
29 #include "device-impl.h"
|
428
|
30 #include "elhash.h"
|
|
31 #include "faces.h"
|
|
32 #include "frame.h"
|
800
|
33 #include "glyphs.h"
|
872
|
34 #include "objects-impl.h"
|
428
|
35 #include "specifier.h"
|
|
36 #include "window.h"
|
|
37
|
1204
|
38 #ifdef HAVE_TTY
|
|
39 #include "console-tty.h"
|
|
40 #endif
|
934
|
41
|
428
|
42 /* Objects that are substituted when an instantiation fails.
|
|
43 If we leave in the Qunbound value, we will probably get crashes. */
|
|
44 Lisp_Object Vthe_null_color_instance, Vthe_null_font_instance;
|
|
45
|
|
46 /* Authors: Ben Wing, Chuck Thompson */
|
|
47
|
2268
|
48 DOESNT_RETURN
|
428
|
49 finalose (void *ptr)
|
|
50 {
|
793
|
51 Lisp_Object obj = wrap_pointer_1 (ptr);
|
|
52
|
563
|
53 invalid_operation
|
428
|
54 ("Can't dump an emacs containing window system objects", obj);
|
|
55 }
|
|
56
|
|
57
|
|
58 /****************************************************************************
|
|
59 * Color-Instance Object *
|
|
60 ****************************************************************************/
|
|
61
|
|
62 Lisp_Object Qcolor_instancep;
|
|
63
|
1204
|
64 static const struct memory_description color_instance_data_description_1 []= {
|
|
65 #ifdef HAVE_TTY
|
3092
|
66 #ifdef NEW_GC
|
|
67 { XD_LISP_OBJECT, tty_console },
|
|
68 #else /* not NEW_GC */
|
2551
|
69 { XD_BLOCK_PTR, tty_console, 1, { &tty_color_instance_data_description } },
|
3092
|
70 #endif /* not NEW_GC */
|
1204
|
71 #endif
|
934
|
72 { XD_END }
|
|
73 };
|
|
74
|
1204
|
75 static const struct sized_memory_description color_instance_data_description = {
|
|
76 sizeof (void *), color_instance_data_description_1
|
934
|
77 };
|
|
78
|
1204
|
79 static const struct memory_description color_instance_description[] = {
|
934
|
80 { XD_INT, offsetof (Lisp_Color_Instance, color_instance_type) },
|
|
81 { XD_LISP_OBJECT, offsetof (Lisp_Color_Instance, name)},
|
|
82 { XD_LISP_OBJECT, offsetof (Lisp_Color_Instance, device)},
|
1204
|
83 { XD_UNION, offsetof (Lisp_Color_Instance, data),
|
2551
|
84 XD_INDIRECT (0, 0), { &color_instance_data_description } },
|
934
|
85 {XD_END}
|
|
86 };
|
|
87
|
428
|
88 static Lisp_Object
|
|
89 mark_color_instance (Lisp_Object obj)
|
|
90 {
|
440
|
91 Lisp_Color_Instance *c = XCOLOR_INSTANCE (obj);
|
428
|
92 mark_object (c->name);
|
|
93 if (!NILP (c->device)) /* Vthe_null_color_instance */
|
|
94 MAYBE_DEVMETH (XDEVICE (c->device), mark_color_instance, (c));
|
|
95
|
|
96 return c->device;
|
|
97 }
|
|
98
|
|
99 static void
|
|
100 print_color_instance (Lisp_Object obj, Lisp_Object printcharfun,
|
|
101 int escapeflag)
|
|
102 {
|
440
|
103 Lisp_Color_Instance *c = XCOLOR_INSTANCE (obj);
|
428
|
104 if (print_readably)
|
563
|
105 printing_unreadable_object ("#<color-instance 0x%x>",
|
428
|
106 c->header.uid);
|
800
|
107 write_fmt_string_lisp (printcharfun, "#<color-instance %s", 1, c->name);
|
|
108 write_fmt_string_lisp (printcharfun, " on %s", 1, c->device);
|
428
|
109 if (!NILP (c->device)) /* Vthe_null_color_instance */
|
|
110 MAYBE_DEVMETH (XDEVICE (c->device), print_color_instance,
|
|
111 (c, printcharfun, escapeflag));
|
800
|
112 write_fmt_string (printcharfun, " 0x%x>", c->header.uid);
|
428
|
113 }
|
|
114
|
|
115 static void
|
|
116 finalize_color_instance (void *header, int for_disksave)
|
|
117 {
|
440
|
118 Lisp_Color_Instance *c = (Lisp_Color_Instance *) header;
|
428
|
119
|
|
120 if (!NILP (c->device))
|
|
121 {
|
|
122 if (for_disksave) finalose (c);
|
|
123 MAYBE_DEVMETH (XDEVICE (c->device), finalize_color_instance, (c));
|
|
124 }
|
|
125 }
|
|
126
|
|
127 static int
|
|
128 color_instance_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
|
|
129 {
|
440
|
130 Lisp_Color_Instance *c1 = XCOLOR_INSTANCE (obj1);
|
|
131 Lisp_Color_Instance *c2 = XCOLOR_INSTANCE (obj2);
|
428
|
132
|
|
133 return (c1 == c2) ||
|
|
134 (EQ (c1->device, c2->device) &&
|
|
135 DEVICEP (c1->device) &&
|
|
136 HAS_DEVMETH_P (XDEVICE (c1->device), color_instance_equal) &&
|
|
137 DEVMETH (XDEVICE (c1->device), color_instance_equal, (c1, c2, depth)));
|
|
138 }
|
|
139
|
2515
|
140 static Hashcode
|
428
|
141 color_instance_hash (Lisp_Object obj, int depth)
|
|
142 {
|
440
|
143 Lisp_Color_Instance *c = XCOLOR_INSTANCE (obj);
|
428
|
144 struct device *d = DEVICEP (c->device) ? XDEVICE (c->device) : 0;
|
|
145
|
2515
|
146 return HASH2 ((Hashcode) d,
|
428
|
147 !d ? LISP_HASH (obj)
|
|
148 : DEVMETH_OR_GIVEN (d, color_instance_hash, (c, depth),
|
|
149 LISP_HASH (obj)));
|
|
150 }
|
|
151
|
934
|
152 DEFINE_LRECORD_IMPLEMENTATION ("color-instance", color_instance,
|
|
153 0, /*dumpable-flag*/
|
|
154 mark_color_instance, print_color_instance,
|
|
155 finalize_color_instance, color_instance_equal,
|
|
156 color_instance_hash,
|
|
157 color_instance_description,
|
|
158 Lisp_Color_Instance);
|
428
|
159
|
|
160 DEFUN ("make-color-instance", Fmake_color_instance, 1, 3, 0, /*
|
|
161 Return a new `color-instance' object named NAME (a string).
|
|
162
|
|
163 Optional argument DEVICE specifies the device this object applies to
|
|
164 and defaults to the selected device.
|
|
165
|
|
166 An error is signaled if the color is unknown or cannot be allocated;
|
444
|
167 however, if optional argument NOERROR is non-nil, nil is simply
|
|
168 returned in this case. (And if NOERROR is other than t, a warning may
|
428
|
169 be issued.)
|
|
170
|
|
171 The returned object is a normal, first-class lisp object. The way you
|
|
172 `deallocate' the color is the way you deallocate any other lisp object:
|
|
173 you drop all pointers to it and allow it to be garbage collected. When
|
|
174 these objects are GCed, the underlying window-system data (e.g. X object)
|
|
175 is deallocated as well.
|
|
176 */
|
444
|
177 (name, device, noerror))
|
428
|
178 {
|
440
|
179 Lisp_Color_Instance *c;
|
428
|
180 int retval;
|
|
181
|
|
182 CHECK_STRING (name);
|
793
|
183 device = wrap_device (decode_device (device));
|
428
|
184
|
3017
|
185 c = ALLOC_LCRECORD_TYPE (Lisp_Color_Instance, &lrecord_color_instance);
|
428
|
186 c->name = name;
|
|
187 c->device = device;
|
|
188 c->data = 0;
|
1204
|
189 c->color_instance_type = get_console_variant (XDEVICE_TYPE (c->device));
|
428
|
190
|
|
191 retval = MAYBE_INT_DEVMETH (XDEVICE (device), initialize_color_instance,
|
|
192 (c, name, device,
|
444
|
193 decode_error_behavior_flag (noerror)));
|
428
|
194 if (!retval)
|
|
195 return Qnil;
|
|
196
|
793
|
197 return wrap_color_instance (c);
|
428
|
198 }
|
|
199
|
|
200 DEFUN ("color-instance-p", Fcolor_instance_p, 1, 1, 0, /*
|
|
201 Return non-nil if OBJECT is a color instance.
|
|
202 */
|
|
203 (object))
|
|
204 {
|
|
205 return COLOR_INSTANCEP (object) ? Qt : Qnil;
|
|
206 }
|
|
207
|
|
208 DEFUN ("color-instance-name", Fcolor_instance_name, 1, 1, 0, /*
|
|
209 Return the name used to allocate COLOR-INSTANCE.
|
|
210 */
|
|
211 (color_instance))
|
|
212 {
|
|
213 CHECK_COLOR_INSTANCE (color_instance);
|
|
214 return XCOLOR_INSTANCE (color_instance)->name;
|
|
215 }
|
|
216
|
|
217 DEFUN ("color-instance-rgb-components", Fcolor_instance_rgb_components, 1, 1, 0, /*
|
|
218 Return a three element list containing the red, green, and blue
|
|
219 color components of COLOR-INSTANCE, or nil if unknown.
|
|
220 Component values range from 0 to 65535.
|
|
221 */
|
|
222 (color_instance))
|
|
223 {
|
440
|
224 Lisp_Color_Instance *c;
|
428
|
225
|
|
226 CHECK_COLOR_INSTANCE (color_instance);
|
|
227 c = XCOLOR_INSTANCE (color_instance);
|
|
228
|
|
229 if (NILP (c->device))
|
|
230 return Qnil;
|
|
231
|
|
232 return MAYBE_LISP_DEVMETH (XDEVICE (c->device),
|
|
233 color_instance_rgb_components,
|
|
234 (c));
|
|
235 }
|
|
236
|
|
237 DEFUN ("valid-color-name-p", Fvalid_color_name_p, 1, 2, 0, /*
|
|
238 Return true if COLOR names a valid color for the current device.
|
|
239
|
|
240 Valid color names for X are listed in the file /usr/lib/X11/rgb.txt, or
|
|
241 whatever the equivalent is on your system.
|
|
242
|
|
243 Valid color names for TTY are those which have an ISO 6429 (ANSI) sequence.
|
|
244 In addition to being a color this may be one of a number of attributes
|
|
245 such as `blink'.
|
|
246 */
|
|
247 (color, device))
|
|
248 {
|
|
249 struct device *d = decode_device (device);
|
|
250
|
|
251 CHECK_STRING (color);
|
|
252 return MAYBE_INT_DEVMETH (d, valid_color_name_p, (d, color)) ? Qt : Qnil;
|
|
253 }
|
|
254
|
2527
|
255 DEFUN ("color-list", Fcolor_list, 0, 1, 0, /*
|
|
256 Return a list of color names.
|
|
257 DEVICE specifies which device to return names for, and defaults to the
|
|
258 currently selected device.
|
|
259 */
|
|
260 (device))
|
|
261 {
|
|
262 device = wrap_device (decode_device (device));
|
|
263
|
|
264 return MAYBE_LISP_DEVMETH (XDEVICE (device), color_list, ());
|
|
265 }
|
|
266
|
428
|
267
|
|
268 /***************************************************************************
|
|
269 * Font-Instance Object *
|
|
270 ***************************************************************************/
|
|
271
|
|
272 Lisp_Object Qfont_instancep;
|
|
273
|
|
274 static Lisp_Object font_instance_truename_internal (Lisp_Object xfont,
|
578
|
275 Error_Behavior errb);
|
934
|
276
|
1204
|
277 static const struct memory_description font_instance_data_description_1 []= {
|
|
278 #ifdef HAVE_TTY
|
3092
|
279 #ifdef NEW_GC
|
|
280 { XD_LISP_OBJECT, tty_console },
|
|
281 #else /* not NEW_GC */
|
|
282 { XD_BLOCK_PTR, tty_console, 1, { &tty_font_instance_data_description } },
|
|
283 #endif /* not NEW_GC */
|
1204
|
284 #endif
|
934
|
285 { XD_END }
|
|
286 };
|
|
287
|
1204
|
288 static const struct sized_memory_description font_instance_data_description = {
|
|
289 sizeof (void *), font_instance_data_description_1
|
934
|
290 };
|
|
291
|
1204
|
292 static const struct memory_description font_instance_description[] = {
|
934
|
293 { XD_INT, offsetof (Lisp_Font_Instance, font_instance_type) },
|
|
294 { XD_LISP_OBJECT, offsetof (Lisp_Font_Instance, name)},
|
|
295 { XD_LISP_OBJECT, offsetof (Lisp_Font_Instance, truename)},
|
|
296 { XD_LISP_OBJECT, offsetof (Lisp_Font_Instance, device)},
|
3094
|
297 { XD_LISP_OBJECT, offsetof (Lisp_Font_Instance, charset)},
|
934
|
298 { XD_UNION, offsetof (Lisp_Font_Instance, data),
|
2551
|
299 XD_INDIRECT (0, 0), { &font_instance_data_description } },
|
1204
|
300 { XD_END }
|
934
|
301 };
|
|
302
|
428
|
303
|
|
304 static Lisp_Object
|
|
305 mark_font_instance (Lisp_Object obj)
|
|
306 {
|
440
|
307 Lisp_Font_Instance *f = XFONT_INSTANCE (obj);
|
428
|
308
|
|
309 mark_object (f->name);
|
872
|
310 mark_object (f->truename);
|
428
|
311 if (!NILP (f->device)) /* Vthe_null_font_instance */
|
|
312 MAYBE_DEVMETH (XDEVICE (f->device), mark_font_instance, (f));
|
|
313
|
|
314 return f->device;
|
|
315 }
|
|
316
|
|
317 static void
|
|
318 print_font_instance (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
319 {
|
440
|
320 Lisp_Font_Instance *f = XFONT_INSTANCE (obj);
|
428
|
321 if (print_readably)
|
563
|
322 printing_unreadable_object ("#<font-instance 0x%x>", f->header.uid);
|
800
|
323 write_fmt_string_lisp (printcharfun, "#<font-instance %S", 1, f->name);
|
|
324 write_fmt_string_lisp (printcharfun, " on %s", 1, f->device);
|
428
|
325 if (!NILP (f->device))
|
3659
|
326 {
|
|
327 MAYBE_DEVMETH (XDEVICE (f->device), print_font_instance,
|
|
328 (f, printcharfun, escapeflag));
|
|
329
|
|
330 }
|
800
|
331 write_fmt_string (printcharfun, " 0x%x>", f->header.uid);
|
428
|
332 }
|
|
333
|
|
334 static void
|
|
335 finalize_font_instance (void *header, int for_disksave)
|
|
336 {
|
440
|
337 Lisp_Font_Instance *f = (Lisp_Font_Instance *) header;
|
428
|
338
|
|
339 if (!NILP (f->device))
|
|
340 {
|
|
341 if (for_disksave) finalose (f);
|
|
342 MAYBE_DEVMETH (XDEVICE (f->device), finalize_font_instance, (f));
|
|
343 }
|
|
344 }
|
|
345
|
|
346 /* Fonts are equal if they resolve to the same name.
|
|
347 Since we call `font-truename' to do this, and since font-truename is lazy,
|
|
348 this means the `equal' could cause XListFonts to be run the first time.
|
|
349 */
|
|
350 static int
|
|
351 font_instance_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
|
|
352 {
|
|
353 /* #### should this be moved into a device method? */
|
793
|
354 return internal_equal (font_instance_truename_internal
|
|
355 (obj1, ERROR_ME_DEBUG_WARN),
|
|
356 font_instance_truename_internal
|
|
357 (obj2, ERROR_ME_DEBUG_WARN),
|
428
|
358 depth + 1);
|
|
359 }
|
|
360
|
2515
|
361 static Hashcode
|
428
|
362 font_instance_hash (Lisp_Object obj, int depth)
|
|
363 {
|
793
|
364 return internal_hash (font_instance_truename_internal
|
|
365 (obj, ERROR_ME_DEBUG_WARN),
|
428
|
366 depth + 1);
|
|
367 }
|
|
368
|
934
|
369 DEFINE_LRECORD_IMPLEMENTATION ("font-instance", font_instance,
|
|
370 0, /*dumpable-flag*/
|
|
371 mark_font_instance, print_font_instance,
|
|
372 finalize_font_instance, font_instance_equal,
|
1204
|
373 font_instance_hash, font_instance_description,
|
|
374 Lisp_Font_Instance);
|
934
|
375
|
428
|
376
|
3094
|
377 /* #### Why is this exposed to Lisp? Used in:
|
|
378 x-frob-font-size, gtk-font-menu-load-font, x-font-menu-load-font-xft,
|
|
379 x-font-menu-load-font-core, mswindows-font-menu-load-font,
|
|
380 mswindows-frob-font-style-and-sizify, mswindows-frob-font-size. */
|
|
381 DEFUN ("make-font-instance", Fmake_font_instance, 1, 4, 0, /*
|
428
|
382 Return a new `font-instance' object named NAME.
|
|
383 DEVICE specifies the device this object applies to and defaults to the
|
|
384 selected device. An error is signalled if the font is unknown or cannot
|
|
385 be allocated; however, if NOERROR is non-nil, nil is simply returned in
|
3094
|
386 this case. CHARSET is used internally. #### make helper function?
|
428
|
387
|
|
388 The returned object is a normal, first-class lisp object. The way you
|
|
389 `deallocate' the font is the way you deallocate any other lisp object:
|
|
390 you drop all pointers to it and allow it to be garbage collected. When
|
3094
|
391 these objects are GCed, the underlying GUI data is deallocated as well.
|
428
|
392 */
|
3094
|
393 (name, device, noerror, charset))
|
428
|
394 {
|
440
|
395 Lisp_Font_Instance *f;
|
428
|
396 int retval = 0;
|
578
|
397 Error_Behavior errb = decode_error_behavior_flag (noerror);
|
428
|
398
|
|
399 if (ERRB_EQ (errb, ERROR_ME))
|
|
400 CHECK_STRING (name);
|
|
401 else if (!STRINGP (name))
|
|
402 return Qnil;
|
|
403
|
793
|
404 device = wrap_device (decode_device (device));
|
428
|
405
|
3017
|
406 f = ALLOC_LCRECORD_TYPE (Lisp_Font_Instance, &lrecord_font_instance);
|
428
|
407 f->name = name;
|
872
|
408 f->truename = Qnil;
|
428
|
409 f->device = device;
|
|
410
|
|
411 f->data = 0;
|
1204
|
412 f->font_instance_type = get_console_variant (XDEVICE_TYPE (f->device));
|
428
|
413
|
|
414 /* Stick some default values here ... */
|
|
415 f->ascent = f->height = 1;
|
|
416 f->descent = 0;
|
|
417 f->width = 1;
|
3094
|
418 f->charset = charset;
|
428
|
419 f->proportional_p = 0;
|
|
420
|
|
421 retval = MAYBE_INT_DEVMETH (XDEVICE (device), initialize_font_instance,
|
|
422 (f, name, device, errb));
|
|
423
|
|
424 if (!retval)
|
|
425 return Qnil;
|
|
426
|
793
|
427 return wrap_font_instance (f);
|
428
|
428 }
|
|
429
|
|
430 DEFUN ("font-instance-p", Ffont_instance_p, 1, 1, 0, /*
|
|
431 Return non-nil if OBJECT is a font instance.
|
|
432 */
|
|
433 (object))
|
|
434 {
|
|
435 return FONT_INSTANCEP (object) ? Qt : Qnil;
|
|
436 }
|
|
437
|
|
438 DEFUN ("font-instance-name", Ffont_instance_name, 1, 1, 0, /*
|
|
439 Return the name used to allocate FONT-INSTANCE.
|
|
440 */
|
|
441 (font_instance))
|
|
442 {
|
|
443 CHECK_FONT_INSTANCE (font_instance);
|
|
444 return XFONT_INSTANCE (font_instance)->name;
|
|
445 }
|
|
446
|
|
447 DEFUN ("font-instance-ascent", Ffont_instance_ascent, 1, 1, 0, /*
|
|
448 Return the ascent in pixels of FONT-INSTANCE.
|
|
449 The returned value is the maximum ascent for all characters in the font,
|
|
450 where a character's ascent is the number of pixels above (and including)
|
|
451 the baseline.
|
|
452 */
|
|
453 (font_instance))
|
|
454 {
|
|
455 CHECK_FONT_INSTANCE (font_instance);
|
|
456 return make_int (XFONT_INSTANCE (font_instance)->ascent);
|
|
457 }
|
|
458
|
|
459 DEFUN ("font-instance-descent", Ffont_instance_descent, 1, 1, 0, /*
|
|
460 Return the descent in pixels of FONT-INSTANCE.
|
|
461 The returned value is the maximum descent for all characters in the font,
|
|
462 where a character's descent is the number of pixels below the baseline.
|
|
463 \(Many characters to do not have any descent. Typical characters with a
|
|
464 descent are lowercase p and lowercase g.)
|
|
465 */
|
|
466 (font_instance))
|
|
467 {
|
|
468 CHECK_FONT_INSTANCE (font_instance);
|
|
469 return make_int (XFONT_INSTANCE (font_instance)->descent);
|
|
470 }
|
|
471
|
|
472 DEFUN ("font-instance-width", Ffont_instance_width, 1, 1, 0, /*
|
|
473 Return the width in pixels of FONT-INSTANCE.
|
|
474 The returned value is the average width for all characters in the font.
|
|
475 */
|
|
476 (font_instance))
|
|
477 {
|
|
478 CHECK_FONT_INSTANCE (font_instance);
|
|
479 return make_int (XFONT_INSTANCE (font_instance)->width);
|
|
480 }
|
|
481
|
|
482 DEFUN ("font-instance-proportional-p", Ffont_instance_proportional_p, 1, 1, 0, /*
|
|
483 Return whether FONT-INSTANCE is proportional.
|
|
484 This means that different characters in the font have different widths.
|
|
485 */
|
|
486 (font_instance))
|
|
487 {
|
|
488 CHECK_FONT_INSTANCE (font_instance);
|
|
489 return XFONT_INSTANCE (font_instance)->proportional_p ? Qt : Qnil;
|
|
490 }
|
|
491
|
|
492 static Lisp_Object
|
|
493 font_instance_truename_internal (Lisp_Object font_instance,
|
578
|
494 Error_Behavior errb)
|
428
|
495 {
|
440
|
496 Lisp_Font_Instance *f = XFONT_INSTANCE (font_instance);
|
|
497
|
428
|
498 if (NILP (f->device))
|
|
499 {
|
563
|
500 maybe_signal_error (Qgui_error, "Couldn't determine font truename",
|
|
501 font_instance, Qfont, errb);
|
428
|
502 return Qnil;
|
|
503 }
|
440
|
504
|
428
|
505 return DEVMETH_OR_GIVEN (XDEVICE (f->device),
|
|
506 font_instance_truename, (f, errb), f->name);
|
|
507 }
|
|
508
|
|
509 DEFUN ("font-instance-truename", Ffont_instance_truename, 1, 1, 0, /*
|
|
510 Return the canonical name of FONT-INSTANCE.
|
|
511 Font names are patterns which may match any number of fonts, of which
|
|
512 the first found is used. This returns an unambiguous name for that font
|
|
513 \(but not necessarily its only unambiguous name).
|
|
514 */
|
|
515 (font_instance))
|
|
516 {
|
|
517 CHECK_FONT_INSTANCE (font_instance);
|
|
518 return font_instance_truename_internal (font_instance, ERROR_ME);
|
|
519 }
|
|
520
|
3094
|
521 DEFUN ("font-instance-charset", Ffont_instance_charset, 1, 1, 0, /*
|
|
522 Return the Mule charset that FONT-INSTANCE was allocated to handle.
|
|
523 */
|
|
524 (font_instance))
|
|
525 {
|
|
526 CHECK_FONT_INSTANCE (font_instance);
|
|
527 return XFONT_INSTANCE (font_instance)->charset;
|
|
528 }
|
|
529
|
428
|
530 DEFUN ("font-instance-properties", Ffont_instance_properties, 1, 1, 0, /*
|
|
531 Return the properties (an alist or nil) of FONT-INSTANCE.
|
|
532 */
|
|
533 (font_instance))
|
|
534 {
|
440
|
535 Lisp_Font_Instance *f;
|
428
|
536
|
|
537 CHECK_FONT_INSTANCE (font_instance);
|
|
538 f = XFONT_INSTANCE (font_instance);
|
|
539
|
|
540 if (NILP (f->device))
|
|
541 return Qnil;
|
|
542
|
|
543 return MAYBE_LISP_DEVMETH (XDEVICE (f->device),
|
|
544 font_instance_properties, (f));
|
|
545 }
|
|
546
|
2527
|
547 DEFUN ("font-list", Ffont_list, 1, 3, 0, /*
|
428
|
548 Return a list of font names matching the given pattern.
|
|
549 DEVICE specifies which device to search for names, and defaults to the
|
|
550 currently selected device.
|
|
551 */
|
1701
|
552 (pattern, device, maxnumber))
|
428
|
553 {
|
|
554 CHECK_STRING (pattern);
|
793
|
555 device = wrap_device (decode_device (device));
|
428
|
556
|
2527
|
557 return MAYBE_LISP_DEVMETH (XDEVICE (device), font_list, (pattern, device,
|
1701
|
558 maxnumber));
|
428
|
559 }
|
|
560
|
|
561
|
|
562 /****************************************************************************
|
|
563 Color Object
|
|
564 ***************************************************************************/
|
1204
|
565
|
|
566 static const struct memory_description color_specifier_description[] = {
|
|
567 { XD_LISP_OBJECT, offsetof (struct color_specifier, face) },
|
|
568 { XD_LISP_OBJECT, offsetof (struct color_specifier, face_property) },
|
|
569 { XD_END }
|
|
570 };
|
|
571
|
|
572 DEFINE_SPECIFIER_TYPE_WITH_DATA (color);
|
428
|
573 /* Qcolor defined in general.c */
|
|
574
|
|
575 static void
|
|
576 color_create (Lisp_Object obj)
|
|
577 {
|
440
|
578 Lisp_Specifier *color = XCOLOR_SPECIFIER (obj);
|
428
|
579
|
|
580 COLOR_SPECIFIER_FACE (color) = Qnil;
|
|
581 COLOR_SPECIFIER_FACE_PROPERTY (color) = Qnil;
|
|
582 }
|
|
583
|
|
584 static void
|
|
585 color_mark (Lisp_Object obj)
|
|
586 {
|
440
|
587 Lisp_Specifier *color = XCOLOR_SPECIFIER (obj);
|
428
|
588
|
|
589 mark_object (COLOR_SPECIFIER_FACE (color));
|
|
590 mark_object (COLOR_SPECIFIER_FACE_PROPERTY (color));
|
|
591 }
|
|
592
|
|
593 /* No equal or hash methods; ignore the face the color is based off
|
|
594 of for `equal' */
|
|
595
|
|
596 static Lisp_Object
|
2286
|
597 color_instantiate (Lisp_Object specifier, Lisp_Object UNUSED (matchspec),
|
428
|
598 Lisp_Object domain, Lisp_Object instantiator,
|
|
599 Lisp_Object depth)
|
|
600 {
|
|
601 /* When called, we're inside of call_with_suspended_errors(),
|
|
602 so we can freely error. */
|
442
|
603 Lisp_Object device = DOMAIN_DEVICE (domain);
|
428
|
604 struct device *d = XDEVICE (device);
|
|
605
|
|
606 if (COLOR_INSTANCEP (instantiator))
|
|
607 {
|
|
608 /* If we are on the same device then we're done. Otherwise change
|
|
609 the instantiator to the name used to generate the pixel and let the
|
|
610 STRINGP case deal with it. */
|
|
611 if (NILP (device) /* Vthe_null_color_instance */
|
|
612 || EQ (device, XCOLOR_INSTANCE (instantiator)->device))
|
|
613 return instantiator;
|
|
614 else
|
|
615 instantiator = Fcolor_instance_name (instantiator);
|
|
616 }
|
|
617
|
|
618 if (STRINGP (instantiator))
|
|
619 {
|
|
620 /* First, look to see if we can retrieve a cached value. */
|
|
621 Lisp_Object instance =
|
|
622 Fgethash (instantiator, d->color_instance_cache, Qunbound);
|
|
623 /* Otherwise, make a new one. */
|
|
624 if (UNBOUNDP (instance))
|
|
625 {
|
|
626 /* make sure we cache the failures, too. */
|
|
627 instance = Fmake_color_instance (instantiator, device, Qt);
|
|
628 Fputhash (instantiator, instance, d->color_instance_cache);
|
|
629 }
|
|
630
|
|
631 return NILP (instance) ? Qunbound : instance;
|
|
632 }
|
|
633 else if (VECTORP (instantiator))
|
|
634 {
|
|
635 switch (XVECTOR_LENGTH (instantiator))
|
|
636 {
|
|
637 case 0:
|
|
638 if (DEVICE_TTY_P (d))
|
|
639 return Vthe_null_color_instance;
|
|
640 else
|
563
|
641 gui_error ("Color instantiator [] only valid on TTY's",
|
428
|
642 device);
|
|
643
|
|
644 case 1:
|
|
645 if (NILP (COLOR_SPECIFIER_FACE (XCOLOR_SPECIFIER (specifier))))
|
563
|
646 gui_error ("Color specifier not attached to a face",
|
428
|
647 instantiator);
|
|
648 return (FACE_PROPERTY_INSTANCE_1
|
|
649 (Fget_face (XVECTOR_DATA (instantiator)[0]),
|
|
650 COLOR_SPECIFIER_FACE_PROPERTY (XCOLOR_SPECIFIER (specifier)),
|
|
651 domain, ERROR_ME, 0, depth));
|
|
652
|
|
653 case 2:
|
|
654 return (FACE_PROPERTY_INSTANCE_1
|
|
655 (Fget_face (XVECTOR_DATA (instantiator)[0]),
|
|
656 XVECTOR_DATA (instantiator)[1], domain, ERROR_ME, 0, depth));
|
|
657
|
|
658 default:
|
2500
|
659 ABORT ();
|
428
|
660 }
|
|
661 }
|
|
662 else if (NILP (instantiator))
|
|
663 {
|
|
664 if (DEVICE_TTY_P (d))
|
|
665 return Vthe_null_color_instance;
|
|
666 else
|
563
|
667 gui_error ("Color instantiator [] only valid on TTY's",
|
428
|
668 device);
|
|
669 }
|
|
670 else
|
2500
|
671 ABORT (); /* The spec validation routines are screwed up. */
|
428
|
672
|
|
673 return Qunbound;
|
|
674 }
|
|
675
|
|
676 static void
|
|
677 color_validate (Lisp_Object instantiator)
|
|
678 {
|
|
679 if (COLOR_INSTANCEP (instantiator) || STRINGP (instantiator))
|
|
680 return;
|
|
681 if (VECTORP (instantiator))
|
|
682 {
|
|
683 if (XVECTOR_LENGTH (instantiator) > 2)
|
563
|
684 sferror ("Inheritance vector must be of size 0 - 2",
|
428
|
685 instantiator);
|
|
686 else if (XVECTOR_LENGTH (instantiator) > 0)
|
|
687 {
|
|
688 Lisp_Object face = XVECTOR_DATA (instantiator)[0];
|
|
689
|
|
690 Fget_face (face);
|
|
691 if (XVECTOR_LENGTH (instantiator) == 2)
|
|
692 {
|
|
693 Lisp_Object field = XVECTOR_DATA (instantiator)[1];
|
|
694 if (!EQ (field, Qforeground) && !EQ (field, Qbackground))
|
563
|
695 invalid_constant
|
428
|
696 ("Inheritance field must be `foreground' or `background'",
|
|
697 field);
|
|
698 }
|
|
699 }
|
|
700 }
|
|
701 else
|
563
|
702 invalid_argument ("Invalid color instantiator", instantiator);
|
428
|
703 }
|
|
704
|
|
705 static void
|
|
706 color_after_change (Lisp_Object specifier, Lisp_Object locale)
|
|
707 {
|
|
708 Lisp_Object face = COLOR_SPECIFIER_FACE (XCOLOR_SPECIFIER (specifier));
|
|
709 Lisp_Object property =
|
|
710 COLOR_SPECIFIER_FACE_PROPERTY (XCOLOR_SPECIFIER (specifier));
|
|
711 if (!NILP (face))
|
448
|
712 {
|
|
713 face_property_was_changed (face, property, locale);
|
|
714 if (BUFFERP (locale))
|
|
715 XBUFFER (locale)->buffer_local_face_property = 1;
|
|
716 }
|
428
|
717 }
|
|
718
|
|
719 void
|
|
720 set_color_attached_to (Lisp_Object obj, Lisp_Object face, Lisp_Object property)
|
|
721 {
|
440
|
722 Lisp_Specifier *color = XCOLOR_SPECIFIER (obj);
|
428
|
723
|
|
724 COLOR_SPECIFIER_FACE (color) = face;
|
|
725 COLOR_SPECIFIER_FACE_PROPERTY (color) = property;
|
|
726 }
|
|
727
|
|
728 DEFUN ("color-specifier-p", Fcolor_specifier_p, 1, 1, 0, /*
|
|
729 Return t if OBJECT is a color specifier.
|
|
730
|
442
|
731 See `make-color-specifier' for a description of possible color instantiators.
|
428
|
732 */
|
|
733 (object))
|
|
734 {
|
|
735 return COLOR_SPECIFIERP (object) ? Qt : Qnil;
|
|
736 }
|
|
737
|
|
738
|
|
739 /****************************************************************************
|
|
740 Font Object
|
|
741 ***************************************************************************/
|
1204
|
742
|
|
743 static const struct memory_description font_specifier_description[] = {
|
|
744 { XD_LISP_OBJECT, offsetof (struct font_specifier, face) },
|
|
745 { XD_LISP_OBJECT, offsetof (struct font_specifier, face_property) },
|
|
746 { XD_END }
|
|
747 };
|
|
748
|
|
749 DEFINE_SPECIFIER_TYPE_WITH_DATA (font);
|
428
|
750 /* Qfont defined in general.c */
|
|
751
|
|
752 static void
|
|
753 font_create (Lisp_Object obj)
|
|
754 {
|
440
|
755 Lisp_Specifier *font = XFONT_SPECIFIER (obj);
|
428
|
756
|
|
757 FONT_SPECIFIER_FACE (font) = Qnil;
|
|
758 FONT_SPECIFIER_FACE_PROPERTY (font) = Qnil;
|
|
759 }
|
|
760
|
|
761 static void
|
|
762 font_mark (Lisp_Object obj)
|
|
763 {
|
440
|
764 Lisp_Specifier *font = XFONT_SPECIFIER (obj);
|
428
|
765
|
|
766 mark_object (FONT_SPECIFIER_FACE (font));
|
|
767 mark_object (FONT_SPECIFIER_FACE_PROPERTY (font));
|
|
768 }
|
|
769
|
|
770 /* No equal or hash methods; ignore the face the font is based off
|
|
771 of for `equal' */
|
|
772
|
|
773 #ifdef MULE
|
|
774
|
872
|
775 /* Given a truename font spec (i.e. the font spec should have its registry
|
|
776 field filled in), does it support displaying characters from CHARSET? */
|
|
777
|
|
778 static int
|
428
|
779 font_spec_matches_charset (struct device *d, Lisp_Object charset,
|
867
|
780 const Ibyte *nonreloc, Lisp_Object reloc,
|
872
|
781 Bytecount offset, Bytecount length,
|
3659
|
782 enum font_specifier_matchspec_stages stage)
|
428
|
783 {
|
|
784 return DEVMETH_OR_GIVEN (d, font_spec_matches_charset,
|
872
|
785 (d, charset, nonreloc, reloc, offset, length,
|
|
786 stage),
|
428
|
787 1);
|
|
788 }
|
|
789
|
|
790 static void
|
|
791 font_validate_matchspec (Lisp_Object matchspec)
|
|
792 {
|
872
|
793 CHECK_CONS (matchspec);
|
|
794 Fget_charset (XCAR (matchspec));
|
3659
|
795
|
|
796 do
|
|
797 {
|
|
798 if (EQ(XCDR(matchspec), Qinitial))
|
|
799 {
|
|
800 break;
|
|
801 }
|
|
802 if (EQ(XCDR(matchspec), Qfinal))
|
|
803 {
|
|
804 break;
|
|
805 }
|
|
806
|
|
807 invalid_argument("Invalid font matchspec stage",
|
|
808 XCDR(matchspec));
|
|
809 } while (0);
|
428
|
810 }
|
|
811
|
872
|
812 void
|
|
813 initialize_charset_font_caches (struct device *d)
|
|
814 {
|
|
815 /* Note that the following tables are bi-level. */
|
|
816 d->charset_font_cache_stage_1 =
|
|
817 make_lisp_hash_table (20, HASH_TABLE_NON_WEAK, HASH_TABLE_EQ);
|
|
818 d->charset_font_cache_stage_2 =
|
|
819 make_lisp_hash_table (20, HASH_TABLE_NON_WEAK, HASH_TABLE_EQ);
|
|
820 }
|
|
821
|
|
822 void
|
|
823 invalidate_charset_font_caches (Lisp_Object charset)
|
|
824 {
|
|
825 /* Invalidate font cache entries for charset on all devices. */
|
|
826 Lisp_Object devcons, concons, hash_table;
|
|
827 DEVICE_LOOP_NO_BREAK (devcons, concons)
|
|
828 {
|
|
829 struct device *d = XDEVICE (XCAR (devcons));
|
|
830 hash_table = Fgethash (charset, d->charset_font_cache_stage_1,
|
|
831 Qunbound);
|
|
832 if (!UNBOUNDP (hash_table))
|
|
833 Fclrhash (hash_table);
|
|
834 hash_table = Fgethash (charset, d->charset_font_cache_stage_2,
|
|
835 Qunbound);
|
|
836 if (!UNBOUNDP (hash_table))
|
|
837 Fclrhash (hash_table);
|
|
838 }
|
|
839 }
|
428
|
840
|
874
|
841 #endif /* MULE */
|
|
842
|
|
843
|
428
|
844 static Lisp_Object
|
2333
|
845 font_instantiate (Lisp_Object UNUSED (specifier),
|
|
846 Lisp_Object USED_IF_MULE (matchspec),
|
428
|
847 Lisp_Object domain, Lisp_Object instantiator,
|
|
848 Lisp_Object depth)
|
|
849 {
|
|
850 /* When called, we're inside of call_with_suspended_errors(),
|
|
851 so we can freely error. */
|
442
|
852 Lisp_Object device = DOMAIN_DEVICE (domain);
|
428
|
853 struct device *d = XDEVICE (device);
|
|
854 Lisp_Object instance;
|
872
|
855 Lisp_Object charset = Qnil;
|
1204
|
856 #ifdef MULE
|
3659
|
857 enum font_specifier_matchspec_stages stage = initial;
|
428
|
858
|
|
859 if (!UNBOUNDP (matchspec))
|
872
|
860 {
|
|
861 charset = Fget_charset (XCAR (matchspec));
|
3659
|
862
|
|
863 #define FROB(new_stage) if (EQ(Q##new_stage, XCDR(matchspec))) \
|
|
864 { \
|
|
865 stage = new_stage; \
|
|
866 }
|
|
867
|
|
868 FROB(initial)
|
|
869 else FROB(final)
|
|
870 else assert(0);
|
|
871
|
|
872 #undef FROB
|
|
873
|
872
|
874 }
|
428
|
875 #endif
|
|
876
|
|
877 if (FONT_INSTANCEP (instantiator))
|
|
878 {
|
|
879 if (NILP (device)
|
|
880 || EQ (device, XFONT_INSTANCE (instantiator)->device))
|
|
881 {
|
|
882 #ifdef MULE
|
872
|
883 if (font_spec_matches_charset (d, charset, 0,
|
428
|
884 Ffont_instance_truename
|
|
885 (instantiator),
|
872
|
886 0, -1, stage))
|
1204
|
887 #endif
|
428
|
888 return instantiator;
|
|
889 }
|
|
890 instantiator = Ffont_instance_name (instantiator);
|
|
891 }
|
|
892
|
|
893 if (STRINGP (instantiator))
|
|
894 {
|
874
|
895 #ifdef MULE
|
3659
|
896 /* #### rename these caches. */
|
872
|
897 Lisp_Object cache = stage ? d->charset_font_cache_stage_2 :
|
|
898 d->charset_font_cache_stage_1;
|
874
|
899 #else
|
|
900 Lisp_Object cache = d->font_instance_cache;
|
|
901 #endif
|
872
|
902
|
428
|
903 #ifdef MULE
|
872
|
904 if (!NILP (charset))
|
428
|
905 {
|
|
906 /* The instantiator is a font spec that could match many
|
|
907 different fonts. We need to find one of those fonts
|
|
908 whose registry matches the registry of the charset in
|
|
909 MATCHSPEC. This is potentially a very slow operation,
|
|
910 as it involves doing an XListFonts() or equivalent to
|
|
911 iterate over all possible fonts, and a regexp match
|
|
912 on each one. So we cache the results. */
|
|
913 Lisp_Object matching_font = Qunbound;
|
872
|
914 Lisp_Object hash_table = Fgethash (charset, cache, Qunbound);
|
428
|
915 if (UNBOUNDP (hash_table))
|
|
916 {
|
|
917 /* need to make a sub hash table. */
|
|
918 hash_table = make_lisp_hash_table (20, HASH_TABLE_KEY_WEAK,
|
|
919 HASH_TABLE_EQUAL);
|
872
|
920 Fputhash (charset, hash_table, cache);
|
428
|
921 }
|
|
922 else
|
|
923 matching_font = Fgethash (instantiator, hash_table, Qunbound);
|
|
924
|
|
925 if (UNBOUNDP (matching_font))
|
|
926 {
|
|
927 /* make sure we cache the failures, too. */
|
|
928 matching_font =
|
|
929 DEVMETH_OR_GIVEN (d, find_charset_font,
|
872
|
930 (device, instantiator, charset, stage),
|
428
|
931 instantiator);
|
|
932 Fputhash (instantiator, matching_font, hash_table);
|
|
933 }
|
|
934 if (NILP (matching_font))
|
|
935 return Qunbound;
|
|
936 instantiator = matching_font;
|
|
937 }
|
|
938 #endif /* MULE */
|
|
939
|
|
940 /* First, look to see if we can retrieve a cached value. */
|
872
|
941 instance = Fgethash (instantiator, cache, Qunbound);
|
428
|
942 /* Otherwise, make a new one. */
|
|
943 if (UNBOUNDP (instance))
|
|
944 {
|
|
945 /* make sure we cache the failures, too. */
|
3094
|
946 instance = Fmake_font_instance (instantiator, device, Qt, charset);
|
872
|
947 Fputhash (instantiator, instance, cache);
|
428
|
948 }
|
|
949
|
|
950 return NILP (instance) ? Qunbound : instance;
|
|
951 }
|
|
952 else if (VECTORP (instantiator))
|
|
953 {
|
3659
|
954 Lisp_Object match_inst = Qunbound;
|
428
|
955 assert (XVECTOR_LENGTH (instantiator) == 1);
|
3659
|
956
|
|
957 match_inst = face_property_matching_instance
|
|
958 (Fget_face (XVECTOR_DATA (instantiator)[0]), Qfont,
|
|
959 charset, domain, ERROR_ME, 0, depth, initial);
|
|
960
|
|
961 if (UNBOUNDP(match_inst))
|
|
962 {
|
|
963 match_inst = face_property_matching_instance
|
|
964 (Fget_face (XVECTOR_DATA (instantiator)[0]), Qfont,
|
|
965 charset, domain, ERROR_ME, 0, depth, final);
|
|
966 }
|
|
967
|
|
968 return match_inst;
|
|
969
|
428
|
970 }
|
|
971 else if (NILP (instantiator))
|
|
972 return Qunbound;
|
|
973 else
|
2500
|
974 ABORT (); /* Eh? */
|
428
|
975
|
|
976 return Qunbound;
|
|
977 }
|
|
978
|
|
979 static void
|
|
980 font_validate (Lisp_Object instantiator)
|
|
981 {
|
|
982 if (FONT_INSTANCEP (instantiator) || STRINGP (instantiator))
|
|
983 return;
|
|
984 if (VECTORP (instantiator))
|
|
985 {
|
|
986 if (XVECTOR_LENGTH (instantiator) != 1)
|
|
987 {
|
563
|
988 sferror
|
428
|
989 ("Vector length must be one for font inheritance", instantiator);
|
|
990 }
|
|
991 Fget_face (XVECTOR_DATA (instantiator)[0]);
|
|
992 }
|
|
993 else
|
563
|
994 invalid_argument ("Must be string, vector, or font-instance",
|
428
|
995 instantiator);
|
|
996 }
|
|
997
|
|
998 static void
|
|
999 font_after_change (Lisp_Object specifier, Lisp_Object locale)
|
|
1000 {
|
|
1001 Lisp_Object face = FONT_SPECIFIER_FACE (XFONT_SPECIFIER (specifier));
|
|
1002 Lisp_Object property =
|
|
1003 FONT_SPECIFIER_FACE_PROPERTY (XFONT_SPECIFIER (specifier));
|
|
1004 if (!NILP (face))
|
448
|
1005 {
|
|
1006 face_property_was_changed (face, property, locale);
|
|
1007 if (BUFFERP (locale))
|
|
1008 XBUFFER (locale)->buffer_local_face_property = 1;
|
|
1009 }
|
428
|
1010 }
|
|
1011
|
|
1012 void
|
|
1013 set_font_attached_to (Lisp_Object obj, Lisp_Object face, Lisp_Object property)
|
|
1014 {
|
440
|
1015 Lisp_Specifier *font = XFONT_SPECIFIER (obj);
|
428
|
1016
|
|
1017 FONT_SPECIFIER_FACE (font) = face;
|
|
1018 FONT_SPECIFIER_FACE_PROPERTY (font) = property;
|
|
1019 }
|
|
1020
|
|
1021 DEFUN ("font-specifier-p", Ffont_specifier_p, 1, 1, 0, /*
|
|
1022 Return non-nil if OBJECT is a font specifier.
|
|
1023
|
442
|
1024 See `make-font-specifier' for a description of possible font instantiators.
|
428
|
1025 */
|
|
1026 (object))
|
|
1027 {
|
|
1028 return FONT_SPECIFIERP (object) ? Qt : Qnil;
|
|
1029 }
|
|
1030
|
|
1031
|
|
1032 /*****************************************************************************
|
|
1033 Face Boolean Object
|
|
1034 ****************************************************************************/
|
1204
|
1035
|
|
1036 static const struct memory_description face_boolean_specifier_description[] = {
|
|
1037 { XD_LISP_OBJECT, offsetof (struct face_boolean_specifier, face) },
|
|
1038 { XD_LISP_OBJECT, offsetof (struct face_boolean_specifier, face_property) },
|
|
1039 { XD_END }
|
|
1040 };
|
|
1041
|
|
1042 DEFINE_SPECIFIER_TYPE_WITH_DATA (face_boolean);
|
428
|
1043 Lisp_Object Qface_boolean;
|
|
1044
|
|
1045 static void
|
|
1046 face_boolean_create (Lisp_Object obj)
|
|
1047 {
|
440
|
1048 Lisp_Specifier *face_boolean = XFACE_BOOLEAN_SPECIFIER (obj);
|
428
|
1049
|
|
1050 FACE_BOOLEAN_SPECIFIER_FACE (face_boolean) = Qnil;
|
|
1051 FACE_BOOLEAN_SPECIFIER_FACE_PROPERTY (face_boolean) = Qnil;
|
|
1052 }
|
|
1053
|
|
1054 static void
|
|
1055 face_boolean_mark (Lisp_Object obj)
|
|
1056 {
|
440
|
1057 Lisp_Specifier *face_boolean = XFACE_BOOLEAN_SPECIFIER (obj);
|
428
|
1058
|
|
1059 mark_object (FACE_BOOLEAN_SPECIFIER_FACE (face_boolean));
|
|
1060 mark_object (FACE_BOOLEAN_SPECIFIER_FACE_PROPERTY (face_boolean));
|
|
1061 }
|
|
1062
|
|
1063 /* No equal or hash methods; ignore the face the face-boolean is based off
|
|
1064 of for `equal' */
|
|
1065
|
|
1066 static Lisp_Object
|
2286
|
1067 face_boolean_instantiate (Lisp_Object specifier,
|
|
1068 Lisp_Object UNUSED (matchspec),
|
428
|
1069 Lisp_Object domain, Lisp_Object instantiator,
|
|
1070 Lisp_Object depth)
|
|
1071 {
|
|
1072 /* When called, we're inside of call_with_suspended_errors(),
|
|
1073 so we can freely error. */
|
|
1074 if (NILP (instantiator) || EQ (instantiator, Qt))
|
|
1075 return instantiator;
|
|
1076 else if (VECTORP (instantiator))
|
|
1077 {
|
|
1078 Lisp_Object retval;
|
|
1079 Lisp_Object prop;
|
|
1080 int instantiator_len = XVECTOR_LENGTH (instantiator);
|
|
1081
|
|
1082 assert (instantiator_len >= 1 && instantiator_len <= 3);
|
|
1083 if (instantiator_len > 1)
|
|
1084 prop = XVECTOR_DATA (instantiator)[1];
|
|
1085 else
|
|
1086 {
|
|
1087 if (NILP (FACE_BOOLEAN_SPECIFIER_FACE
|
|
1088 (XFACE_BOOLEAN_SPECIFIER (specifier))))
|
563
|
1089 gui_error
|
428
|
1090 ("Face-boolean specifier not attached to a face", instantiator);
|
|
1091 prop = FACE_BOOLEAN_SPECIFIER_FACE_PROPERTY
|
|
1092 (XFACE_BOOLEAN_SPECIFIER (specifier));
|
|
1093 }
|
|
1094
|
|
1095 retval = (FACE_PROPERTY_INSTANCE_1
|
|
1096 (Fget_face (XVECTOR_DATA (instantiator)[0]),
|
|
1097 prop, domain, ERROR_ME, 0, depth));
|
|
1098
|
|
1099 if (instantiator_len == 3 && !NILP (XVECTOR_DATA (instantiator)[2]))
|
|
1100 retval = NILP (retval) ? Qt : Qnil;
|
|
1101
|
|
1102 return retval;
|
|
1103 }
|
|
1104 else
|
2500
|
1105 ABORT (); /* Eh? */
|
428
|
1106
|
|
1107 return Qunbound;
|
|
1108 }
|
|
1109
|
|
1110 static void
|
|
1111 face_boolean_validate (Lisp_Object instantiator)
|
|
1112 {
|
|
1113 if (NILP (instantiator) || EQ (instantiator, Qt))
|
|
1114 return;
|
|
1115 else if (VECTORP (instantiator) &&
|
|
1116 (XVECTOR_LENGTH (instantiator) >= 1 &&
|
|
1117 XVECTOR_LENGTH (instantiator) <= 3))
|
|
1118 {
|
|
1119 Lisp_Object face = XVECTOR_DATA (instantiator)[0];
|
|
1120
|
|
1121 Fget_face (face);
|
|
1122
|
|
1123 if (XVECTOR_LENGTH (instantiator) > 1)
|
|
1124 {
|
|
1125 Lisp_Object field = XVECTOR_DATA (instantiator)[1];
|
|
1126 if (!EQ (field, Qunderline)
|
|
1127 && !EQ (field, Qstrikethru)
|
|
1128 && !EQ (field, Qhighlight)
|
|
1129 && !EQ (field, Qdim)
|
|
1130 && !EQ (field, Qblinking)
|
|
1131 && !EQ (field, Qreverse))
|
563
|
1132 invalid_constant ("Invalid face-boolean inheritance field",
|
428
|
1133 field);
|
|
1134 }
|
|
1135 }
|
|
1136 else if (VECTORP (instantiator))
|
563
|
1137 sferror ("Wrong length for face-boolean inheritance spec",
|
428
|
1138 instantiator);
|
|
1139 else
|
563
|
1140 invalid_argument ("Face-boolean instantiator must be nil, t, or vector",
|
428
|
1141 instantiator);
|
|
1142 }
|
|
1143
|
|
1144 static void
|
|
1145 face_boolean_after_change (Lisp_Object specifier, Lisp_Object locale)
|
|
1146 {
|
|
1147 Lisp_Object face =
|
|
1148 FACE_BOOLEAN_SPECIFIER_FACE (XFACE_BOOLEAN_SPECIFIER (specifier));
|
|
1149 Lisp_Object property =
|
|
1150 FACE_BOOLEAN_SPECIFIER_FACE_PROPERTY (XFACE_BOOLEAN_SPECIFIER (specifier));
|
|
1151 if (!NILP (face))
|
448
|
1152 {
|
|
1153 face_property_was_changed (face, property, locale);
|
|
1154 if (BUFFERP (locale))
|
|
1155 XBUFFER (locale)->buffer_local_face_property = 1;
|
|
1156 }
|
428
|
1157 }
|
|
1158
|
|
1159 void
|
|
1160 set_face_boolean_attached_to (Lisp_Object obj, Lisp_Object face,
|
|
1161 Lisp_Object property)
|
|
1162 {
|
440
|
1163 Lisp_Specifier *face_boolean = XFACE_BOOLEAN_SPECIFIER (obj);
|
428
|
1164
|
|
1165 FACE_BOOLEAN_SPECIFIER_FACE (face_boolean) = face;
|
|
1166 FACE_BOOLEAN_SPECIFIER_FACE_PROPERTY (face_boolean) = property;
|
|
1167 }
|
|
1168
|
|
1169 DEFUN ("face-boolean-specifier-p", Fface_boolean_specifier_p, 1, 1, 0, /*
|
|
1170 Return non-nil if OBJECT is a face-boolean specifier.
|
|
1171
|
442
|
1172 See `make-face-boolean-specifier' for a description of possible
|
|
1173 face-boolean instantiators.
|
428
|
1174 */
|
|
1175 (object))
|
|
1176 {
|
|
1177 return FACE_BOOLEAN_SPECIFIERP (object) ? Qt : Qnil;
|
|
1178 }
|
|
1179
|
|
1180
|
|
1181 /************************************************************************/
|
|
1182 /* initialization */
|
|
1183 /************************************************************************/
|
|
1184
|
|
1185 void
|
|
1186 syms_of_objects (void)
|
|
1187 {
|
442
|
1188 INIT_LRECORD_IMPLEMENTATION (color_instance);
|
|
1189 INIT_LRECORD_IMPLEMENTATION (font_instance);
|
|
1190
|
428
|
1191 DEFSUBR (Fcolor_specifier_p);
|
|
1192 DEFSUBR (Ffont_specifier_p);
|
|
1193 DEFSUBR (Fface_boolean_specifier_p);
|
|
1194
|
563
|
1195 DEFSYMBOL_MULTIWORD_PREDICATE (Qcolor_instancep);
|
428
|
1196 DEFSUBR (Fmake_color_instance);
|
|
1197 DEFSUBR (Fcolor_instance_p);
|
|
1198 DEFSUBR (Fcolor_instance_name);
|
|
1199 DEFSUBR (Fcolor_instance_rgb_components);
|
|
1200 DEFSUBR (Fvalid_color_name_p);
|
2527
|
1201 DEFSUBR (Fcolor_list);
|
428
|
1202
|
563
|
1203 DEFSYMBOL_MULTIWORD_PREDICATE (Qfont_instancep);
|
428
|
1204 DEFSUBR (Fmake_font_instance);
|
|
1205 DEFSUBR (Ffont_instance_p);
|
|
1206 DEFSUBR (Ffont_instance_name);
|
|
1207 DEFSUBR (Ffont_instance_ascent);
|
|
1208 DEFSUBR (Ffont_instance_descent);
|
|
1209 DEFSUBR (Ffont_instance_width);
|
3094
|
1210 DEFSUBR (Ffont_instance_charset);
|
428
|
1211 DEFSUBR (Ffont_instance_proportional_p);
|
|
1212 DEFSUBR (Ffont_instance_truename);
|
|
1213 DEFSUBR (Ffont_instance_properties);
|
2527
|
1214 DEFSUBR (Ffont_list);
|
428
|
1215
|
|
1216 /* Qcolor, Qfont defined in general.c */
|
563
|
1217 DEFSYMBOL (Qface_boolean);
|
428
|
1218 }
|
|
1219
|
|
1220 void
|
|
1221 specifier_type_create_objects (void)
|
|
1222 {
|
|
1223 INITIALIZE_SPECIFIER_TYPE_WITH_DATA (color, "color", "color-specifier-p");
|
|
1224 INITIALIZE_SPECIFIER_TYPE_WITH_DATA (font, "font", "font-specifier-p");
|
|
1225 INITIALIZE_SPECIFIER_TYPE_WITH_DATA (face_boolean, "face-boolean",
|
|
1226 "face-boolean-specifier-p");
|
|
1227
|
|
1228 SPECIFIER_HAS_METHOD (color, instantiate);
|
|
1229 SPECIFIER_HAS_METHOD (font, instantiate);
|
|
1230 SPECIFIER_HAS_METHOD (face_boolean, instantiate);
|
|
1231
|
|
1232 SPECIFIER_HAS_METHOD (color, validate);
|
|
1233 SPECIFIER_HAS_METHOD (font, validate);
|
|
1234 SPECIFIER_HAS_METHOD (face_boolean, validate);
|
|
1235
|
|
1236 SPECIFIER_HAS_METHOD (color, create);
|
|
1237 SPECIFIER_HAS_METHOD (font, create);
|
|
1238 SPECIFIER_HAS_METHOD (face_boolean, create);
|
|
1239
|
|
1240 SPECIFIER_HAS_METHOD (color, mark);
|
|
1241 SPECIFIER_HAS_METHOD (font, mark);
|
|
1242 SPECIFIER_HAS_METHOD (face_boolean, mark);
|
|
1243
|
|
1244 SPECIFIER_HAS_METHOD (color, after_change);
|
|
1245 SPECIFIER_HAS_METHOD (font, after_change);
|
|
1246 SPECIFIER_HAS_METHOD (face_boolean, after_change);
|
|
1247
|
|
1248 #ifdef MULE
|
|
1249 SPECIFIER_HAS_METHOD (font, validate_matchspec);
|
|
1250 #endif
|
|
1251 }
|
|
1252
|
|
1253 void
|
|
1254 reinit_specifier_type_create_objects (void)
|
|
1255 {
|
|
1256 REINITIALIZE_SPECIFIER_TYPE (color);
|
|
1257 REINITIALIZE_SPECIFIER_TYPE (font);
|
|
1258 REINITIALIZE_SPECIFIER_TYPE (face_boolean);
|
|
1259 }
|
|
1260
|
|
1261 void
|
|
1262 reinit_vars_of_objects (void)
|
|
1263 {
|
|
1264 staticpro_nodump (&Vthe_null_color_instance);
|
|
1265 {
|
440
|
1266 Lisp_Color_Instance *c =
|
3017
|
1267 ALLOC_LCRECORD_TYPE (Lisp_Color_Instance, &lrecord_color_instance);
|
428
|
1268 c->name = Qnil;
|
|
1269 c->device = Qnil;
|
|
1270 c->data = 0;
|
|
1271
|
793
|
1272 Vthe_null_color_instance = wrap_color_instance (c);
|
428
|
1273 }
|
|
1274
|
|
1275 staticpro_nodump (&Vthe_null_font_instance);
|
|
1276 {
|
440
|
1277 Lisp_Font_Instance *f =
|
3017
|
1278 ALLOC_LCRECORD_TYPE (Lisp_Font_Instance, &lrecord_font_instance);
|
428
|
1279 f->name = Qnil;
|
872
|
1280 f->truename = Qnil;
|
428
|
1281 f->device = Qnil;
|
|
1282 f->data = 0;
|
|
1283
|
|
1284 f->ascent = f->height = 0;
|
|
1285 f->descent = 0;
|
|
1286 f->width = 0;
|
|
1287 f->proportional_p = 0;
|
|
1288
|
793
|
1289 Vthe_null_font_instance = wrap_font_instance (f);
|
428
|
1290 }
|
|
1291 }
|
|
1292
|
|
1293 void
|
|
1294 vars_of_objects (void)
|
|
1295 {
|
|
1296 }
|