comparison src/objects-x.c @ 272:c5d627a313b1 r21-0b34

Import from CVS: tag r21-0b34
author cvs
date Mon, 13 Aug 2007 10:28:48 +0200
parents b2472a1930f2
children 182f72e8cd0d
comparison
equal deleted inserted replaced
271:c7b7086b0a39 272:c5d627a313b1
34 34
35 #include "buffer.h" 35 #include "buffer.h"
36 #include "device.h" 36 #include "device.h"
37 #include "insdel.h" 37 #include "insdel.h"
38 38
39 int handle_nonfull_spec_fonts; 39 int x_handle_non_fully_specified_fonts;
40 40
41 41
42 /************************************************************************/ 42 /************************************************************************/
43 /* color instances */ 43 /* color instances */
44 /************************************************************************/ 44 /************************************************************************/
150 color matching with StaticColor visuals. */ 150 color matching with StaticColor visuals. */
151 XColor *cells; 151 XColor *cells;
152 /* JH: I can't believe there's no way to go backwards from a 152 /* JH: I can't believe there's no way to go backwards from a
153 colormap ID and get its visual and number of entries, but X 153 colormap ID and get its visual and number of entries, but X
154 apparently isn't built that way... */ 154 apparently isn't built that way... */
155 int no_cells = visual->map_entries; 155 int no_cells = visual->map_entries;
156 int nearest; 156 int nearest;
157 long nearest_delta, trial_delta; 157 long nearest_delta, trial_delta;
158 int x; 158 int x;
159 159
160 cells = alloca_array (XColor, no_cells); 160 cells = alloca_array (XColor, no_cells);
161 161
162 for (x = 0; x < no_cells; x++) 162 for (x = 0; x < no_cells; x++)
163 cells[x].pixel = x; 163 cells[x].pixel = x;
164 164
165 /* read the current colormap */ 165 /* read the current colormap */
166 XQueryColors (display, colormap, cells, no_cells); 166 XQueryColors (display, colormap, cells, no_cells);
167 nearest = 0; 167 nearest = 0;
168 /* I'm assuming CSE so I'm not going to condense this. */ 168 /* I'm assuming CSE so I'm not going to condense this. */
169 nearest_delta = ((((color_def->red >> 8) - (cells[0].red >> 8)) 169 nearest_delta = ((((color_def->red >> 8) - (cells[0].red >> 8))
217 dpy = DEVICE_X_DISPLAY (d); 217 dpy = DEVICE_X_DISPLAY (d);
218 xs = DefaultScreenOfDisplay (dpy); 218 xs = DefaultScreenOfDisplay (dpy);
219 cmap = DEVICE_X_COLORMAP(d); 219 cmap = DEVICE_X_COLORMAP(d);
220 visual = DEVICE_X_VISUAL (d); 220 visual = DEVICE_X_VISUAL (d);
221 221
222 memset (color, 0, sizeof (*color)); 222 xzero (*color);
223 { 223 {
224 CONST Extbyte *extname; 224 CONST Extbyte *extname;
225 Extcount extnamelen; 225 Extcount extnamelen;
226 226
227 GET_CHARPTR_EXT_BINARY_DATA_ALLOCA (name, len, extname, extnamelen); 227 GET_CHARPTR_EXT_BINARY_DATA_ALLOCA (name, len, extname, extnamelen);
260 return 0; 260 return 0;
261 261
262 /* Don't allocate the data until we're sure that we will succeed, 262 /* Don't allocate the data until we're sure that we will succeed,
263 or the finalize method may get fucked. */ 263 or the finalize method may get fucked. */
264 c->data = xnew (struct x_color_instance_data); 264 c->data = xnew (struct x_color_instance_data);
265 if (result == 3) 265 if (result == 3)
266 COLOR_INSTANCE_X_DEALLOC (c) = 0; 266 COLOR_INSTANCE_X_DEALLOC (c) = 0;
267 else 267 else
268 COLOR_INSTANCE_X_DEALLOC (c) = 1; 268 COLOR_INSTANCE_X_DEALLOC (c) = 1;
269 COLOR_INSTANCE_X_COLOR (c) = color; 269 COLOR_INSTANCE_X_COLOR (c) = color;
270 return 1; 270 return 1;
287 { 287 {
288 if (c->data) 288 if (c->data)
289 { 289 {
290 if (DEVICE_LIVE_P (XDEVICE (c->device))) 290 if (DEVICE_LIVE_P (XDEVICE (c->device)))
291 { 291 {
292 if (COLOR_INSTANCE_X_DEALLOC (c)) 292 if (COLOR_INSTANCE_X_DEALLOC (c))
293 { 293 {
294 XFreeColors (DEVICE_X_DISPLAY (XDEVICE (c->device)), DEVICE_X_COLORMAP (XDEVICE (c->device)), 294 XFreeColors (DEVICE_X_DISPLAY (XDEVICE (c->device)), DEVICE_X_COLORMAP (XDEVICE (c->device)),
295 &COLOR_INSTANCE_X_COLOR (c).pixel, 1, 0); 295 &COLOR_INSTANCE_X_COLOR (c).pixel, 1, 0);
296 } 296 }
297 } 297 }
390 f->descent = xf->descent; 390 f->descent = xf->descent;
391 f->height = xf->ascent + xf->descent; 391 f->height = xf->ascent + xf->descent;
392 { 392 {
393 /* following change suggested by Ted Phelps <phelps@dstc.edu.au> */ 393 /* following change suggested by Ted Phelps <phelps@dstc.edu.au> */
394 unsigned int def_char = 'n'; /*xf->default_char;*/ 394 unsigned int def_char = 'n'; /*xf->default_char;*/
395 int byte1, byte2; 395 unsigned int byte1, byte2;
396 396
397 once_more: 397 once_more:
398 byte1 = def_char >> 8; 398 byte1 = def_char >> 8;
399 byte2 = def_char & 0xFF; 399 byte2 = def_char & 0xFF;
400 400
401 if (xf->per_char) 401 if (xf->per_char)
402 { 402 {
403 /* Old versions of the R5 font server have garbage (>63k) as 403 /* Old versions of the R5 font server have garbage (>63k) as
404 def_char. 'n' might not be a valid character. */ 404 def_char. 'n' might not be a valid character. */
405 if (byte1 < xf->min_byte1 || byte1 > xf->max_byte1 || 405 if (byte1 < xf->min_byte1 ||
406 byte2 < xf->min_char_or_byte2 || byte2 > xf->max_char_or_byte2) 406 byte1 > xf->max_byte1 ||
407 byte2 < xf->min_char_or_byte2 ||
408 byte2 > xf->max_char_or_byte2)
407 f->width = 0; 409 f->width = 0;
408 else 410 else
409 f->width = xf->per_char[(byte1 - xf->min_byte1) * 411 f->width = xf->per_char[(byte1 - xf->min_byte1) *
410 (xf->max_char_or_byte2 - 412 (xf->max_char_or_byte2 -
411 xf->min_char_or_byte2 + 1) + 413 xf->min_char_or_byte2 + 1) +
438 when using proportional width fonts if this flag is not set. 440 when using proportional width fonts if this flag is not set.
439 Unfortunately so many of the fucking X fonts are not fully 441 Unfortunately so many of the fucking X fonts are not fully
440 defined that we could almost just get rid of this damn flag and 442 defined that we could almost just get rid of this damn flag and
441 make it an assertion. */ 443 make it an assertion. */
442 f->proportional_p = (xf->min_bounds.width != xf->max_bounds.width || 444 f->proportional_p = (xf->min_bounds.width != xf->max_bounds.width ||
443 (handle_nonfull_spec_fonts && 445 (x_handle_non_fully_specified_fonts &&
444 !xf->all_chars_exist)); 446 !xf->all_chars_exist));
445 447
446 return 1; 448 return 1;
447 } 449 }
448 450
776 FONT_INSTANCE_X_TRUENAME (f) = 778 FONT_INSTANCE_X_TRUENAME (f) =
777 x_font_truename (dpy, name, FONT_INSTANCE_X_FONT (f)); 779 x_font_truename (dpy, name, FONT_INSTANCE_X_FONT (f));
778 } 780 }
779 if (NILP (FONT_INSTANCE_X_TRUENAME (f))) 781 if (NILP (FONT_INSTANCE_X_TRUENAME (f)))
780 { 782 {
781 Lisp_Object font_instance = Qnil; 783 Lisp_Object font_instance;
782 XSETFONT_INSTANCE (font_instance, f); 784 XSETFONT_INSTANCE (font_instance, f);
783 785
784 maybe_signal_simple_error ("couldn't determine font truename", 786 maybe_signal_simple_error ("couldn't determine font truename",
785 font_instance, Qfont, errb); 787 font_instance, Qfont, errb);
786 /* Ok, just this once, return the font name as the truename. 788 /* Ok, just this once, return the font name as the truename.
915 } 917 }
916 918
917 /* find a font spec that matches font spec FONT and also matches 919 /* find a font spec that matches font spec FONT and also matches
918 (the registry of) CHARSET. */ 920 (the registry of) CHARSET. */
919 static Lisp_Object 921 static Lisp_Object
920 x_find_charset_font (Lisp_Object device, Lisp_Object font, 922 x_find_charset_font (Lisp_Object device, Lisp_Object font, Lisp_Object charset)
921 Lisp_Object charset)
922 { 923 {
923 char **names; 924 char **names;
924 int count = 0; 925 int count = 0;
925 Lisp_Object result = Qnil; 926 Lisp_Object result = Qnil;
926 CONST char *patternext; 927 CONST char *patternext;
928 929
929 GET_C_STRING_BINARY_DATA_ALLOCA (font, patternext); 930 GET_C_STRING_BINARY_DATA_ALLOCA (font, patternext);
930 931
931 names = XListFonts (DEVICE_X_DISPLAY (XDEVICE (device)), 932 names = XListFonts (DEVICE_X_DISPLAY (XDEVICE (device)),
932 patternext, MAX_FONT_COUNT, &count); 933 patternext, MAX_FONT_COUNT, &count);
934 /* ### This code seems awfully bogus -- mrb */
933 for (i = 0; i < count; i ++) 935 for (i = 0; i < count; i ++)
934 { 936 {
935 CONST char *intname; 937 CONST Bufbyte *intname;
936 938
937 GET_C_CHARPTR_INT_BINARY_DATA_ALLOCA (names[i], intname); 939 GET_C_CHARPTR_INT_BINARY_DATA_ALLOCA (names[i], intname);
938 if (x_font_spec_matches_charset (XDEVICE (device), charset, 940 if (x_font_spec_matches_charset (XDEVICE (device), charset,
939 (unsigned char *) intname, 941 intname, Qnil, 0, -1))
940 Qnil, 0, -1))
941 { 942 {
942 result = build_string (intname); 943 result = build_string ((char *) intname);
943 break; 944 break;
944 } 945 }
945 } 946 }
946 947
947 if (names) 948 if (names)
995 } 996 }
996 997
997 void 998 void
998 vars_of_objects_x (void) 999 vars_of_objects_x (void)
999 { 1000 {
1000 DEFVAR_BOOL ("x-handle-non-fully-specified-fonts",&handle_nonfull_spec_fonts /* 1001 DEFVAR_BOOL ("x-handle-non-fully-specified-fonts",
1002 &x_handle_non_fully_specified_fonts /*
1001 If this is true then fonts which do not have all characters specified 1003 If this is true then fonts which do not have all characters specified
1002 will be considered to be proportional width even if they are actually 1004 will be considered to be proportional width even if they are actually
1003 fixed-width. If this is not done then characters which are supposed to 1005 fixed-width. If this is not done then characters which are supposed to
1004 have 0 width may appear to actually have some width. 1006 have 0 width may appear to actually have some width.
1005 1007
1006 Note: While setting this to t guarantees correct output in all 1008 Note: While setting this to t guarantees correct output in all
1007 circumstances, it also causes a noticeable performance hit when using 1009 circumstances, it also causes a noticeable performance hit when using
1008 fixed-width fonts. Since most people don't use characters which could 1010 fixed-width fonts. Since most people don't use characters which could
1009 cause problems this is set to nil by default. 1011 cause problems this is set to nil by default.
1010 */ ); 1012 */ );
1011 handle_nonfull_spec_fonts = 0; 1013 x_handle_non_fully_specified_fonts = 0;
1012 } 1014 }
1013 1015
1014 void 1016 void
1015 Xatoms_of_objects_x (struct device *d) 1017 Xatoms_of_objects_x (struct device *d)
1016 { 1018 {