0
|
1 /* Generic glyph/image implementation + display tables
|
|
2 Copyright (C) 1994, 1995 Board of Trustees, University of Illinois.
|
|
3 Copyright (C) 1995 Tinker Systems
|
|
4 Copyright (C) 1995, 1996 Ben Wing
|
|
5 Copyright (C) 1995 Sun Microsystems
|
173
|
6
|
0
|
7 This file is part of XEmacs.
|
|
8
|
|
9 XEmacs is free software; you can redistribute it and/or modify it
|
|
10 under the terms of the GNU General Public License as published by the
|
|
11 Free Software Foundation; either version 2, or (at your option) any
|
|
12 later version.
|
|
13
|
|
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
17 for more details.
|
|
18
|
|
19 You should have received a copy of the GNU General Public License
|
|
20 along with XEmacs; see the file COPYING. If not, write to
|
|
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 Boston, MA 02111-1307, USA. */
|
|
23
|
|
24 /* Synched up with: Not in FSF. */
|
|
25
|
|
26 /* Written by Ben Wing and Chuck Thompson */
|
|
27
|
|
28 #include <config.h>
|
|
29 #include "lisp.h"
|
|
30
|
|
31 #include "buffer.h"
|
|
32 #include "device.h"
|
|
33 #include "elhash.h"
|
|
34 #include "faces.h"
|
|
35 #include "frame.h"
|
276
|
36 #include "insdel.h"
|
0
|
37 #include "glyphs.h"
|
|
38 #include "objects.h"
|
|
39 #include "redisplay.h"
|
|
40 #include "window.h"
|
|
41
|
276
|
42 #ifdef HAVE_XPM
|
|
43 #include <X11/xpm.h>
|
|
44 #endif
|
|
45
|
269
|
46 Lisp_Object Qimage_conversion_error;
|
|
47
|
0
|
48 Lisp_Object Qglyphp, Qcontrib_p, Qbaseline;
|
|
49 Lisp_Object Qbuffer_glyph_p, Qpointer_glyph_p, Qicon_glyph_p;
|
|
50 Lisp_Object Qnothing_image_instance_p, Qtext_image_instance_p;
|
|
51 Lisp_Object Qmono_pixmap_image_instance_p;
|
|
52 Lisp_Object Qcolor_pixmap_image_instance_p;
|
|
53 Lisp_Object Qpointer_image_instance_p;
|
|
54 Lisp_Object Qsubwindow_image_instance_p;
|
|
55 Lisp_Object Qconst_glyph_variable;
|
|
56 Lisp_Object Qmono_pixmap, Qcolor_pixmap, Qsubwindow;
|
272
|
57 Lisp_Object Q_file, Q_data, Q_face;
|
|
58 Lisp_Object Qformatted_string;
|
0
|
59
|
|
60 Lisp_Object Vcurrent_display_table;
|
|
61 Lisp_Object Vtruncation_glyph, Vcontinuation_glyph, Voctal_escape_glyph;
|
|
62 Lisp_Object Vcontrol_arrow_glyph, Vinvisible_text_glyph, Vhscroll_glyph;
|
|
63 Lisp_Object Vxemacs_logo;
|
|
64 Lisp_Object Vthe_nothing_vector;
|
272
|
65 Lisp_Object Vimage_instantiator_format_list;
|
|
66 Lisp_Object Vimage_instance_type_list;
|
|
67 Lisp_Object Vglyph_type_list;
|
|
68
|
0
|
69 DEFINE_IMAGE_INSTANTIATOR_FORMAT (nothing);
|
|
70 DEFINE_IMAGE_INSTANTIATOR_FORMAT (inherit);
|
|
71 DEFINE_IMAGE_INSTANTIATOR_FORMAT (string);
|
|
72 DEFINE_IMAGE_INSTANTIATOR_FORMAT (formatted_string);
|
|
73
|
288
|
74 #ifdef HAVE_WINDOW_SYSTEM
|
|
75 DEFINE_IMAGE_INSTANTIATOR_FORMAT (xbm);
|
|
76 Lisp_Object Qxbm;
|
|
77
|
|
78 Lisp_Object Q_mask_file, Q_mask_data, Q_hotspot_x, Q_hotspot_y;
|
|
79 Lisp_Object Q_foreground, Q_background;
|
|
80 #ifndef BitmapSuccess
|
|
81 #define BitmapSuccess 0
|
|
82 #define BitmapOpenFailed 1
|
|
83 #define BitmapFileInvalid 2
|
|
84 #define BitmapNoMemory 3
|
|
85 #endif
|
|
86 #endif
|
278
|
87
|
276
|
88 #ifdef HAVE_XPM
|
|
89 DEFINE_IMAGE_INSTANTIATOR_FORMAT (xpm);
|
|
90 Lisp_Object Qxpm;
|
|
91 Lisp_Object Q_color_symbols;
|
|
92 #endif
|
|
93
|
185
|
94 typedef struct image_instantiator_format_entry image_instantiator_format_entry;
|
0
|
95 struct image_instantiator_format_entry
|
|
96 {
|
|
97 Lisp_Object symbol;
|
|
98 struct image_instantiator_methods *meths;
|
|
99 };
|
|
100
|
185
|
101 typedef struct
|
0
|
102 {
|
|
103 Dynarr_declare (struct image_instantiator_format_entry);
|
|
104 } image_instantiator_format_entry_dynarr;
|
|
105
|
|
106 image_instantiator_format_entry_dynarr *
|
|
107 the_image_instantiator_format_entry_dynarr;
|
|
108
|
|
109 static Lisp_Object allocate_image_instance (Lisp_Object device);
|
|
110 static void image_validate (Lisp_Object instantiator);
|
|
111 static void glyph_property_was_changed (Lisp_Object glyph,
|
|
112 Lisp_Object property,
|
|
113 Lisp_Object locale);
|
272
|
114 EXFUN (Fimage_instance_type, 1);
|
|
115 EXFUN (Fglyph_type, 1);
|
0
|
116
|
|
117
|
|
118 /****************************************************************************
|
|
119 * Image Instantiators *
|
|
120 ****************************************************************************/
|
|
121
|
|
122 static struct image_instantiator_methods *
|
|
123 decode_image_instantiator_format (Lisp_Object format, Error_behavior errb)
|
|
124 {
|
|
125 int i;
|
|
126
|
|
127 if (!SYMBOLP (format))
|
|
128 {
|
|
129 if (ERRB_EQ (errb, ERROR_ME))
|
|
130 CHECK_SYMBOL (format);
|
|
131 return 0;
|
|
132 }
|
|
133
|
|
134 for (i = 0; i < Dynarr_length (the_image_instantiator_format_entry_dynarr);
|
|
135 i++)
|
|
136 {
|
|
137 if (EQ (format,
|
|
138 Dynarr_at (the_image_instantiator_format_entry_dynarr, i).
|
|
139 symbol))
|
|
140 return Dynarr_at (the_image_instantiator_format_entry_dynarr, i).meths;
|
|
141 }
|
|
142
|
|
143 maybe_signal_simple_error ("Invalid image-instantiator format", format,
|
|
144 Qimage, errb);
|
|
145
|
|
146 return 0;
|
|
147 }
|
|
148
|
|
149 static int
|
|
150 valid_image_instantiator_format_p (Lisp_Object format)
|
|
151 {
|
272
|
152 return (decode_image_instantiator_format (format, ERROR_ME_NOT) != 0);
|
0
|
153 }
|
|
154
|
284
|
155 DEFUN ("valid-image-instantiator-format-p", Fvalid_image_instantiator_format_p,
|
|
156 1, 1, 0, /*
|
0
|
157 Given an IMAGE-INSTANTIATOR-FORMAT, return non-nil if it is valid.
|
120
|
158 Valid formats are some subset of 'nothing, 'string, 'formatted-string,
|
|
159 'xpm, 'xbm, 'xface, 'gif, 'jpeg, 'png, 'tiff, 'cursor-font, 'font,
|
272
|
160 'autodetect, and 'subwindow, depending on how XEmacs was compiled.
|
20
|
161 */
|
|
162 (image_instantiator_format))
|
0
|
163 {
|
272
|
164 return valid_image_instantiator_format_p (image_instantiator_format) ?
|
|
165 Qt : Qnil;
|
0
|
166 }
|
|
167
|
284
|
168 DEFUN ("image-instantiator-format-list", Fimage_instantiator_format_list,
|
|
169 0, 0, 0, /*
|
0
|
170 Return a list of valid image-instantiator formats.
|
20
|
171 */
|
|
172 ())
|
0
|
173 {
|
|
174 return Fcopy_sequence (Vimage_instantiator_format_list);
|
|
175 }
|
|
176
|
|
177 void
|
|
178 add_entry_to_image_instantiator_format_list (Lisp_Object symbol,
|
|
179 struct
|
|
180 image_instantiator_methods *meths)
|
|
181 {
|
|
182 struct image_instantiator_format_entry entry;
|
|
183
|
|
184 entry.symbol = symbol;
|
|
185 entry.meths = meths;
|
|
186 Dynarr_add (the_image_instantiator_format_entry_dynarr, entry);
|
|
187 Vimage_instantiator_format_list =
|
|
188 Fcons (symbol, Vimage_instantiator_format_list);
|
|
189 }
|
|
190
|
|
191 static Lisp_Object *
|
|
192 get_image_conversion_list (Lisp_Object console_type)
|
|
193 {
|
|
194 return &decode_console_type (console_type, ERROR_ME)->image_conversion_list;
|
|
195 }
|
|
196
|
284
|
197 DEFUN ("set-console-type-image-conversion-list", Fset_console_type_image_conversion_list,
|
|
198 2, 2, 0, /*
|
0
|
199 Set the image-conversion-list for consoles of the given TYPE.
|
|
200 The image-conversion-list specifies how image instantiators that
|
|
201 are strings should be interpreted. Each element of the list should be
|
|
202 a list of two elements (a regular expression string and a vector) or
|
|
203 a list of three elements (the preceding two plus an integer index into
|
|
204 the vector). The string is converted to the vector associated with the
|
|
205 first matching regular expression. If a vector index is specified, the
|
|
206 string itself is substituted into that position in the vector.
|
|
207
|
|
208 Note: The conversion above is applied when the image instantiator is
|
|
209 added to an image specifier, not when the specifier is actually
|
|
210 instantiated. Therefore, changing the image-conversion-list only affects
|
|
211 newly-added instantiators. Existing instantiators in glyphs and image
|
|
212 specifiers will not be affected.
|
20
|
213 */
|
|
214 (console_type, list))
|
0
|
215 {
|
|
216 Lisp_Object tail;
|
|
217 Lisp_Object *imlist = get_image_conversion_list (console_type);
|
|
218
|
|
219 /* Check the list to make sure that it only has valid entries. */
|
|
220
|
|
221 EXTERNAL_LIST_LOOP (tail, list)
|
|
222 {
|
|
223 Lisp_Object mapping = XCAR (tail);
|
|
224
|
|
225 /* Mapping form should be (STRING VECTOR) or (STRING VECTOR INTEGER) */
|
|
226 if (!CONSP (mapping) ||
|
|
227 !CONSP (XCDR (mapping)) ||
|
|
228 (!NILP (XCDR (XCDR (mapping))) &&
|
|
229 (!CONSP (XCDR (XCDR (mapping))) ||
|
|
230 !NILP (XCDR (XCDR (XCDR (mapping)))))))
|
|
231 signal_simple_error ("Invalid mapping form", mapping);
|
|
232 else
|
|
233 {
|
|
234 Lisp_Object exp = XCAR (mapping);
|
|
235 Lisp_Object typevec = XCAR (XCDR (mapping));
|
|
236 Lisp_Object pos = Qnil;
|
|
237 Lisp_Object newvec;
|
|
238 struct gcpro gcpro1;
|
|
239
|
|
240 CHECK_STRING (exp);
|
|
241 CHECK_VECTOR (typevec);
|
|
242 if (!NILP (XCDR (XCDR (mapping))))
|
|
243 {
|
|
244 pos = XCAR (XCDR (XCDR (mapping)));
|
|
245 CHECK_INT (pos);
|
|
246 if (XINT (pos) < 0 ||
|
173
|
247 XINT (pos) >= XVECTOR_LENGTH (typevec))
|
0
|
248 args_out_of_range_3
|
173
|
249 (pos, Qzero, make_int (XVECTOR_LENGTH (typevec) - 1));
|
0
|
250 }
|
173
|
251
|
0
|
252 newvec = Fcopy_sequence (typevec);
|
|
253 if (INTP (pos))
|
173
|
254 XVECTOR_DATA (newvec)[XINT (pos)] = exp;
|
0
|
255 GCPRO1 (newvec);
|
|
256 image_validate (newvec);
|
|
257 UNGCPRO;
|
|
258 }
|
|
259 }
|
|
260
|
|
261 *imlist = Fcopy_tree (list, Qt);
|
|
262 return list;
|
|
263 }
|
|
264
|
284
|
265 DEFUN ("console-type-image-conversion-list", Fconsole_type_image_conversion_list,
|
|
266 1, 1, 0, /*
|
0
|
267 Return the image-conversion-list for devices of the given TYPE.
|
|
268 The image-conversion-list specifies how to interpret image string
|
|
269 instantiators for the specified console type. See
|
|
270 `set-console-type-image-conversion-list' for a description of its syntax.
|
20
|
271 */
|
|
272 (console_type))
|
0
|
273 {
|
|
274 return Fcopy_tree (*get_image_conversion_list (console_type), Qt);
|
|
275 }
|
|
276
|
185
|
277 /* Process a string instantiator according to the image-conversion-list for
|
0
|
278 CONSOLE_TYPE. Returns a vector. */
|
|
279
|
|
280 static Lisp_Object
|
|
281 process_image_string_instantiator (Lisp_Object data,
|
|
282 Lisp_Object console_type,
|
|
283 int dest_mask)
|
|
284 {
|
|
285 Lisp_Object tail;
|
|
286
|
|
287 LIST_LOOP (tail, *get_image_conversion_list (console_type))
|
|
288 {
|
|
289 Lisp_Object mapping = XCAR (tail);
|
|
290 Lisp_Object exp = XCAR (mapping);
|
|
291 Lisp_Object typevec = XCAR (XCDR (mapping));
|
|
292
|
|
293 /* if the result is of a type that can't be instantiated
|
|
294 (e.g. a string when we're dealing with a pointer glyph),
|
|
295 skip it. */
|
|
296 if (!(dest_mask &
|
|
297 IIFORMAT_METH (decode_image_instantiator_format
|
173
|
298 (XVECTOR_DATA (typevec)[0], ERROR_ME),
|
0
|
299 possible_dest_types, ())))
|
|
300 continue;
|
|
301 if (fast_string_match (exp, 0, data, 0, -1, 0, ERROR_ME, 0) >= 0)
|
|
302 {
|
|
303 if (!NILP (XCDR (XCDR (mapping))))
|
|
304 {
|
|
305 int pos = XINT (XCAR (XCDR (XCDR (mapping))));
|
|
306 Lisp_Object newvec = Fcopy_sequence (typevec);
|
173
|
307 XVECTOR_DATA (newvec)[pos] = data;
|
0
|
308 return newvec;
|
|
309 }
|
|
310 else
|
|
311 return typevec;
|
|
312 }
|
|
313 }
|
|
314
|
|
315 /* Oh well. */
|
|
316 signal_simple_error ("Unable to interpret glyph instantiator",
|
|
317 data);
|
173
|
318
|
0
|
319 return Qnil;
|
|
320 }
|
|
321
|
|
322 Lisp_Object
|
|
323 find_keyword_in_vector_or_given (Lisp_Object vector, Lisp_Object keyword,
|
173
|
324 Lisp_Object default_)
|
0
|
325 {
|
|
326 Lisp_Object *elt;
|
|
327 int instantiator_len;
|
|
328
|
173
|
329 elt = XVECTOR_DATA (vector);
|
|
330 instantiator_len = XVECTOR_LENGTH (vector);
|
0
|
331
|
|
332 elt++;
|
|
333 instantiator_len--;
|
|
334
|
|
335 while (instantiator_len > 0)
|
|
336 {
|
|
337 if (EQ (elt[0], keyword))
|
|
338 return elt[1];
|
|
339 elt += 2;
|
|
340 instantiator_len -= 2;
|
|
341 }
|
|
342
|
173
|
343 return default_;
|
0
|
344 }
|
|
345
|
|
346 Lisp_Object
|
|
347 find_keyword_in_vector (Lisp_Object vector, Lisp_Object keyword)
|
|
348 {
|
|
349 return find_keyword_in_vector_or_given (vector, keyword, Qnil);
|
|
350 }
|
|
351
|
|
352 void
|
|
353 check_valid_string (Lisp_Object data)
|
|
354 {
|
|
355 CHECK_STRING (data);
|
|
356 }
|
|
357
|
|
358 static void
|
|
359 check_valid_face (Lisp_Object data)
|
|
360 {
|
|
361 Fget_face (data);
|
|
362 }
|
|
363
|
|
364 void
|
|
365 check_valid_int (Lisp_Object data)
|
|
366 {
|
|
367 CHECK_INT (data);
|
|
368 }
|
|
369
|
|
370 void
|
|
371 file_or_data_must_be_present (Lisp_Object instantiator)
|
|
372 {
|
|
373 if (NILP (find_keyword_in_vector (instantiator, Q_file)) &&
|
|
374 NILP (find_keyword_in_vector (instantiator, Q_data)))
|
|
375 signal_simple_error ("Must supply either :file or :data",
|
|
376 instantiator);
|
|
377 }
|
|
378
|
|
379 void
|
|
380 data_must_be_present (Lisp_Object instantiator)
|
|
381 {
|
|
382 if (NILP (find_keyword_in_vector (instantiator, Q_data)))
|
|
383 signal_simple_error ("Must supply :data", instantiator);
|
|
384 }
|
|
385
|
|
386 static void
|
|
387 face_must_be_present (Lisp_Object instantiator)
|
|
388 {
|
|
389 if (NILP (find_keyword_in_vector (instantiator, Q_face)))
|
|
390 signal_simple_error ("Must supply :face", instantiator);
|
|
391 }
|
|
392
|
|
393 /* utility function useful in retrieving data from a file. */
|
|
394
|
|
395 Lisp_Object
|
|
396 make_string_from_file (Lisp_Object file)
|
|
397 {
|
116
|
398 /* This function can call lisp */
|
0
|
399 int count = specpdl_depth ();
|
|
400 Lisp_Object temp_buffer;
|
|
401 struct gcpro gcpro1;
|
|
402 Lisp_Object data;
|
173
|
403
|
0
|
404 specbind (Qinhibit_quit, Qt);
|
|
405 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
406 temp_buffer = Fget_buffer_create (build_string (" *pixmap conversion*"));
|
|
407 GCPRO1 (temp_buffer);
|
|
408 set_buffer_internal (XBUFFER (temp_buffer));
|
223
|
409 Ferase_buffer (Qnil);
|
169
|
410 specbind (intern ("format-alist"), Qnil);
|
70
|
411 Finsert_file_contents_internal (file, Qnil, Qnil, Qnil, Qnil, Qnil, Qnil);
|
223
|
412 data = Fbuffer_substring (Qnil, Qnil, Qnil);
|
0
|
413 unbind_to (count, Qnil);
|
|
414 UNGCPRO;
|
|
415 return data;
|
|
416 }
|
|
417
|
|
418 /* The following two functions are provided to make it easier for
|
|
419 the normalize methods to work with keyword-value vectors.
|
|
420 Hash tables are kind of heavyweight for this purpose.
|
|
421 (If vectors were resizable, we could avoid this problem;
|
|
422 but they're not.) An alternative approach that might be
|
|
423 more efficient but require more work is to use a type of
|
|
424 assoc-Dynarr and provide primitives for deleting elements out
|
|
425 of it. (However, you'd also have to add an unwind-protect
|
|
426 to make sure the Dynarr got freed in case of an error in
|
|
427 the normalization process.) */
|
|
428
|
|
429 Lisp_Object
|
|
430 tagged_vector_to_alist (Lisp_Object vector)
|
|
431 {
|
173
|
432 Lisp_Object *elt = XVECTOR_DATA (vector);
|
|
433 int len = XVECTOR_LENGTH (vector);
|
0
|
434 Lisp_Object result = Qnil;
|
|
435
|
|
436 assert (len & 1);
|
|
437 for (len -= 2; len >= 1; len -= 2)
|
|
438 result = Fcons (Fcons (elt[len], elt[len+1]), result);
|
|
439
|
|
440 return result;
|
|
441 }
|
|
442
|
|
443 Lisp_Object
|
|
444 alist_to_tagged_vector (Lisp_Object tag, Lisp_Object alist)
|
|
445 {
|
|
446 int len = 1 + 2 * XINT (Flength (alist));
|
185
|
447 Lisp_Object *elt = alloca_array (Lisp_Object, len);
|
0
|
448 int i;
|
|
449 Lisp_Object rest;
|
|
450
|
|
451 i = 0;
|
|
452 elt[i++] = tag;
|
|
453 LIST_LOOP (rest, alist)
|
|
454 {
|
|
455 Lisp_Object pair = XCAR (rest);
|
|
456 elt[i] = XCAR (pair);
|
|
457 elt[i+1] = XCDR (pair);
|
|
458 i += 2;
|
|
459 }
|
|
460
|
|
461 return Fvector (len, elt);
|
|
462 }
|
|
463
|
|
464 static Lisp_Object
|
|
465 normalize_image_instantiator (Lisp_Object instantiator,
|
|
466 Lisp_Object contype,
|
|
467 Lisp_Object dest_mask)
|
|
468 {
|
327
|
469 struct gcpro gcpro1;
|
|
470
|
|
471 GCPRO1(instantiator);
|
|
472
|
0
|
473 if (IMAGE_INSTANCEP (instantiator))
|
327
|
474 RETURN_UNGCPRO (instantiator);
|
0
|
475
|
|
476 if (STRINGP (instantiator))
|
|
477 instantiator = process_image_string_instantiator (instantiator, contype,
|
|
478 XINT (dest_mask));
|
|
479
|
|
480 assert (VECTORP (instantiator));
|
|
481 /* We have to always store the actual pixmap data and not the
|
|
482 filename even though this is a potential memory pig. We have to
|
|
483 do this because it is quite possible that we will need to
|
|
484 instantiate a new instance of the pixmap and the file will no
|
|
485 longer exist (e.g. w3 pixmaps are almost always from temporary
|
|
486 files). */
|
272
|
487 {
|
|
488 struct image_instantiator_methods * meths =
|
|
489 decode_image_instantiator_format (XVECTOR_DATA (instantiator)[0],
|
|
490 ERROR_ME);
|
327
|
491 RETURN_UNGCPRO (IIFORMAT_METH_OR_GIVEN (meths, normalize,
|
272
|
492 (instantiator, contype),
|
327
|
493 instantiator));
|
272
|
494 }
|
0
|
495 }
|
|
496
|
|
497 static Lisp_Object
|
124
|
498 instantiate_image_instantiator (Lisp_Object device, Lisp_Object domain,
|
|
499 Lisp_Object instantiator,
|
0
|
500 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
501 int dest_mask)
|
|
502 {
|
272
|
503 Lisp_Object ii = allocate_image_instance (device);
|
|
504 struct image_instantiator_methods *meths;
|
0
|
505 struct gcpro gcpro1;
|
|
506
|
|
507 GCPRO1 (ii);
|
272
|
508 meths = decode_image_instantiator_format (XVECTOR_DATA (instantiator)[0],
|
|
509 ERROR_ME);
|
|
510 if (!HAS_IIFORMAT_METH_P (meths, instantiate))
|
|
511 signal_simple_error
|
|
512 ("Don't know how to instantiate this image instantiator?",
|
|
513 instantiator);
|
|
514 IIFORMAT_METH (meths, instantiate, (ii, instantiator, pointer_fg,
|
|
515 pointer_bg, dest_mask, domain));
|
0
|
516 UNGCPRO;
|
|
517
|
|
518 return ii;
|
|
519 }
|
|
520
|
|
521
|
|
522 /****************************************************************************
|
|
523 * Image-Instance Object *
|
|
524 ****************************************************************************/
|
|
525
|
|
526 Lisp_Object Qimage_instancep;
|
272
|
527
|
0
|
528 static Lisp_Object
|
|
529 mark_image_instance (Lisp_Object obj, void (*markobj) (Lisp_Object))
|
|
530 {
|
|
531 struct Lisp_Image_Instance *i = XIMAGE_INSTANCE (obj);
|
|
532
|
|
533 (markobj) (i->name);
|
|
534 switch (IMAGE_INSTANCE_TYPE (i))
|
|
535 {
|
|
536 case IMAGE_TEXT:
|
|
537 (markobj) (IMAGE_INSTANCE_TEXT_STRING (i));
|
|
538 break;
|
|
539 case IMAGE_MONO_PIXMAP:
|
|
540 case IMAGE_COLOR_PIXMAP:
|
|
541 (markobj) (IMAGE_INSTANCE_PIXMAP_FILENAME (i));
|
|
542 (markobj) (IMAGE_INSTANCE_PIXMAP_MASK_FILENAME (i));
|
|
543 (markobj) (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (i));
|
|
544 (markobj) (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (i));
|
|
545 (markobj) (IMAGE_INSTANCE_PIXMAP_FG (i));
|
|
546 (markobj) (IMAGE_INSTANCE_PIXMAP_BG (i));
|
|
547 break;
|
|
548 case IMAGE_SUBWINDOW:
|
|
549 /* #### implement me */
|
|
550 break;
|
|
551 default:
|
|
552 break;
|
|
553 }
|
|
554
|
|
555 MAYBE_DEVMETH (XDEVICE (i->device), mark_image_instance, (i, markobj));
|
|
556
|
173
|
557 return i->device;
|
0
|
558 }
|
|
559
|
|
560 static void
|
|
561 print_image_instance (Lisp_Object obj, Lisp_Object printcharfun,
|
|
562 int escapeflag)
|
|
563 {
|
|
564 char buf[100];
|
|
565 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (obj);
|
|
566
|
|
567 if (print_readably)
|
|
568 error ("printing unreadable object #<image-instance 0x%x>",
|
|
569 ii->header.uid);
|
|
570 write_c_string ("#<image-instance (", printcharfun);
|
|
571 print_internal (Fimage_instance_type (obj), printcharfun, 0);
|
|
572 write_c_string (") ", printcharfun);
|
|
573 if (!NILP (ii->name))
|
|
574 {
|
|
575 print_internal (ii->name, printcharfun, 1);
|
|
576 write_c_string (" ", printcharfun);
|
|
577 }
|
|
578 write_c_string ("on ", printcharfun);
|
|
579 print_internal (ii->device, printcharfun, 0);
|
|
580 write_c_string (" ", printcharfun);
|
|
581 switch (IMAGE_INSTANCE_TYPE (ii))
|
|
582 {
|
|
583 case IMAGE_NOTHING:
|
|
584 break;
|
|
585
|
|
586 case IMAGE_TEXT:
|
|
587 print_internal (IMAGE_INSTANCE_TEXT_STRING (ii), printcharfun, 1);
|
|
588 break;
|
|
589
|
|
590 case IMAGE_MONO_PIXMAP:
|
|
591 case IMAGE_COLOR_PIXMAP:
|
|
592 case IMAGE_POINTER:
|
|
593 if (STRINGP (IMAGE_INSTANCE_PIXMAP_FILENAME (ii)))
|
|
594 {
|
|
595 char *s;
|
|
596 Lisp_Object filename = IMAGE_INSTANCE_PIXMAP_FILENAME (ii);
|
14
|
597 s = strrchr ((char *) XSTRING_DATA (filename), '/');
|
0
|
598 if (s)
|
|
599 print_internal (build_string (s + 1), printcharfun, 1);
|
|
600 else
|
|
601 print_internal (filename, printcharfun, 1);
|
|
602 }
|
|
603 if (IMAGE_INSTANCE_PIXMAP_DEPTH (ii) > 1)
|
|
604 sprintf (buf, " %dx%dx%d", IMAGE_INSTANCE_PIXMAP_WIDTH (ii),
|
|
605 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii),
|
|
606 IMAGE_INSTANCE_PIXMAP_DEPTH (ii));
|
|
607 else
|
|
608 sprintf (buf, " %dx%d", IMAGE_INSTANCE_PIXMAP_WIDTH (ii),
|
|
609 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii));
|
|
610 write_c_string (buf, printcharfun);
|
|
611 if (!NILP (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii)) ||
|
|
612 !NILP (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii)))
|
|
613 {
|
|
614 write_c_string (" @", printcharfun);
|
|
615 if (!NILP (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii)))
|
|
616 {
|
276
|
617 long_to_string (buf, XINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii)));
|
0
|
618 write_c_string (buf, printcharfun);
|
|
619 }
|
|
620 else
|
|
621 write_c_string ("??", printcharfun);
|
|
622 write_c_string (",", printcharfun);
|
|
623 if (!NILP (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii)))
|
|
624 {
|
276
|
625 long_to_string (buf, XINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii)));
|
0
|
626 write_c_string (buf, printcharfun);
|
|
627 }
|
|
628 else
|
|
629 write_c_string ("??", printcharfun);
|
|
630 }
|
|
631 if (!NILP (IMAGE_INSTANCE_PIXMAP_FG (ii)) ||
|
|
632 !NILP (IMAGE_INSTANCE_PIXMAP_BG (ii)))
|
|
633 {
|
|
634 write_c_string (" (", printcharfun);
|
|
635 if (!NILP (IMAGE_INSTANCE_PIXMAP_FG (ii)))
|
|
636 {
|
|
637 print_internal
|
|
638 (XCOLOR_INSTANCE
|
|
639 (IMAGE_INSTANCE_PIXMAP_FG (ii))->name, printcharfun, 0);
|
|
640 }
|
|
641 write_c_string ("/", printcharfun);
|
|
642 if (!NILP (IMAGE_INSTANCE_PIXMAP_BG (ii)))
|
|
643 {
|
|
644 print_internal
|
|
645 (XCOLOR_INSTANCE
|
|
646 (IMAGE_INSTANCE_PIXMAP_BG (ii))->name, printcharfun, 0);
|
|
647 }
|
|
648 write_c_string (")", printcharfun);
|
|
649 }
|
|
650 break;
|
|
651
|
|
652 case IMAGE_SUBWINDOW:
|
|
653 /* #### implement me */
|
|
654 break;
|
|
655
|
|
656 default:
|
|
657 abort ();
|
|
658 }
|
|
659
|
|
660 MAYBE_DEVMETH (XDEVICE (ii->device), print_image_instance,
|
|
661 (ii, printcharfun, escapeflag));
|
|
662 sprintf (buf, " 0x%x>", ii->header.uid);
|
|
663 write_c_string (buf, printcharfun);
|
|
664 }
|
|
665
|
|
666 static void
|
|
667 finalize_image_instance (void *header, int for_disksave)
|
|
668 {
|
|
669 struct Lisp_Image_Instance *i = (struct Lisp_Image_Instance *) header;
|
|
670
|
|
671 if (IMAGE_INSTANCE_TYPE (i) == IMAGE_NOTHING)
|
|
672 /* objects like this exist at dump time, so don't bomb out. */
|
|
673 return;
|
|
674 if (for_disksave) finalose (i);
|
|
675
|
|
676 MAYBE_DEVMETH (XDEVICE (i->device), finalize_image_instance, (i));
|
|
677 }
|
|
678
|
|
679 static int
|
|
680 image_instance_equal (Lisp_Object o1, Lisp_Object o2, int depth)
|
|
681 {
|
|
682 struct Lisp_Image_Instance *i1 = XIMAGE_INSTANCE (o1);
|
|
683 struct Lisp_Image_Instance *i2 = XIMAGE_INSTANCE (o2);
|
|
684 struct device *d1 = XDEVICE (i1->device);
|
|
685 struct device *d2 = XDEVICE (i2->device);
|
|
686
|
|
687 if (d1 != d2)
|
|
688 return 0;
|
|
689 if (IMAGE_INSTANCE_TYPE (i1) != IMAGE_INSTANCE_TYPE (i2))
|
|
690 return 0;
|
|
691 if (!internal_equal (IMAGE_INSTANCE_NAME (i1), IMAGE_INSTANCE_NAME (i2),
|
|
692 depth + 1))
|
|
693 return 0;
|
|
694
|
|
695 switch (IMAGE_INSTANCE_TYPE (i1))
|
|
696 {
|
|
697 case IMAGE_NOTHING:
|
|
698 break;
|
|
699
|
|
700 case IMAGE_TEXT:
|
|
701 if (!internal_equal (IMAGE_INSTANCE_TEXT_STRING (i1),
|
|
702 IMAGE_INSTANCE_TEXT_STRING (i2),
|
|
703 depth + 1))
|
|
704 return 0;
|
|
705 break;
|
|
706
|
|
707 case IMAGE_MONO_PIXMAP:
|
|
708 case IMAGE_COLOR_PIXMAP:
|
|
709 case IMAGE_POINTER:
|
|
710 if (!(IMAGE_INSTANCE_PIXMAP_WIDTH (i1) ==
|
|
711 IMAGE_INSTANCE_PIXMAP_WIDTH (i2) &&
|
|
712 IMAGE_INSTANCE_PIXMAP_HEIGHT (i1) ==
|
|
713 IMAGE_INSTANCE_PIXMAP_HEIGHT (i2) &&
|
|
714 IMAGE_INSTANCE_PIXMAP_DEPTH (i1) ==
|
|
715 IMAGE_INSTANCE_PIXMAP_DEPTH (i2) &&
|
|
716 EQ (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (i1),
|
|
717 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (i2)) &&
|
|
718 EQ (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (i1),
|
|
719 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (i2)) &&
|
|
720 internal_equal (IMAGE_INSTANCE_PIXMAP_FILENAME (i1),
|
|
721 IMAGE_INSTANCE_PIXMAP_FILENAME (i2),
|
|
722 depth + 1) &&
|
|
723 internal_equal (IMAGE_INSTANCE_PIXMAP_MASK_FILENAME (i1),
|
|
724 IMAGE_INSTANCE_PIXMAP_MASK_FILENAME (i2),
|
|
725 depth + 1)))
|
|
726 return 0;
|
|
727 break;
|
|
728
|
|
729 case IMAGE_SUBWINDOW:
|
|
730 /* #### implement me */
|
|
731 break;
|
|
732
|
|
733 default:
|
|
734 abort ();
|
|
735 }
|
|
736
|
|
737 return DEVMETH_OR_GIVEN (d1, image_instance_equal, (i1, i2, depth), 1);
|
|
738 }
|
|
739
|
|
740 static unsigned long
|
|
741 image_instance_hash (Lisp_Object obj, int depth)
|
|
742 {
|
|
743 struct Lisp_Image_Instance *i = XIMAGE_INSTANCE (obj);
|
|
744 struct device *d = XDEVICE (i->device);
|
|
745 unsigned long hash = (unsigned long) d;
|
|
746
|
|
747 switch (IMAGE_INSTANCE_TYPE (i))
|
|
748 {
|
|
749 case IMAGE_NOTHING:
|
|
750 break;
|
|
751
|
|
752 case IMAGE_TEXT:
|
|
753 hash = HASH2 (hash, internal_hash (IMAGE_INSTANCE_TEXT_STRING (i),
|
|
754 depth + 1));
|
|
755 break;
|
|
756
|
|
757 case IMAGE_MONO_PIXMAP:
|
|
758 case IMAGE_COLOR_PIXMAP:
|
|
759 case IMAGE_POINTER:
|
|
760 hash = HASH5 (hash, IMAGE_INSTANCE_PIXMAP_WIDTH (i),
|
|
761 IMAGE_INSTANCE_PIXMAP_HEIGHT (i),
|
|
762 IMAGE_INSTANCE_PIXMAP_DEPTH (i),
|
|
763 internal_hash (IMAGE_INSTANCE_PIXMAP_FILENAME (i),
|
|
764 depth + 1));
|
|
765 break;
|
|
766
|
|
767 case IMAGE_SUBWINDOW:
|
|
768 /* #### implement me */
|
|
769 break;
|
|
770
|
|
771 default:
|
|
772 abort ();
|
|
773 }
|
|
774
|
|
775 return HASH2 (hash, DEVMETH_OR_GIVEN (d, image_instance_hash, (i, depth),
|
|
776 0));
|
|
777 }
|
|
778
|
272
|
779 DEFINE_LRECORD_IMPLEMENTATION ("image-instance", image_instance,
|
|
780 mark_image_instance, print_image_instance,
|
|
781 finalize_image_instance, image_instance_equal,
|
|
782 image_instance_hash,
|
|
783 struct Lisp_Image_Instance);
|
|
784
|
0
|
785 static Lisp_Object
|
|
786 allocate_image_instance (Lisp_Object device)
|
|
787 {
|
|
788 struct Lisp_Image_Instance *lp =
|
185
|
789 alloc_lcrecord_type (struct Lisp_Image_Instance, lrecord_image_instance);
|
272
|
790 Lisp_Object val;
|
0
|
791
|
|
792 zero_lcrecord (lp);
|
|
793 lp->device = device;
|
|
794 lp->type = IMAGE_NOTHING;
|
|
795 lp->name = Qnil;
|
|
796 XSETIMAGE_INSTANCE (val, lp);
|
|
797 return val;
|
|
798 }
|
|
799
|
|
800 static enum image_instance_type
|
|
801 decode_image_instance_type (Lisp_Object type, Error_behavior errb)
|
|
802 {
|
|
803 if (ERRB_EQ (errb, ERROR_ME))
|
|
804 CHECK_SYMBOL (type);
|
|
805
|
185
|
806 if (EQ (type, Qnothing)) return IMAGE_NOTHING;
|
|
807 if (EQ (type, Qtext)) return IMAGE_TEXT;
|
|
808 if (EQ (type, Qmono_pixmap)) return IMAGE_MONO_PIXMAP;
|
|
809 if (EQ (type, Qcolor_pixmap)) return IMAGE_COLOR_PIXMAP;
|
|
810 if (EQ (type, Qpointer)) return IMAGE_POINTER;
|
|
811 if (EQ (type, Qsubwindow)) return IMAGE_SUBWINDOW;
|
0
|
812
|
|
813 maybe_signal_simple_error ("Invalid image-instance type", type,
|
|
814 Qimage, errb);
|
185
|
815
|
|
816 return IMAGE_UNKNOWN; /* not reached */
|
0
|
817 }
|
|
818
|
|
819 static Lisp_Object
|
|
820 encode_image_instance_type (enum image_instance_type type)
|
|
821 {
|
|
822 switch (type)
|
|
823 {
|
185
|
824 case IMAGE_NOTHING: return Qnothing;
|
|
825 case IMAGE_TEXT: return Qtext;
|
|
826 case IMAGE_MONO_PIXMAP: return Qmono_pixmap;
|
|
827 case IMAGE_COLOR_PIXMAP: return Qcolor_pixmap;
|
|
828 case IMAGE_POINTER: return Qpointer;
|
|
829 case IMAGE_SUBWINDOW: return Qsubwindow;
|
0
|
830 default:
|
|
831 abort ();
|
|
832 }
|
|
833
|
|
834 return Qnil; /* not reached */
|
|
835 }
|
|
836
|
|
837 static int
|
|
838 image_instance_type_to_mask (enum image_instance_type type)
|
|
839 {
|
|
840 /* This depends on the fact that enums are assigned consecutive
|
|
841 integers starting at 0. (Remember that IMAGE_UNKNOWN is the
|
|
842 first enum.) I'm fairly sure this behavior in ANSI-mandated,
|
|
843 so there should be no portability problems here. */
|
|
844 return (1 << ((int) (type) - 1));
|
|
845 }
|
|
846
|
|
847 static int
|
|
848 decode_image_instance_type_list (Lisp_Object list)
|
|
849 {
|
|
850 Lisp_Object rest;
|
|
851 int mask = 0;
|
|
852
|
|
853 if (NILP (list))
|
|
854 return ~0;
|
|
855
|
|
856 if (!CONSP (list))
|
|
857 {
|
|
858 enum image_instance_type type =
|
|
859 decode_image_instance_type (list, ERROR_ME);
|
|
860 return image_instance_type_to_mask (type);
|
|
861 }
|
|
862
|
|
863 EXTERNAL_LIST_LOOP (rest, list)
|
|
864 {
|
|
865 enum image_instance_type type =
|
|
866 decode_image_instance_type (XCAR (rest), ERROR_ME);
|
|
867 mask |= image_instance_type_to_mask (type);
|
|
868 }
|
|
869
|
|
870 return mask;
|
|
871 }
|
|
872
|
|
873 static Lisp_Object
|
|
874 encode_image_instance_type_list (int mask)
|
|
875 {
|
|
876 int count = 0;
|
|
877 Lisp_Object result = Qnil;
|
|
878
|
|
879 while (mask)
|
|
880 {
|
|
881 count++;
|
|
882 if (mask & 1)
|
|
883 result = Fcons (encode_image_instance_type
|
|
884 ((enum image_instance_type) count), result);
|
|
885 mask >>= 1;
|
|
886 }
|
|
887
|
|
888 return Fnreverse (result);
|
|
889 }
|
|
890
|
|
891 DOESNT_RETURN
|
|
892 incompatible_image_types (Lisp_Object instantiator, int given_dest_mask,
|
|
893 int desired_dest_mask)
|
|
894 {
|
|
895 signal_error
|
|
896 (Qerror,
|
|
897 list2
|
|
898 (emacs_doprnt_string_lisp_2
|
|
899 ((CONST Bufbyte *)
|
|
900 "No compatible image-instance types given: wanted one of %s, got %s",
|
|
901 Qnil, -1, 2,
|
|
902 encode_image_instance_type_list (desired_dest_mask),
|
|
903 encode_image_instance_type_list (given_dest_mask)),
|
|
904 instantiator));
|
|
905 }
|
|
906
|
|
907 static int
|
|
908 valid_image_instance_type_p (Lisp_Object type)
|
|
909 {
|
185
|
910 return !NILP (memq_no_quit (type, Vimage_instance_type_list));
|
0
|
911 }
|
|
912
|
20
|
913 DEFUN ("valid-image-instance-type-p", Fvalid_image_instance_type_p, 1, 1, 0, /*
|
0
|
914 Given an IMAGE-INSTANCE-TYPE, return non-nil if it is valid.
|
|
915 Valid types are some subset of 'nothing, 'text, 'mono-pixmap, 'color-pixmap,
|
|
916 'pointer, and 'subwindow, depending on how XEmacs was compiled.
|
20
|
917 */
|
|
918 (image_instance_type))
|
0
|
919 {
|
185
|
920 return valid_image_instance_type_p (image_instance_type) ? Qt : Qnil;
|
0
|
921 }
|
|
922
|
20
|
923 DEFUN ("image-instance-type-list", Fimage_instance_type_list, 0, 0, 0, /*
|
0
|
924 Return a list of valid image-instance types.
|
20
|
925 */
|
|
926 ())
|
0
|
927 {
|
|
928 return Fcopy_sequence (Vimage_instance_type_list);
|
|
929 }
|
|
930
|
|
931 Error_behavior
|
|
932 decode_error_behavior_flag (Lisp_Object no_error)
|
|
933 {
|
185
|
934 if (NILP (no_error)) return ERROR_ME;
|
|
935 else if (EQ (no_error, Qt)) return ERROR_ME_NOT;
|
|
936 else return ERROR_ME_WARN;
|
0
|
937 }
|
|
938
|
|
939 Lisp_Object
|
|
940 encode_error_behavior_flag (Error_behavior errb)
|
|
941 {
|
|
942 if (ERRB_EQ (errb, ERROR_ME))
|
|
943 return Qnil;
|
|
944 else if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
945 return Qt;
|
|
946 else
|
|
947 {
|
|
948 assert (ERRB_EQ (errb, ERROR_ME_WARN));
|
|
949 return Qwarning;
|
|
950 }
|
|
951 }
|
|
952
|
|
953 static Lisp_Object
|
|
954 make_image_instance_1 (Lisp_Object data, Lisp_Object device,
|
|
955 Lisp_Object dest_types)
|
|
956 {
|
|
957 Lisp_Object ii;
|
|
958 struct gcpro gcpro1;
|
|
959 int dest_mask;
|
|
960
|
|
961 XSETDEVICE (device, decode_device (device));
|
|
962 /* instantiate_image_instantiator() will abort if given an
|
|
963 image instance ... */
|
|
964 if (IMAGE_INSTANCEP (data))
|
|
965 signal_simple_error ("image instances not allowed here", data);
|
|
966 image_validate (data);
|
|
967 dest_mask = decode_image_instance_type_list (dest_types);
|
|
968 data = normalize_image_instantiator (data, DEVICE_TYPE (XDEVICE (device)),
|
|
969 make_int (dest_mask));
|
|
970 GCPRO1 (data);
|
173
|
971 if (VECTORP (data) && EQ (XVECTOR_DATA (data)[0], Qinherit))
|
0
|
972 signal_simple_error ("inheritance not allowed here", data);
|
124
|
973 ii = instantiate_image_instantiator (device, device, data,
|
|
974 Qnil, Qnil, dest_mask);
|
0
|
975 RETURN_UNGCPRO (ii);
|
|
976 }
|
|
977
|
20
|
978 DEFUN ("make-image-instance", Fmake_image_instance, 1, 4, 0, /*
|
272
|
979 Return a new `image-instance' object.
|
0
|
980
|
|
981 Image-instance objects encapsulate the way a particular image (pixmap,
|
|
982 etc.) is displayed on a particular device. In most circumstances, you
|
|
983 do not need to directly create image instances; use a glyph instead.
|
|
984 However, it may occasionally be useful to explicitly create image
|
|
985 instances, if you want more control over the instantiation process.
|
|
986
|
|
987 DATA is an image instantiator, which describes the image; see
|
|
988 `image-specifier-p' for a description of the allowed values.
|
|
989
|
|
990 DEST-TYPES should be a list of allowed image instance types that can
|
|
991 be generated. The recognized image instance types are
|
|
992
|
|
993 'nothing
|
|
994 Nothing is displayed.
|
|
995 'text
|
|
996 Displayed as text. The foreground and background colors and the
|
|
997 font of the text are specified independent of the pixmap. Typically
|
|
998 these attributes will come from the face of the surrounding text,
|
|
999 unless a face is specified for the glyph in which the image appears.
|
|
1000 'mono-pixmap
|
|
1001 Displayed as a mono pixmap (a pixmap with only two colors where the
|
|
1002 foreground and background can be specified independent of the pixmap;
|
|
1003 typically the pixmap assumes the foreground and background colors of
|
|
1004 the text around it, unless a face is specified for the glyph in which
|
|
1005 the image appears).
|
|
1006 'color-pixmap
|
|
1007 Displayed as a color pixmap.
|
|
1008 'pointer
|
|
1009 Used as the mouse pointer for a window.
|
|
1010 'subwindow
|
|
1011 A child window that is treated as an image. This allows (e.g.)
|
|
1012 another program to be responsible for drawing into the window.
|
|
1013 Not currently implemented.
|
|
1014
|
|
1015 The DEST-TYPES list is unordered. If multiple destination types
|
185
|
1016 are possible for a given instantiator, the "most natural" type
|
0
|
1017 for the instantiator's format is chosen. (For XBM, the most natural
|
|
1018 types are `mono-pixmap', followed by `color-pixmap', followed by
|
|
1019 `pointer'. For the other normal image formats, the most natural
|
|
1020 types are `color-pixmap', followed by `mono-pixmap', followed by
|
|
1021 `pointer'. For the string and formatted-string formats, the most
|
|
1022 natural types are `text', followed by `mono-pixmap' (not currently
|
|
1023 implemented), followed by `color-pixmap' (not currently implemented).
|
|
1024 The other formats can only be instantiated as one type. (If you
|
|
1025 want to control more specifically the order of the types into which
|
|
1026 an image is instantiated, just call `make-image-instance' repeatedly
|
|
1027 until it succeeds, passing less and less preferred destination types
|
|
1028 each time.
|
|
1029
|
|
1030 If DEST-TYPES is omitted, all possible types are allowed.
|
|
1031
|
|
1032 NO-ERROR controls what happens when the image cannot be generated.
|
|
1033 If nil, an error message is generated. If t, no messages are
|
|
1034 generated and this function returns nil. If anything else, a warning
|
|
1035 message is generated and this function returns nil.
|
20
|
1036 */
|
|
1037 (data, device, dest_types, no_error))
|
0
|
1038 {
|
|
1039 Error_behavior errb = decode_error_behavior_flag (no_error);
|
|
1040
|
74
|
1041 return call_with_suspended_errors ((lisp_fn_t) make_image_instance_1,
|
0
|
1042 Qnil, Qimage, errb,
|
|
1043 3, data, device, dest_types);
|
|
1044 }
|
|
1045
|
20
|
1046 DEFUN ("image-instance-p", Fimage_instance_p, 1, 1, 0, /*
|
0
|
1047 Return non-nil if OBJECT is an image instance.
|
20
|
1048 */
|
|
1049 (object))
|
0
|
1050 {
|
173
|
1051 return IMAGE_INSTANCEP (object) ? Qt : Qnil;
|
0
|
1052 }
|
|
1053
|
20
|
1054 DEFUN ("image-instance-type", Fimage_instance_type, 1, 1, 0, /*
|
0
|
1055 Return the type of the given image instance.
|
|
1056 The return value will be one of 'nothing, 'text, 'mono-pixmap,
|
|
1057 'color-pixmap, 'pointer, or 'subwindow.
|
20
|
1058 */
|
|
1059 (image_instance))
|
0
|
1060 {
|
|
1061 CHECK_IMAGE_INSTANCE (image_instance);
|
|
1062 return encode_image_instance_type (XIMAGE_INSTANCE_TYPE (image_instance));
|
|
1063 }
|
|
1064
|
20
|
1065 DEFUN ("image-instance-name", Fimage_instance_name, 1, 1, 0, /*
|
0
|
1066 Return the name of the given image instance.
|
20
|
1067 */
|
|
1068 (image_instance))
|
0
|
1069 {
|
|
1070 CHECK_IMAGE_INSTANCE (image_instance);
|
173
|
1071 return XIMAGE_INSTANCE_NAME (image_instance);
|
0
|
1072 }
|
|
1073
|
20
|
1074 DEFUN ("image-instance-string", Fimage_instance_string, 1, 1, 0, /*
|
0
|
1075 Return the string of the given image instance.
|
|
1076 This will only be non-nil for text image instances.
|
20
|
1077 */
|
|
1078 (image_instance))
|
0
|
1079 {
|
|
1080 CHECK_IMAGE_INSTANCE (image_instance);
|
|
1081 if (XIMAGE_INSTANCE_TYPE (image_instance) == IMAGE_TEXT)
|
173
|
1082 return XIMAGE_INSTANCE_TEXT_STRING (image_instance);
|
0
|
1083 else
|
|
1084 return Qnil;
|
|
1085 }
|
|
1086
|
20
|
1087 DEFUN ("image-instance-file-name", Fimage_instance_file_name, 1, 1, 0, /*
|
0
|
1088 Return the file name from which IMAGE-INSTANCE was read, if known.
|
20
|
1089 */
|
|
1090 (image_instance))
|
0
|
1091 {
|
|
1092 CHECK_IMAGE_INSTANCE (image_instance);
|
|
1093
|
|
1094 switch (XIMAGE_INSTANCE_TYPE (image_instance))
|
|
1095 {
|
|
1096 case IMAGE_MONO_PIXMAP:
|
|
1097 case IMAGE_COLOR_PIXMAP:
|
|
1098 case IMAGE_POINTER:
|
|
1099 return XIMAGE_INSTANCE_PIXMAP_FILENAME (image_instance);
|
|
1100
|
|
1101 default:
|
|
1102 return Qnil;
|
|
1103 }
|
|
1104 }
|
|
1105
|
20
|
1106 DEFUN ("image-instance-mask-file-name", Fimage_instance_mask_file_name, 1, 1, 0, /*
|
0
|
1107 Return the file name from which IMAGE-INSTANCE's mask was read, if known.
|
20
|
1108 */
|
|
1109 (image_instance))
|
0
|
1110 {
|
|
1111 CHECK_IMAGE_INSTANCE (image_instance);
|
|
1112
|
|
1113 switch (XIMAGE_INSTANCE_TYPE (image_instance))
|
|
1114 {
|
|
1115 case IMAGE_MONO_PIXMAP:
|
|
1116 case IMAGE_COLOR_PIXMAP:
|
|
1117 case IMAGE_POINTER:
|
|
1118 return XIMAGE_INSTANCE_PIXMAP_MASK_FILENAME (image_instance);
|
|
1119
|
|
1120 default:
|
|
1121 return Qnil;
|
|
1122 }
|
|
1123 }
|
|
1124
|
20
|
1125 DEFUN ("image-instance-depth", Fimage_instance_depth, 1, 1, 0, /*
|
0
|
1126 Return the depth of the image instance.
|
|
1127 This is 0 for a bitmap, or a positive integer for a pixmap.
|
20
|
1128 */
|
|
1129 (image_instance))
|
0
|
1130 {
|
|
1131 CHECK_IMAGE_INSTANCE (image_instance);
|
|
1132
|
|
1133 switch (XIMAGE_INSTANCE_TYPE (image_instance))
|
|
1134 {
|
|
1135 case IMAGE_MONO_PIXMAP:
|
|
1136 case IMAGE_COLOR_PIXMAP:
|
|
1137 case IMAGE_POINTER:
|
173
|
1138 return make_int (XIMAGE_INSTANCE_PIXMAP_DEPTH (image_instance));
|
0
|
1139
|
|
1140 default:
|
|
1141 return Qnil;
|
|
1142 }
|
|
1143 }
|
|
1144
|
20
|
1145 DEFUN ("image-instance-height", Fimage_instance_height, 1, 1, 0, /*
|
0
|
1146 Return the height of the image instance, in pixels.
|
20
|
1147 */
|
|
1148 (image_instance))
|
0
|
1149 {
|
|
1150 CHECK_IMAGE_INSTANCE (image_instance);
|
|
1151
|
|
1152 switch (XIMAGE_INSTANCE_TYPE (image_instance))
|
|
1153 {
|
|
1154 case IMAGE_MONO_PIXMAP:
|
|
1155 case IMAGE_COLOR_PIXMAP:
|
|
1156 case IMAGE_POINTER:
|
173
|
1157 return make_int (XIMAGE_INSTANCE_PIXMAP_HEIGHT (image_instance));
|
0
|
1158
|
|
1159 default:
|
|
1160 return Qnil;
|
|
1161 }
|
|
1162 }
|
|
1163
|
20
|
1164 DEFUN ("image-instance-width", Fimage_instance_width, 1, 1, 0, /*
|
0
|
1165 Return the width of the image instance, in pixels.
|
20
|
1166 */
|
|
1167 (image_instance))
|
0
|
1168 {
|
|
1169 CHECK_IMAGE_INSTANCE (image_instance);
|
|
1170
|
|
1171 switch (XIMAGE_INSTANCE_TYPE (image_instance))
|
|
1172 {
|
|
1173 case IMAGE_MONO_PIXMAP:
|
|
1174 case IMAGE_COLOR_PIXMAP:
|
|
1175 case IMAGE_POINTER:
|
173
|
1176 return make_int (XIMAGE_INSTANCE_PIXMAP_WIDTH (image_instance));
|
0
|
1177
|
|
1178 default:
|
|
1179 return Qnil;
|
|
1180 }
|
|
1181 }
|
|
1182
|
20
|
1183 DEFUN ("image-instance-hotspot-x", Fimage_instance_hotspot_x, 1, 1, 0, /*
|
0
|
1184 Return the X coordinate of the image instance's hotspot, if known.
|
|
1185 This is a point relative to the origin of the pixmap. When an image is
|
|
1186 used as a mouse pointer, the hotspot is the point on the image that sits
|
|
1187 over the location that the pointer points to. This is, for example, the
|
|
1188 tip of the arrow or the center of the crosshairs.
|
|
1189 This will always be nil for a non-pointer image instance.
|
20
|
1190 */
|
|
1191 (image_instance))
|
0
|
1192 {
|
|
1193 CHECK_IMAGE_INSTANCE (image_instance);
|
|
1194
|
|
1195 switch (XIMAGE_INSTANCE_TYPE (image_instance))
|
|
1196 {
|
|
1197 case IMAGE_MONO_PIXMAP:
|
|
1198 case IMAGE_COLOR_PIXMAP:
|
|
1199 case IMAGE_POINTER:
|
|
1200 return XIMAGE_INSTANCE_PIXMAP_HOTSPOT_X (image_instance);
|
|
1201
|
|
1202 default:
|
|
1203 return Qnil;
|
|
1204 }
|
|
1205 }
|
|
1206
|
20
|
1207 DEFUN ("image-instance-hotspot-y", Fimage_instance_hotspot_y, 1, 1, 0, /*
|
0
|
1208 Return the Y coordinate of the image instance's hotspot, if known.
|
|
1209 This is a point relative to the origin of the pixmap. When an image is
|
|
1210 used as a mouse pointer, the hotspot is the point on the image that sits
|
|
1211 over the location that the pointer points to. This is, for example, the
|
|
1212 tip of the arrow or the center of the crosshairs.
|
|
1213 This will always be nil for a non-pointer image instance.
|
20
|
1214 */
|
|
1215 (image_instance))
|
0
|
1216 {
|
|
1217 CHECK_IMAGE_INSTANCE (image_instance);
|
|
1218
|
|
1219 switch (XIMAGE_INSTANCE_TYPE (image_instance))
|
|
1220 {
|
|
1221 case IMAGE_MONO_PIXMAP:
|
|
1222 case IMAGE_COLOR_PIXMAP:
|
|
1223 case IMAGE_POINTER:
|
|
1224 return XIMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (image_instance);
|
|
1225
|
|
1226 default:
|
|
1227 return Qnil;
|
|
1228 }
|
|
1229 }
|
|
1230
|
20
|
1231 DEFUN ("image-instance-foreground", Fimage_instance_foreground, 1, 1, 0, /*
|
0
|
1232 Return the foreground color of IMAGE-INSTANCE, if applicable.
|
|
1233 This will be a color instance or nil. (It will only be non-nil for
|
|
1234 colorized mono pixmaps and for pointers.)
|
20
|
1235 */
|
|
1236 (image_instance))
|
0
|
1237 {
|
|
1238 CHECK_IMAGE_INSTANCE (image_instance);
|
|
1239
|
|
1240 switch (XIMAGE_INSTANCE_TYPE (image_instance))
|
|
1241 {
|
|
1242 case IMAGE_MONO_PIXMAP:
|
|
1243 case IMAGE_COLOR_PIXMAP:
|
|
1244 case IMAGE_POINTER:
|
|
1245 return XIMAGE_INSTANCE_PIXMAP_FG (image_instance);
|
|
1246
|
|
1247 default:
|
|
1248 return Qnil;
|
|
1249 }
|
|
1250 }
|
|
1251
|
20
|
1252 DEFUN ("image-instance-background", Fimage_instance_background, 1, 1, 0, /*
|
0
|
1253 Return the background color of IMAGE-INSTANCE, if applicable.
|
|
1254 This will be a color instance or nil. (It will only be non-nil for
|
|
1255 colorized mono pixmaps and for pointers.)
|
20
|
1256 */
|
|
1257 (image_instance))
|
0
|
1258 {
|
|
1259 CHECK_IMAGE_INSTANCE (image_instance);
|
|
1260
|
|
1261 switch (XIMAGE_INSTANCE_TYPE (image_instance))
|
|
1262 {
|
|
1263 case IMAGE_MONO_PIXMAP:
|
|
1264 case IMAGE_COLOR_PIXMAP:
|
|
1265 case IMAGE_POINTER:
|
|
1266 return XIMAGE_INSTANCE_PIXMAP_BG (image_instance);
|
|
1267
|
|
1268 default:
|
|
1269 return Qnil;
|
|
1270 }
|
|
1271 }
|
|
1272
|
|
1273
|
20
|
1274 DEFUN ("colorize-image-instance", Fcolorize_image_instance, 3, 3, 0, /*
|
0
|
1275 Make the image instance be displayed in the given colors.
|
|
1276 This function returns a new image instance that is exactly like the
|
|
1277 specified one except that (if possible) the foreground and background
|
|
1278 colors and as specified. Currently, this only does anything if the image
|
|
1279 instance is a mono pixmap; otherwise, the same image instance is returned.
|
20
|
1280 */
|
|
1281 (image_instance, foreground, background))
|
0
|
1282 {
|
|
1283 Lisp_Object new;
|
|
1284 Lisp_Object device;
|
|
1285
|
|
1286 CHECK_IMAGE_INSTANCE (image_instance);
|
|
1287 CHECK_COLOR_INSTANCE (foreground);
|
|
1288 CHECK_COLOR_INSTANCE (background);
|
|
1289
|
|
1290 device = XIMAGE_INSTANCE_DEVICE (image_instance);
|
|
1291 if (!HAS_DEVMETH_P (XDEVICE (device), colorize_image_instance))
|
|
1292 return image_instance;
|
|
1293
|
|
1294 new = allocate_image_instance (device);
|
|
1295 copy_lcrecord (XIMAGE_INSTANCE (new), XIMAGE_INSTANCE (image_instance));
|
|
1296 /* note that if this method returns non-zero, this method MUST
|
|
1297 copy any window-system resources, so that when one image instance is
|
|
1298 freed, the other one is not hosed. */
|
|
1299 if (!DEVMETH (XDEVICE (device), colorize_image_instance, (new, foreground,
|
|
1300 background)))
|
|
1301 return image_instance;
|
|
1302 return new;
|
|
1303 }
|
|
1304
|
|
1305
|
276
|
1306 /************************************************************************/
|
|
1307 /* error helpers */
|
|
1308 /************************************************************************/
|
|
1309 DOESNT_RETURN
|
|
1310 signal_image_error (CONST char *reason, Lisp_Object frob)
|
|
1311 {
|
|
1312 signal_error (Qimage_conversion_error,
|
|
1313 list2 (build_translated_string (reason), frob));
|
|
1314 }
|
|
1315
|
|
1316 DOESNT_RETURN
|
|
1317 signal_image_error_2 (CONST char *reason, Lisp_Object frob0, Lisp_Object frob1)
|
|
1318 {
|
|
1319 signal_error (Qimage_conversion_error,
|
|
1320 list3 (build_translated_string (reason), frob0, frob1));
|
|
1321 }
|
|
1322
|
0
|
1323 /****************************************************************************
|
|
1324 * nothing *
|
|
1325 ****************************************************************************/
|
|
1326
|
|
1327 static int
|
74
|
1328 nothing_possible_dest_types (void)
|
0
|
1329 {
|
|
1330 return IMAGE_NOTHING_MASK;
|
|
1331 }
|
|
1332
|
|
1333 static void
|
|
1334 nothing_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1335 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
124
|
1336 int dest_mask, Lisp_Object domain)
|
0
|
1337 {
|
|
1338 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
1339
|
|
1340 if (dest_mask & IMAGE_NOTHING_MASK)
|
|
1341 IMAGE_INSTANCE_TYPE (ii) = IMAGE_NOTHING;
|
|
1342 else
|
|
1343 incompatible_image_types (instantiator, dest_mask, IMAGE_NOTHING_MASK);
|
|
1344 }
|
|
1345
|
|
1346
|
|
1347 /****************************************************************************
|
|
1348 * inherit *
|
|
1349 ****************************************************************************/
|
|
1350
|
|
1351 static void
|
|
1352 inherit_validate (Lisp_Object instantiator)
|
|
1353 {
|
|
1354 face_must_be_present (instantiator);
|
|
1355 }
|
|
1356
|
|
1357 static Lisp_Object
|
|
1358 inherit_normalize (Lisp_Object inst, Lisp_Object console_type)
|
|
1359 {
|
|
1360 Lisp_Object face;
|
|
1361
|
173
|
1362 assert (XVECTOR_LENGTH (inst) == 3);
|
|
1363 face = XVECTOR_DATA (inst)[2];
|
0
|
1364 if (!FACEP (face))
|
|
1365 inst = vector3 (Qinherit, Q_face, Fget_face (face));
|
|
1366 return inst;
|
|
1367 }
|
|
1368
|
|
1369 static int
|
74
|
1370 inherit_possible_dest_types (void)
|
0
|
1371 {
|
|
1372 return IMAGE_MONO_PIXMAP_MASK;
|
|
1373 }
|
|
1374
|
|
1375 static void
|
|
1376 inherit_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1377 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
124
|
1378 int dest_mask, Lisp_Object domain)
|
0
|
1379 {
|
|
1380 /* handled specially in image_instantiate */
|
|
1381 abort ();
|
|
1382 }
|
|
1383
|
|
1384
|
|
1385 /****************************************************************************
|
|
1386 * string *
|
|
1387 ****************************************************************************/
|
|
1388
|
|
1389 static void
|
|
1390 string_validate (Lisp_Object instantiator)
|
|
1391 {
|
|
1392 data_must_be_present (instantiator);
|
|
1393 }
|
|
1394
|
|
1395 static int
|
74
|
1396 string_possible_dest_types (void)
|
0
|
1397 {
|
|
1398 return IMAGE_TEXT_MASK;
|
|
1399 }
|
|
1400
|
|
1401 /* called from autodetect_instantiate() */
|
|
1402 void
|
|
1403 string_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1404 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
124
|
1405 int dest_mask, Lisp_Object domain)
|
0
|
1406 {
|
|
1407 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
1408 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
1409
|
|
1410 assert (!NILP (data));
|
|
1411 if (dest_mask & IMAGE_TEXT_MASK)
|
|
1412 {
|
|
1413 IMAGE_INSTANCE_TYPE (ii) = IMAGE_TEXT;
|
|
1414 IMAGE_INSTANCE_TEXT_STRING (ii) = data;
|
|
1415 }
|
|
1416 else
|
|
1417 incompatible_image_types (instantiator, dest_mask, IMAGE_TEXT_MASK);
|
|
1418 }
|
|
1419
|
|
1420
|
|
1421 /****************************************************************************
|
|
1422 * formatted-string *
|
|
1423 ****************************************************************************/
|
|
1424
|
|
1425 static void
|
|
1426 formatted_string_validate (Lisp_Object instantiator)
|
|
1427 {
|
|
1428 data_must_be_present (instantiator);
|
|
1429 }
|
|
1430
|
|
1431 static int
|
74
|
1432 formatted_string_possible_dest_types (void)
|
0
|
1433 {
|
|
1434 return IMAGE_TEXT_MASK;
|
|
1435 }
|
|
1436
|
|
1437 static void
|
|
1438 formatted_string_instantiate (Lisp_Object image_instance,
|
|
1439 Lisp_Object instantiator,
|
|
1440 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
124
|
1441 int dest_mask, Lisp_Object domain)
|
0
|
1442 {
|
|
1443 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
1444 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
1445
|
|
1446 assert (!NILP (data));
|
|
1447 /* #### implement this */
|
|
1448 warn_when_safe (Qunimplemented, Qnotice,
|
|
1449 "`formatted-string' not yet implemented; assuming `string'");
|
|
1450 if (dest_mask & IMAGE_TEXT_MASK)
|
|
1451 {
|
|
1452 IMAGE_INSTANCE_TYPE (ii) = IMAGE_TEXT;
|
|
1453 IMAGE_INSTANCE_TEXT_STRING (ii) = data;
|
|
1454 }
|
|
1455 else
|
|
1456 incompatible_image_types (instantiator, dest_mask, IMAGE_TEXT_MASK);
|
|
1457 }
|
|
1458
|
|
1459
|
278
|
1460 /************************************************************************/
|
|
1461 /* pixmap file functions */
|
|
1462 /************************************************************************/
|
|
1463
|
|
1464 /* If INSTANTIATOR refers to inline data, return Qnil.
|
|
1465 If INSTANTIATOR refers to data in a file, return the full filename
|
|
1466 if it exists; otherwise, return a cons of (filename).
|
|
1467
|
|
1468 FILE_KEYWORD and DATA_KEYWORD are symbols specifying the
|
|
1469 keywords used to look up the file and inline data,
|
|
1470 respectively, in the instantiator. Normally these would
|
|
1471 be Q_file and Q_data, but might be different for mask data. */
|
|
1472
|
|
1473 Lisp_Object
|
|
1474 potential_pixmap_file_instantiator (Lisp_Object instantiator,
|
|
1475 Lisp_Object file_keyword,
|
|
1476 Lisp_Object data_keyword,
|
|
1477 Lisp_Object console_type)
|
|
1478 {
|
|
1479 Lisp_Object file;
|
|
1480 Lisp_Object data;
|
|
1481
|
|
1482 assert (VECTORP (instantiator));
|
|
1483
|
|
1484 data = find_keyword_in_vector (instantiator, data_keyword);
|
|
1485 file = find_keyword_in_vector (instantiator, file_keyword);
|
|
1486
|
|
1487 if (!NILP (file) && NILP (data))
|
|
1488 {
|
|
1489 Lisp_Object retval = MAYBE_LISP_CONTYPE_METH
|
|
1490 (decode_console_type(console_type, ERROR_ME),
|
|
1491 locate_pixmap_file, (file));
|
|
1492
|
|
1493 if (!NILP (retval))
|
|
1494 return retval;
|
|
1495 else
|
|
1496 return Fcons (file, Qnil); /* should have been file */
|
|
1497 }
|
|
1498
|
|
1499 return Qnil;
|
|
1500 }
|
|
1501
|
|
1502 Lisp_Object
|
|
1503 simple_image_type_normalize (Lisp_Object inst, Lisp_Object console_type,
|
|
1504 Lisp_Object image_type_tag)
|
|
1505 {
|
|
1506 /* This function can call lisp */
|
|
1507 Lisp_Object file = Qnil;
|
|
1508 struct gcpro gcpro1, gcpro2;
|
|
1509 Lisp_Object alist = Qnil;
|
|
1510
|
|
1511 GCPRO2 (file, alist);
|
|
1512
|
|
1513 /* Now, convert any file data into inline data. At the end of this,
|
|
1514 `data' will contain the inline data (if any) or Qnil, and `file'
|
|
1515 will contain the name this data was derived from (if known) or
|
|
1516 Qnil.
|
|
1517
|
|
1518 Note that if we cannot generate any regular inline data, we
|
|
1519 skip out. */
|
|
1520
|
|
1521 file = potential_pixmap_file_instantiator (inst, Q_file, Q_data,
|
|
1522 console_type);
|
|
1523
|
|
1524 if (CONSP (file)) /* failure locating filename */
|
|
1525 signal_double_file_error ("Opening pixmap file",
|
|
1526 "no such file or directory",
|
|
1527 Fcar (file));
|
|
1528
|
|
1529 if (NILP (file)) /* no conversion necessary */
|
|
1530 RETURN_UNGCPRO (inst);
|
|
1531
|
|
1532 alist = tagged_vector_to_alist (inst);
|
|
1533
|
|
1534 {
|
|
1535 Lisp_Object data = make_string_from_file (file);
|
|
1536 alist = remassq_no_quit (Q_file, alist);
|
|
1537 /* there can't be a :data at this point. */
|
|
1538 alist = Fcons (Fcons (Q_file, file),
|
|
1539 Fcons (Fcons (Q_data, data), alist));
|
|
1540 }
|
|
1541
|
|
1542 {
|
|
1543 Lisp_Object result = alist_to_tagged_vector (image_type_tag, alist);
|
|
1544 free_alist (alist);
|
|
1545 RETURN_UNGCPRO (result);
|
|
1546 }
|
|
1547 }
|
|
1548
|
|
1549
|
288
|
1550 #ifdef HAVE_WINDOW_SYSTEM
|
|
1551 /**********************************************************************
|
|
1552 * XBM *
|
|
1553 **********************************************************************/
|
|
1554
|
|
1555 /* Check if DATA represents a valid inline XBM spec (i.e. a list
|
|
1556 of (width height bits), with checking done on the dimensions).
|
|
1557 If not, signal an error. */
|
|
1558
|
|
1559 static void
|
|
1560 check_valid_xbm_inline (Lisp_Object data)
|
|
1561 {
|
|
1562 Lisp_Object width, height, bits;
|
|
1563
|
|
1564 if (!CONSP (data) ||
|
|
1565 !CONSP (XCDR (data)) ||
|
|
1566 !CONSP (XCDR (XCDR (data))) ||
|
|
1567 !NILP (XCDR (XCDR (XCDR (data)))))
|
|
1568 signal_simple_error ("Must be list of 3 elements", data);
|
|
1569
|
|
1570 width = XCAR (data);
|
|
1571 height = XCAR (XCDR (data));
|
|
1572 bits = XCAR (XCDR (XCDR (data)));
|
|
1573
|
|
1574 CHECK_STRING (bits);
|
|
1575
|
|
1576 if (!NATNUMP (width))
|
|
1577 signal_simple_error ("Width must be a natural number", width);
|
|
1578
|
|
1579 if (!NATNUMP (height))
|
|
1580 signal_simple_error ("Height must be a natural number", height);
|
|
1581
|
|
1582 if (((XINT (width) * XINT (height)) / 8) > XSTRING_CHAR_LENGTH (bits))
|
|
1583 signal_simple_error ("data is too short for width and height",
|
|
1584 vector3 (width, height, bits));
|
|
1585 }
|
|
1586
|
|
1587 /* Validate method for XBM's. */
|
|
1588
|
|
1589 static void
|
|
1590 xbm_validate (Lisp_Object instantiator)
|
|
1591 {
|
|
1592 file_or_data_must_be_present (instantiator);
|
|
1593 }
|
|
1594
|
|
1595 /* Given a filename that is supposed to contain XBM data, return
|
|
1596 the inline representation of it as (width height bits). Return
|
|
1597 the hotspot through XHOT and YHOT, if those pointers are not 0.
|
|
1598 If there is no hotspot, XHOT and YHOT will contain -1.
|
|
1599
|
|
1600 If the function fails:
|
|
1601
|
|
1602 -- if OK_IF_DATA_INVALID is set and the data was invalid,
|
|
1603 return Qt.
|
|
1604 -- maybe return an error, or return Qnil.
|
|
1605 */
|
|
1606
|
290
|
1607 #ifndef HAVE_X_WINDOWS
|
|
1608 #define XFree(data) free(data)
|
|
1609 #endif
|
288
|
1610
|
|
1611 Lisp_Object
|
|
1612 bitmap_to_lisp_data (Lisp_Object name, int *xhot, int *yhot,
|
|
1613 int ok_if_data_invalid)
|
|
1614 {
|
|
1615 unsigned int w, h;
|
|
1616 Extbyte *data;
|
|
1617 int result;
|
|
1618 CONST char *filename_ext;
|
|
1619
|
|
1620 GET_C_STRING_FILENAME_DATA_ALLOCA (name, filename_ext);
|
|
1621 result = read_bitmap_data_from_file (filename_ext, &w, &h,
|
|
1622 &data, xhot, yhot);
|
|
1623
|
|
1624 if (result == BitmapSuccess)
|
|
1625 {
|
|
1626 Lisp_Object retval;
|
|
1627 int len = (w + 7) / 8 * h;
|
|
1628
|
|
1629 retval = list3 (make_int (w), make_int (h),
|
|
1630 make_ext_string (data, len, FORMAT_BINARY));
|
|
1631 XFree ((char *) data);
|
|
1632 return retval;
|
|
1633 }
|
|
1634
|
|
1635 switch (result)
|
|
1636 {
|
|
1637 case BitmapOpenFailed:
|
|
1638 {
|
|
1639 /* should never happen */
|
|
1640 signal_double_file_error ("Opening bitmap file",
|
|
1641 "no such file or directory",
|
|
1642 name);
|
|
1643 }
|
|
1644 case BitmapFileInvalid:
|
|
1645 {
|
|
1646 if (ok_if_data_invalid)
|
|
1647 return Qt;
|
|
1648 signal_double_file_error ("Reading bitmap file",
|
|
1649 "invalid data in file",
|
|
1650 name);
|
|
1651 }
|
|
1652 case BitmapNoMemory:
|
|
1653 {
|
|
1654 signal_double_file_error ("Reading bitmap file",
|
|
1655 "out of memory",
|
|
1656 name);
|
|
1657 }
|
|
1658 default:
|
|
1659 {
|
|
1660 signal_double_file_error_2 ("Reading bitmap file",
|
|
1661 "unknown error code",
|
|
1662 make_int (result), name);
|
|
1663 }
|
|
1664 }
|
|
1665
|
|
1666 return Qnil; /* not reached */
|
|
1667 }
|
|
1668
|
|
1669 Lisp_Object
|
|
1670 xbm_mask_file_munging (Lisp_Object alist, Lisp_Object file,
|
|
1671 Lisp_Object mask_file, Lisp_Object console_type)
|
|
1672 {
|
|
1673 /* This is unclean but it's fairly standard -- a number of the
|
|
1674 bitmaps in /usr/include/X11/bitmaps use it -- so we support
|
|
1675 it. */
|
|
1676 if (NILP (mask_file)
|
|
1677 /* don't override explicitly specified mask data. */
|
|
1678 && NILP (assq_no_quit (Q_mask_data, alist))
|
|
1679 && !NILP (file))
|
|
1680 {
|
|
1681 mask_file = MAYBE_LISP_CONTYPE_METH
|
|
1682 (decode_console_type(console_type, ERROR_ME),
|
|
1683 locate_pixmap_file, (concat2 (file, build_string ("Mask"))));
|
|
1684 if (NILP (mask_file))
|
|
1685 mask_file = MAYBE_LISP_CONTYPE_METH
|
|
1686 (decode_console_type(console_type, ERROR_ME),
|
|
1687 locate_pixmap_file, (concat2 (file, build_string ("msk"))));
|
|
1688 }
|
|
1689
|
|
1690 if (!NILP (mask_file))
|
|
1691 {
|
|
1692 Lisp_Object mask_data =
|
|
1693 bitmap_to_lisp_data (mask_file, 0, 0, 0);
|
|
1694 alist = remassq_no_quit (Q_mask_file, alist);
|
|
1695 /* there can't be a :mask-data at this point. */
|
|
1696 alist = Fcons (Fcons (Q_mask_file, mask_file),
|
|
1697 Fcons (Fcons (Q_mask_data, mask_data), alist));
|
|
1698 }
|
|
1699
|
|
1700 return alist;
|
|
1701 }
|
|
1702
|
|
1703 /* Normalize method for XBM's. */
|
|
1704
|
|
1705 static Lisp_Object
|
|
1706 xbm_normalize (Lisp_Object inst, Lisp_Object console_type)
|
|
1707 {
|
|
1708 Lisp_Object file = Qnil, mask_file = Qnil;
|
|
1709 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
1710 Lisp_Object alist = Qnil;
|
|
1711
|
|
1712 GCPRO3 (file, mask_file, alist);
|
|
1713
|
|
1714 /* Now, convert any file data into inline data for both the regular
|
|
1715 data and the mask data. At the end of this, `data' will contain
|
|
1716 the inline data (if any) or Qnil, and `file' will contain
|
|
1717 the name this data was derived from (if known) or Qnil.
|
|
1718 Likewise for `mask_file' and `mask_data'.
|
|
1719
|
|
1720 Note that if we cannot generate any regular inline data, we
|
|
1721 skip out. */
|
|
1722
|
|
1723 file = potential_pixmap_file_instantiator (inst, Q_file, Q_data,
|
|
1724 console_type);
|
|
1725 mask_file = potential_pixmap_file_instantiator (inst, Q_mask_file,
|
|
1726 Q_mask_data, console_type);
|
|
1727
|
|
1728 if (CONSP (file)) /* failure locating filename */
|
|
1729 signal_double_file_error ("Opening bitmap file",
|
|
1730 "no such file or directory",
|
|
1731 Fcar (file));
|
|
1732
|
|
1733 if (NILP (file) && NILP (mask_file)) /* no conversion necessary */
|
|
1734 RETURN_UNGCPRO (inst);
|
|
1735
|
|
1736 alist = tagged_vector_to_alist (inst);
|
|
1737
|
|
1738 if (!NILP (file))
|
|
1739 {
|
|
1740 int xhot, yhot;
|
|
1741 Lisp_Object data = bitmap_to_lisp_data (file, &xhot, &yhot, 0);
|
|
1742 alist = remassq_no_quit (Q_file, alist);
|
|
1743 /* there can't be a :data at this point. */
|
|
1744 alist = Fcons (Fcons (Q_file, file),
|
|
1745 Fcons (Fcons (Q_data, data), alist));
|
|
1746
|
|
1747 if (xhot != -1 && NILP (assq_no_quit (Q_hotspot_x, alist)))
|
|
1748 alist = Fcons (Fcons (Q_hotspot_x, make_int (xhot)),
|
|
1749 alist);
|
|
1750 if (yhot != -1 && NILP (assq_no_quit (Q_hotspot_y, alist)))
|
|
1751 alist = Fcons (Fcons (Q_hotspot_y, make_int (yhot)),
|
|
1752 alist);
|
|
1753 }
|
|
1754
|
|
1755 alist = xbm_mask_file_munging (alist, file, mask_file, console_type);
|
|
1756
|
|
1757 {
|
|
1758 Lisp_Object result = alist_to_tagged_vector (Qxbm, alist);
|
|
1759 free_alist (alist);
|
|
1760 RETURN_UNGCPRO (result);
|
|
1761 }
|
|
1762 }
|
|
1763
|
|
1764
|
|
1765 static int
|
|
1766 xbm_possible_dest_types (void)
|
|
1767 {
|
|
1768 return
|
|
1769 IMAGE_MONO_PIXMAP_MASK |
|
|
1770 IMAGE_COLOR_PIXMAP_MASK |
|
|
1771 IMAGE_POINTER_MASK;
|
|
1772 }
|
|
1773
|
|
1774 static void
|
|
1775 xbm_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1776 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
1777 int dest_mask, Lisp_Object domain)
|
|
1778 {
|
|
1779 Lisp_Object device= IMAGE_INSTANCE_DEVICE (XIMAGE_INSTANCE (image_instance));
|
|
1780
|
|
1781 MAYBE_DEVMETH (XDEVICE (device),
|
|
1782 xbm_instantiate,
|
|
1783 (image_instance, instantiator, pointer_fg,
|
|
1784 pointer_bg, dest_mask, domain));
|
|
1785 }
|
|
1786
|
|
1787 #endif
|
|
1788
|
|
1789
|
276
|
1790 #ifdef HAVE_XPM
|
|
1791
|
|
1792 /**********************************************************************
|
|
1793 * XPM *
|
|
1794 **********************************************************************/
|
|
1795
|
280
|
1796 Lisp_Object
|
|
1797 pixmap_to_lisp_data (Lisp_Object name, int ok_if_data_invalid)
|
|
1798 {
|
|
1799 char **data;
|
|
1800 int result;
|
|
1801
|
|
1802 result = XpmReadFileToData ((char *) XSTRING_DATA (name), &data);
|
|
1803
|
|
1804 if (result == XpmSuccess)
|
|
1805 {
|
|
1806 Lisp_Object retval = Qnil;
|
|
1807 struct buffer *old_buffer = current_buffer;
|
|
1808 Lisp_Object temp_buffer =
|
|
1809 Fget_buffer_create (build_string (" *pixmap conversion*"));
|
|
1810 int elt;
|
|
1811 int height, width, ncolors;
|
|
1812 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
1813 int speccount = specpdl_depth ();
|
|
1814
|
|
1815 GCPRO3 (name, retval, temp_buffer);
|
|
1816
|
|
1817 specbind (Qinhibit_quit, Qt);
|
|
1818 set_buffer_internal (XBUFFER (temp_buffer));
|
|
1819 Ferase_buffer (Qnil);
|
|
1820
|
|
1821 buffer_insert_c_string (current_buffer, "/* XPM */\r");
|
|
1822 buffer_insert_c_string (current_buffer, "static char *pixmap[] = {\r");
|
|
1823
|
|
1824 sscanf (data[0], "%d %d %d", &height, &width, &ncolors);
|
|
1825 for (elt = 0; elt <= width + ncolors; elt++)
|
|
1826 {
|
|
1827 buffer_insert_c_string (current_buffer, "\"");
|
|
1828 buffer_insert_c_string (current_buffer, data[elt]);
|
|
1829
|
|
1830 if (elt < width + ncolors)
|
|
1831 buffer_insert_c_string (current_buffer, "\",\r");
|
|
1832 else
|
|
1833 buffer_insert_c_string (current_buffer, "\"};\r");
|
|
1834 }
|
|
1835
|
|
1836 retval = Fbuffer_substring (Qnil, Qnil, Qnil);
|
|
1837 XpmFree (data);
|
|
1838
|
|
1839 set_buffer_internal (old_buffer);
|
|
1840 unbind_to (speccount, Qnil);
|
|
1841
|
|
1842 RETURN_UNGCPRO (retval);
|
|
1843 }
|
|
1844
|
|
1845 switch (result)
|
|
1846 {
|
|
1847 case XpmFileInvalid:
|
|
1848 {
|
|
1849 if (ok_if_data_invalid)
|
|
1850 return Qt;
|
|
1851 signal_image_error ("invalid XPM data in file", name);
|
|
1852 }
|
|
1853 case XpmNoMemory:
|
|
1854 {
|
|
1855 signal_double_file_error ("Reading pixmap file",
|
|
1856 "out of memory", name);
|
|
1857 }
|
|
1858 case XpmOpenFailed:
|
|
1859 {
|
|
1860 /* should never happen? */
|
|
1861 signal_double_file_error ("Opening pixmap file",
|
|
1862 "no such file or directory", name);
|
|
1863 }
|
|
1864 default:
|
|
1865 {
|
|
1866 signal_double_file_error_2 ("Parsing pixmap file",
|
|
1867 "unknown error code",
|
|
1868 make_int (result), name);
|
|
1869 break;
|
|
1870 }
|
|
1871 }
|
|
1872
|
|
1873 return Qnil; /* not reached */
|
|
1874 }
|
|
1875
|
276
|
1876 static void
|
|
1877 check_valid_xpm_color_symbols (Lisp_Object data)
|
|
1878 {
|
|
1879 Lisp_Object rest;
|
|
1880
|
|
1881 for (rest = data; !NILP (rest); rest = XCDR (rest))
|
|
1882 {
|
|
1883 if (!CONSP (rest) ||
|
|
1884 !CONSP (XCAR (rest)) ||
|
|
1885 !STRINGP (XCAR (XCAR (rest))) ||
|
|
1886 (!STRINGP (XCDR (XCAR (rest))) &&
|
|
1887 !COLOR_SPECIFIERP (XCDR (XCAR (rest)))))
|
|
1888 signal_simple_error ("Invalid color symbol alist", data);
|
|
1889 }
|
|
1890 }
|
|
1891
|
|
1892 static void
|
|
1893 xpm_validate (Lisp_Object instantiator)
|
|
1894 {
|
|
1895 file_or_data_must_be_present (instantiator);
|
|
1896 }
|
|
1897
|
|
1898 Lisp_Object Vxpm_color_symbols;
|
|
1899
|
|
1900 Lisp_Object
|
|
1901 evaluate_xpm_color_symbols (void)
|
|
1902 {
|
|
1903 Lisp_Object rest, results = Qnil;
|
|
1904 struct gcpro gcpro1, gcpro2;
|
|
1905
|
|
1906 GCPRO2 (rest, results);
|
|
1907 for (rest = Vxpm_color_symbols; !NILP (rest); rest = XCDR (rest))
|
|
1908 {
|
|
1909 Lisp_Object name, value, cons;
|
|
1910
|
|
1911 CHECK_CONS (rest);
|
|
1912 cons = XCAR (rest);
|
|
1913 CHECK_CONS (cons);
|
|
1914 name = XCAR (cons);
|
|
1915 CHECK_STRING (name);
|
|
1916 value = XCDR (cons);
|
|
1917 CHECK_CONS (value);
|
|
1918 value = XCAR (value);
|
|
1919 value = Feval (value);
|
|
1920 if (NILP (value))
|
|
1921 continue;
|
|
1922 if (!STRINGP (value) && !COLOR_SPECIFIERP (value))
|
|
1923 signal_simple_error
|
|
1924 ("Result from xpm-color-symbols eval must be nil, string, or color",
|
|
1925 value);
|
|
1926 results = Fcons (Fcons (name, value), results);
|
|
1927 }
|
|
1928 UNGCPRO; /* no more evaluation */
|
|
1929 return results;
|
|
1930 }
|
|
1931
|
|
1932 static Lisp_Object
|
|
1933 xpm_normalize (Lisp_Object inst, Lisp_Object console_type)
|
|
1934 {
|
280
|
1935 Lisp_Object file = Qnil;
|
|
1936 Lisp_Object color_symbols;
|
|
1937 struct gcpro gcpro1, gcpro2;
|
|
1938 Lisp_Object alist = Qnil;
|
|
1939
|
|
1940 GCPRO2 (file, alist);
|
|
1941
|
|
1942 /* Now, convert any file data into inline data. At the end of this,
|
|
1943 `data' will contain the inline data (if any) or Qnil, and
|
|
1944 `file' will contain the name this data was derived from (if
|
|
1945 known) or Qnil.
|
|
1946
|
|
1947 Note that if we cannot generate any regular inline data, we
|
|
1948 skip out. */
|
|
1949
|
|
1950 file = potential_pixmap_file_instantiator (inst, Q_file, Q_data,
|
|
1951 console_type);
|
|
1952
|
|
1953 if (CONSP (file)) /* failure locating filename */
|
|
1954 signal_double_file_error ("Opening pixmap file",
|
|
1955 "no such file or directory",
|
|
1956 Fcar (file));
|
|
1957
|
|
1958 color_symbols = find_keyword_in_vector_or_given (inst, Q_color_symbols,
|
|
1959 Qunbound);
|
|
1960
|
|
1961 if (NILP (file) && !UNBOUNDP (color_symbols))
|
|
1962 /* no conversion necessary */
|
|
1963 RETURN_UNGCPRO (inst);
|
|
1964
|
|
1965 alist = tagged_vector_to_alist (inst);
|
|
1966
|
|
1967 if (!NILP (file))
|
|
1968 {
|
|
1969 Lisp_Object data = pixmap_to_lisp_data (file, 0);
|
|
1970 alist = remassq_no_quit (Q_file, alist);
|
|
1971 /* there can't be a :data at this point. */
|
|
1972 alist = Fcons (Fcons (Q_file, file),
|
|
1973 Fcons (Fcons (Q_data, data), alist));
|
|
1974 }
|
|
1975
|
|
1976 if (UNBOUNDP (color_symbols))
|
|
1977 {
|
|
1978 color_symbols = evaluate_xpm_color_symbols ();
|
|
1979 alist = Fcons (Fcons (Q_color_symbols, color_symbols),
|
|
1980 alist);
|
|
1981 }
|
|
1982
|
|
1983 {
|
|
1984 Lisp_Object result = alist_to_tagged_vector (Qxpm, alist);
|
|
1985 free_alist (alist);
|
|
1986 RETURN_UNGCPRO (result);
|
|
1987 }
|
276
|
1988 }
|
|
1989
|
|
1990 static int
|
|
1991 xpm_possible_dest_types (void)
|
|
1992 {
|
|
1993 return
|
|
1994 IMAGE_MONO_PIXMAP_MASK |
|
|
1995 IMAGE_COLOR_PIXMAP_MASK |
|
|
1996 IMAGE_POINTER_MASK;
|
|
1997 }
|
|
1998
|
|
1999 static void
|
|
2000 xpm_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
2001 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
2002 int dest_mask, Lisp_Object domain)
|
|
2003 {
|
|
2004 Lisp_Object device= IMAGE_INSTANCE_DEVICE (XIMAGE_INSTANCE (image_instance));
|
280
|
2005
|
|
2006 MAYBE_DEVMETH (XDEVICE (device),
|
|
2007 xpm_instantiate,
|
|
2008 (image_instance, instantiator, pointer_fg,
|
|
2009 pointer_bg, dest_mask, domain));
|
276
|
2010 }
|
|
2011
|
|
2012 #endif /* HAVE_XPM */
|
|
2013
|
|
2014
|
0
|
2015 /****************************************************************************
|
|
2016 * Image Specifier Object *
|
|
2017 ****************************************************************************/
|
|
2018
|
|
2019 DEFINE_SPECIFIER_TYPE (image);
|
|
2020
|
|
2021 static void
|
|
2022 image_create (Lisp_Object obj)
|
|
2023 {
|
|
2024 struct Lisp_Specifier *image = XIMAGE_SPECIFIER (obj);
|
|
2025
|
|
2026 IMAGE_SPECIFIER_ALLOWED (image) = ~0; /* all are allowed */
|
|
2027 IMAGE_SPECIFIER_ATTACHEE (image) = Qnil;
|
|
2028 IMAGE_SPECIFIER_ATTACHEE_PROPERTY (image) = Qnil;
|
|
2029 }
|
|
2030
|
|
2031 static void
|
|
2032 image_mark (Lisp_Object obj, void (*markobj) (Lisp_Object))
|
|
2033 {
|
|
2034 struct Lisp_Specifier *image = XIMAGE_SPECIFIER (obj);
|
|
2035
|
|
2036 ((markobj) (IMAGE_SPECIFIER_ATTACHEE (image)));
|
|
2037 ((markobj) (IMAGE_SPECIFIER_ATTACHEE_PROPERTY (image)));
|
|
2038 }
|
|
2039
|
|
2040 static Lisp_Object
|
|
2041 image_instantiate_cache_result (Lisp_Object locative)
|
|
2042 {
|
272
|
2043 /* locative = (instance instantiator . subtable) */
|
|
2044 Fputhash (XCAR (XCDR (locative)), XCAR (locative), XCDR (XCDR (locative)));
|
0
|
2045 free_cons (XCONS (XCDR (locative)));
|
|
2046 free_cons (XCONS (locative));
|
|
2047 return Qnil;
|
|
2048 }
|
|
2049
|
|
2050 /* Given a specification for an image, return an instance of
|
|
2051 the image which matches the given instantiator and which can be
|
|
2052 displayed in the given domain. */
|
|
2053
|
|
2054 static Lisp_Object
|
|
2055 image_instantiate (Lisp_Object specifier, Lisp_Object matchspec,
|
|
2056 Lisp_Object domain, Lisp_Object instantiator,
|
|
2057 Lisp_Object depth)
|
|
2058 {
|
|
2059 Lisp_Object device = DFW_DEVICE (domain);
|
|
2060 struct device *d = XDEVICE (device);
|
|
2061 int dest_mask = XIMAGE_SPECIFIER_ALLOWED (specifier);
|
|
2062 int pointerp = dest_mask & image_instance_type_to_mask (IMAGE_POINTER);
|
|
2063
|
|
2064 if (IMAGE_INSTANCEP (instantiator))
|
|
2065 {
|
|
2066 /* make sure that the image instance's device and type are
|
|
2067 matching. */
|
|
2068
|
|
2069 if (EQ (device, XIMAGE_INSTANCE_DEVICE (instantiator)))
|
|
2070 {
|
|
2071 int mask =
|
|
2072 image_instance_type_to_mask (XIMAGE_INSTANCE_TYPE (instantiator));
|
|
2073 if (mask & dest_mask)
|
|
2074 return instantiator;
|
|
2075 else
|
|
2076 signal_simple_error ("Type of image instance not allowed here",
|
|
2077 instantiator);
|
|
2078 }
|
|
2079 else
|
|
2080 signal_simple_error_2 ("Wrong device for image instance",
|
|
2081 instantiator, device);
|
|
2082 }
|
|
2083 else if (VECTORP (instantiator)
|
173
|
2084 && EQ (XVECTOR_DATA (instantiator)[0], Qinherit))
|
0
|
2085 {
|
173
|
2086 assert (XVECTOR_LENGTH (instantiator) == 3);
|
0
|
2087 return (FACE_PROPERTY_INSTANCE
|
173
|
2088 (Fget_face (XVECTOR_DATA (instantiator)[2]),
|
0
|
2089 Qbackground_pixmap, domain, 0, depth));
|
|
2090 }
|
|
2091 else
|
|
2092 {
|
|
2093 Lisp_Object instance;
|
|
2094 Lisp_Object subtable;
|
|
2095 Lisp_Object ls3 = Qnil;
|
|
2096 Lisp_Object pointer_fg = Qnil;
|
|
2097 Lisp_Object pointer_bg = Qnil;
|
|
2098
|
|
2099 if (pointerp)
|
|
2100 {
|
|
2101 pointer_fg = FACE_FOREGROUND (Vpointer_face, domain);
|
|
2102 pointer_bg = FACE_BACKGROUND (Vpointer_face, domain);
|
|
2103 ls3 = list3 (instantiator, pointer_fg, pointer_bg);
|
|
2104 }
|
|
2105
|
|
2106 /* First look in the hash table. */
|
|
2107 subtable = Fgethash (make_int (dest_mask), d->image_instance_cache,
|
|
2108 Qunbound);
|
|
2109 if (UNBOUNDP (subtable))
|
|
2110 {
|
|
2111 /* For the image instance cache, we do comparisons with EQ rather
|
|
2112 than with EQUAL, as we do for color and font names.
|
|
2113 The reasons are:
|
|
2114
|
|
2115 1) pixmap data can be very long, and thus the hashing and
|
|
2116 comparing will take awhile.
|
|
2117 2) It's not so likely that we'll run into things that are EQUAL
|
|
2118 but not EQ (that can happen a lot with faces, because their
|
|
2119 specifiers are copied around); but pixmaps tend not to be
|
|
2120 in faces.
|
|
2121
|
|
2122 However, if the image-instance could be a pointer, we have to
|
|
2123 use EQUAL because we massaged the instantiator into a cons3
|
|
2124 also containing the foreground and background of the
|
|
2125 pointer face.
|
|
2126 */
|
|
2127
|
|
2128 subtable = make_lisp_hashtable (20,
|
|
2129 pointerp ? HASHTABLE_KEY_CAR_WEAK
|
|
2130 : HASHTABLE_KEY_WEAK,
|
|
2131 pointerp ? HASHTABLE_EQUAL
|
|
2132 : HASHTABLE_EQ);
|
|
2133 Fputhash (make_int (dest_mask), subtable,
|
|
2134 d->image_instance_cache);
|
|
2135 instance = Qunbound;
|
|
2136 }
|
|
2137 else
|
|
2138 instance = Fgethash (pointerp ? ls3 : instantiator,
|
|
2139 subtable, Qunbound);
|
|
2140
|
|
2141 if (UNBOUNDP (instance))
|
|
2142 {
|
|
2143 Lisp_Object locative =
|
|
2144 noseeum_cons (Qnil,
|
|
2145 noseeum_cons (pointerp ? ls3 : instantiator,
|
|
2146 subtable));
|
|
2147 int speccount = specpdl_depth ();
|
|
2148
|
|
2149 /* make sure we cache the failures, too.
|
|
2150 Use an unwind-protect to catch such errors.
|
|
2151 If we fail, the unwind-protect records nil in
|
|
2152 the hash table. If we succeed, we change the
|
|
2153 car of the locative to the resulting instance,
|
|
2154 which gets recorded instead. */
|
|
2155 record_unwind_protect (image_instantiate_cache_result,
|
|
2156 locative);
|
|
2157 instance = instantiate_image_instantiator (device,
|
124
|
2158 domain,
|
0
|
2159 instantiator,
|
|
2160 pointer_fg, pointer_bg,
|
|
2161 dest_mask);
|
|
2162 Fsetcar (locative, instance);
|
|
2163 unbind_to (speccount, Qnil);
|
|
2164 }
|
|
2165 else
|
|
2166 free_list (ls3);
|
|
2167
|
|
2168 if (NILP (instance))
|
|
2169 signal_simple_error ("Can't instantiate image (probably cached)",
|
|
2170 instantiator);
|
|
2171 return instance;
|
|
2172 }
|
|
2173
|
|
2174 abort ();
|
|
2175 return Qnil; /* not reached */
|
|
2176 }
|
|
2177
|
|
2178 /* Validate an image instantiator. */
|
|
2179
|
|
2180 static void
|
|
2181 image_validate (Lisp_Object instantiator)
|
|
2182 {
|
|
2183 if (IMAGE_INSTANCEP (instantiator) || STRINGP (instantiator))
|
|
2184 return;
|
|
2185 else if (VECTORP (instantiator))
|
|
2186 {
|
173
|
2187 Lisp_Object *elt = XVECTOR_DATA (instantiator);
|
|
2188 int instantiator_len = XVECTOR_LENGTH (instantiator);
|
0
|
2189 struct image_instantiator_methods *meths;
|
|
2190 Lisp_Object already_seen = Qnil;
|
|
2191 struct gcpro gcpro1;
|
|
2192 int i;
|
|
2193
|
|
2194 if (instantiator_len < 1)
|
|
2195 signal_simple_error ("Vector length must be at least 1",
|
|
2196 instantiator);
|
|
2197
|
|
2198 meths = decode_image_instantiator_format (elt[0], ERROR_ME);
|
|
2199 if (!(instantiator_len & 1))
|
|
2200 signal_simple_error
|
|
2201 ("Must have alternating keyword/value pairs", instantiator);
|
|
2202
|
|
2203 GCPRO1 (already_seen);
|
|
2204
|
|
2205 for (i = 1; i < instantiator_len; i += 2)
|
|
2206 {
|
|
2207 Lisp_Object keyword = elt[i];
|
|
2208 Lisp_Object value = elt[i+1];
|
|
2209 int j;
|
|
2210
|
|
2211 CHECK_SYMBOL (keyword);
|
|
2212 if (!SYMBOL_IS_KEYWORD (keyword))
|
|
2213 signal_simple_error ("Symbol must begin with a colon", keyword);
|
|
2214
|
|
2215 for (j = 0; j < Dynarr_length (meths->keywords); j++)
|
|
2216 if (EQ (keyword, Dynarr_at (meths->keywords, j).keyword))
|
|
2217 break;
|
|
2218
|
|
2219 if (j == Dynarr_length (meths->keywords))
|
|
2220 signal_simple_error ("Unrecognized keyword", keyword);
|
|
2221
|
|
2222 if (!Dynarr_at (meths->keywords, j).multiple_p)
|
|
2223 {
|
|
2224 if (!NILP (memq_no_quit (keyword, already_seen)))
|
|
2225 signal_simple_error
|
|
2226 ("Keyword may not appear more than once", keyword);
|
|
2227 already_seen = Fcons (keyword, already_seen);
|
|
2228 }
|
|
2229
|
|
2230 (Dynarr_at (meths->keywords, j).validate) (value);
|
|
2231 }
|
|
2232
|
|
2233 UNGCPRO;
|
|
2234
|
|
2235 MAYBE_IIFORMAT_METH (meths, validate, (instantiator));
|
|
2236 }
|
|
2237 else
|
|
2238 signal_simple_error ("Must be string or vector", instantiator);
|
|
2239 }
|
|
2240
|
|
2241 static void
|
|
2242 image_after_change (Lisp_Object specifier, Lisp_Object locale)
|
|
2243 {
|
|
2244 Lisp_Object attachee =
|
|
2245 IMAGE_SPECIFIER_ATTACHEE (XIMAGE_SPECIFIER (specifier));
|
|
2246 Lisp_Object property =
|
|
2247 IMAGE_SPECIFIER_ATTACHEE_PROPERTY (XIMAGE_SPECIFIER (specifier));
|
|
2248 if (FACEP (attachee))
|
|
2249 face_property_was_changed (attachee, property, locale);
|
|
2250 else if (GLYPHP (attachee))
|
|
2251 glyph_property_was_changed (attachee, property, locale);
|
|
2252 }
|
|
2253
|
|
2254 void
|
|
2255 set_image_attached_to (Lisp_Object obj, Lisp_Object face_or_glyph,
|
|
2256 Lisp_Object property)
|
|
2257 {
|
|
2258 struct Lisp_Specifier *image = XIMAGE_SPECIFIER (obj);
|
|
2259
|
|
2260 IMAGE_SPECIFIER_ATTACHEE (image) = face_or_glyph;
|
|
2261 IMAGE_SPECIFIER_ATTACHEE_PROPERTY (image) = property;
|
|
2262 }
|
|
2263
|
|
2264 static Lisp_Object
|
|
2265 image_going_to_add (Lisp_Object specifier, Lisp_Object locale,
|
|
2266 Lisp_Object tag_set, Lisp_Object instantiator)
|
|
2267 {
|
|
2268 Lisp_Object possible_console_types = Qnil;
|
|
2269 Lisp_Object rest;
|
|
2270 Lisp_Object retlist = Qnil;
|
|
2271 struct gcpro gcpro1, gcpro2;
|
|
2272
|
|
2273 LIST_LOOP (rest, Vconsole_type_list)
|
|
2274 {
|
|
2275 Lisp_Object contype = XCAR (rest);
|
|
2276 if (!NILP (memq_no_quit (contype, tag_set)))
|
|
2277 possible_console_types = Fcons (contype, possible_console_types);
|
|
2278 }
|
|
2279
|
|
2280 if (XINT (Flength (possible_console_types)) > 1)
|
|
2281 /* two conflicting console types specified */
|
|
2282 return Qnil;
|
|
2283
|
|
2284 if (NILP (possible_console_types))
|
|
2285 possible_console_types = Vconsole_type_list;
|
|
2286
|
|
2287 GCPRO2 (retlist, possible_console_types);
|
|
2288
|
|
2289 LIST_LOOP (rest, possible_console_types)
|
|
2290 {
|
|
2291 Lisp_Object contype = XCAR (rest);
|
272
|
2292 Lisp_Object newinst = call_with_suspended_errors
|
74
|
2293 ((lisp_fn_t) normalize_image_instantiator,
|
|
2294 Qnil, Qimage, ERROR_ME_NOT, 3, instantiator, contype,
|
|
2295 make_int (XIMAGE_SPECIFIER_ALLOWED (specifier)));
|
84
|
2296
|
0
|
2297 if (!NILP (newinst))
|
|
2298 {
|
|
2299 Lisp_Object newtag;
|
|
2300 if (NILP (memq_no_quit (contype, tag_set)))
|
|
2301 newtag = Fcons (contype, tag_set);
|
|
2302 else
|
|
2303 newtag = tag_set;
|
|
2304 retlist = Fcons (Fcons (newtag, newinst), retlist);
|
|
2305 }
|
|
2306 }
|
|
2307
|
|
2308 UNGCPRO;
|
|
2309
|
|
2310 return retlist;
|
|
2311 }
|
|
2312
|
20
|
2313 DEFUN ("image-specifier-p", Fimage_specifier_p, 1, 1, 0, /*
|
0
|
2314 Return non-nil if OBJECT is an image specifier.
|
|
2315
|
|
2316 An image specifier is used for images (pixmaps and the like). It is used
|
|
2317 to describe the actual image in a glyph. It is instanced as an image-
|
|
2318 instance.
|
|
2319
|
|
2320 Image instantiators come in many formats: `xbm', `xpm', `gif', `jpeg',
|
|
2321 etc. This describes the format of the data describing the image. The
|
|
2322 resulting image instances also come in many types -- `mono-pixmap',
|
|
2323 `color-pixmap', `text', `pointer', etc. This refers to the behavior of
|
|
2324 the image and the sorts of places it can appear. (For example, a
|
|
2325 color-pixmap image has fixed colors specified for it, while a
|
185
|
2326 mono-pixmap image comes in two unspecified shades "foreground" and
|
|
2327 "background" that are determined from the face of the glyph or
|
0
|
2328 surrounding text; a text image appears as a string of text and has an
|
|
2329 unspecified foreground, background, and font; a pointer image behaves
|
|
2330 like a mono-pixmap image but can only be used as a mouse pointer
|
|
2331 \[mono-pixmap images cannot be used as mouse pointers]; etc.) It is
|
|
2332 important to keep the distinction between image instantiator format and
|
|
2333 image instance type in mind. Typically, a given image instantiator
|
|
2334 format can result in many different image instance types (for example,
|
|
2335 `xpm' can be instanced as `color-pixmap', `mono-pixmap', or `pointer';
|
|
2336 whereas `cursor-font' can be instanced only as `pointer'), and a
|
|
2337 particular image instance type can be generated by many different
|
|
2338 image instantiator formats (e.g. `color-pixmap' can be generated by `xpm',
|
|
2339 `gif', `jpeg', etc.).
|
|
2340
|
|
2341 See `make-image-instance' for a more detailed discussion of image
|
|
2342 instance types.
|
|
2343
|
|
2344 An image instantiator should be a string or a vector of the form
|
|
2345
|
|
2346 [FORMAT :KEYWORD VALUE ...]
|
|
2347
|
|
2348 i.e. a format symbol followed by zero or more alternating keyword-value
|
|
2349 pairs. FORMAT should be one of
|
|
2350
|
|
2351 'nothing
|
|
2352 (Don't display anything; no keywords are valid for this.
|
|
2353 Can only be instanced as `nothing'.)
|
|
2354 'string
|
|
2355 (Display this image as a text string. Can only be instanced
|
|
2356 as `text', although support for instancing as `mono-pixmap'
|
|
2357 should be added.)
|
|
2358 'formatted-string
|
|
2359 (Display this image as a text string, with replaceable fields;
|
|
2360 not currently implemented.)
|
|
2361 'xbm
|
|
2362 (An X bitmap; only if X support was compiled into this XEmacs.
|
|
2363 Can be instanced as `mono-pixmap', `color-pixmap', or `pointer'.)
|
|
2364 'xpm
|
|
2365 (An XPM pixmap; only if XPM support was compiled into this XEmacs.
|
|
2366 Can be instanced as `color-pixmap', `mono-pixmap', or `pointer'.)
|
|
2367 'xface
|
|
2368 (An X-Face bitmap, used to encode people's faces in e-mail messages;
|
|
2369 only if X-Face support was compiled into this XEmacs. Can be
|
|
2370 instanced as `mono-pixmap', `color-pixmap', or `pointer'.)
|
|
2371 'gif
|
|
2372 (A GIF87 or GIF89 image; only if GIF support was compiled into this
|
308
|
2373 XEmacs. NOTE: only the first frame of animated gifs will be displayed.
|
|
2374 Can be instanced as `color-pixmap'.)
|
0
|
2375 'jpeg
|
|
2376 (A JPEG image; only if JPEG support was compiled into this XEmacs.
|
|
2377 Can be instanced as `color-pixmap'.)
|
|
2378 'png
|
308
|
2379 (A PNG image; only if PNG support was compiled into this XEmacs.
|
0
|
2380 Can be instanced as `color-pixmap'.)
|
|
2381 'tiff
|
308
|
2382 (A TIFF image; only if TIFF support was compiled into this XEmacs.
|
|
2383 Can be instanced as `color-pixmap'.)
|
0
|
2384 'cursor-font
|
185
|
2385 (One of the standard cursor-font names, such as "watch" or
|
|
2386 "right_ptr" under X. Under X, this is, more specifically, any
|
0
|
2387 of the standard cursor names from appendix B of the Xlib manual
|
|
2388 [also known as the file <X11/cursorfont.h>] minus the XC_ prefix.
|
|
2389 On other window systems, the valid names will be specific to the
|
|
2390 type of window system. Can only be instanced as `pointer'.)
|
|
2391 'font
|
|
2392 (A glyph from a font; i.e. the name of a font, and glyph index into it
|
185
|
2393 of the form "FONT fontname index [[mask-font] mask-index]".
|
0
|
2394 Currently can only be instanced as `pointer', although this should
|
|
2395 probably be fixed.)
|
|
2396 'subwindow
|
|
2397 (An embedded X window; not currently implemented.)
|
122
|
2398 'autodetect
|
0
|
2399 (XEmacs tries to guess what format the data is in. If X support
|
|
2400 exists, the data string will be checked to see if it names a filename.
|
|
2401 If so, and this filename contains XBM or XPM data, the appropriate
|
|
2402 sort of pixmap or pointer will be created. [This includes picking up
|
|
2403 any specified hotspot or associated mask file.] Otherwise, if `pointer'
|
|
2404 is one of the allowable image-instance types and the string names a
|
|
2405 valid cursor-font name, the image will be created as a pointer.
|
|
2406 Otherwise, the image will be displayed as text. If no X support
|
|
2407 exists, the image will always be displayed as text.)
|
|
2408 'inherit
|
|
2409 Inherit from the background-pixmap property of a face.
|
|
2410
|
|
2411 The valid keywords are:
|
|
2412
|
|
2413 :data
|
|
2414 (Inline data. For most formats above, this should be a string. For
|
|
2415 XBM images, this should be a list of three elements: width, height, and
|
|
2416 a string of bit data. This keyword is not valid for instantiator
|
|
2417 formats `nothing' and `inherit'.)
|
|
2418 :file
|
|
2419 (Data is contained in a file. The value is the name of this file.
|
|
2420 If both :data and :file are specified, the image is created from
|
|
2421 what is specified in :data and the string in :file becomes the
|
|
2422 value of the `image-instance-file-name' function when applied to
|
|
2423 the resulting image-instance. This keyword is not valid for
|
|
2424 instantiator formats `nothing', `string', `formatted-string',
|
122
|
2425 `cursor-font', `font', `autodetect', and `inherit'.)
|
0
|
2426 :foreground
|
|
2427 :background
|
|
2428 (For `xbm', `xface', `cursor-font', and `font'. These keywords
|
|
2429 allow you to explicitly specify foreground and background colors.
|
|
2430 The argument should be anything acceptable to `make-color-instance'.
|
|
2431 This will cause what would be a `mono-pixmap' to instead be colorized
|
|
2432 as a two-color color-pixmap, and specifies the foreground and/or
|
|
2433 background colors for a pointer instead of black and white.)
|
|
2434 :mask-data
|
|
2435 (For `xbm' and `xface'. This specifies a mask to be used with the
|
|
2436 bitmap. The format is a list of width, height, and bits, like for
|
|
2437 :data.)
|
|
2438 :mask-file
|
|
2439 (For `xbm' and `xface'. This specifies a file containing the mask data.
|
|
2440 If neither a mask file nor inline mask data is given for an XBM image,
|
|
2441 and the XBM image comes from a file, XEmacs will look for a mask file
|
185
|
2442 with the same name as the image file but with "Mask" or "msk"
|
|
2443 appended. For example, if you specify the XBM file "left_ptr"
|
|
2444 [usually located in "/usr/include/X11/bitmaps"], the associated
|
|
2445 mask file "left_ptrmsk" will automatically be picked up.)
|
0
|
2446 :hotspot-x
|
|
2447 :hotspot-y
|
|
2448 (For `xbm' and `xface'. These keywords specify a hotspot if the image
|
|
2449 is instantiated as a `pointer'. Note that if the XBM image file
|
|
2450 specifies a hotspot, it will automatically be picked up if no
|
|
2451 explicit hotspot is given.)
|
|
2452 :color-symbols
|
|
2453 (Only for `xpm'. This specifies an alist that maps strings
|
|
2454 that specify symbolic color names to the actual color to be used
|
|
2455 for that symbolic color (in the form of a string or a color-specifier
|
|
2456 object). If this is not specified, the contents of `xpm-color-symbols'
|
|
2457 are used to generate the alist.)
|
|
2458 :face
|
|
2459 (Only for `inherit'. This specifies the face to inherit from.)
|
|
2460
|
|
2461 If instead of a vector, the instantiator is a string, it will be
|
|
2462 converted into a vector by looking it up according to the specs in the
|
|
2463 `console-type-image-conversion-list' (q.v.) for the console type of
|
|
2464 the domain (usually a window; sometimes a frame or device) over which
|
|
2465 the image is being instantiated.
|
|
2466
|
|
2467 If the instantiator specifies data from a file, the data will be read
|
|
2468 in at the time that the instantiator is added to the image (which may
|
|
2469 be well before when the image is actually displayed), and the
|
|
2470 instantiator will be converted into one of the inline-data forms, with
|
|
2471 the filename retained using a :file keyword. This implies that the
|
|
2472 file must exist when the instantiator is added to the image, but does
|
|
2473 not need to exist at any other time (e.g. it may safely be a temporary
|
|
2474 file).
|
20
|
2475 */
|
|
2476 (object))
|
0
|
2477 {
|
173
|
2478 return IMAGE_SPECIFIERP (object) ? Qt : Qnil;
|
0
|
2479 }
|
|
2480
|
|
2481
|
|
2482 /****************************************************************************
|
|
2483 * Glyph Object *
|
|
2484 ****************************************************************************/
|
|
2485
|
|
2486 static Lisp_Object
|
|
2487 mark_glyph (Lisp_Object obj, void (*markobj) (Lisp_Object))
|
|
2488 {
|
272
|
2489 struct Lisp_Glyph *glyph = XGLYPH (obj);
|
0
|
2490
|
|
2491 ((markobj) (glyph->image));
|
|
2492 ((markobj) (glyph->contrib_p));
|
|
2493 ((markobj) (glyph->baseline));
|
|
2494 ((markobj) (glyph->face));
|
|
2495
|
173
|
2496 return glyph->plist;
|
0
|
2497 }
|
|
2498
|
|
2499 static void
|
|
2500 print_glyph (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
2501 {
|
|
2502 struct Lisp_Glyph *glyph = XGLYPH (obj);
|
|
2503 char buf[20];
|
|
2504
|
|
2505 if (print_readably)
|
|
2506 error ("printing unreadable object #<glyph 0x%x>", glyph->header.uid);
|
|
2507
|
|
2508 write_c_string ("#<glyph (", printcharfun);
|
|
2509 print_internal (Fglyph_type (obj), printcharfun, 0);
|
|
2510 write_c_string (") ", printcharfun);
|
|
2511 print_internal (glyph->image, printcharfun, 1);
|
|
2512 sprintf (buf, "0x%x>", glyph->header.uid);
|
|
2513 write_c_string (buf, printcharfun);
|
|
2514 }
|
|
2515
|
|
2516 /* Glyphs are equal if all of their display attributes are equal. We
|
|
2517 don't compare names or doc-strings, because that would make equal
|
|
2518 be eq.
|
|
2519
|
|
2520 This isn't concerned with "unspecified" attributes, that's what
|
|
2521 #'glyph-differs-from-default-p is for. */
|
|
2522 static int
|
|
2523 glyph_equal (Lisp_Object o1, Lisp_Object o2, int depth)
|
|
2524 {
|
|
2525 struct Lisp_Glyph *g1 = XGLYPH (o1);
|
|
2526 struct Lisp_Glyph *g2 = XGLYPH (o2);
|
|
2527
|
|
2528 depth++;
|
|
2529
|
185
|
2530 return (internal_equal (g1->image, g2->image, depth) &&
|
|
2531 internal_equal (g1->contrib_p, g2->contrib_p, depth) &&
|
|
2532 internal_equal (g1->baseline, g2->baseline, depth) &&
|
|
2533 internal_equal (g1->face, g2->face, depth) &&
|
|
2534 !plists_differ (g1->plist, g2->plist, 0, 0, depth + 1));
|
0
|
2535 }
|
|
2536
|
|
2537 static unsigned long
|
|
2538 glyph_hash (Lisp_Object obj, int depth)
|
|
2539 {
|
|
2540 depth++;
|
|
2541
|
|
2542 /* No need to hash all of the elements; that would take too long.
|
|
2543 Just hash the most common ones. */
|
185
|
2544 return HASH2 (internal_hash (XGLYPH (obj)->image, depth),
|
|
2545 internal_hash (XGLYPH (obj)->face, depth));
|
0
|
2546 }
|
|
2547
|
|
2548 static Lisp_Object
|
|
2549 glyph_getprop (Lisp_Object obj, Lisp_Object prop)
|
|
2550 {
|
|
2551 struct Lisp_Glyph *g = XGLYPH (obj);
|
272
|
2552
|
185
|
2553 if (EQ (prop, Qimage)) return g->image;
|
|
2554 if (EQ (prop, Qcontrib_p)) return g->contrib_p;
|
|
2555 if (EQ (prop, Qbaseline)) return g->baseline;
|
|
2556 if (EQ (prop, Qface)) return g->face;
|
0
|
2557
|
|
2558 return external_plist_get (&g->plist, prop, 0, ERROR_ME);
|
|
2559 }
|
|
2560
|
|
2561 static int
|
|
2562 glyph_putprop (Lisp_Object obj, Lisp_Object prop, Lisp_Object value)
|
|
2563 {
|
185
|
2564 if ((EQ (prop, Qimage)) ||
|
|
2565 (EQ (prop, Qcontrib_p)) ||
|
|
2566 (EQ (prop, Qbaseline)))
|
|
2567 return 0;
|
0
|
2568
|
|
2569 if (EQ (prop, Qface))
|
|
2570 {
|
185
|
2571 XGLYPH (obj)->face = Fget_face (value);
|
0
|
2572 return 1;
|
|
2573 }
|
|
2574
|
185
|
2575 external_plist_put (&XGLYPH (obj)->plist, prop, value, 0, ERROR_ME);
|
0
|
2576 return 1;
|
|
2577 }
|
|
2578
|
|
2579 static int
|
|
2580 glyph_remprop (Lisp_Object obj, Lisp_Object prop)
|
|
2581 {
|
185
|
2582 if ((EQ (prop, Qimage)) ||
|
|
2583 (EQ (prop, Qcontrib_p)) ||
|
|
2584 (EQ (prop, Qbaseline)))
|
|
2585 return -1;
|
0
|
2586
|
|
2587 if (EQ (prop, Qface))
|
|
2588 {
|
185
|
2589 XGLYPH (obj)->face = Qnil;
|
0
|
2590 return 1;
|
|
2591 }
|
|
2592
|
185
|
2593 return external_remprop (&XGLYPH (obj)->plist, prop, 0, ERROR_ME);
|
0
|
2594 }
|
|
2595
|
|
2596 static Lisp_Object
|
|
2597 glyph_plist (Lisp_Object obj)
|
|
2598 {
|
272
|
2599 struct Lisp_Glyph *glyph = XGLYPH (obj);
|
|
2600 Lisp_Object result = glyph->plist;
|
|
2601
|
|
2602 result = cons3 (Qface, glyph->face, result);
|
|
2603 result = cons3 (Qbaseline, glyph->baseline, result);
|
|
2604 result = cons3 (Qcontrib_p, glyph->contrib_p, result);
|
|
2605 result = cons3 (Qimage, glyph->image, result);
|
|
2606
|
|
2607 return result;
|
0
|
2608 }
|
|
2609
|
272
|
2610 DEFINE_LRECORD_IMPLEMENTATION_WITH_PROPS ("glyph", glyph,
|
|
2611 mark_glyph, print_glyph, 0,
|
|
2612 glyph_equal, glyph_hash,
|
|
2613 glyph_getprop, glyph_putprop,
|
|
2614 glyph_remprop, glyph_plist,
|
|
2615 struct Lisp_Glyph);
|
|
2616
|
0
|
2617 Lisp_Object
|
|
2618 allocate_glyph (enum glyph_type type,
|
|
2619 void (*after_change) (Lisp_Object glyph, Lisp_Object property,
|
|
2620 Lisp_Object locale))
|
|
2621 {
|
249
|
2622 /* This function can GC */
|
0
|
2623 Lisp_Object obj = Qnil;
|
|
2624 struct Lisp_Glyph *g =
|
185
|
2625 alloc_lcrecord_type (struct Lisp_Glyph, lrecord_glyph);
|
173
|
2626
|
0
|
2627 g->type = type;
|
249
|
2628 g->image = Fmake_specifier (Qimage); /* This function can GC */
|
0
|
2629 switch (g->type)
|
|
2630 {
|
|
2631 case GLYPH_BUFFER:
|
|
2632 XIMAGE_SPECIFIER_ALLOWED (g->image) =
|
|
2633 IMAGE_NOTHING_MASK | IMAGE_TEXT_MASK | IMAGE_MONO_PIXMAP_MASK |
|
|
2634 IMAGE_COLOR_PIXMAP_MASK | IMAGE_SUBWINDOW_MASK;
|
|
2635 break;
|
|
2636 case GLYPH_POINTER:
|
|
2637 XIMAGE_SPECIFIER_ALLOWED (g->image) =
|
|
2638 IMAGE_NOTHING_MASK | IMAGE_POINTER_MASK;
|
|
2639 break;
|
|
2640 case GLYPH_ICON:
|
|
2641 XIMAGE_SPECIFIER_ALLOWED (g->image) =
|
|
2642 IMAGE_NOTHING_MASK | IMAGE_MONO_PIXMAP_MASK | IMAGE_COLOR_PIXMAP_MASK;
|
|
2643 break;
|
|
2644 default:
|
|
2645 abort ();
|
|
2646 }
|
|
2647
|
249
|
2648 /* I think Fmake_specifier can GC. I think set_specifier_fallback can GC. */
|
|
2649 /* We're getting enough reports of odd behavior in this area it seems */
|
|
2650 /* best to GCPRO everything. */
|
|
2651 {
|
|
2652 Lisp_Object tem1 = list1 (Fcons (Qnil, Vthe_nothing_vector));
|
|
2653 Lisp_Object tem2 = list1 (Fcons (Qnil, Qt));
|
|
2654 Lisp_Object tem3 = list1 (Fcons (Qnil, Qnil));
|
|
2655 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
|
2656
|
|
2657 GCPRO4 (obj, tem1, tem2, tem3);
|
|
2658
|
|
2659 set_specifier_fallback (g->image, tem1);
|
|
2660 g->contrib_p = Fmake_specifier (Qboolean);
|
|
2661 set_specifier_fallback (g->contrib_p, tem2);
|
|
2662 /* #### should have a specifier for the following */
|
|
2663 g->baseline = Fmake_specifier (Qgeneric);
|
|
2664 set_specifier_fallback (g->baseline, tem3);
|
|
2665 g->face = Qnil;
|
|
2666 g->plist = Qnil;
|
|
2667 g->after_change = after_change;
|
|
2668 XSETGLYPH (obj, g);
|
|
2669
|
|
2670 set_image_attached_to (g->image, obj, Qimage);
|
|
2671 UNGCPRO;
|
|
2672 }
|
0
|
2673
|
|
2674 return obj;
|
|
2675 }
|
|
2676
|
|
2677 static enum glyph_type
|
|
2678 decode_glyph_type (Lisp_Object type, Error_behavior errb)
|
|
2679 {
|
|
2680 if (NILP (type))
|
|
2681 return GLYPH_BUFFER;
|
|
2682
|
|
2683 if (ERRB_EQ (errb, ERROR_ME))
|
|
2684 CHECK_SYMBOL (type);
|
|
2685
|
185
|
2686 if (EQ (type, Qbuffer)) return GLYPH_BUFFER;
|
|
2687 if (EQ (type, Qpointer)) return GLYPH_POINTER;
|
|
2688 if (EQ (type, Qicon)) return GLYPH_ICON;
|
0
|
2689
|
|
2690 maybe_signal_simple_error ("Invalid glyph type", type, Qimage, errb);
|
185
|
2691
|
0
|
2692 return GLYPH_UNKNOWN;
|
|
2693 }
|
|
2694
|
|
2695 static int
|
|
2696 valid_glyph_type_p (Lisp_Object type)
|
|
2697 {
|
185
|
2698 return !NILP (memq_no_quit (type, Vglyph_type_list));
|
0
|
2699 }
|
|
2700
|
20
|
2701 DEFUN ("valid-glyph-type-p", Fvalid_glyph_type_p, 1, 1, 0, /*
|
0
|
2702 Given a GLYPH-TYPE, return non-nil if it is valid.
|
|
2703 Valid types are `buffer', `pointer', and `icon'.
|
20
|
2704 */
|
|
2705 (glyph_type))
|
0
|
2706 {
|
185
|
2707 return valid_glyph_type_p (glyph_type) ? Qt : Qnil;
|
0
|
2708 }
|
|
2709
|
20
|
2710 DEFUN ("glyph-type-list", Fglyph_type_list, 0, 0, 0, /*
|
0
|
2711 Return a list of valid glyph types.
|
20
|
2712 */
|
|
2713 ())
|
0
|
2714 {
|
|
2715 return Fcopy_sequence (Vglyph_type_list);
|
|
2716 }
|
|
2717
|
20
|
2718 DEFUN ("make-glyph-internal", Fmake_glyph_internal, 0, 1, 0, /*
|
272
|
2719 Create and return a new uninitialized glyph or type TYPE.
|
0
|
2720
|
|
2721 TYPE specifies the type of the glyph; this should be one of `buffer',
|
|
2722 `pointer', or `icon', and defaults to `buffer'. The type of the glyph
|
|
2723 specifies in which contexts the glyph can be used, and controls the
|
|
2724 allowable image types into which the glyph's image can be
|
|
2725 instantiated.
|
|
2726
|
|
2727 `buffer' glyphs can be used as the begin-glyph or end-glyph of an
|
|
2728 extent, in the modeline, and in the toolbar. Their image can be
|
|
2729 instantiated as `nothing', `mono-pixmap', `color-pixmap', `text',
|
|
2730 and `subwindow'.
|
|
2731
|
|
2732 `pointer' glyphs can be used to specify the mouse pointer. Their
|
|
2733 image can be instantiated as `pointer'.
|
|
2734
|
|
2735 `icon' glyphs can be used to specify the icon used when a frame is
|
|
2736 iconified. Their image can be instantiated as `mono-pixmap' and
|
|
2737 `color-pixmap'.
|
20
|
2738 */
|
|
2739 (type))
|
0
|
2740 {
|
|
2741 enum glyph_type typeval = decode_glyph_type (type, ERROR_ME);
|
|
2742 return allocate_glyph (typeval, 0);
|
|
2743 }
|
|
2744
|
20
|
2745 DEFUN ("glyphp", Fglyphp, 1, 1, 0, /*
|
0
|
2746 Return non-nil if OBJECT is a glyph.
|
|
2747
|
|
2748 A glyph is an object used for pixmaps and the like. It is used
|
|
2749 in begin-glyphs and end-glyphs attached to extents, in marginal and textual
|
|
2750 annotations, in overlay arrows (overlay-arrow-* variables), in toolbar
|
|
2751 buttons, and the like. Its image is described using an image specifier --
|
|
2752 see `image-specifier-p'.
|
20
|
2753 */
|
|
2754 (object))
|
0
|
2755 {
|
|
2756 return GLYPHP (object) ? Qt : Qnil;
|
|
2757 }
|
|
2758
|
20
|
2759 DEFUN ("glyph-type", Fglyph_type, 1, 1, 0, /*
|
0
|
2760 Return the type of the given glyph.
|
|
2761 The return value will be one of 'buffer, 'pointer, or 'icon.
|
20
|
2762 */
|
|
2763 (glyph))
|
0
|
2764 {
|
|
2765 CHECK_GLYPH (glyph);
|
|
2766 switch (XGLYPH_TYPE (glyph))
|
|
2767 {
|
185
|
2768 case GLYPH_BUFFER: return Qbuffer;
|
|
2769 case GLYPH_POINTER: return Qpointer;
|
|
2770 case GLYPH_ICON: return Qicon;
|
0
|
2771 default:
|
|
2772 abort ();
|
185
|
2773 return Qnil; /* not reached */
|
0
|
2774 }
|
|
2775 }
|
|
2776
|
|
2777 /*****************************************************************************
|
|
2778 glyph_width
|
|
2779
|
|
2780 Return the width of the given GLYPH on the given WINDOW. If the
|
|
2781 instance is a string then the width is calculated using the font of
|
|
2782 the given FACE, unless a face is defined by the glyph itself.
|
|
2783 ****************************************************************************/
|
|
2784 unsigned short
|
|
2785 glyph_width (Lisp_Object glyph, Lisp_Object frame_face,
|
|
2786 face_index window_findex, Lisp_Object window)
|
|
2787 {
|
|
2788 Lisp_Object instance;
|
|
2789 Lisp_Object frame = XWINDOW (window)->frame;
|
|
2790
|
|
2791 /* #### We somehow need to distinguish between the user causing this
|
|
2792 error condition and a bug causing it. */
|
|
2793 if (!GLYPHP (glyph))
|
|
2794 return 0;
|
|
2795 else
|
|
2796 instance = glyph_image_instance (glyph, window, ERROR_ME_NOT, 1);
|
|
2797
|
|
2798 if (!IMAGE_INSTANCEP (instance))
|
|
2799 return 0;
|
|
2800
|
|
2801 switch (XIMAGE_INSTANCE_TYPE (instance))
|
|
2802 {
|
|
2803 case IMAGE_TEXT:
|
|
2804 {
|
|
2805 Lisp_Object str = XIMAGE_INSTANCE_TEXT_STRING (instance);
|
|
2806 Lisp_Object private_face = XGLYPH_FACE(glyph);
|
|
2807
|
|
2808 if (!NILP (private_face))
|
173
|
2809 return redisplay_frame_text_width_string (XFRAME (frame),
|
|
2810 private_face,
|
|
2811 0, str, 0, -1);
|
0
|
2812 else
|
|
2813 if (!NILP (frame_face))
|
173
|
2814 return redisplay_frame_text_width_string (XFRAME (frame),
|
|
2815 frame_face,
|
|
2816 0, str, 0, -1);
|
0
|
2817 else
|
173
|
2818 return redisplay_text_width_string (XWINDOW (window),
|
|
2819 window_findex,
|
|
2820 0, str, 0, -1);
|
0
|
2821 }
|
|
2822
|
|
2823 case IMAGE_MONO_PIXMAP:
|
|
2824 case IMAGE_COLOR_PIXMAP:
|
|
2825 case IMAGE_POINTER:
|
|
2826 return XIMAGE_INSTANCE_PIXMAP_WIDTH (instance);
|
|
2827
|
|
2828 case IMAGE_NOTHING:
|
|
2829 return 0;
|
|
2830
|
|
2831 case IMAGE_SUBWINDOW:
|
|
2832 /* #### implement me */
|
|
2833 return 0;
|
|
2834
|
|
2835 default:
|
|
2836 abort ();
|
|
2837 return 0;
|
|
2838 }
|
|
2839 }
|
|
2840
|
20
|
2841 DEFUN ("glyph-width", Fglyph_width, 1, 2, 0, /*
|
0
|
2842 Return the width of GLYPH on WINDOW.
|
|
2843 This may not be exact as it does not take into account all of the context
|
|
2844 that redisplay will.
|
20
|
2845 */
|
|
2846 (glyph, window))
|
0
|
2847 {
|
|
2848 XSETWINDOW (window, decode_window (window));
|
|
2849 CHECK_GLYPH (glyph);
|
|
2850
|
173
|
2851 return make_int (glyph_width (glyph, Qnil, DEFAULT_INDEX, window));
|
0
|
2852 }
|
|
2853
|
|
2854 #define RETURN_ASCENT 0
|
|
2855 #define RETURN_DESCENT 1
|
|
2856 #define RETURN_HEIGHT 2
|
|
2857
|
|
2858 Lisp_Object
|
|
2859 glyph_image_instance (Lisp_Object glyph, Lisp_Object domain,
|
|
2860 Error_behavior errb, int no_quit)
|
|
2861 {
|
|
2862 Lisp_Object specifier = GLYPH_IMAGE (XGLYPH (glyph));
|
|
2863
|
|
2864 /* This can never return Qunbound. All glyphs have 'nothing as
|
|
2865 a fallback. */
|
|
2866 return specifier_instance (specifier, Qunbound, domain, errb, no_quit, 0,
|
|
2867 Qzero);
|
|
2868 }
|
|
2869
|
|
2870 static unsigned short
|
|
2871 glyph_height_internal (Lisp_Object glyph, Lisp_Object frame_face,
|
|
2872 face_index window_findex, Lisp_Object window,
|
|
2873 int function)
|
|
2874 {
|
|
2875 Lisp_Object instance;
|
|
2876 Lisp_Object frame = XWINDOW (window)->frame;
|
|
2877
|
|
2878 if (!GLYPHP (glyph))
|
|
2879 return 0;
|
|
2880 else
|
|
2881 instance = glyph_image_instance (glyph, window, ERROR_ME_NOT, 1);
|
|
2882
|
|
2883 if (!IMAGE_INSTANCEP (instance))
|
|
2884 return 0;
|
|
2885
|
|
2886 switch (XIMAGE_INSTANCE_TYPE (instance))
|
|
2887 {
|
|
2888 case IMAGE_TEXT:
|
|
2889 {
|
|
2890 struct font_metric_info fm;
|
|
2891 Lisp_Object string = XIMAGE_INSTANCE_TEXT_STRING (instance);
|
|
2892 unsigned char charsets[NUM_LEADING_BYTES];
|
|
2893 struct face_cachel frame_cachel;
|
|
2894 struct face_cachel *cachel;
|
|
2895
|
|
2896 find_charsets_in_bufbyte_string (charsets,
|
82
|
2897 XSTRING_DATA (string),
|
14
|
2898 XSTRING_LENGTH (string));
|
0
|
2899
|
|
2900 if (!NILP (frame_face))
|
|
2901 {
|
|
2902 reset_face_cachel (&frame_cachel);
|
|
2903 update_face_cachel_data (&frame_cachel, frame, frame_face);
|
|
2904 cachel = &frame_cachel;
|
|
2905 }
|
|
2906 else
|
|
2907 cachel = WINDOW_FACE_CACHEL (XWINDOW (window), window_findex);
|
|
2908 ensure_face_cachel_complete (cachel, window, charsets);
|
|
2909
|
|
2910 face_cachel_charset_font_metric_info (cachel, charsets, &fm);
|
173
|
2911
|
185
|
2912 switch (function)
|
|
2913 {
|
|
2914 case RETURN_ASCENT: return fm.ascent;
|
|
2915 case RETURN_DESCENT: return fm.descent;
|
|
2916 case RETURN_HEIGHT: return fm.ascent + fm.descent;
|
|
2917 default:
|
|
2918 abort ();
|
|
2919 return 0; /* not reached */
|
|
2920 }
|
0
|
2921 }
|
|
2922
|
|
2923 case IMAGE_MONO_PIXMAP:
|
|
2924 case IMAGE_COLOR_PIXMAP:
|
|
2925 case IMAGE_POINTER:
|
|
2926 /* #### Ugh ugh ugh -- temporary crap */
|
|
2927 if (function == RETURN_ASCENT || function == RETURN_HEIGHT)
|
|
2928 return XIMAGE_INSTANCE_PIXMAP_HEIGHT (instance);
|
|
2929 else
|
|
2930 return 0;
|
|
2931
|
|
2932 case IMAGE_NOTHING:
|
|
2933 return 0;
|
|
2934
|
|
2935 case IMAGE_SUBWINDOW:
|
|
2936 /* #### implement me */
|
|
2937 return 0;
|
|
2938
|
|
2939 default:
|
|
2940 abort ();
|
|
2941 return 0;
|
|
2942 }
|
|
2943 }
|
|
2944
|
|
2945 unsigned short
|
|
2946 glyph_ascent (Lisp_Object glyph, Lisp_Object frame_face,
|
|
2947 face_index window_findex, Lisp_Object window)
|
|
2948 {
|
|
2949 return glyph_height_internal (glyph, frame_face, window_findex, window,
|
|
2950 RETURN_ASCENT);
|
|
2951 }
|
|
2952
|
|
2953 unsigned short
|
|
2954 glyph_descent (Lisp_Object glyph, Lisp_Object frame_face,
|
|
2955 face_index window_findex, Lisp_Object window)
|
|
2956 {
|
|
2957 return glyph_height_internal (glyph, frame_face, window_findex, window,
|
|
2958 RETURN_DESCENT);
|
|
2959 }
|
|
2960
|
|
2961 /* strictly a convenience function. */
|
|
2962 unsigned short
|
|
2963 glyph_height (Lisp_Object glyph, Lisp_Object frame_face,
|
|
2964 face_index window_findex, Lisp_Object window)
|
|
2965 {
|
|
2966 return glyph_height_internal (glyph, frame_face, window_findex, window,
|
|
2967 RETURN_HEIGHT);
|
|
2968 }
|
|
2969
|
20
|
2970 DEFUN ("glyph-ascent", Fglyph_ascent, 1, 2, 0, /*
|
0
|
2971 Return the ascent value of GLYPH on WINDOW.
|
|
2972 This may not be exact as it does not take into account all of the context
|
|
2973 that redisplay will.
|
20
|
2974 */
|
|
2975 (glyph, window))
|
0
|
2976 {
|
|
2977 XSETWINDOW (window, decode_window (window));
|
|
2978 CHECK_GLYPH (glyph);
|
|
2979
|
173
|
2980 return make_int (glyph_ascent (glyph, Qnil, DEFAULT_INDEX, window));
|
0
|
2981 }
|
|
2982
|
20
|
2983 DEFUN ("glyph-descent", Fglyph_descent, 1, 2, 0, /*
|
0
|
2984 Return the descent value of GLYPH on WINDOW.
|
|
2985 This may not be exact as it does not take into account all of the context
|
|
2986 that redisplay will.
|
20
|
2987 */
|
|
2988 (glyph, window))
|
0
|
2989 {
|
|
2990 XSETWINDOW (window, decode_window (window));
|
|
2991 CHECK_GLYPH (glyph);
|
|
2992
|
173
|
2993 return make_int (glyph_descent (glyph, Qnil, DEFAULT_INDEX, window));
|
0
|
2994 }
|
|
2995
|
|
2996 /* This is redundant but I bet a lot of people expect it to exist. */
|
20
|
2997 DEFUN ("glyph-height", Fglyph_height, 1, 2, 0, /*
|
0
|
2998 Return the height of GLYPH on WINDOW.
|
|
2999 This may not be exact as it does not take into account all of the context
|
|
3000 that redisplay will.
|
20
|
3001 */
|
|
3002 (glyph, window))
|
0
|
3003 {
|
|
3004 XSETWINDOW (window, decode_window (window));
|
|
3005 CHECK_GLYPH (glyph);
|
|
3006
|
173
|
3007 return make_int (glyph_height (glyph, Qnil, DEFAULT_INDEX, window));
|
0
|
3008 }
|
|
3009
|
|
3010 #undef RETURN_ASCENT
|
|
3011 #undef RETURN_DESCENT
|
|
3012 #undef RETURN_HEIGHT
|
|
3013
|
|
3014 /* #### do we need to cache this info to speed things up? */
|
|
3015
|
|
3016 Lisp_Object
|
|
3017 glyph_baseline (Lisp_Object glyph, Lisp_Object domain)
|
|
3018 {
|
|
3019 if (!GLYPHP (glyph))
|
|
3020 return Qnil;
|
|
3021 else
|
|
3022 {
|
|
3023 Lisp_Object retval =
|
|
3024 specifier_instance_no_quit (GLYPH_BASELINE (XGLYPH (glyph)),
|
|
3025 /* #### look into ERROR_ME_NOT */
|
|
3026 Qunbound, domain, ERROR_ME_NOT,
|
|
3027 0, Qzero);
|
|
3028 if (!NILP (retval) && !INTP (retval))
|
|
3029 retval = Qnil;
|
|
3030 else if (INTP (retval))
|
|
3031 {
|
|
3032 if (XINT (retval) < 0)
|
|
3033 retval = Qzero;
|
|
3034 if (XINT (retval) > 100)
|
|
3035 retval = make_int (100);
|
|
3036 }
|
|
3037 return retval;
|
|
3038 }
|
|
3039 }
|
|
3040
|
|
3041 Lisp_Object
|
|
3042 glyph_face (Lisp_Object glyph, Lisp_Object domain)
|
|
3043 {
|
|
3044 /* #### Domain parameter not currently used but it will be */
|
185
|
3045 return GLYPHP (glyph) ? GLYPH_FACE (XGLYPH (glyph)) : Qnil;
|
0
|
3046 }
|
|
3047
|
|
3048 int
|
|
3049 glyph_contrib_p (Lisp_Object glyph, Lisp_Object domain)
|
|
3050 {
|
|
3051 if (!GLYPHP (glyph))
|
|
3052 return 0;
|
|
3053 else
|
173
|
3054 return !NILP (specifier_instance_no_quit
|
|
3055 (GLYPH_CONTRIB_P (XGLYPH (glyph)), Qunbound, domain,
|
|
3056 /* #### look into ERROR_ME_NOT */
|
|
3057 ERROR_ME_NOT, 0, Qzero));
|
0
|
3058 }
|
|
3059
|
|
3060 static void
|
|
3061 glyph_property_was_changed (Lisp_Object glyph, Lisp_Object property,
|
|
3062 Lisp_Object locale)
|
|
3063 {
|
|
3064 if (XGLYPH (glyph)->after_change)
|
|
3065 (XGLYPH (glyph)->after_change) (glyph, property, locale);
|
|
3066 }
|
|
3067
|
|
3068
|
|
3069 /*****************************************************************************
|
|
3070 * glyph cachel functions *
|
|
3071 *****************************************************************************/
|
|
3072
|
|
3073 /*
|
|
3074 #### All of this is 95% copied from face cachels.
|
|
3075 Consider consolidating.
|
|
3076 #### We need to add a dirty flag to the glyphs.
|
|
3077 */
|
|
3078
|
|
3079 void
|
|
3080 mark_glyph_cachels (glyph_cachel_dynarr *elements,
|
|
3081 void (*markobj) (Lisp_Object))
|
|
3082 {
|
|
3083 int elt;
|
|
3084
|
|
3085 if (!elements)
|
|
3086 return;
|
|
3087
|
|
3088 for (elt = 0; elt < Dynarr_length (elements); elt++)
|
|
3089 {
|
|
3090 struct glyph_cachel *cachel = Dynarr_atp (elements, elt);
|
|
3091 ((markobj) (cachel->glyph));
|
|
3092 }
|
|
3093 }
|
|
3094
|
|
3095 static void
|
|
3096 update_glyph_cachel_data (struct window *w, Lisp_Object glyph,
|
|
3097 struct glyph_cachel *cachel)
|
|
3098 {
|
|
3099 /* #### This should be || !cachel->updated */
|
|
3100 if (NILP (cachel->glyph) || !EQ (cachel->glyph, glyph))
|
|
3101 {
|
272
|
3102 Lisp_Object window;
|
0
|
3103
|
|
3104 XSETWINDOW (window, w);
|
|
3105
|
|
3106 /* #### This could be sped up if we redid things to grab the glyph
|
|
3107 instantiation and passed it to the size functions. */
|
185
|
3108 cachel->glyph = glyph;
|
|
3109 cachel->width = glyph_width (glyph, Qnil, DEFAULT_INDEX, window);
|
|
3110 cachel->ascent = glyph_ascent (glyph, Qnil, DEFAULT_INDEX, window);
|
|
3111 cachel->descent = glyph_descent (glyph, Qnil, DEFAULT_INDEX, window);
|
0
|
3112 }
|
|
3113
|
|
3114 cachel->updated = 1;
|
|
3115 }
|
|
3116
|
|
3117 static void
|
|
3118 add_glyph_cachel (struct window *w, Lisp_Object glyph)
|
|
3119 {
|
|
3120 struct glyph_cachel new_cachel;
|
|
3121
|
272
|
3122 xzero (new_cachel);
|
0
|
3123 new_cachel.glyph = Qnil;
|
|
3124
|
|
3125 update_glyph_cachel_data (w, glyph, &new_cachel);
|
|
3126 Dynarr_add (w->glyph_cachels, new_cachel);
|
|
3127 }
|
|
3128
|
|
3129 static glyph_index
|
|
3130 get_glyph_cachel_index (struct window *w, Lisp_Object glyph)
|
|
3131 {
|
|
3132 int elt;
|
|
3133
|
|
3134 if (noninteractive)
|
|
3135 return 0;
|
|
3136
|
|
3137 for (elt = 0; elt < Dynarr_length (w->glyph_cachels); elt++)
|
|
3138 {
|
|
3139 struct glyph_cachel *cachel =
|
|
3140 Dynarr_atp (w->glyph_cachels, elt);
|
|
3141
|
|
3142 if (EQ (cachel->glyph, glyph) && !NILP (glyph))
|
|
3143 {
|
|
3144 if (!cachel->updated)
|
|
3145 update_glyph_cachel_data (w, glyph, cachel);
|
|
3146 return elt;
|
|
3147 }
|
|
3148 }
|
|
3149
|
|
3150 /* If we didn't find the glyph, add it and then return its index. */
|
|
3151 add_glyph_cachel (w, glyph);
|
|
3152 return elt;
|
|
3153 }
|
|
3154
|
|
3155 void
|
|
3156 reset_glyph_cachels (struct window *w)
|
|
3157 {
|
|
3158 Dynarr_reset (w->glyph_cachels);
|
|
3159 get_glyph_cachel_index (w, Vcontinuation_glyph);
|
|
3160 get_glyph_cachel_index (w, Vtruncation_glyph);
|
|
3161 get_glyph_cachel_index (w, Vhscroll_glyph);
|
|
3162 get_glyph_cachel_index (w, Vcontrol_arrow_glyph);
|
|
3163 get_glyph_cachel_index (w, Voctal_escape_glyph);
|
|
3164 get_glyph_cachel_index (w, Vinvisible_text_glyph);
|
|
3165 }
|
|
3166
|
|
3167 void
|
|
3168 mark_glyph_cachels_as_not_updated (struct window *w)
|
|
3169 {
|
|
3170 int elt;
|
|
3171
|
|
3172 /* We need to have a dirty flag to tell if the glyph has changed.
|
|
3173 We can check to see if each glyph variable is actually a
|
|
3174 completely different glyph, though. */
|
|
3175 #define FROB(glyph_obj, gindex) \
|
|
3176 update_glyph_cachel_data (w, glyph_obj, \
|
|
3177 Dynarr_atp (w->glyph_cachels, gindex))
|
|
3178
|
|
3179 FROB (Vcontinuation_glyph, CONT_GLYPH_INDEX);
|
|
3180 FROB (Vtruncation_glyph, TRUN_GLYPH_INDEX);
|
|
3181 FROB (Vhscroll_glyph, HSCROLL_GLYPH_INDEX);
|
|
3182 FROB (Vcontrol_arrow_glyph, CONTROL_GLYPH_INDEX);
|
|
3183 FROB (Voctal_escape_glyph, OCT_ESC_GLYPH_INDEX);
|
|
3184 FROB (Vinvisible_text_glyph, INVIS_GLYPH_INDEX);
|
|
3185 #undef FROB
|
|
3186
|
|
3187 for (elt = 0; elt < Dynarr_length (w->glyph_cachels); elt++)
|
|
3188 Dynarr_atp (w->glyph_cachels, elt)->updated = 0;
|
|
3189 }
|
|
3190
|
|
3191 #ifdef MEMORY_USAGE_STATS
|
|
3192
|
|
3193 int
|
|
3194 compute_glyph_cachel_usage (glyph_cachel_dynarr *glyph_cachels,
|
|
3195 struct overhead_stats *ovstats)
|
|
3196 {
|
|
3197 int total = 0;
|
|
3198
|
|
3199 if (glyph_cachels)
|
|
3200 total += Dynarr_memory_usage (glyph_cachels, ovstats);
|
|
3201
|
|
3202 return total;
|
|
3203 }
|
|
3204
|
|
3205 #endif /* MEMORY_USAGE_STATS */
|
|
3206
|
|
3207
|
|
3208 /*****************************************************************************
|
|
3209 * display tables *
|
|
3210 *****************************************************************************/
|
|
3211
|
|
3212 /* Get the display table for use currently on window W with face FACE.
|
|
3213 Precedence:
|
|
3214
|
|
3215 -- FACE's display table
|
|
3216 -- W's display table (comes from specifier `current-display-table')
|
|
3217
|
|
3218 Ignore the specified tables if they are not valid;
|
|
3219 if no valid table is specified, return 0. */
|
|
3220
|
|
3221 struct Lisp_Vector *
|
|
3222 get_display_table (struct window *w, face_index findex)
|
|
3223 {
|
272
|
3224 Lisp_Object tem;
|
0
|
3225
|
|
3226 tem = WINDOW_FACE_CACHEL_DISPLAY_TABLE (w, findex);
|
173
|
3227 if (VECTORP (tem) && XVECTOR_LENGTH (tem) == DISP_TABLE_SIZE)
|
0
|
3228 return XVECTOR (tem);
|
|
3229
|
|
3230 tem = w->display_table;
|
173
|
3231 if (VECTORP (tem) && XVECTOR_LENGTH (tem) == DISP_TABLE_SIZE)
|
0
|
3232 return XVECTOR (tem);
|
|
3233
|
|
3234 return 0;
|
|
3235 }
|
|
3236
|
|
3237
|
|
3238 /*****************************************************************************
|
|
3239 * initialization *
|
|
3240 *****************************************************************************/
|
|
3241
|
|
3242 void
|
|
3243 syms_of_glyphs (void)
|
|
3244 {
|
|
3245 /* image instantiators */
|
|
3246
|
20
|
3247 DEFSUBR (Fimage_instantiator_format_list);
|
|
3248 DEFSUBR (Fvalid_image_instantiator_format_p);
|
|
3249 DEFSUBR (Fset_console_type_image_conversion_list);
|
|
3250 DEFSUBR (Fconsole_type_image_conversion_list);
|
0
|
3251
|
|
3252 defkeyword (&Q_file, ":file");
|
|
3253 defkeyword (&Q_data, ":data");
|
|
3254 defkeyword (&Q_face, ":face");
|
|
3255
|
276
|
3256 #ifdef HAVE_XPM
|
|
3257 defkeyword (&Q_color_symbols, ":color-symbols");
|
|
3258 #endif
|
288
|
3259 #ifdef HAVE_WINDOW_SYSTEM
|
|
3260 defkeyword (&Q_mask_file, ":mask-file");
|
|
3261 defkeyword (&Q_mask_data, ":mask-data");
|
|
3262 defkeyword (&Q_hotspot_x, ":hotspot-x");
|
|
3263 defkeyword (&Q_hotspot_y, ":hotspot-y");
|
|
3264 defkeyword (&Q_foreground, ":foreground");
|
|
3265 defkeyword (&Q_background, ":background");
|
|
3266 #endif
|
0
|
3267 /* image specifiers */
|
|
3268
|
20
|
3269 DEFSUBR (Fimage_specifier_p);
|
0
|
3270 /* Qimage in general.c */
|
|
3271
|
|
3272 /* image instances */
|
|
3273
|
|
3274 defsymbol (&Qimage_instancep, "image-instance-p");
|
|
3275
|
|
3276 defsymbol (&Qnothing_image_instance_p, "nothing-image-instance-p");
|
|
3277 defsymbol (&Qtext_image_instance_p, "text-image-instance-p");
|
|
3278 defsymbol (&Qmono_pixmap_image_instance_p, "mono-pixmap-image-instance-p");
|
|
3279 defsymbol (&Qcolor_pixmap_image_instance_p, "color-pixmap-image-instance-p");
|
|
3280 defsymbol (&Qpointer_image_instance_p, "pointer-image-instance-p");
|
|
3281 defsymbol (&Qsubwindow_image_instance_p, "subwindow-image-instance-p");
|
|
3282
|
20
|
3283 DEFSUBR (Fmake_image_instance);
|
|
3284 DEFSUBR (Fimage_instance_p);
|
|
3285 DEFSUBR (Fimage_instance_type);
|
|
3286 DEFSUBR (Fvalid_image_instance_type_p);
|
|
3287 DEFSUBR (Fimage_instance_type_list);
|
|
3288 DEFSUBR (Fimage_instance_name);
|
|
3289 DEFSUBR (Fimage_instance_string);
|
|
3290 DEFSUBR (Fimage_instance_file_name);
|
|
3291 DEFSUBR (Fimage_instance_mask_file_name);
|
|
3292 DEFSUBR (Fimage_instance_depth);
|
|
3293 DEFSUBR (Fimage_instance_height);
|
|
3294 DEFSUBR (Fimage_instance_width);
|
|
3295 DEFSUBR (Fimage_instance_hotspot_x);
|
|
3296 DEFSUBR (Fimage_instance_hotspot_y);
|
|
3297 DEFSUBR (Fimage_instance_foreground);
|
|
3298 DEFSUBR (Fimage_instance_background);
|
|
3299 DEFSUBR (Fcolorize_image_instance);
|
0
|
3300
|
|
3301 /* Qnothing defined as part of the "nothing" image-instantiator
|
|
3302 type. */
|
|
3303 /* Qtext defined in general.c */
|
|
3304 defsymbol (&Qmono_pixmap, "mono-pixmap");
|
|
3305 defsymbol (&Qcolor_pixmap, "color-pixmap");
|
|
3306 /* Qpointer defined in general.c */
|
|
3307 defsymbol (&Qsubwindow, "subwindow");
|
|
3308
|
|
3309 /* glyphs */
|
|
3310
|
|
3311 defsymbol (&Qglyphp, "glyphp");
|
|
3312 defsymbol (&Qcontrib_p, "contrib-p");
|
|
3313 defsymbol (&Qbaseline, "baseline");
|
|
3314
|
|
3315 defsymbol (&Qbuffer_glyph_p, "buffer-glyph-p");
|
|
3316 defsymbol (&Qpointer_glyph_p, "pointer-glyph-p");
|
|
3317 defsymbol (&Qicon_glyph_p, "icon-glyph-p");
|
|
3318
|
|
3319 defsymbol (&Qconst_glyph_variable, "const-glyph-variable");
|
|
3320
|
20
|
3321 DEFSUBR (Fglyph_type);
|
|
3322 DEFSUBR (Fvalid_glyph_type_p);
|
|
3323 DEFSUBR (Fglyph_type_list);
|
|
3324 DEFSUBR (Fglyphp);
|
|
3325 DEFSUBR (Fmake_glyph_internal);
|
|
3326 DEFSUBR (Fglyph_width);
|
|
3327 DEFSUBR (Fglyph_ascent);
|
|
3328 DEFSUBR (Fglyph_descent);
|
|
3329 DEFSUBR (Fglyph_height);
|
0
|
3330
|
|
3331 /* Qbuffer defined in general.c. */
|
|
3332 /* Qpointer defined above */
|
269
|
3333
|
|
3334 /* Errors */
|
|
3335 deferror (&Qimage_conversion_error,
|
|
3336 "image-conversion-error",
|
|
3337 "image-conversion error", Qio_error);
|
|
3338
|
0
|
3339 }
|
|
3340
|
|
3341 void
|
|
3342 specifier_type_create_image (void)
|
|
3343 {
|
|
3344 /* image specifiers */
|
|
3345
|
|
3346 INITIALIZE_SPECIFIER_TYPE_WITH_DATA (image, "image", "imagep");
|
|
3347
|
|
3348 SPECIFIER_HAS_METHOD (image, create);
|
|
3349 SPECIFIER_HAS_METHOD (image, mark);
|
|
3350 SPECIFIER_HAS_METHOD (image, instantiate);
|
|
3351 SPECIFIER_HAS_METHOD (image, validate);
|
|
3352 SPECIFIER_HAS_METHOD (image, after_change);
|
|
3353 SPECIFIER_HAS_METHOD (image, going_to_add);
|
|
3354 }
|
|
3355
|
|
3356 void
|
|
3357 image_instantiator_format_create (void)
|
|
3358 {
|
|
3359 /* image instantiators */
|
|
3360
|
|
3361 the_image_instantiator_format_entry_dynarr =
|
185
|
3362 Dynarr_new (image_instantiator_format_entry);
|
0
|
3363
|
|
3364 Vimage_instantiator_format_list = Qnil;
|
|
3365 staticpro (&Vimage_instantiator_format_list);
|
|
3366
|
|
3367 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (nothing, "nothing");
|
|
3368
|
|
3369 IIFORMAT_HAS_METHOD (nothing, possible_dest_types);
|
|
3370 IIFORMAT_HAS_METHOD (nothing, instantiate);
|
|
3371
|
|
3372 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (inherit, "inherit");
|
|
3373
|
|
3374 IIFORMAT_HAS_METHOD (inherit, validate);
|
|
3375 IIFORMAT_HAS_METHOD (inherit, normalize);
|
|
3376 IIFORMAT_HAS_METHOD (inherit, possible_dest_types);
|
|
3377 IIFORMAT_HAS_METHOD (inherit, instantiate);
|
|
3378
|
|
3379 IIFORMAT_VALID_KEYWORD (inherit, Q_face, check_valid_face);
|
|
3380
|
|
3381 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (string, "string");
|
|
3382
|
|
3383 IIFORMAT_HAS_METHOD (string, validate);
|
|
3384 IIFORMAT_HAS_METHOD (string, possible_dest_types);
|
|
3385 IIFORMAT_HAS_METHOD (string, instantiate);
|
|
3386
|
|
3387 IIFORMAT_VALID_KEYWORD (string, Q_data, check_valid_string);
|
|
3388
|
|
3389 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (formatted_string, "formatted-string");
|
|
3390
|
|
3391 IIFORMAT_HAS_METHOD (formatted_string, validate);
|
|
3392 IIFORMAT_HAS_METHOD (formatted_string, possible_dest_types);
|
|
3393 IIFORMAT_HAS_METHOD (formatted_string, instantiate);
|
|
3394
|
|
3395 IIFORMAT_VALID_KEYWORD (formatted_string, Q_data, check_valid_string);
|
276
|
3396
|
288
|
3397 #ifdef HAVE_WINDOW_SYSTEM
|
|
3398 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (xbm, "xbm");
|
|
3399
|
|
3400 IIFORMAT_HAS_METHOD (xbm, validate);
|
|
3401 IIFORMAT_HAS_METHOD (xbm, normalize);
|
|
3402 IIFORMAT_HAS_METHOD (xbm, possible_dest_types);
|
|
3403 IIFORMAT_HAS_METHOD (xbm, instantiate);
|
|
3404
|
|
3405 IIFORMAT_VALID_KEYWORD (xbm, Q_data, check_valid_xbm_inline);
|
|
3406 IIFORMAT_VALID_KEYWORD (xbm, Q_file, check_valid_string);
|
|
3407 IIFORMAT_VALID_KEYWORD (xbm, Q_mask_data, check_valid_xbm_inline);
|
|
3408 IIFORMAT_VALID_KEYWORD (xbm, Q_mask_file, check_valid_string);
|
|
3409 IIFORMAT_VALID_KEYWORD (xbm, Q_hotspot_x, check_valid_int);
|
|
3410 IIFORMAT_VALID_KEYWORD (xbm, Q_hotspot_y, check_valid_int);
|
|
3411 IIFORMAT_VALID_KEYWORD (xbm, Q_foreground, check_valid_string);
|
|
3412 IIFORMAT_VALID_KEYWORD (xbm, Q_background, check_valid_string);
|
|
3413 #endif /* HAVE_WINDOW_SYSTEM */
|
|
3414
|
276
|
3415 #ifdef HAVE_XPM
|
|
3416 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (xpm, "xpm");
|
|
3417
|
|
3418 IIFORMAT_HAS_METHOD (xpm, validate);
|
|
3419 IIFORMAT_HAS_METHOD (xpm, normalize);
|
|
3420 IIFORMAT_HAS_METHOD (xpm, possible_dest_types);
|
|
3421 IIFORMAT_HAS_METHOD (xpm, instantiate);
|
|
3422
|
|
3423 IIFORMAT_VALID_KEYWORD (xpm, Q_data, check_valid_string);
|
|
3424 IIFORMAT_VALID_KEYWORD (xpm, Q_file, check_valid_string);
|
|
3425 IIFORMAT_VALID_KEYWORD (xpm, Q_color_symbols, check_valid_xpm_color_symbols);
|
284
|
3426 #endif /* HAVE_XPM */
|
0
|
3427 }
|
|
3428
|
|
3429 void
|
|
3430 vars_of_glyphs (void)
|
|
3431 {
|
|
3432 Vthe_nothing_vector = vector1 (Qnothing);
|
|
3433 staticpro (&Vthe_nothing_vector);
|
|
3434
|
|
3435 /* image instances */
|
|
3436
|
|
3437 Vimage_instance_type_list = list6 (Qnothing, Qtext, Qmono_pixmap,
|
|
3438 Qcolor_pixmap, Qpointer, Qsubwindow);
|
|
3439 staticpro (&Vimage_instance_type_list);
|
|
3440
|
|
3441 /* glyphs */
|
|
3442
|
|
3443 Vglyph_type_list = list3 (Qbuffer, Qpointer, Qicon);
|
|
3444 staticpro (&Vglyph_type_list);
|
|
3445
|
|
3446 /* The octal-escape glyph, control-arrow-glyph and
|
|
3447 invisible-text-glyph are completely initialized in glyphs.el */
|
|
3448
|
|
3449 DEFVAR_LISP ("octal-escape-glyph", &Voctal_escape_glyph /*
|
|
3450 What to prefix character codes displayed in octal with.
|
|
3451 */);
|
|
3452 Voctal_escape_glyph = allocate_glyph (GLYPH_BUFFER, redisplay_glyph_changed);
|
|
3453
|
|
3454 DEFVAR_LISP ("control-arrow-glyph", &Vcontrol_arrow_glyph /*
|
|
3455 What to use as an arrow for control characters.
|
|
3456 */);
|
|
3457 Vcontrol_arrow_glyph = allocate_glyph (GLYPH_BUFFER,
|
|
3458 redisplay_glyph_changed);
|
|
3459
|
|
3460 DEFVAR_LISP ("invisible-text-glyph", &Vinvisible_text_glyph /*
|
|
3461 What to use to indicate the presence of invisible text.
|
|
3462 This is the glyph that is displayed when an ellipsis is called for
|
|
3463 \(see `selective-display-ellipses' and `buffer-invisibility-spec').
|
185
|
3464 Normally this is three dots ("...").
|
0
|
3465 */);
|
|
3466 Vinvisible_text_glyph = allocate_glyph (GLYPH_BUFFER,
|
|
3467 redisplay_glyph_changed);
|
|
3468
|
|
3469 /* Partially initialized in glyphs.el */
|
|
3470 DEFVAR_LISP ("hscroll-glyph", &Vhscroll_glyph /*
|
|
3471 What to display at the beginning of horizontally scrolled lines.
|
|
3472 */);
|
|
3473 Vhscroll_glyph = allocate_glyph (GLYPH_BUFFER, redisplay_glyph_changed);
|
276
|
3474
|
|
3475 #ifdef HAVE_XPM
|
|
3476 Fprovide (Qxpm);
|
|
3477
|
|
3478 DEFVAR_LISP ("xpm-color-symbols", &Vxpm_color_symbols /*
|
|
3479 Definitions of logical color-names used when reading XPM files.
|
|
3480 Elements of this list should be of the form (COLOR-NAME FORM-TO-EVALUATE).
|
|
3481 The COLOR-NAME should be a string, which is the name of the color to define;
|
|
3482 the FORM should evaluate to a `color' specifier object, or a string to be
|
|
3483 passed to `make-color-instance'. If a loaded XPM file references a symbolic
|
|
3484 color called COLOR-NAME, it will display as the computed color instead.
|
|
3485
|
|
3486 The default value of this variable defines the logical color names
|
|
3487 \"foreground\" and \"background\" to be the colors of the `default' face.
|
|
3488 */ );
|
|
3489 Vxpm_color_symbols = Qnil; /* initialized in x-faces.el */
|
284
|
3490 #endif /* HAVE_XPM */
|
0
|
3491 }
|
|
3492
|
|
3493 void
|
|
3494 specifier_vars_of_glyphs (void)
|
|
3495 {
|
249
|
3496 /* #### Can we GC here? The set_specifier_* calls definitely need */
|
|
3497 /* protection. */
|
0
|
3498 /* display tables */
|
|
3499
|
|
3500 DEFVAR_SPECIFIER ("current-display-table", &Vcurrent_display_table /*
|
|
3501 *The display table currently in use.
|
|
3502 This is a specifier; use `set-specifier' to change it.
|
|
3503 The display table is a vector created with `make-display-table'.
|
|
3504 The 256 elements control how to display each possible text character.
|
|
3505 Each value should be a string, a glyph, a vector or nil.
|
|
3506 If a value is a vector it must be composed only of strings and glyphs.
|
|
3507 nil means display the character in the default fashion.
|
|
3508 Faces can have their own, overriding display table.
|
|
3509 */ );
|
116
|
3510 Vcurrent_display_table = Fmake_specifier (Qdisplay_table);
|
0
|
3511 set_specifier_fallback (Vcurrent_display_table,
|
|
3512 list1 (Fcons (Qnil, Qnil)));
|
|
3513 set_specifier_caching (Vcurrent_display_table,
|
|
3514 slot_offset (struct window,
|
|
3515 display_table),
|
|
3516 some_window_value_changed,
|
|
3517 0, 0);
|
|
3518 }
|
|
3519
|
|
3520 void
|
|
3521 complex_vars_of_glyphs (void)
|
|
3522 {
|
|
3523 /* Partially initialized in glyphs-x.c, glyphs.el */
|
|
3524 DEFVAR_LISP ("truncation-glyph", &Vtruncation_glyph /*
|
|
3525 What to display at the end of truncated lines.
|
|
3526 */ );
|
|
3527 Vtruncation_glyph = allocate_glyph (GLYPH_BUFFER, redisplay_glyph_changed);
|
|
3528
|
|
3529 /* Partially initialized in glyphs-x.c, glyphs.el */
|
|
3530 DEFVAR_LISP ("continuation-glyph", &Vcontinuation_glyph /*
|
|
3531 What to display at the end of wrapped lines.
|
|
3532 */ );
|
|
3533 Vcontinuation_glyph = allocate_glyph (GLYPH_BUFFER, redisplay_glyph_changed);
|
|
3534
|
|
3535 /* Partially initialized in glyphs-x.c, glyphs.el */
|
|
3536 DEFVAR_LISP ("xemacs-logo", &Vxemacs_logo /*
|
|
3537 The glyph used to display the XEmacs logo at startup.
|
|
3538 */ );
|
|
3539 Vxemacs_logo = allocate_glyph (GLYPH_BUFFER, 0);
|
|
3540 }
|