Mercurial > hg > xemacs-beta
annotate src/objects-xlike-inc.c @ 4614:afbfad080ddd
The URLs in our current config.guess and config.sub files are obsolete.
Update to the latest upstream release to get correct URLs, as well as fixes
and enhancements to those scripts.
| author | Jerry James <james@xemacs.org> |
|---|---|
| date | Wed, 11 Feb 2009 11:09:35 -0700 |
| parents | ea66743ff201 |
| children | 5d67242595a8 |
| rev | line source |
|---|---|
| 3659 | 1 /* Shared object code between X and GTK -- include file. |
| 2 Copyright (C) 1991-5, 1997 Free Software Foundation, Inc. | |
| 3 Copyright (C) 1995 Sun Microsystems, Inc. | |
| 4 Copyright (C) 1996, 2001, 2002, 2003 Ben Wing. | |
| 5 | |
| 6 This file is part of XEmacs. | |
| 7 | |
| 8 XEmacs is free software; you can redistribute it and/or modify it | |
| 9 under the terms of the GNU General Public License as published by the | |
| 10 Free Software Foundation; either version 2, or (at your option) any | |
| 11 later version. | |
| 12 | |
| 13 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
| 14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 16 for more details. | |
| 17 | |
| 18 You should have received a copy of the GNU General Public License | |
| 19 along with XEmacs; see the file COPYING. If not, write to | |
| 20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
| 21 Boston, MA 02111-1307, USA. */ | |
| 22 | |
| 23 /* Synched up with: Not in FSF. */ | |
| 24 | |
| 25 /* Pango is ready for prime-time now, as far as I understand it. The GTK | |
| 26 people should be using that. Oh well. (Aidan Kehoe, Sat Nov 4 12:41:12 | |
| 27 CET 2006) */ | |
| 28 | |
| 29 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901) | |
| 30 | |
| 31 #ifdef DEBUG_XEMACS | |
| 32 # define DEBUG_OBJECTS(FORMAT, ...) \ | |
| 33 do { if (debug_x_objects) stderr_out(FORMAT, __VA_ARGS__); } while (0) | |
| 34 #else /* DEBUG_XEMACS */ | |
| 35 # define DEBUG_OBJECTS(format, ...) | |
| 36 #endif /* DEBUG_XEMACS */ | |
| 37 | |
| 38 #elif defined(__GNUC__) | |
| 39 | |
| 40 #ifdef DEBUG_XEMACS | |
| 41 # define DEBUG_OBJECTS(format, args...) \ | |
| 42 do { if (debug_x_objects) stderr_out(format, args ); } while (0) | |
| 43 #else /* DEBUG_XEMACS */ | |
| 44 # define DEBUG_OBJECTS(format, args...) | |
| 45 #endif /* DEBUG_XEMACS */ | |
| 46 | |
| 47 #else /* defined(__STDC_VERSION__) [...] */ | |
| 48 # define DEBUG_OBJECTS (void) | |
| 49 #endif | |
| 50 | |
| 51 #ifdef MULE | |
| 52 | |
| 53 /* For some code it's reasonable to have only one copy and conditionalize | |
| 54 at run-time. For other code it isn't. */ | |
| 55 | |
| 56 static int | |
| 57 count_hyphens(const Ibyte *str, Bytecount length, Ibyte **last_hyphen) | |
| 58 { | |
| 59 int hyphen_count = 0; | |
| 60 const Ibyte *hyphening = str; | |
| 61 const Ibyte *new_hyphening; | |
| 62 | |
| 63 for (hyphen_count = 0; | |
| 4124 | 64 NULL != (new_hyphening = (Ibyte *) memchr((const void *)hyphening, '-', length)); |
| 3659 | 65 hyphen_count++) |
| 66 { | |
| 67 ++new_hyphening; | |
| 68 length -= new_hyphening - hyphening; | |
| 69 hyphening = new_hyphening; | |
| 70 } | |
| 71 | |
| 72 if (NULL != last_hyphen) | |
| 73 { | |
| 74 *last_hyphen = (Ibyte *)hyphening; | |
| 75 } | |
| 76 | |
| 77 return hyphen_count; | |
| 78 } | |
| 79 | |
| 80 static int | |
| 81 #ifdef THIS_IS_GTK | |
| 82 gtk_font_spec_matches_charset (struct device * USED_IF_XFT (d), | |
| 83 Lisp_Object charset, | |
| 84 const Ibyte *nonreloc, Lisp_Object reloc, | |
| 85 Bytecount offset, Bytecount length, | |
| 86 enum font_specifier_matchspec_stages stage) | |
| 87 #else | |
| 88 x_font_spec_matches_charset (struct device * USED_IF_XFT (d), | |
| 89 Lisp_Object charset, | |
| 90 const Ibyte *nonreloc, Lisp_Object reloc, | |
| 91 Bytecount offset, Bytecount length, | |
| 92 enum font_specifier_matchspec_stages stage) | |
| 93 #endif | |
| 94 { | |
| 95 Lisp_Object registries = Qnil; | |
| 96 long i, registries_len; | |
| 97 const Ibyte *the_nonreloc; | |
| 98 Bytecount the_length; | |
| 99 | |
| 100 the_nonreloc = nonreloc; | |
| 101 the_length = length; | |
| 102 | |
| 103 if (!the_nonreloc) | |
| 104 the_nonreloc = XSTRING_DATA (reloc); | |
| 105 fixup_internal_substring (nonreloc, reloc, offset, &the_length); | |
| 106 the_nonreloc += offset; | |
| 107 | |
| 108 #ifdef USE_XFT | |
| 109 if (stage) | |
| 110 { | |
| 111 Display *dpy = DEVICE_X_DISPLAY (d); | |
| 112 Extbyte *extname; | |
| 113 XftFont *rf; | |
| 114 const Ibyte *the_nonreloc; | |
| 115 | |
| 116 if (!NILP(reloc)) | |
| 117 { | |
| 118 the_nonreloc = XSTRING_DATA (reloc); | |
| 119 LISP_STRING_TO_EXTERNAL (reloc, extname, Qx_font_name_encoding); | |
| 120 rf = xft_open_font_by_name (dpy, extname); | |
| 121 return 0; /* #### maybe this will compile and run ;) */ | |
| 122 /* Jesus, Stephen, what the fuck? */ | |
| 123 } | |
| 124 } | |
| 125 #endif | |
| 126 | |
| 127 /* Hmm, this smells bad. */ | |
|
4353
4143b78d0df0
Merge an old patch of Ben's, involving font instantiation and charsets.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4124
diff
changeset
|
128 if (NILP (charset)) |
| 3659 | 129 return 1; |
| 130 | |
| 131 /* Hack! Short font names don't have the registry in them, | |
| 132 so we just assume the user knows what they're doing in the | |
| 133 case of ASCII. For other charsets, you gotta give the | |
| 134 long form; sorry buster. | |
| 135 #### FMH: this screws fontconfig/Xft? | |
| 136 STRATEGY: use fontconfig's ability to hack languages and character | |
| 137 sets (lang and charset properties). | |
| 138 #### Maybe we can use the fontconfig model to eliminate the difference | |
| 139 between faces and fonts? No - it looks like that would be an abuse | |
| 140 (fontconfig doesn't know about colors, although Xft does). | |
| 141 */ | |
| 142 if (EQ (charset, Vcharset_ascii) && | |
| 143 (!memchr (the_nonreloc, '*', the_length)) | |
| 144 && (5 > (count_hyphens(the_nonreloc, the_length, NULL)))) | |
| 145 { | |
| 146 return 1; | |
| 147 } | |
| 148 | |
| 149 if (final == stage) | |
| 150 { | |
| 151 registries = Qunicode_registries; | |
| 152 } | |
| 153 else if (initial == stage) | |
| 154 { | |
| 155 registries = XCHARSET_REGISTRIES (charset); | |
| 156 if (NILP(registries)) | |
| 157 { | |
| 158 return 0; | |
| 159 } | |
| 160 } | |
| 161 else assert(0); | |
| 162 | |
| 163 CHECK_VECTOR (registries); | |
| 164 registries_len = XVECTOR_LENGTH(registries); | |
| 165 | |
| 166 for (i = 0; i < registries_len; ++i) | |
| 167 { | |
| 168 if (!(STRINGP(XVECTOR_DATA(registries)[i])) | |
| 169 || (XSTRING_LENGTH(XVECTOR_DATA(registries)[i]) > the_length)) | |
| 170 { | |
| 171 continue; | |
| 172 } | |
| 173 | |
| 174 /* Check if the font spec ends in the registry specified. X11 says | |
| 175 this comparison is case insensitive: XLFD, section 3.11: | |
| 176 | |
| 177 "Alphabetic case distinctions are allowed but are for human | |
| 178 readability concerns only. Conforming X servers will perform | |
| 179 matching on font name query or open requests independent of case." */ | |
| 180 if (0 == qxestrcasecmp(XSTRING_DATA(XVECTOR_DATA(registries)[i]), | |
| 181 the_nonreloc + (the_length - | |
| 182 XSTRING_LENGTH | |
| 183 (XVECTOR_DATA(registries)[i])))) | |
| 184 { | |
| 185 return 1; | |
| 186 } | |
| 187 } | |
| 188 return 0; | |
| 189 } | |
| 190 | |
| 191 static Lisp_Object | |
| 192 xlistfonts_checking_charset (Lisp_Object device, const Extbyte *xlfd, | |
| 193 Lisp_Object charset, | |
| 194 enum font_specifier_matchspec_stages stage) | |
| 195 { | |
| 196 Extbyte **names; | |
| 197 Lisp_Object result = Qnil; | |
| 198 int count = 0, i; | |
| 199 DECLARE_EISTRING(ei_single_result); | |
| 200 | |
| 201 names = XListFonts ( | |
| 202 #ifdef THIS_IS_GTK | |
| 203 GDK_DISPLAY (), | |
| 204 #else | |
| 205 DEVICE_X_DISPLAY (XDEVICE (device)), | |
| 206 #endif | |
| 207 xlfd, MAX_FONT_COUNT, &count); | |
| 208 | |
| 209 for (i = 0; i < count; ++i) | |
| 210 { | |
| 211 eireset(ei_single_result); | |
| 212 eicpy_ext(ei_single_result, names[i], Qx_font_name_encoding); | |
| 213 | |
| 214 if (DEVMETH_OR_GIVEN(XDEVICE (device), font_spec_matches_charset, | |
| 215 (XDEVICE (device), charset, | |
| 216 eidata(ei_single_result), Qnil, 0, | |
| 217 -1, stage), 0)) | |
| 218 { | |
| 219 result = eimake_string(ei_single_result); | |
| 220 DEBUG_OBJECTS ("in xlistfonts_checking_charset, returning %s\n", | |
| 221 eidata(ei_single_result)); | |
| 222 break; | |
| 223 } | |
| 224 } | |
| 225 | |
| 226 if (names) | |
| 227 { | |
| 228 XFreeFontNames (names); | |
| 229 } | |
| 230 | |
| 231 return result; | |
| 232 } | |
| 233 | |
| 234 #ifdef USE_XFT | |
| 235 /* #### debug functions: find a better place for us */ | |
| 236 const char *FcResultToString (FcResult r); | |
| 237 const char * | |
| 238 FcResultToString (FcResult r) | |
| 239 { | |
| 240 static char buffer[256]; | |
| 241 switch (r) | |
| 242 { | |
| 243 case FcResultMatch: | |
| 244 return "FcResultMatch"; | |
| 245 case FcResultNoMatch: | |
| 246 return "FcResultNoMatch"; | |
| 247 case FcResultTypeMismatch: | |
| 248 return "FcResultTypeMismatch"; | |
| 249 case FcResultNoId: | |
| 250 return "FcResultNoId"; | |
| 251 default: | |
| 252 snprintf (buffer, 255, "FcResultUndocumentedValue (%d)", r); | |
| 253 return buffer; | |
| 254 } | |
| 255 } | |
| 256 | |
| 257 const char *FcTypeOfValueToString (FcValue v); | |
| 258 const char * | |
| 259 FcTypeOfValueToString (FcValue v) | |
| 260 { | |
| 261 static char buffer[256]; | |
| 262 switch (v.type) | |
| 263 { | |
| 264 case FcTypeMatrix: | |
| 265 return "FcTypeMatrix"; | |
| 266 case FcTypeString: | |
| 267 return "FcTypeString"; | |
| 268 case FcTypeVoid: | |
| 269 return "FcTypeVoid"; | |
| 270 case FcTypeDouble: | |
| 271 return "FcTypeDouble"; | |
| 272 case FcTypeInteger: | |
| 273 return "FcTypeInteger"; | |
| 274 case FcTypeBool: | |
| 275 return "FcTypeBool"; | |
| 276 case FcTypeCharSet: | |
| 277 return "FcTypeCharSet"; | |
| 278 case FcTypeLangSet: | |
| 279 return "FcTypeLangSet"; | |
| 280 /* #### There is no union member of this type, but there are void* and | |
| 281 FcPattern* members, as of fontconfig.h FC_VERSION 10002 */ | |
| 282 case FcTypeFTFace: | |
| 283 return "FcTypeFTFace"; | |
| 284 default: | |
| 285 snprintf (buffer, 255, "FcTypeUndocumentedType (%d)", v.type); | |
| 286 return buffer; | |
| 287 } | |
| 288 } | |
| 289 | |
| 290 static FcCharSet * | |
| 291 mule_to_fc_charset (Lisp_Object cs) | |
| 292 { | |
| 293 int ucode, i, j; | |
| 294 FcCharSet *fccs; | |
| 295 | |
| 296 CHECK_CHARSET (cs); | |
| 297 fccs = FcCharSetCreate (); | |
| 298 /* #### do we also need to deal with 94 vs. 96 charsets? | |
| 299 ie, how are SP and DEL treated in ASCII? non-graphic should return -1 */ | |
| 300 if (1 == XCHARSET_DIMENSION (cs)) | |
| 301 /* Unicode tables are indexed by offsets from ASCII SP, not by ASCII */ | |
| 302 for (i = 0; i < 96; i++) | |
| 303 { | |
| 304 ucode = ((int *) XCHARSET_TO_UNICODE_TABLE (cs))[i]; | |
| 305 if (ucode >= 0) | |
| 306 /* #### should check for allocation failure */ | |
| 307 FcCharSetAddChar (fccs, (FcChar32) ucode); | |
| 308 } | |
| 309 else if (2 == XCHARSET_DIMENSION (cs)) | |
| 310 /* Unicode tables are indexed by offsets from ASCII SP, not by ASCII */ | |
| 311 for (i = 0; i < 96; i++) | |
| 312 for (j = 0; j < 96; j++) | |
| 313 { | |
| 314 ucode = ((int **) XCHARSET_TO_UNICODE_TABLE (cs))[i][j]; | |
| 315 if (ucode >= 0) | |
| 316 /* #### should check for allocation failure */ | |
| 317 FcCharSetAddChar (fccs, (FcChar32) ucode); | |
| 318 } | |
| 319 else | |
| 320 { | |
| 321 FcCharSetDestroy (fccs); | |
| 322 fccs = NULL; | |
| 323 } | |
| 324 return fccs; | |
| 325 } | |
| 326 | |
| 327 struct charset_reporter { | |
| 328 Lisp_Object *charset; | |
| 329 /* This is a debug facility, require ASCII. */ | |
| 330 Extbyte *language; /* ASCII, please */ | |
| 331 /* Technically this is FcChar8, but fsckin' GCC 4 bitches. */ | |
| 332 Extbyte *rfc3066; /* ASCII, please */ | |
| 333 }; | |
| 334 | |
| 335 static struct charset_reporter charset_table[] = | |
| 336 { | |
| 337 /* #### It's my branch, my favorite charsets get checked first! | |
| 338 That's a joke, Son. | |
| 339 Ie, I don't know what I'm doing, so my charsets first is as good as | |
| 340 any other arbitrary order. If you have a better idea, speak up! */ | |
| 341 { &Vcharset_ascii, "English", "en" }, | |
| 342 { &Vcharset_japanese_jisx0208, "Japanese", "ja" }, | |
| 343 { &Vcharset_japanese_jisx0212, "Japanese", "ja" }, | |
| 344 { &Vcharset_katakana_jisx0201, "Japanese", "ja" }, | |
| 345 { &Vcharset_latin_jisx0201, "Japanese", "ja" }, | |
| 346 { &Vcharset_japanese_jisx0208_1978, "Japanese", "ja" }, | |
| 347 { &Vcharset_greek_iso8859_7, "Greek", "el" }, | |
| 348 /* #### all the Chinese need checking | |
| 349 Damn the blood-sucking ISO anyway. */ | |
| 350 { &Vcharset_chinese_gb2312, "simplified Chinese", "zh-CN" }, | |
| 351 { &Vcharset_korean_ksc5601, "Korean", "ko" }, | |
| 352 { &Vcharset_chinese_cns11643_1, "traditional Chinese", "zh-TW" }, | |
| 353 { &Vcharset_chinese_cns11643_2, "traditional Chinese", "zh-TW" }, | |
| 354 { &Vcharset_latin_iso8859_1, NULL, NULL }, | |
| 355 { &Vcharset_latin_iso8859_2, NULL, NULL }, | |
| 356 { &Vcharset_latin_iso8859_3, NULL, NULL }, | |
| 357 { &Vcharset_latin_iso8859_4, NULL, NULL }, | |
| 358 { &Vcharset_latin_iso8859_9, NULL, NULL }, | |
| 359 { &Vcharset_latin_iso8859_15, NULL, NULL }, | |
| 360 { &Vcharset_thai_tis620, NULL, NULL }, | |
| 361 { &Vcharset_hebrew_iso8859_8, "Hebrew", "he" }, | |
| 362 { &Vcharset_cyrillic_iso8859_5, NULL, NULL }, | |
| 363 /* #### these probably are not quite right */ | |
| 364 { &Vcharset_chinese_big5_1, "traditional Chinese", "zh-TW" }, | |
| 365 { &Vcharset_chinese_big5_2, "traditional Chinese", "zh-TW" }, | |
| 366 { NULL, NULL, NULL } | |
| 367 }; | |
| 368 | |
| 369 /* Choose appropriate font name for debug messages. | |
| 370 Use only in the top half of next function (enforced with #undef). */ | |
| 371 #define DECLARE_DEBUG_FONTNAME(__xemacs_name) \ | |
| 372 Eistring *__xemacs_name; \ | |
| 373 do \ | |
| 374 { \ | |
| 375 __xemacs_name = debug_xft > 2 ? eistr_fullname \ | |
| 376 : debug_xft > 1 ? eistr_longname \ | |
| 377 : eistr_shortname; \ | |
| 378 } while (0) | |
| 379 | |
| 380 static Lisp_Object | |
| 381 xft_find_charset_font (Lisp_Object font, Lisp_Object charset, | |
| 382 enum font_specifier_matchspec_stages stage) | |
| 383 { | |
| 384 const Extbyte *patternext; | |
| 385 Lisp_Object result = Qnil; | |
| 386 | |
| 387 /* #### with Xft need to handle second stage here -- sjt | |
| 388 Hm. Or maybe not. That would be cool. :-) */ | |
| 389 if (stage) | |
| 390 return Qnil; | |
| 391 | |
| 392 /* Fontconfig converts all FreeType names to UTF-8 before passing them | |
| 393 back to callers---see fcfreetype.c (FcFreeTypeQuery). | |
| 394 I don't believe this is documented. */ | |
| 395 | |
| 396 DEBUG_XFT1 (1, "confirming charset for font instance %s\n", | |
| 397 XSTRING_DATA(font)); | |
| 398 | |
| 399 /* #### this looks like a fair amount of work, but the basic design | |
| 400 has never been rethought, and it should be | |
| 401 | |
| 402 what really should happen here is that we use FcFontSort (FcFontList?) | |
| 403 to get a list of matching fonts, then pick the first (best) one that | |
| 404 gives language or repertoire coverage. | |
| 405 */ | |
| 406 | |
| 407 FcInit (); /* No-op if already initialized. | |
| 408 In fontconfig 2.3.2, this cannot return | |
| 409 failure, but that looks like a bug. We | |
| 410 check for it with FcGetCurrentConfig(), | |
| 411 which *can* fail. */ | |
| 412 if (!FcConfigGetCurrent()) /* #### We should expose FcInit* interfaces | |
| 413 to LISP and decide when to reinitialize | |
| 414 intelligently. */ | |
| 415 stderr_out ("Failed fontconfig initialization\n"); | |
| 416 else | |
| 417 { | |
| 418 FcPattern *fontxft; /* long-lived, freed at end of this block */ | |
| 419 FcResult fcresult; | |
| 420 FcConfig *fcc; | |
| 421 FcChar8 *lang = (FcChar8 *) "en"; /* #### fix this bogus hack! */ | |
| 422 FcCharSet *fccs = NULL; | |
| 423 DECLARE_EISTRING (eistr_shortname); /* user-friendly nickname */ | |
| 424 DECLARE_EISTRING (eistr_longname); /* omit FC_LANG and FC_CHARSET */ | |
| 425 DECLARE_EISTRING (eistr_fullname); /* everything */ | |
| 426 | |
| 427 LISP_STRING_TO_EXTERNAL (font, patternext, Qfc_font_name_encoding); | |
| 428 fcc = FcConfigGetCurrent (); | |
| 429 | |
| 430 /* parse the name, do the substitutions, and match the font */ | |
| 431 | |
| 432 { | |
| 433 FcPattern *p = FcNameParse ((FcChar8 *) patternext); | |
| 434 PRINT_XFT_PATTERN (3, "FcNameParse'ed name is %s\n", p); | |
| 435 /* #### Next two return FcBool, but what does the return mean? */ | |
| 436 /* The order is correct according the fontconfig docs. */ | |
| 437 FcConfigSubstitute (fcc, p, FcMatchPattern); | |
| 438 PRINT_XFT_PATTERN (2, "FcConfigSubstitute'ed name is %s\n", p); | |
| 439 FcDefaultSubstitute (p); | |
| 440 PRINT_XFT_PATTERN (3, "FcDefaultSubstitute'ed name is %s\n", p); | |
| 441 /* #### check fcresult of following match? */ | |
| 442 fontxft = FcFontMatch (fcc, p, &fcresult); | |
| 443 /* this prints the long fontconfig name */ | |
| 444 PRINT_XFT_PATTERN (1, "FcFontMatch'ed name is %s\n", fontxft); | |
| 445 FcPatternDestroy (p); | |
| 446 } | |
| 447 | |
| 448 /* heuristic to give reasonable-length names for debug reports | |
| 449 | |
| 450 I considered #ifdef SUPPORT_FULL_FONTCONFIG_NAME etc but that's | |
| 451 pointless. We're just going to remove this code once the font/ | |
| 452 face refactoring is done, but until then it could be very useful. | |
| 453 */ | |
| 454 { | |
| 455 FcPattern *p = FcFontRenderPrepare (fcc, fontxft, fontxft); | |
| 456 FcChar8 *name; | |
| 457 | |
| 458 /* full name, including language coverage and repertoire */ | |
| 459 name = FcNameUnparse (p); | |
| 460 eicpy_ext (eistr_fullname, (Extbyte *) name, Qfc_font_name_encoding); | |
| 461 free (name); | |
| 462 | |
| 463 /* long name, omitting coverage and repertoire, plus a number | |
| 464 of rarely useful properties */ | |
| 465 FcPatternDel (p, FC_CHARSET); | |
| 466 FcPatternDel (p, FC_LANG); | |
| 3841 | 467 #ifdef FC_WIDTH |
| 3659 | 468 FcPatternDel (p, FC_WIDTH); |
| 3841 | 469 #endif |
| 3659 | 470 FcPatternDel (p, FC_SPACING); |
| 471 FcPatternDel (p, FC_HINTING); | |
| 472 FcPatternDel (p, FC_VERTICAL_LAYOUT); | |
| 473 FcPatternDel (p, FC_AUTOHINT); | |
| 474 FcPatternDel (p, FC_GLOBAL_ADVANCE); | |
| 475 FcPatternDel (p, FC_INDEX); | |
| 476 FcPatternDel (p, FC_SCALE); | |
| 477 FcPatternDel (p, FC_FONTVERSION); | |
| 478 name = FcNameUnparse (p); | |
| 479 eicpy_ext (eistr_longname, (Extbyte *) name, Qfc_font_name_encoding); | |
| 480 free (name); | |
| 481 | |
| 482 /* nickname, just family and size, but | |
| 483 "family" names usually have style, slant, and weight */ | |
| 484 FcPatternDel (p, FC_FOUNDRY); | |
| 485 FcPatternDel (p, FC_STYLE); | |
| 486 FcPatternDel (p, FC_SLANT); | |
| 487 FcPatternDel (p, FC_WEIGHT); | |
| 488 FcPatternDel (p, FC_PIXEL_SIZE); | |
| 489 FcPatternDel (p, FC_OUTLINE); | |
| 490 FcPatternDel (p, FC_SCALABLE); | |
| 491 FcPatternDel (p, FC_DPI); | |
| 492 name = FcNameUnparse (p); | |
| 493 eicpy_ext (eistr_shortname, (Extbyte *) name, Qfc_font_name_encoding); | |
| 494 free (name); | |
| 495 | |
| 496 FcPatternDestroy (p); | |
| 497 } | |
| 498 | |
| 499 /* The language approach may better in the long run, but we can't use | |
| 500 it based on Mule charsets; fontconfig doesn't provide a way to test | |
| 501 for unions of languages, etc. That will require support from the | |
| 502 text module. | |
| 503 | |
| 504 Optimization: cache the generated FcCharSet in the Mule charset. | |
| 505 Don't forget to destroy it if the Mule charset gets deallocated. */ | |
| 506 | |
| 507 { | |
| 508 /* This block possibly should be a function, but it generates | |
| 509 multiple values. I find the "pass an address to return the | |
| 510 value in" idiom opaque, so prefer a block. */ | |
| 511 struct charset_reporter *cr; | |
| 512 for (cr = charset_table; | |
| 513 cr->charset && !EQ (*(cr->charset), charset); | |
| 514 cr++) | |
| 515 ; | |
| 516 | |
| 517 if (cr->rfc3066) | |
| 518 { | |
| 519 DECLARE_DEBUG_FONTNAME (name); | |
| 520 CHECKING_LANG (0, eidata(name), cr->language); | |
| 521 lang = (FcChar8 *) cr->rfc3066; | |
| 522 } | |
| 523 else if (cr->charset) | |
| 524 { | |
| 525 /* what the hey, build 'em on the fly */ | |
| 526 /* #### in the case of error this could return NULL! */ | |
| 527 fccs = mule_to_fc_charset (charset); | |
| 528 lang = (FcChar8 *) XSTRING_DATA (XSYMBOL | |
| 529 (XCHARSET_NAME (charset))-> name); | |
| 530 } | |
| 531 else | |
| 532 { | |
| 533 /* OK, we fell off the end of the table */ | |
| 534 warn_when_safe_lispobj (intern ("xft"), intern ("alert"), | |
| 535 list2 (build_string ("unchecked charset"), | |
| 536 charset)); | |
| 537 /* default to "en" | |
| 538 #### THIS IS WRONG, WRONG, WRONG!! | |
| 539 It is why we never fall through to XLFD-checking. */ | |
| 540 } | |
| 541 | |
| 542 ASSERT_ASCTEXT_ASCII((Extbyte *) lang); | |
| 543 | |
| 544 if (fccs) | |
| 545 { | |
| 546 /* check for character set coverage */ | |
| 547 int i = 0; | |
| 548 FcCharSet *v; | |
| 549 FcResult r = FcPatternGetCharSet (fontxft, FC_CHARSET, i, &v); | |
| 550 | |
| 551 if (r == FcResultTypeMismatch) | |
| 552 { | |
| 553 DEBUG_XFT0 (0, "Unexpected type return in charset value\n"); | |
| 554 result = Qnil; | |
| 555 } | |
| 556 else if (r == FcResultMatch && FcCharSetIsSubset (fccs, v)) | |
| 557 { | |
| 558 /* The full pattern with the bitmap coverage is massively | |
| 559 unwieldy, but the shorter names are just *wrong*. We | |
| 560 should have the full thing internally as truename, and | |
| 561 filter stuff the client doesn't want to see on output. | |
| 562 Should we just store it into the truename right here? */ | |
| 563 DECLARE_DEBUG_FONTNAME (name); | |
| 564 DEBUG_XFT2 (0, "Xft font %s supports %s\n", | |
| 565 eidata(name), lang); | |
| 566 #ifdef RETURN_LONG_FONTCONFIG_NAMES | |
| 567 result = eimake_string(eistr_fullname); | |
| 568 #else | |
| 569 result = eimake_string(eistr_longname); | |
| 570 #endif | |
| 571 } | |
| 572 else | |
| 573 { | |
| 574 DECLARE_DEBUG_FONTNAME (name); | |
| 575 DEBUG_XFT2 (0, "Xft font %s doesn't support %s\n", | |
| 576 eidata(name), lang); | |
| 577 result = Qnil; | |
| 578 } | |
| 579 | |
| 580 /* clean up */ | |
| 581 FcCharSetDestroy (fccs); | |
| 582 } | |
| 583 else | |
| 584 { | |
| 585 /* check for language coverage */ | |
| 586 int i = 0; | |
| 587 FcValue v; | |
| 588 /* the main event */ | |
| 589 FcResult r = FcPatternGet (fontxft, FC_LANG, i, &v); | |
| 590 | |
| 591 if (r == FcResultMatch) | |
| 592 { | |
| 593 if (v.type != FcTypeLangSet) /* excessive paranoia */ | |
| 594 { | |
| 595 ASSERT_ASCTEXT_ASCII(FcTypeOfValueToString(v)); | |
| 596 /* Urk! Fall back and punt to core font. */ | |
| 597 DEBUG_XFT1 (0, "Unexpected type of lang value (%s)\n", | |
| 598 FcTypeOfValueToString (v)); | |
| 599 result = Qnil; | |
| 600 } | |
| 601 else if (FcLangSetHasLang (v.u.l, lang) != FcLangDifferentLang) | |
| 602 { | |
| 603 DECLARE_DEBUG_FONTNAME (name); | |
| 604 DEBUG_XFT2 (0, "Xft font %s supports %s\n", | |
| 605 eidata(name), lang); | |
| 606 #ifdef RETURN_LONG_FONTCONFIG_NAMES | |
| 607 result = eimake_string(eistr_fullname); | |
| 608 #else | |
| 609 result = eimake_string(eistr_longname); | |
| 610 #endif | |
| 611 } | |
| 612 else | |
| 613 { | |
| 614 DECLARE_DEBUG_FONTNAME (name); | |
| 615 DEBUG_XFT2 (0, "Xft font %s doesn't support %s\n", | |
| 616 eidata(name), lang); | |
| 617 result = Qnil; | |
| 618 } | |
| 619 } | |
| 620 else | |
| 621 { | |
| 622 ASSERT_ASCTEXT_ASCII(FcResultToString(r)); | |
| 623 DEBUG_XFT1 (0, "Getting lang: unexpected result=%s\n", | |
| 624 FcResultToString (r)); | |
| 625 result = Qnil; | |
| 626 } | |
| 627 } | |
| 628 | |
| 629 /* clean up and maybe return */ | |
| 630 FcPatternDestroy (fontxft); | |
| 631 if (!UNBOUNDP (result)) | |
| 632 return result; | |
| 633 } | |
| 634 } | |
| 635 return Qnil; | |
| 636 } | |
| 637 #undef DECLARE_DEBUG_FONTNAME | |
| 638 | |
| 639 #endif /* USE_XFT */ | |
| 640 | |
| 641 /* find a font spec that matches font spec FONT and also matches | |
| 642 (the registry of) CHARSET. */ | |
| 643 static Lisp_Object | |
| 644 #ifdef THIS_IS_GTK | |
| 645 gtk_find_charset_font (Lisp_Object device, Lisp_Object font, | |
| 646 Lisp_Object charset, | |
| 647 enum font_specifier_matchspec_stages stage) | |
| 648 #else | |
| 649 x_find_charset_font (Lisp_Object device, Lisp_Object font, Lisp_Object charset, | |
| 650 enum font_specifier_matchspec_stages stage) | |
| 651 #endif | |
| 652 { | |
| 653 Lisp_Object result = Qnil, registries = Qnil; | |
| 654 int j, hyphen_count, registries_len = 0; | |
| 655 Ibyte *hyphening, *new_hyphening; | |
| 656 Bytecount xlfd_length; | |
| 657 | |
| 658 DECLARE_EISTRING(ei_xlfd_without_registry); | |
| 659 DECLARE_EISTRING(ei_xlfd); | |
| 660 | |
| 661 #ifdef USE_XFT | |
| 662 result = xft_find_charset_font(font, charset, stage); | |
| 663 if (!NILP(result)) | |
| 664 { | |
| 665 return result; | |
| 666 } | |
| 667 #endif | |
| 668 | |
| 669 switch (stage) | |
| 670 { | |
| 671 case initial: | |
| 672 { | |
| 673 if (!(NILP(XCHARSET_REGISTRIES(charset))) | |
| 674 && VECTORP(XCHARSET_REGISTRIES(charset))) | |
| 675 { | |
| 676 registries_len = XVECTOR_LENGTH(XCHARSET_REGISTRIES(charset)); | |
| 677 registries = XCHARSET_REGISTRIES(charset); | |
| 678 } | |
| 679 break; | |
| 680 } | |
| 681 case final: | |
| 682 { | |
| 683 registries_len = 1; | |
| 684 registries = Qunicode_registries; | |
| 685 break; | |
| 686 } | |
| 687 default: | |
| 688 { | |
| 689 assert(0); | |
| 690 break; | |
| 691 } | |
| 692 } | |
| 693 | |
| 694 eicpy_lstr(ei_xlfd, font); | |
| 695 hyphening = eidata(ei_xlfd); | |
| 696 xlfd_length = eilen(ei_xlfd); | |
| 697 | |
| 698 /* Count the hyphens in the string, moving new_hyphening to just after the | |
| 699 last one. */ | |
| 700 hyphen_count = count_hyphens(hyphening, xlfd_length, &new_hyphening); | |
| 701 | |
| 702 if (0 == registries_len || (5 > hyphen_count && | |
| 703 !(1 == xlfd_length && '*' == *hyphening))) | |
| 704 { | |
| 705 /* No proper XLFD specified, or we can't modify the pattern to change | |
| 706 the registry and encoding to match what we want, or we have no | |
| 707 information on the registry needed. */ | |
| 708 eito_external(ei_xlfd, Qx_font_name_encoding); | |
| 709 DEBUG_OBJECTS ("about to xlistfonts_checking_charset, XLFD %s\n", | |
| 710 eidata(ei_xlfd)); | |
| 711 result = xlistfonts_checking_charset (device, eiextdata(ei_xlfd), | |
| 712 charset, stage); | |
| 713 /* No need to loop through the available registries; return | |
| 714 immediately. */ | |
| 715 return result; | |
| 716 } | |
| 717 else if (1 == xlfd_length && '*' == *hyphening) | |
| 718 { | |
| 719 /* It's a single asterisk. We can add the registry directly to the | |
| 720 end. */ | |
| 721 eicpy_ch(ei_xlfd_without_registry, '*'); | |
| 722 } | |
| 723 else | |
| 724 { | |
| 725 /* It's a fully-specified XLFD. Work out where the registry and | |
| 726 encoding are, and initialise ei_xlfd_without_registry to the string | |
| 727 without them. */ | |
| 728 | |
| 729 /* count_hyphens has set new_hyphening to just after the last | |
| 730 hyphen. Move back to just after the hyphen before it. */ | |
| 731 | |
| 732 for (new_hyphening -= 2; new_hyphening > hyphening | |
| 733 && '-' != *new_hyphening; --new_hyphening) | |
| 734 ; | |
| 735 ++new_hyphening; | |
| 736 | |
| 737 eicpy_ei(ei_xlfd_without_registry, ei_xlfd); | |
| 738 | |
| 739 /* Manipulate ei_xlfd_without_registry, using the information about | |
| 740 ei_xlfd, to which it's identical. */ | |
| 741 eidel(ei_xlfd_without_registry, new_hyphening - hyphening, -1, | |
| 742 eilen(ei_xlfd) - (new_hyphening - hyphening), -1); | |
| 743 | |
| 744 } | |
| 745 | |
| 746 /* Now, loop through the registries and encodings defined for this | |
| 747 charset, doing an XListFonts each time with the pattern modified to | |
| 748 specify the regisry and encoding. This avoids huge amounts of IPC and | |
| 749 duplicated searching; now we use the searching the X server was doing | |
| 750 anyway, where before the X server did its search, transferred huge | |
| 751 amounts of data, and then we proceeded to do a regexp search on that | |
| 752 data. */ | |
| 753 for (j = 0; j < registries_len && NILP(result); ++j) | |
| 754 { | |
| 755 eireset(ei_xlfd); | |
| 756 eicpy_ei(ei_xlfd, ei_xlfd_without_registry); | |
| 757 | |
| 758 eicat_lstr(ei_xlfd, XVECTOR_DATA(registries)[j]); | |
| 759 | |
| 760 eito_external(ei_xlfd, Qx_font_name_encoding); | |
| 761 | |
| 762 DEBUG_OBJECTS ("about to xlistfonts_checking_charset, XLFD %s\n", | |
| 763 eidata(ei_xlfd)); | |
| 764 result = xlistfonts_checking_charset (device, eiextdata(ei_xlfd), | |
| 765 charset, stage); | |
| 766 } | |
| 767 | |
| 3676 | 768 /* In the event that the charset is ASCII and we haven't matched |
| 769 anything up to now, even with a pattern of "*", add "iso8859-1" | |
| 770 to the charset's registry and try again. Not returning a result | |
| 771 for ASCII means our frame geometry calculations are | |
| 772 inconsistent, and that we may crash. */ | |
| 773 | |
| 774 if (1 == xlfd_length && EQ(charset, Vcharset_ascii) && NILP(result) | |
| 775 && ('*' == eigetch(ei_xlfd_without_registry, 0))) | |
| 776 | |
| 777 { | |
| 778 int have_latin1 = 0; | |
| 779 | |
| 780 /* Set this to, for example, is08859-1 if you want to see the | |
| 781 error behaviour. */ | |
| 782 | |
| 783 #define FALLBACK_ASCII_REGISTRY "iso8859-1" | |
| 784 | |
| 785 for (j = 0; j < registries_len; ++j) | |
| 786 { | |
| 787 if (0 == qxestrcasecmp(XSTRING_DATA(XVECTOR_DATA(registries)[j]), | |
| 4124 | 788 (Ibyte *) FALLBACK_ASCII_REGISTRY)) |
| 3676 | 789 { |
| 790 have_latin1 = 1; | |
| 791 break; | |
| 792 } | |
| 793 } | |
| 794 | |
| 795 if (!have_latin1) | |
| 796 { | |
| 797 Lisp_Object new_registries = make_vector(registries_len + 1, Qnil); | |
| 798 | |
| 799 XVECTOR_DATA(new_registries)[0] | |
| 800 = build_string(FALLBACK_ASCII_REGISTRY); | |
| 801 | |
| 802 memcpy(XVECTOR_DATA(new_registries) + 1, | |
| 803 XVECTOR_DATA(registries), | |
| 804 sizeof XVECTOR_DATA(registries)[0] * | |
| 805 XVECTOR_LENGTH(registries)); | |
| 806 | |
| 807 /* Calling set_charset_registries instead of overwriting the | |
| 808 value directly, to allow the charset font caches to be | |
| 809 invalidated and a change to the default face to be | |
| 810 noted. */ | |
| 811 set_charset_registries(charset, new_registries); | |
| 812 | |
| 3680 | 813 warn_when_safe (Qface, Qwarning, |
| 814 "Your ASCII charset registries contain nothing " | |
| 815 "sensible. Adding `" FALLBACK_ASCII_REGISTRY "'."); | |
| 816 | |
| 3676 | 817 /* And recurse. */ |
| 818 result = | |
| 819 DEVMETH_OR_GIVEN (XDEVICE (device), find_charset_font, | |
| 820 (device, font, charset, stage), | |
| 821 result); | |
| 822 } | |
| 823 else | |
| 824 { | |
| 825 DECLARE_EISTRING (ei_connection_name); | |
| 826 | |
| 827 /* We preserve a copy of the connection name for the error message | |
| 828 after the device is deleted. */ | |
| 829 eicpy_lstr (ei_connection_name, | |
| 830 DEVICE_CONNECTION (XDEVICE(device))); | |
| 831 | |
| 832 stderr_out ("Cannot find a font for ASCII, deleting device on %s\n", | |
| 833 eidata (ei_connection_name)); | |
| 834 | |
| 835 io_error_delete_device (device); | |
| 836 | |
| 837 /* Do a normal warning in the event that we have other, non-X | |
| 838 frames available. (If we don't, io_error_delete_device will | |
| 839 have exited.) */ | |
| 840 warn_when_safe | |
| 841 (Qface, Qerror, | |
| 842 "Cannot find a font for ASCII, deleting device on %s.\n" | |
| 843 "\n" | |
| 844 "Your X server fonts appear to be inconsistent; fix them, or\n" | |
| 845 "the next frame you create on that DISPLAY will crash this\n" | |
| 846 "XEmacs. At a minimum, provide one font with an XLFD ending\n" | |
| 847 "in `" FALLBACK_ASCII_REGISTRY "', so we can work out what size\n" | |
| 848 "a frame should be. ", | |
| 849 eidata (ei_connection_name)); | |
| 850 } | |
| 851 | |
| 852 } | |
| 853 | |
| 3659 | 854 /* This function used to return the font spec, in the case where a font |
| 855 didn't exist on the X server but it did match the charset. We're not | |
| 856 doing that any more, because none of the other platform code does, and | |
| 857 the old behaviour was badly-judged in other respects, so I don't trust | |
| 858 the original author to have had a good reason for it. */ | |
| 859 | |
| 860 return result; | |
| 861 } | |
| 862 | |
| 863 #endif /* MULE */ |
