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