0
|
1 /* X-specific Lisp objects.
|
|
2 Copyright (C) 1993, 1994 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1995 Board of Trustees, University of Illinois.
|
|
4 Copyright (C) 1995 Tinker Systems.
|
|
5 Copyright (C) 1995, 1996 Ben Wing.
|
|
6 Copyright (C) 1995 Sun Microsystems, Inc.
|
|
7
|
|
8 This file is part of XEmacs.
|
|
9
|
|
10 XEmacs is free software; you can redistribute it and/or modify it
|
|
11 under the terms of the GNU General Public License as published by the
|
|
12 Free Software Foundation; either version 2, or (at your option) any
|
|
13 later version.
|
|
14
|
|
15 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
18 for more details.
|
|
19
|
|
20 You should have received a copy of the GNU General Public License
|
|
21 along with XEmacs; see the file COPYING. If not, write to
|
|
22 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
23 Boston, MA 02111-1307, USA. */
|
|
24
|
|
25 /* Synched up with: Not in FSF. */
|
|
26
|
|
27 /* Authors: Jamie Zawinski, Chuck Thompson, Ben Wing */
|
|
28
|
|
29 #include <config.h>
|
|
30 #include "lisp.h"
|
|
31
|
|
32 #include "console-x.h"
|
|
33 #include "objects-x.h"
|
|
34
|
|
35 #include "buffer.h"
|
|
36 #include "device.h"
|
|
37 #include "insdel.h"
|
|
38
|
|
39 int handle_nonfull_spec_fonts;
|
|
40
|
|
41
|
|
42 /************************************************************************/
|
|
43 /* color instances */
|
|
44 /************************************************************************/
|
|
45
|
|
46 /* Replacement for XAllocColor() that tries to return the nearest
|
|
47 available color if the colormap is full. From FSF Emacs. */
|
|
48
|
|
49 int
|
|
50 allocate_nearest_color (Display *display, Colormap screen_colormap,
|
|
51 XColor *color_def)
|
|
52 {
|
|
53 int status;
|
|
54
|
|
55 status = XAllocColor (display, screen_colormap, color_def);
|
|
56 if (!status)
|
|
57 {
|
|
58 /* If we got to this point, the colormap is full, so we're
|
|
59 going to try and get the next closest color.
|
|
60 The algorithm used is a least-squares matching, which is
|
|
61 what X uses for closest color matching with StaticColor visuals. */
|
|
62
|
|
63 XColor *cells;
|
|
64 int no_cells;
|
|
65 int nearest;
|
|
66 long nearest_delta, trial_delta;
|
|
67 int x;
|
|
68
|
|
69 no_cells = XDisplayCells (display, XDefaultScreen (display));
|
|
70 cells = (XColor *) alloca (sizeof (XColor) * no_cells);
|
|
71
|
|
72 for (x = 0; x < no_cells; x++)
|
|
73 cells[x].pixel = x;
|
|
74
|
|
75 XQueryColors (display, screen_colormap, cells, no_cells);
|
|
76 nearest = 0;
|
|
77 /* I'm assuming CSE so I'm not going to condense this. */
|
|
78 nearest_delta = ((((color_def->red >> 8) - (cells[0].red >> 8))
|
|
79 * ((color_def->red >> 8) - (cells[0].red >> 8)))
|
|
80 +
|
|
81 (((color_def->green >> 8) - (cells[0].green >> 8))
|
|
82 * ((color_def->green >> 8) - (cells[0].green >> 8)))
|
|
83 +
|
|
84 (((color_def->blue >> 8) - (cells[0].blue >> 8))
|
|
85 * ((color_def->blue >> 8) - (cells[0].blue >> 8))));
|
|
86 for (x = 1; x < no_cells; x++)
|
|
87 {
|
|
88 trial_delta = ((((color_def->red >> 8) - (cells[x].red >> 8))
|
|
89 * ((color_def->red >> 8) - (cells[x].red >> 8)))
|
|
90 +
|
|
91 (((color_def->green >> 8) - (cells[x].green >> 8))
|
|
92 * ((color_def->green >> 8) - (cells[x].green >> 8)))
|
|
93 +
|
|
94 (((color_def->blue >> 8) - (cells[x].blue >> 8))
|
|
95 * ((color_def->blue >> 8) - (cells[x].blue >> 8))));
|
|
96 if (trial_delta < nearest_delta)
|
|
97 {
|
|
98 nearest = x;
|
|
99 nearest_delta = trial_delta;
|
|
100 }
|
|
101 }
|
|
102 color_def->red = cells[nearest].red;
|
|
103 color_def->green = cells[nearest].green;
|
|
104 color_def->blue = cells[nearest].blue;
|
|
105 status = XAllocColor (display, screen_colormap, color_def);
|
|
106 }
|
|
107
|
|
108 return status;
|
|
109 }
|
|
110
|
|
111 int
|
|
112 x_parse_nearest_color (struct device *d, XColor *color, Bufbyte *name,
|
|
113 Bytecount len, Error_behavior errb)
|
|
114 {
|
|
115 Display *dpy;
|
|
116 Screen *xs;
|
|
117 Colormap cmap;
|
|
118 int result;
|
|
119
|
|
120 dpy = DEVICE_X_DISPLAY (d);
|
|
121 xs = DefaultScreenOfDisplay (dpy);
|
|
122 cmap = DefaultColormapOfScreen (xs);
|
|
123
|
|
124 memset (color, 0, sizeof (*color));
|
|
125 {
|
|
126 CONST Extbyte *extname;
|
|
127 Extcount extnamelen;
|
|
128
|
|
129 GET_CHARPTR_EXT_BINARY_DATA_ALLOCA (name, len, extname, extnamelen);
|
|
130 result = XParseColor (dpy, cmap, (char *) extname, color);
|
|
131 }
|
|
132 if (!result)
|
|
133 {
|
|
134 maybe_signal_simple_error ("unrecognized color", make_string (name, len),
|
|
135 Qcolor, errb);
|
|
136 return 0;
|
|
137 }
|
|
138 result = allocate_nearest_color (dpy, cmap, color);
|
|
139 if (!result)
|
|
140 {
|
|
141 maybe_signal_simple_error ("couldn't allocate color",
|
|
142 make_string (name, len), Qcolor, errb);
|
|
143 return 0;
|
|
144 }
|
|
145
|
|
146 return 1;
|
|
147 }
|
|
148
|
|
149 static int
|
|
150 x_initialize_color_instance (struct Lisp_Color_Instance *c, Lisp_Object name,
|
|
151 Lisp_Object device, Error_behavior errb)
|
|
152 {
|
|
153 XColor color;
|
|
154 int result;
|
|
155
|
|
156 result = x_parse_nearest_color (XDEVICE (device), &color,
|
14
|
157 XSTRING_DATA (name),
|
|
158 XSTRING_LENGTH (name),
|
0
|
159 errb);
|
|
160
|
|
161 if (!result)
|
|
162 return 0;
|
|
163
|
|
164 /* Don't allocate the data until we're sure that we will succeed,
|
|
165 or the finalize method may get fucked. */
|
|
166 c->data = malloc_type (struct x_color_instance_data);
|
|
167 COLOR_INSTANCE_X_COLOR (c) = color;
|
|
168 return 1;
|
|
169 }
|
|
170
|
|
171 static void
|
|
172 x_print_color_instance (struct Lisp_Color_Instance *c,
|
|
173 Lisp_Object printcharfun,
|
|
174 int escapeflag)
|
|
175 {
|
|
176 char buf[100];
|
|
177 XColor color = COLOR_INSTANCE_X_COLOR (c);
|
|
178 sprintf (buf, " %ld=(%X,%X,%X)",
|
|
179 color.pixel, color.red, color.green, color.blue);
|
|
180 write_c_string (buf, printcharfun);
|
|
181 }
|
|
182
|
|
183 static void
|
|
184 x_finalize_color_instance (struct Lisp_Color_Instance *c)
|
|
185 {
|
|
186 if (c->data)
|
|
187 {
|
|
188 if (DEVICE_LIVE_P (XDEVICE (c->device)))
|
|
189 {
|
|
190 Display *dpy = DEVICE_X_DISPLAY (XDEVICE (c->device));
|
|
191
|
|
192 XFreeColors (dpy,
|
|
193 DefaultColormapOfScreen (DefaultScreenOfDisplay (dpy)),
|
|
194 &COLOR_INSTANCE_X_COLOR (c).pixel, 1, 0);
|
|
195 }
|
|
196 xfree (c->data);
|
|
197 c->data = 0;
|
|
198 }
|
|
199 }
|
|
200
|
|
201 /* Color instances are equal if they resolve to the same color on the
|
|
202 screen (have the same RGB values). I imagine that
|
|
203 "same RGV values" == "same cell in the colormap." Arguably we should
|
|
204 be comparing their names instead. */
|
|
205
|
|
206 static int
|
|
207 x_color_instance_equal (struct Lisp_Color_Instance *c1,
|
|
208 struct Lisp_Color_Instance *c2,
|
|
209 int depth)
|
|
210 {
|
|
211 XColor color1 = COLOR_INSTANCE_X_COLOR (c1);
|
|
212 XColor color2 = COLOR_INSTANCE_X_COLOR (c2);
|
|
213 return ((color1.red == color2.red) &&
|
|
214 (color1.green == color2.green) &&
|
|
215 (color1.blue == color2.blue));
|
|
216 }
|
|
217
|
|
218 static unsigned long
|
|
219 x_color_instance_hash (struct Lisp_Color_Instance *c, int depth)
|
|
220 {
|
|
221 XColor color = COLOR_INSTANCE_X_COLOR (c);
|
|
222 return HASH3 (color.red, color.green, color.blue);
|
|
223 }
|
|
224
|
|
225 static Lisp_Object
|
|
226 x_color_instance_rgb_components (struct Lisp_Color_Instance *c)
|
|
227 {
|
|
228 XColor color = COLOR_INSTANCE_X_COLOR (c);
|
|
229 return (list3 (make_int (color.red),
|
|
230 make_int (color.green),
|
|
231 make_int (color.blue)));
|
|
232 }
|
|
233
|
|
234 static int
|
|
235 x_valid_color_name_p (struct device *d, Lisp_Object color)
|
|
236 {
|
|
237 XColor c;
|
|
238 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
239 CONST char *extname;
|
|
240
|
|
241 GET_C_STRING_CTEXT_DATA_ALLOCA (color, extname);
|
|
242
|
|
243 return XParseColor (dpy,
|
|
244 DefaultColormapOfScreen (DefaultScreenOfDisplay (dpy)),
|
|
245 extname, &c);
|
|
246 }
|
|
247
|
|
248
|
|
249 /************************************************************************/
|
|
250 /* font instances */
|
|
251 /************************************************************************/
|
|
252
|
|
253 static int
|
|
254 x_initialize_font_instance (struct Lisp_Font_Instance *f, Lisp_Object name,
|
|
255 Lisp_Object device, Error_behavior errb)
|
|
256 {
|
|
257 Display *dpy;
|
|
258 XFontStruct *xf;
|
|
259 CONST char *extname;
|
|
260
|
|
261 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
|
|
262 GET_C_STRING_CTEXT_DATA_ALLOCA (f->name, extname);
|
|
263 xf = XLoadQueryFont (dpy, extname);
|
|
264
|
|
265 if (!xf)
|
|
266 {
|
|
267 maybe_signal_simple_error ("couldn't load font", f->name,
|
|
268 Qfont, errb);
|
|
269 return 0;
|
|
270 }
|
|
271
|
|
272 if (!xf->max_bounds.width)
|
|
273 {
|
|
274 /* yes, this has been known to happen. */
|
|
275 XFreeFont (dpy, xf);
|
|
276 maybe_signal_simple_error ("X font is too small", f->name,
|
|
277 Qfont, errb);
|
|
278 return 0;
|
|
279 }
|
|
280
|
|
281 /* Don't allocate the data until we're sure that we will succeed,
|
|
282 or the finalize method may get fucked. */
|
|
283 f->data = malloc_type (struct x_font_instance_data);
|
|
284 FONT_INSTANCE_X_TRUENAME (f) = Qnil;
|
|
285 FONT_INSTANCE_X_FONT (f) = xf;
|
|
286 f->ascent = xf->ascent;
|
|
287 f->descent = xf->descent;
|
|
288 f->height = xf->ascent + xf->descent;
|
|
289 {
|
14
|
290 /* following change suggested by Ted Phelps <phelps@dstc.edu.au> */
|
|
291 unsigned int def_char = 'n'; /*xf->default_char;*/
|
0
|
292 int byte1, byte2;
|
|
293
|
|
294 once_more:
|
|
295 byte1 = def_char >> 8;
|
|
296 byte2 = def_char & 0xFF;
|
|
297
|
|
298 if (xf->per_char)
|
|
299 {
|
|
300 /* Old versions of the R5 font server have garbage (>63k) as
|
|
301 def_char. 'n' might not be a valid character. */
|
|
302 if (byte1 < xf->min_byte1 || byte1 > xf->max_byte1 ||
|
|
303 byte2 < xf->min_char_or_byte2 || byte2 > xf->max_char_or_byte2)
|
|
304 f->width = 0;
|
|
305 else
|
|
306 f->width = xf->per_char[(byte1 - xf->min_byte1) *
|
|
307 (xf->max_char_or_byte2 -
|
|
308 xf->min_char_or_byte2 + 1) +
|
|
309 (byte2 - xf->min_char_or_byte2)].width;
|
|
310 }
|
|
311 else
|
|
312 f->width = xf->max_bounds.width;
|
|
313
|
|
314 /* Some fonts have a default char whose width is 0. This is no good.
|
|
315 If that's the case, first try 'n' as the default char, and if n has
|
|
316 0 width too (unlikely) then just use the max width. */
|
|
317 if (f->width == 0)
|
|
318 {
|
14
|
319 if (def_char == xf->default_char)
|
0
|
320 f->width = xf->max_bounds.width;
|
|
321 else
|
|
322 {
|
14
|
323 def_char = xf->default_char;
|
0
|
324 goto once_more;
|
|
325 }
|
|
326 }
|
|
327 }
|
|
328 /* If all characters don't exist then there could potentially be
|
|
329 0-width characters lurking out there. Not setting this flag
|
|
330 trips an optimization that would make them appear to have width
|
|
331 to redisplay. This is bad. So we set it if not all characters
|
|
332 have the same width or if not all characters are defined.
|
|
333 */
|
|
334 /* #### This sucks. There is a measurable performance increase
|
|
335 when using proportional width fonts if this flag is not set.
|
|
336 Unfortunately so many of the fucking X fonts are not fully
|
|
337 defined that we could almost just get rid of this damn flag and
|
|
338 make it an assertion. */
|
|
339 f->proportional_p = (xf->min_bounds.width != xf->max_bounds.width ||
|
|
340 (handle_nonfull_spec_fonts &&
|
|
341 !xf->all_chars_exist));
|
|
342
|
|
343 return 1;
|
|
344 }
|
|
345
|
|
346 static void
|
|
347 x_mark_font_instance (struct Lisp_Font_Instance *f,
|
|
348 void (*markobj) (Lisp_Object))
|
|
349 {
|
|
350 ((markobj) (FONT_INSTANCE_X_TRUENAME (f)));
|
|
351 }
|
|
352
|
|
353 static void
|
|
354 x_print_font_instance (struct Lisp_Font_Instance *f,
|
|
355 Lisp_Object printcharfun,
|
|
356 int escapeflag)
|
|
357 {
|
|
358 char buf[200];
|
|
359 sprintf (buf, " 0x%lx", (unsigned long) FONT_INSTANCE_X_FONT (f)->fid);
|
|
360 write_c_string (buf, printcharfun);
|
|
361 }
|
|
362
|
|
363 static void
|
|
364 x_finalize_font_instance (struct Lisp_Font_Instance *f)
|
|
365 {
|
|
366
|
|
367 if (f->data)
|
|
368 {
|
|
369 if (DEVICE_LIVE_P (XDEVICE (f->device)))
|
|
370 {
|
|
371 Display *dpy = DEVICE_X_DISPLAY (XDEVICE (f->device));
|
|
372
|
|
373 XFreeFont (dpy, FONT_INSTANCE_X_FONT (f));
|
|
374 }
|
|
375 xfree (f->data);
|
|
376 f->data = 0;
|
|
377 }
|
|
378 }
|
|
379
|
|
380 /* Determining the truename of a font is hard. (Big surprise.)
|
|
381
|
|
382 By "truename" we mean an XLFD-form name which contains no wildcards, yet
|
|
383 which resolves to *exactly* the same font as the one which we already have
|
|
384 the (probably wildcarded) name and `XFontStruct' of.
|
|
385
|
|
386 One might think that the first font returned by XListFonts would be the one
|
|
387 that XOpenFont would pick. Apparently this is the case on some servers,
|
|
388 but not on others. It would seem not to be specified.
|
|
389
|
|
390 The MIT R5 server sometimes appears to be picking the lexicographically
|
|
391 smallest font which matches the name (thus picking "adobe" fonts before
|
|
392 "bitstream" fonts even if the bitstream fonts are earlier in the path, and
|
|
393 also picking 100dpi adobe fonts over 75dpi adobe fonts even though the
|
|
394 75dpi are in the path earlier) but sometimes appears to be doing something
|
|
395 else entirely (for example, removing the bitsream fonts from the path will
|
|
396 cause the 75dpi adobe fonts to be used instead of the100dpi, even though
|
|
397 their relative positions in the path (and their names!) have not changed).
|
|
398
|
|
399 The documentation for XSetFontPath() seems to indicate that the order of
|
|
400 entries in the font path means something, but it's pretty noncommital about
|
|
401 it, and the spirit of the law is apparently not being obeyed...
|
|
402
|
|
403 All the fonts I've seen have a property named `FONT' which contains the
|
|
404 truename of the font. However, there are two problems with using this: the
|
|
405 first is that the X Protocol Document is quite explicit that all properties
|
|
406 are optional, so we can't depend on it being there. The second is that
|
|
407 it's concievable that this alleged truename isn't actually accessible as a
|
|
408 font, due to some difference of opinion between the font designers and
|
|
409 whoever installed the font on the system.
|
|
410
|
|
411 So, our first attempt is to look for a FONT property, and then verify that
|
|
412 the name there is a valid name by running XListFonts on it. There's still
|
|
413 the potential that this could be true but we could still be being lied to,
|
|
414 but that seems pretty remote.
|
|
415
|
|
416 Late breaking news: I've gotten reports that SunOS 4.1.3U1
|
|
417 with OpenWound 3.0 has a font whose truename is really
|
|
418 "-Adobe-Courier-Medium-R-Normal--12-120-75-75-M-70-ISO8859-1"
|
|
419 but whose FONT property contains "Courier".
|
|
420
|
|
421 So we disbelieve the FONT property unless it begins with a dash and
|
|
422 is more than 30 characters long. X Windows: The defacto substandard.
|
|
423 X Windows: Complex nonsolutions to simple nonproblems. X Windows:
|
|
424 Live the nightmare.
|
|
425
|
|
426 If the FONT property doesn't exist, then we try and construct an XLFD name
|
|
427 out of the other font properties (FOUNDRY, FAMILY_NAME, WEIGHT_NAME, etc).
|
|
428 This is necessary at least for some versions of OpenWound. But who knows
|
|
429 what the future will bring.
|
|
430
|
|
431 If that doesn't work, then we use XListFonts and either take the first font
|
|
432 (which I think is the most sensible thing) or we find the lexicographically
|
|
433 least, depending on whether the preprocessor constant `XOPENFONT_SORTS' is
|
|
434 defined. This sucks because the two behaviors are a property of the server
|
|
435 being used, not the architecture on which emacs has been compiled. Also,
|
|
436 as I described above, sorting isn't ALWAYS what the server does. Really it
|
|
437 does something seemingly random. There is no reliable way to win if the
|
|
438 FONT property isn't present.
|
|
439
|
|
440 Another possibility which I haven't bothered to implement would be to map
|
|
441 over all of the matching fonts and find the first one that has the same
|
|
442 character metrics as the font we already have loaded. Even if this didn't
|
|
443 return exactly the same font, it would at least return one whose characters
|
|
444 were the same sizes, which would probably be good enough.
|
|
445
|
|
446 More late-breaking news: on RS/6000 AIX 3.2.4, the expression
|
|
447 XLoadQueryFont (dpy, "-*-Fixed-Medium-R-*-*-*-130-75-75-*-*-ISO8859-1")
|
|
448 actually returns the font
|
|
449 -Misc-Fixed-Medium-R-Normal--13-120-75-75-C-80-ISO8859-1
|
|
450 which is crazy, because that font doesn't even match that pattern! It is
|
|
451 also not included in the output produced by `xlsfonts' with that pattern.
|
|
452
|
|
453 So this is yet another example of XListFonts() and XOpenFont() using
|
|
454 completely different algorithms. This, however, is a goofier example of
|
|
455 this bug, because in this case, it's not just the search order that is
|
|
456 different -- the sets don't even intersect.
|
|
457
|
|
458 If anyone has any better ideas how to do this, or any insights on what it is
|
|
459 that the various servers are actually doing, please let me know! -- jwz. */
|
|
460
|
|
461 static int
|
|
462 valid_x_font_name_p (Display *dpy, char *name)
|
|
463 {
|
|
464 /* Maybe this should be implemented by callign XLoadFont and trapping
|
|
465 the error. That would be a lot of work, and wasteful as hell, but
|
|
466 might be more correct.
|
|
467 */
|
|
468 int nnames = 0;
|
|
469 char **names = 0;
|
|
470 if (! name)
|
|
471 return 0;
|
|
472 names = XListFonts (dpy, name, 1, &nnames);
|
|
473 if (names)
|
|
474 XFreeFontNames (names);
|
|
475 return (nnames != 0);
|
|
476 }
|
|
477
|
|
478 static char *
|
|
479 truename_via_FONT_prop (Display *dpy, XFontStruct *font)
|
|
480 {
|
|
481 unsigned long value = 0;
|
|
482 char *result = 0;
|
|
483 if (XGetFontProperty (font, XA_FONT, &value))
|
|
484 result = XGetAtomName (dpy, value);
|
|
485 /* result is now 0, or the string value of the FONT property. */
|
|
486 if (result)
|
|
487 {
|
|
488 /* Verify that result is an XLFD name (roughly...) */
|
|
489 if (result [0] != '-' || strlen (result) < (unsigned int) 30)
|
|
490 {
|
|
491 XFree (result);
|
|
492 result = 0;
|
|
493 }
|
|
494 }
|
|
495 return result; /* this must be freed by caller if non-0 */
|
|
496 }
|
|
497
|
|
498 static char *
|
|
499 truename_via_random_props (Display *dpy, XFontStruct *font)
|
|
500 {
|
|
501 struct device *d = get_device_from_display (dpy);
|
|
502 unsigned long value = 0;
|
|
503 char *foundry, *family, *weight, *slant, *setwidth, *add_style;
|
|
504 unsigned long pixel, point, res_x, res_y;
|
|
505 char *spacing;
|
|
506 unsigned long avg_width;
|
|
507 char *registry, *encoding;
|
|
508 char composed_name [2048];
|
|
509 int ok = 0;
|
|
510 char *result;
|
|
511
|
|
512 #define get_string(atom,var) \
|
|
513 if (XGetFontProperty (font, (atom), &value)) \
|
|
514 var = XGetAtomName (dpy, value); \
|
|
515 else { \
|
|
516 var = 0; \
|
|
517 goto FAIL; }
|
|
518 #define get_number(atom,var) \
|
|
519 if (!XGetFontProperty (font, (atom), &var) || \
|
|
520 var > 999) \
|
|
521 goto FAIL;
|
|
522
|
|
523 foundry = family = weight = slant = setwidth = 0;
|
|
524 add_style = spacing = registry = encoding = 0;
|
|
525
|
|
526 get_string (DEVICE_XATOM_FOUNDRY (d), foundry);
|
|
527 get_string (DEVICE_XATOM_FAMILY_NAME (d), family);
|
|
528 get_string (DEVICE_XATOM_WEIGHT_NAME (d), weight);
|
|
529 get_string (DEVICE_XATOM_SLANT (d), slant);
|
|
530 get_string (DEVICE_XATOM_SETWIDTH_NAME (d), setwidth);
|
|
531 get_string (DEVICE_XATOM_ADD_STYLE_NAME (d), add_style);
|
|
532 get_number (DEVICE_XATOM_PIXEL_SIZE (d), pixel);
|
|
533 get_number (DEVICE_XATOM_POINT_SIZE (d), point);
|
|
534 get_number (DEVICE_XATOM_RESOLUTION_X (d), res_x);
|
|
535 get_number (DEVICE_XATOM_RESOLUTION_Y (d), res_y);
|
|
536 get_string (DEVICE_XATOM_SPACING (d), spacing);
|
|
537 get_number (DEVICE_XATOM_AVERAGE_WIDTH (d), avg_width);
|
|
538 get_string (DEVICE_XATOM_CHARSET_REGISTRY (d), registry);
|
|
539 get_string (DEVICE_XATOM_CHARSET_ENCODING (d), encoding);
|
|
540 #undef get_number
|
|
541 #undef get_string
|
|
542
|
|
543 sprintf (composed_name,
|
|
544 "-%s-%s-%s-%s-%s-%s-%ld-%ld-%ld-%ld-%s-%ld-%s-%s",
|
|
545 foundry, family, weight, slant, setwidth, add_style, pixel,
|
|
546 point, res_x, res_y, spacing, avg_width, registry, encoding);
|
|
547 ok = 1;
|
|
548
|
|
549 FAIL:
|
|
550 if (ok)
|
|
551 {
|
|
552 int L = strlen (composed_name) + 1;
|
|
553 result = xmalloc (L);
|
|
554 strncpy (result, composed_name, L);
|
|
555 }
|
|
556 else
|
|
557 result = 0;
|
|
558
|
|
559 if (foundry) XFree (foundry);
|
|
560 if (family) XFree (family);
|
|
561 if (weight) XFree (weight);
|
|
562 if (slant) XFree (slant);
|
|
563 if (setwidth) XFree (setwidth);
|
|
564 if (add_style) XFree (add_style);
|
|
565 if (spacing) XFree (spacing);
|
|
566 if (registry) XFree (registry);
|
|
567 if (encoding) XFree (encoding);
|
|
568
|
|
569 return result;
|
|
570 }
|
|
571
|
|
572 /* Unbounded, for sufficiently small values of infinity... */
|
|
573 #define MAX_FONT_COUNT 5000
|
|
574
|
|
575 static char *
|
|
576 truename_via_XListFonts (Display *dpy, char *font_name)
|
|
577 {
|
|
578 char *result = 0;
|
|
579 char **names;
|
|
580 int count = 0;
|
|
581
|
|
582 #ifndef XOPENFONT_SORTS
|
|
583 /* In a sensible world, the first font returned by XListFonts()
|
|
584 would be the font that XOpenFont() would use. */
|
|
585 names = XListFonts (dpy, font_name, 1, &count);
|
|
586 if (count) result = names [0];
|
|
587 #else
|
|
588 /* But the world I live in is much more perverse. */
|
|
589 names = XListFonts (dpy, font_name, MAX_FONT_COUNT, &count);
|
|
590 while (count--)
|
|
591 /* If names[count] is lexicographically less than result, use it.
|
|
592 (#### Should we be comparing case-insensitively?) */
|
|
593 if (result == 0 || (strcmp (result, names [count]) < 0))
|
|
594 result = names [count];
|
|
595 #endif
|
|
596
|
|
597 if (result)
|
|
598 result = xstrdup (result);
|
|
599 if (names)
|
|
600 XFreeFontNames (names);
|
|
601
|
|
602 return result; /* this must be freed by caller if non-0 */
|
|
603 }
|
|
604
|
|
605 static Lisp_Object
|
|
606 x_font_truename (Display *dpy, char *name, XFontStruct *font)
|
|
607 {
|
|
608 char *truename_FONT = 0;
|
|
609 char *truename_random = 0;
|
|
610 char *truename = 0;
|
|
611
|
|
612 /* The search order is:
|
|
613 - if FONT property exists, and is a valid name, return it.
|
|
614 - if the other props exist, and add up to a valid name, return it.
|
|
615 - if we find a matching name with XListFonts, return it.
|
|
616 - if FONT property exists, return it regardless.
|
|
617 - if other props exist, return the resultant name regardless.
|
|
618 - else return 0.
|
|
619 */
|
|
620
|
|
621 truename = truename_FONT = truename_via_FONT_prop (dpy, font);
|
|
622 if (truename && !valid_x_font_name_p (dpy, truename))
|
|
623 truename = 0;
|
|
624 if (!truename)
|
|
625 truename = truename_random = truename_via_random_props (dpy, font);
|
|
626 if (truename && !valid_x_font_name_p (dpy, truename))
|
|
627 truename = 0;
|
|
628 if (!truename && name)
|
|
629 truename = truename_via_XListFonts (dpy, name);
|
|
630
|
|
631 if (!truename)
|
|
632 {
|
|
633 /* Gag - we weren't able to find a seemingly-valid truename.
|
|
634 Well, maybe we're on one of those braindead systems where
|
|
635 XListFonts() and XLoadFont() are in violent disagreement.
|
|
636 If we were able to compute a truename, try using that even
|
|
637 if evidence suggests that it's not a valid name - because
|
|
638 maybe it is, really, and that's better than nothing.
|
|
639 X Windows: You'll envy the dead.
|
|
640 */
|
|
641 if (truename_FONT)
|
|
642 truename = truename_FONT;
|
|
643 else if (truename_random)
|
|
644 truename = truename_random;
|
|
645 }
|
|
646
|
|
647 /* One or both of these are not being used - free them. */
|
|
648 if (truename_FONT && truename_FONT != truename)
|
|
649 XFree (truename_FONT);
|
|
650 if (truename_random && truename_random != truename)
|
|
651 XFree (truename_random);
|
|
652
|
|
653 if (truename)
|
|
654 {
|
|
655 Lisp_Object result = build_string (truename);
|
|
656 xfree (truename);
|
|
657 return result;
|
|
658 }
|
|
659 else
|
|
660 return Qnil;
|
|
661 }
|
|
662
|
|
663 static Lisp_Object
|
|
664 x_font_instance_truename (struct Lisp_Font_Instance *f, Error_behavior errb)
|
|
665 {
|
|
666 struct device *d = XDEVICE (f->device);
|
|
667
|
|
668 if (NILP (FONT_INSTANCE_X_TRUENAME (f)))
|
|
669 {
|
|
670 Display *dpy = DEVICE_X_DISPLAY (d);
|
14
|
671 char *name = (char *) XSTRING_DATA (f->name);
|
0
|
672 {
|
|
673 FONT_INSTANCE_X_TRUENAME (f) =
|
|
674 x_font_truename (dpy, name, FONT_INSTANCE_X_FONT (f));
|
|
675 }
|
|
676 if (NILP (FONT_INSTANCE_X_TRUENAME (f)))
|
|
677 {
|
|
678 Lisp_Object font_instance = Qnil;
|
|
679 XSETFONT_INSTANCE (font_instance, f);
|
|
680
|
|
681 maybe_signal_simple_error ("couldn't determine font truename",
|
|
682 font_instance, Qfont, errb);
|
|
683 /* Ok, just this once, return the font name as the truename.
|
|
684 (This is only used by Fequal() right now.) */
|
|
685 return f->name;
|
|
686 }
|
|
687 }
|
|
688 return (FONT_INSTANCE_X_TRUENAME (f));
|
|
689 }
|
|
690
|
|
691 static Lisp_Object
|
|
692 x_font_instance_properties (struct Lisp_Font_Instance *f)
|
|
693 {
|
|
694 struct device *d = XDEVICE (f->device);
|
|
695 int i;
|
|
696 Lisp_Object result = Qnil;
|
|
697 XFontProp *props;
|
|
698 Display *dpy;
|
|
699
|
|
700 dpy = DEVICE_X_DISPLAY (d);
|
|
701 props = FONT_INSTANCE_X_FONT (f)->properties;
|
|
702 for (i = FONT_INSTANCE_X_FONT (f)->n_properties - 1; i >= 0; i--)
|
|
703 {
|
|
704 char *name_str = 0;
|
|
705 char *val_str = 0;
|
|
706 Lisp_Object name, value;
|
|
707 Atom atom = props [i].name;
|
|
708 name_str = XGetAtomName (dpy, atom);
|
|
709 name = (name_str ? intern (name_str) : Qnil);
|
|
710 if (name_str &&
|
|
711 (atom == XA_FONT ||
|
|
712 atom == DEVICE_XATOM_FOUNDRY (d) ||
|
|
713 atom == DEVICE_XATOM_FAMILY_NAME (d) ||
|
|
714 atom == DEVICE_XATOM_WEIGHT_NAME (d) ||
|
|
715 atom == DEVICE_XATOM_SLANT (d) ||
|
|
716 atom == DEVICE_XATOM_SETWIDTH_NAME (d) ||
|
|
717 atom == DEVICE_XATOM_ADD_STYLE_NAME (d) ||
|
|
718 atom == DEVICE_XATOM_SPACING (d) ||
|
|
719 atom == DEVICE_XATOM_CHARSET_REGISTRY (d) ||
|
|
720 atom == DEVICE_XATOM_CHARSET_ENCODING (d) ||
|
|
721 !strcmp (name_str, "CHARSET_COLLECTIONS") ||
|
|
722 !strcmp (name_str, "FONTNAME_REGISTRY") ||
|
|
723 !strcmp (name_str, "CLASSIFICATION") ||
|
|
724 !strcmp (name_str, "COPYRIGHT") ||
|
|
725 !strcmp (name_str, "DEVICE_FONT_NAME") ||
|
|
726 !strcmp (name_str, "FULL_NAME") ||
|
|
727 !strcmp (name_str, "MONOSPACED") ||
|
|
728 !strcmp (name_str, "QUALITY") ||
|
|
729 !strcmp (name_str, "RELATIVE_SET") ||
|
|
730 !strcmp (name_str, "RELATIVE_WEIGHT") ||
|
|
731 !strcmp (name_str, "STYLE")))
|
|
732 {
|
|
733 val_str = XGetAtomName (dpy, props [i].card32);
|
|
734 value = (val_str ? build_string (val_str) : Qnil);
|
|
735 }
|
|
736 else
|
|
737 value = make_int (props [i].card32);
|
|
738 if (name_str) XFree (name_str);
|
|
739 result = Fcons (Fcons (name, value), result);
|
|
740 }
|
|
741 return result;
|
|
742 }
|
|
743
|
|
744 static Lisp_Object
|
|
745 x_list_fonts (Lisp_Object pattern, Lisp_Object device)
|
|
746 {
|
|
747 char **names;
|
|
748 int count = 0;
|
|
749 Lisp_Object result = Qnil;
|
|
750 CONST char *patternext;
|
|
751
|
|
752 GET_C_STRING_BINARY_DATA_ALLOCA (pattern, patternext);
|
|
753
|
|
754 names = XListFonts (DEVICE_X_DISPLAY (XDEVICE (device)),
|
|
755 patternext, MAX_FONT_COUNT, &count);
|
|
756 while (count--)
|
|
757 result = Fcons (build_ext_string (names [count], FORMAT_BINARY), result);
|
|
758 if (names)
|
|
759 XFreeFontNames (names);
|
|
760 return result;
|
|
761 }
|
|
762
|
|
763
|
|
764 /************************************************************************/
|
|
765 /* initialization */
|
|
766 /************************************************************************/
|
|
767
|
|
768 void
|
|
769 syms_of_objects_x (void)
|
|
770 {
|
|
771 }
|
|
772
|
|
773 void
|
|
774 console_type_create_objects_x (void)
|
|
775 {
|
|
776 /* object methods */
|
|
777
|
|
778 CONSOLE_HAS_METHOD (x, initialize_color_instance);
|
|
779 CONSOLE_HAS_METHOD (x, print_color_instance);
|
|
780 CONSOLE_HAS_METHOD (x, finalize_color_instance);
|
|
781 CONSOLE_HAS_METHOD (x, color_instance_equal);
|
|
782 CONSOLE_HAS_METHOD (x, color_instance_hash);
|
|
783 CONSOLE_HAS_METHOD (x, color_instance_rgb_components);
|
|
784 CONSOLE_HAS_METHOD (x, valid_color_name_p);
|
|
785
|
|
786 CONSOLE_HAS_METHOD (x, initialize_font_instance);
|
|
787 CONSOLE_HAS_METHOD (x, mark_font_instance);
|
|
788 CONSOLE_HAS_METHOD (x, print_font_instance);
|
|
789 CONSOLE_HAS_METHOD (x, finalize_font_instance);
|
|
790 CONSOLE_HAS_METHOD (x, font_instance_truename);
|
|
791 CONSOLE_HAS_METHOD (x, font_instance_properties);
|
|
792 CONSOLE_HAS_METHOD (x, list_fonts);
|
|
793 }
|
|
794
|
|
795 void
|
|
796 vars_of_objects_x (void)
|
|
797 {
|
|
798 DEFVAR_BOOL ("x-handle-non-fully-specified-fonts",&handle_nonfull_spec_fonts /*
|
|
799 If this is true then fonts which do not have all characters specified
|
|
800 will be considered to be proportional width even if they are actually
|
|
801 fixed-width. If this is not done then characters which are supposed to
|
|
802 have 0 width may appear to actually have some width.
|
|
803
|
|
804 Note: While setting this to t guarantees correct output in all
|
|
805 circumstances, it also causes a noticeable performance hit when using
|
|
806 fixed-width fonts. Since most people don't use characters which could
|
|
807 cause problems this is set to nil by default.
|
|
808 */ );
|
|
809 handle_nonfull_spec_fonts = 0;
|
|
810 }
|
|
811
|
|
812 void
|
|
813 Xatoms_of_objects_x (struct device *d)
|
|
814 {
|
|
815 #define ATOM(x) XInternAtom (DEVICE_X_DISPLAY (d), (x), False)
|
2
|
816 #define ATOMIZE(x) DEVICE_XATOM_##x (d) = ATOM(#x)
|
|
817 ATOMIZE (FOUNDRY);
|
|
818 ATOMIZE (FAMILY_NAME);
|
|
819 ATOMIZE (WEIGHT_NAME);
|
|
820 ATOMIZE (SLANT);
|
|
821 ATOMIZE (SETWIDTH_NAME);
|
|
822 ATOMIZE (ADD_STYLE_NAME);
|
|
823 ATOMIZE (PIXEL_SIZE);
|
|
824 ATOMIZE (POINT_SIZE);
|
|
825 ATOMIZE (RESOLUTION_X);
|
|
826 ATOMIZE (RESOLUTION_Y);
|
|
827 ATOMIZE (SPACING);
|
|
828 ATOMIZE (AVERAGE_WIDTH);
|
|
829 ATOMIZE (CHARSET_REGISTRY);
|
|
830 ATOMIZE (CHARSET_ENCODING);
|
0
|
831 }
|