2 * X11 physical font objects
4 * Copyright 1997 Alex Korobka
6 * TODO: Mapping algorithm tweaks, FO_SYNTH_... flags (ExtTextOut() will
7 * have to be changed for that), dynamic font loading (FreeType).
12 #include <X11/Xatom.h>
21 #include <sys/types.h>
31 #include "debugtools.h"
32 #include "user.h" /* for TWEAK_WineLook (FIXME) */
36 DEFAULT_DEBUG_CHANNEL(font);
38 #define X_PFONT_MAGIC (0xFADE0000)
39 #define X_FMC_MAGIC (0x0000CAFE)
41 #define MAX_FONTS 1024*16
42 #define MAX_LFD_LENGTH 256
46 #define DEF_POINT_SIZE 8 /* CreateFont(0 .. ) gets this */
47 #define DEF_SCALABLE_HEIGHT 100 /* pixels */
48 #define MIN_FONT_SIZE 2 /* Min size in pixels */
49 #define MAX_FONT_SIZE 1000 /* Max size in pixels */
51 #define REMOVE_SUBSETS 1
52 #define UNMARK_SUBSETS 0
55 #define FF_FAMILY (FF_MODERN | FF_SWISS | FF_ROMAN | FF_DECORATIVE | FF_SCRIPT)
57 typedef struct __fontAlias
61 struct __fontAlias* next;
64 static fontAlias *aliasTable = NULL;
66 UINT16 XTextCaps = TC_OP_CHARACTER | TC_OP_STROKE |
67 TC_CP_STROKE | TC_CR_ANY |
68 TC_SA_DOUBLE | TC_SA_INTEGER | TC_SA_CONTIN |
69 TC_UA_ABLE | TC_SO_ABLE | TC_RA_ABLE;
71 /* X11R6 adds TC_SF_X_YINDEP, maybe more... */
73 static const char* INIFontMetrics = "/cachedmetrics.";
74 static const char* INIFontSection = "fonts";
75 static const char* INIAliasSection = "Alias";
76 static const char* INIIgnoreSection = "Ignore";
77 static const char* INIDefault = "Default";
78 static const char* INIDefaultFixed = "DefaultFixed";
79 static const char* INIResolution = "Resolution";
80 static const char* INIGlobalMetrics = "FontMetrics";
81 static const char* INIDefaultSerif = "DefaultSerif";
82 static const char* INIDefaultSansSerif = "DefaultSansSerif";
85 /* FIXME - are there any more Latin charsets ? */
86 /* FIXME - RUSSIAN, ARABIC, GREEK, HEBREW are NOT Latin */
87 #define IS_LATIN_CHARSET(ch) \
88 ((ch)==ANSI_CHARSET ||\
90 (ch)==ISO3_CHARSET ||\
91 (ch)==ISO4_CHARSET ||\
92 (ch)==RUSSIAN_CHARSET ||\
93 (ch)==ARABIC_CHARSET ||\
94 (ch)==GREEK_CHARSET ||\
95 (ch)==HEBREW_CHARSET ||\
96 (ch)==TURKISH_CHARSET ||\
97 (ch)==ISO10_CHARSET ||\
98 (ch)==BALTIC_CHARSET ||\
101 /* suffix-charset mapping tables - must be less than 254 entries long */
103 typedef struct __sufch
106 WORD charset; /* hibyte != 0 means *internal* charset */
111 static const SuffixCharset sufch_ansi[] = {
112 { "0", ANSI_CHARSET, 1252, X11DRV_CPTABLE_SBCS },
113 { NULL, ANSI_CHARSET, 1252, X11DRV_CPTABLE_SBCS }};
115 static const SuffixCharset sufch_iso646[] = {
116 { "irv", ANSI_CHARSET, 1252, X11DRV_CPTABLE_SBCS },
117 { NULL, ANSI_CHARSET, 1252, X11DRV_CPTABLE_SBCS }};
119 static const SuffixCharset sufch_iso8859[] = {
120 { "1", ANSI_CHARSET, 28591, X11DRV_CPTABLE_SBCS },
121 { "2", EE_CHARSET, 28592, X11DRV_CPTABLE_SBCS },
122 { "3", ISO3_CHARSET, 28593, X11DRV_CPTABLE_SBCS },
123 { "4", ISO4_CHARSET, 28594, X11DRV_CPTABLE_SBCS },
124 { "5", RUSSIAN_CHARSET, 28595, X11DRV_CPTABLE_SBCS },
125 { "6", ARABIC_CHARSET, 28596, X11DRV_CPTABLE_SBCS },
126 { "7", GREEK_CHARSET, 28597, X11DRV_CPTABLE_SBCS },
127 { "8", HEBREW_CHARSET, 28598, X11DRV_CPTABLE_SBCS },
128 { "9", TURKISH_CHARSET, 28599, X11DRV_CPTABLE_SBCS },
129 { "10", ISO10_CHARSET, 28600, X11DRV_CPTABLE_SBCS },
130 { "11", THAI_CHARSET, 874, X11DRV_CPTABLE_SBCS }, /* FIXME */
131 { "12", SYMBOL_CHARSET, CP_SYMBOL, X11DRV_CPTABLE_SBCS },
132 { "13", BALTIC_CHARSET, 28603, X11DRV_CPTABLE_SBCS },
133 { "14", CELTIC_CHARSET, 28604, X11DRV_CPTABLE_SBCS },
134 { "15", ANSI_CHARSET, 28605, X11DRV_CPTABLE_SBCS },
135 { NULL, ANSI_CHARSET, 1252, X11DRV_CPTABLE_SBCS }};
137 static const SuffixCharset sufch_microsoft[] = {
138 { "cp1250", EE_CHARSET, 1250, X11DRV_CPTABLE_SBCS },
139 { "cp1251", RUSSIAN_CHARSET, 1251, X11DRV_CPTABLE_SBCS },
140 { "cp1252", ANSI_CHARSET, 1252, X11DRV_CPTABLE_SBCS },
141 { "cp1253", GREEK_CHARSET, 1253, X11DRV_CPTABLE_SBCS },
142 { "cp1254", TURKISH_CHARSET, 1254, X11DRV_CPTABLE_SBCS },
143 { "cp1255", HEBREW_CHARSET, 1255, X11DRV_CPTABLE_SBCS },
144 { "cp1256", ARABIC_CHARSET, 1256, X11DRV_CPTABLE_SBCS },
145 { "cp1257", BALTIC_CHARSET, 1257, X11DRV_CPTABLE_SBCS },
146 { "fontspecific", SYMBOL_CHARSET, CP_SYMBOL, X11DRV_CPTABLE_SBCS },
147 { "symbol", SYMBOL_CHARSET, CP_SYMBOL, X11DRV_CPTABLE_SBCS },
148 { NULL, ANSI_CHARSET, 1252, X11DRV_CPTABLE_SBCS }};
150 static const SuffixCharset sufch_tcvn[] = {
151 { "0", TCVN_CHARSET, 1252, X11DRV_CPTABLE_SBCS }, /* FIXME */
152 { NULL, TCVN_CHARSET, 1252, X11DRV_CPTABLE_SBCS }};
154 static const SuffixCharset sufch_tis620[] = {
155 { "0", THAI_CHARSET, 874, X11DRV_CPTABLE_SBCS }, /* FIXME */
156 { NULL, THAI_CHARSET, 874, X11DRV_CPTABLE_SBCS }};
158 static const SuffixCharset sufch_viscii[] = {
159 { "1", VISCII_CHARSET, 1252, X11DRV_CPTABLE_SBCS }, /* FIXME */
160 { NULL, VISCII_CHARSET, 1252, X11DRV_CPTABLE_SBCS }};
162 static const SuffixCharset sufch_windows[] = {
163 { "1250", EE_CHARSET, 1250, X11DRV_CPTABLE_SBCS },
164 { "1251", RUSSIAN_CHARSET, 1251, X11DRV_CPTABLE_SBCS },
165 { "1252", ANSI_CHARSET, 1252, X11DRV_CPTABLE_SBCS },
166 { "1253", GREEK_CHARSET, 1253, X11DRV_CPTABLE_SBCS },
167 { "1254", TURKISH_CHARSET, 1254, X11DRV_CPTABLE_SBCS },
168 { "1255", HEBREW_CHARSET, 1255, X11DRV_CPTABLE_SBCS },
169 { "1256", ARABIC_CHARSET, 1256, X11DRV_CPTABLE_SBCS },
170 { "1257", BALTIC_CHARSET, 1257, X11DRV_CPTABLE_SBCS },
171 { NULL, ANSI_CHARSET, 1252, X11DRV_CPTABLE_SBCS }};
173 static const SuffixCharset sufch_koi8[] = {
174 { "r", RUSSIAN_CHARSET, 20866, X11DRV_CPTABLE_SBCS },
175 { "ru", RUSSIAN_CHARSET, 20866, X11DRV_CPTABLE_SBCS },
176 { "u", RUSSIAN_CHARSET, 20866, X11DRV_CPTABLE_SBCS },
177 { NULL, RUSSIAN_CHARSET, 20866, X11DRV_CPTABLE_SBCS }};
179 static const SuffixCharset sufch_jisx0201[] = {
180 { "0", X11FONT_JISX0201_CHARSET, 932, X11DRV_CPTABLE_SBCS },
181 { NULL, X11FONT_JISX0201_CHARSET, 932, X11DRV_CPTABLE_SBCS }};
183 static const SuffixCharset sufch_jisx0208[] = {
184 { "0", SHIFTJIS_CHARSET, 932, X11DRV_CPTABLE_CP932 },
185 { NULL, SHIFTJIS_CHARSET, 932, X11DRV_CPTABLE_CP932 }};
187 static const SuffixCharset sufch_jisx0212[] = {
188 { "0", X11FONT_JISX0212_CHARSET, 932, X11DRV_CPTABLE_CP932 },
189 { NULL, X11FONT_JISX0212_CHARSET, 932, X11DRV_CPTABLE_CP932 }};
191 static const SuffixCharset sufch_ksc5601[] = {
192 { "0", HANGEUL_CHARSET, 949, X11DRV_CPTABLE_CP949 },
193 { NULL, HANGEUL_CHARSET, 949, X11DRV_CPTABLE_CP949 }};
195 static const SuffixCharset sufch_gb2312[] = {
196 { "0", GB2312_CHARSET, 936, X11DRV_CPTABLE_CP936 },
197 { NULL, GB2312_CHARSET, 936, X11DRV_CPTABLE_CP936 }};
199 static const SuffixCharset sufch_big5[] = {
200 { "0", CHINESEBIG5_CHARSET, 950, X11DRV_CPTABLE_CP950 },
201 { NULL, CHINESEBIG5_CHARSET, 950, X11DRV_CPTABLE_CP950 }};
203 static const SuffixCharset sufch_unicode[] = {
204 { "0", DEFAULT_CHARSET, 0, X11DRV_CPTABLE_UNICODE },
205 { NULL, DEFAULT_CHARSET, 0, X11DRV_CPTABLE_UNICODE }};
207 static const SuffixCharset sufch_iso10646[] = {
208 { "1", DEFAULT_CHARSET, 0, X11DRV_CPTABLE_UNICODE },
209 { NULL, DEFAULT_CHARSET, 0, X11DRV_CPTABLE_UNICODE }};
211 /* Each of these must be matched explicitly */
212 static const SuffixCharset sufch_any[] = {
213 { "fontspecific", SYMBOL_CHARSET, CP_SYMBOL, X11DRV_CPTABLE_SBCS },
214 { NULL, 0, 0, X11DRV_CPTABLE_SBCS }};
220 const SuffixCharset* sufch;
222 } fontEncodingTemplate;
224 /* Note: we can attach additional encoding mappings to the end
225 * of this table at runtime.
227 static fontEncodingTemplate __fETTable[] = {
228 { "ansi", sufch_ansi, &__fETTable[1] },
229 { "ascii", sufch_ansi, &__fETTable[2] },
230 { "iso646.1991", sufch_iso646, &__fETTable[3] },
231 { "iso8859", sufch_iso8859, &__fETTable[4] },
232 { "microsoft", sufch_microsoft, &__fETTable[5] },
233 { "tcvn", sufch_tcvn, &__fETTable[6] },
234 { "tis620.2533", sufch_tis620, &__fETTable[7] },
235 { "viscii1.1", sufch_viscii, &__fETTable[8] },
236 { "windows", sufch_windows, &__fETTable[9] },
237 { "koi8", sufch_koi8, &__fETTable[10]},
238 { "jisx0201.1976",sufch_jisx0201, &__fETTable[11]},
239 { "jisc6226.1978",sufch_jisx0208, &__fETTable[12]},
240 { "jisx0208.1983",sufch_jisx0208, &__fETTable[13]},
241 { "jisx0208.1990",sufch_jisx0208, &__fETTable[14]},
242 { "jisx0212.1990",sufch_jisx0212, &__fETTable[15]},
243 { "ksc5601.1987", sufch_ksc5601, &__fETTable[16]},
244 { "gb2312.1980", sufch_gb2312, &__fETTable[17]},
245 { "big5.et", sufch_big5, &__fETTable[18]},
246 { "unicode", sufch_unicode, &__fETTable[19]},
247 { "iso10646", sufch_iso10646, &__fETTable[20]},
248 { "cp", sufch_windows, &__fETTable[21]},
249 /* NULL prefix matches anything so put it last */
250 { NULL, sufch_any, NULL },
252 static fontEncodingTemplate* fETTable = __fETTable;
254 /* a charset database for known facenames */
255 struct CharsetBindingInfo
257 const char* pszFaceName;
260 static const struct CharsetBindingInfo charsetbindings[] =
262 /* special facenames */
263 { "System", DEFAULT_CHARSET },
264 { "FixedSys", DEFAULT_CHARSET },
266 /* known facenames */
267 { "MS Serif", ANSI_CHARSET },
268 { "MS Sans Serif", ANSI_CHARSET },
269 { "Courier", ANSI_CHARSET },
270 { "Symbol", SYMBOL_CHARSET },
272 { "Arial", ANSI_CHARSET },
273 { "Arial Greek", GREEK_CHARSET },
274 { "Arial Tur", TURKISH_CHARSET },
275 { "Arial Baltic", BALTIC_CHARSET },
276 { "Arial CE", EASTEUROPE_CHARSET },
277 { "Arial Cyr", RUSSIAN_CHARSET },
278 { "Courier New", ANSI_CHARSET },
279 { "Courier New Greek", GREEK_CHARSET },
280 { "Courier New Tur", TURKISH_CHARSET },
281 { "Courier New Baltic", BALTIC_CHARSET },
282 { "Courier New CE", EASTEUROPE_CHARSET },
283 { "Courier New Cyr", RUSSIAN_CHARSET },
284 { "Times New Roman", ANSI_CHARSET },
285 { "Times New Roman Greek", GREEK_CHARSET },
286 { "Times New Roman Tur", TURKISH_CHARSET },
287 { "Times New Roman Baltic", BALTIC_CHARSET },
288 { "Times New Roman CE", EASTEUROPE_CHARSET },
289 { "Times New Roman Cyr", RUSSIAN_CHARSET },
291 { "\x82\x6c\x82\x72 \x83\x53\x83\x56\x83\x62\x83\x4e",
292 SHIFTJIS_CHARSET }, /* MS gothic */
293 { "\x82\x6c\x82\x72 \x82\x6f\x83\x53\x83\x56\x83\x62\x83\x4e",
294 SHIFTJIS_CHARSET }, /* MS P gothic */
295 { "\x82\x6c\x82\x72 \x96\xbe\x92\xa9",
296 SHIFTJIS_CHARSET }, /* MS mincho */
297 { "\x82\x6c\x82\x72 \x82\x6f\x96\xbe\x92\xa9",
298 SHIFTJIS_CHARSET }, /* MS P mincho */
299 { "GulimChe", HANGEUL_CHARSET },
300 { "MS Song", GB2312_CHARSET },
301 { "MS Hei", GB2312_CHARSET },
307 static int DefResolution = 0;
309 static CRITICAL_SECTION crtsc_fonts_X11 = CRITICAL_SECTION_INIT;
311 static fontResource* fontList = NULL;
312 static fontObject* fontCache = NULL; /* array */
313 static int fontCacheSize = FONTCACHE;
314 static int fontLF = -1, fontMRU = -1; /* last free, most recently used */
316 #define __PFONT(pFont) ( fontCache + ((UINT)(pFont) & 0x0000FFFF) )
317 #define CHECK_PFONT(pFont) ( (((UINT)(pFont) & 0xFFFF0000) == X_PFONT_MAGIC) &&\
318 (((UINT)(pFont) & 0x0000FFFF) < fontCacheSize) )
320 static Atom RAW_ASCENT;
321 static Atom RAW_DESCENT;
323 /***********************************************************************
324 * Helper macros from X distribution
327 #define CI_NONEXISTCHAR(cs) (((cs)->width == 0) && \
328 (((cs)->rbearing|(cs)->lbearing| \
329 (cs)->ascent|(cs)->descent) == 0))
331 #define CI_GET_CHAR_INFO(fs,col,def,cs) \
334 if (col >= fs->min_char_or_byte2 && col <= fs->max_char_or_byte2) { \
335 if (fs->per_char == NULL) { \
336 cs = &fs->min_bounds; \
338 cs = &fs->per_char[(col - fs->min_char_or_byte2)]; \
339 if (CI_NONEXISTCHAR(cs)) cs = def; \
344 #define CI_GET_DEFAULT_INFO(fs,cs) \
345 CI_GET_CHAR_INFO(fs, fs->default_char, NULL, cs)
347 /***********************************************************************
350 static UINT16 __lfCheckSum( LPLOGFONT16 plf )
352 CHAR font[LF_FACESIZE];
358 for (i = 0; i < 9; i++) checksum ^= *ptr++;
359 for (i = 0; i < LF_FACESIZE; i++)
361 font[i] = tolower(plf->lfFaceName[i]);
362 if (!font[i] || font[i] == ' ') break;
364 for (ptr = (UINT16 *)font, i >>= 1; i > 0; i-- ) checksum ^= *ptr++;
368 static UINT16 __genericCheckSum( const void *ptr, int size )
370 unsigned int checksum = 0;
371 const char *p = (const char *)ptr;
373 checksum ^= (checksum << 3) + (checksum >> 29) + *p++;
375 return checksum & 0xffff;
378 /*************************************************************************
379 * LFD parse/compose routines
381 * NB. LFD_Parse will use lpFont for its own ends, so if you want to keep it
384 * These functions also do TILDE to HYPHEN conversion
386 static LFD* LFD_Parse(LPSTR lpFont)
389 char *lpch = lpFont, *lfd_fld[LFD_FIELDS], *field_start;
393 WARN("font '%s' doesn't begin with '%c'\n", lpFont, HYPHEN);
397 field_start = ++lpch;
398 for( i = 0; i < LFD_FIELDS; )
403 lfd_fld[i] = field_start;
405 field_start = ++lpch;
409 lfd_fld[i] = field_start;
413 else if (*lpch == TILDE)
421 /* Fill in the empty fields with NULLS */
422 for (; i< LFD_FIELDS; i++)
425 WARN("Extra ignored in font '%s'\n", lpFont);
427 lfd = HeapAlloc( GetProcessHeap(), 0, sizeof(LFD) );
430 lfd->foundry = lfd_fld[0];
431 lfd->family = lfd_fld[1];
432 lfd->weight = lfd_fld[2];
433 lfd->slant = lfd_fld[3];
434 lfd->set_width = lfd_fld[4];
435 lfd->add_style = lfd_fld[5];
436 lfd->pixel_size = lfd_fld[6];
437 lfd->point_size = lfd_fld[7];
438 lfd->resolution_x = lfd_fld[8];
439 lfd->resolution_y = lfd_fld[9];
440 lfd->spacing = lfd_fld[10];
441 lfd->average_width = lfd_fld[11];
442 lfd->charset_registry = lfd_fld[12];
443 lfd->charset_encoding = lfd_fld[13];
449 static void LFD_UnParse(LPSTR dp, UINT buf_size, LFD* lfd)
451 const char* lfd_fld[LFD_FIELDS];
455 return; /* Dont be silly */
457 lfd_fld[0] = lfd->foundry;
458 lfd_fld[1] = lfd->family;
459 lfd_fld[2] = lfd->weight ;
460 lfd_fld[3] = lfd->slant ;
461 lfd_fld[4] = lfd->set_width ;
462 lfd_fld[5] = lfd->add_style;
463 lfd_fld[6] = lfd->pixel_size;
464 lfd_fld[7] = lfd->point_size;
465 lfd_fld[8] = lfd->resolution_x;
466 lfd_fld[9] = lfd->resolution_y ;
467 lfd_fld[10] = lfd->spacing ;
468 lfd_fld[11] = lfd->average_width ;
469 lfd_fld[12] = lfd->charset_registry ;
470 lfd_fld[13] = lfd->charset_encoding ;
472 buf_size--; /* Room for the terminator */
474 for (i = 0; i < LFD_FIELDS; i++)
476 const char* sp = lfd_fld[i];
477 if (!sp || !buf_size)
482 while (buf_size > 0 && *sp)
484 *dp = (*sp == HYPHEN) ? TILDE : *sp;
493 static void LFD_GetWeight( fontInfo* fi, LPCSTR lpStr)
495 int j = strlen(lpStr);
496 if( j == 1 && *lpStr == '0')
497 fi->fi_flags |= FI_POLYWEIGHT;
500 if( !strcasecmp( "bold", lpStr) )
501 fi->df.dfWeight = FW_BOLD;
502 else if( !strcasecmp( "demi", lpStr) )
504 fi->fi_flags |= FI_FW_DEMI;
505 fi->df.dfWeight = FW_DEMIBOLD;
507 else if( !strcasecmp( "book", lpStr) )
509 fi->fi_flags |= FI_FW_BOOK;
510 fi->df.dfWeight = FW_REGULAR;
515 if( !strcasecmp( "light", lpStr) )
516 fi->df.dfWeight = FW_LIGHT;
517 else if( !strcasecmp( "black", lpStr) )
518 fi->df.dfWeight = FW_BLACK;
520 else if( j == 6 && !strcasecmp( "medium", lpStr) )
521 fi->df.dfWeight = FW_REGULAR;
522 else if( j == 8 && !strcasecmp( "demibold", lpStr) )
523 fi->df.dfWeight = FW_DEMIBOLD;
525 fi->df.dfWeight = FW_DONTCARE; /* FIXME: try to get something
526 * from the weight property */
529 static BOOL LFD_GetSlant( fontInfo* fi, LPCSTR lpStr)
531 int l = strlen(lpStr);
534 switch( tolower( *lpStr ) )
536 case '0': fi->fi_flags |= FI_POLYSLANT; /* haven't seen this one yet */
538 case 'r': fi->df.dfItalic = 0;
541 fi->fi_flags |= FI_OBLIQUE;
542 case 'i': fi->df.dfItalic = 1;
550 static void LFD_GetStyle( fontInfo* fi, LPCSTR lpstr, int dec_style_check)
552 int j = strlen(lpstr);
553 if( j > 3 ) /* find out is there "sans" or "script" */
557 if( strstr(lpstr, "sans") )
559 fi->df.dfPitchAndFamily |= FF_SWISS;
562 if( strstr(lpstr, "script") )
564 fi->df.dfPitchAndFamily |= FF_SCRIPT;
567 if( !j && dec_style_check )
568 fi->df.dfPitchAndFamily |= FF_DECORATIVE;
572 /*************************************************************************
577 * Fill in some fields in the fontInfo struct.
579 static int LFD_InitFontInfo( fontInfo* fi, const LFD* lfd, LPCSTR fullname )
581 int i, j, dec_style_check, scalability;
582 fontEncodingTemplate* boba;
583 const char* ridiculous = "font '%s' has ridiculous %s\n";
586 if (!lfd->charset_registry)
588 WARN("font '%s' does not have enough fields\n", fullname);
592 memset(fi, 0, sizeof(fontInfo) );
595 LFD_GetWeight( fi, lfd->weight);
598 dec_style_check = LFD_GetSlant( fi, lfd->slant);
601 lpstr = lfd->set_width;
602 if( strcasecmp( "normal", lpstr) ) /* XXX 'narrow', 'condensed', etc... */
603 dec_style_check = TRUE;
605 fi->fi_flags |= FI_NORMAL;
608 LFD_GetStyle(fi, lfd->add_style, dec_style_check);
610 /* pixel & decipoint height, and res_x & y */
614 j = strlen(lfd->pixel_size);
615 if( j == 0 || j > 3 )
617 WARN(ridiculous, fullname, "pixel_size");
620 if( !(fi->lfd_height = atoi(lfd->pixel_size)) )
623 j = strlen(lfd->point_size);
624 if( j == 0 || j > 3 )
626 WARN(ridiculous, fullname, "point_size");
629 if( !(atoi(lfd->point_size)) )
632 j = strlen(lfd->resolution_x);
633 if( j == 0 || j > 3 )
635 WARN(ridiculous, fullname, "resolution_x");
638 if( !(fi->lfd_resolution = atoi(lfd->resolution_x)) )
641 j = strlen(lfd->resolution_y);
642 if( j == 0 || j > 3 )
644 WARN(ridiculous, fullname, "resolution_y");
647 if( !(atoi(lfd->resolution_y)) )
650 /* Check scalability */
655 case 4: /* Scalable */
656 fi->fi_flags |= FI_SCALABLE;
659 /* #$%^!!! X11R6 mutant garbage (scalable bitmap) */
660 TRACE("Skipping scalable bitmap '%s'\n", fullname);
663 WARN("Font '%s' has weird scalability\n", fullname);
668 lpstr = lfd->spacing;
672 WARN("font '%s' has no spacing\n", fullname);
675 case 'p': fi->fi_flags |= FI_VARIABLEPITCH;
677 case 'c': fi->df.dfPitchAndFamily |= FF_MODERN;
678 fi->fi_flags |= FI_FIXEDEX;
680 case 'm': fi->fi_flags |= FI_FIXEDPITCH;
683 /* Of course this line does nothing */
684 fi->df.dfPitchAndFamily |= DEFAULT_PITCH | FF_DONTCARE;
687 /* average width - */
688 lpstr = lfd->average_width;
690 if( j == 0 || j > 3 )
692 WARN(ridiculous, fullname, "average_width");
696 if( !(atoi(lpstr)) && !scalability )
698 WARN("font '%s' has average_width 0 but is not scalable!!\n", fullname);
702 /* charset registry, charset encoding - */
703 lpstr = lfd->charset_registry;
704 if( strstr(lpstr, "ksc") ||
705 strstr(lpstr, "gb2312") ||
706 strstr(lpstr, "big5") )
708 FIXME("DBCS fonts like '%s' are not working correctly now.\n", fullname);
711 fi->df.dfCharSet = ANSI_CHARSET;
713 for( i = 0, boba = fETTable; boba; boba = boba->next, i++ )
715 if (!boba->prefix || !strcasecmp(lpstr, boba->prefix))
717 if (lfd->charset_encoding)
719 for( j = 0; boba->sufch[j].psuffix; j++ )
721 if( !strcasecmp(lfd->charset_encoding, boba->sufch[j].psuffix ))
723 fi->df.dfCharSet = (BYTE)(boba->sufch[j].charset & 0xff);
724 fi->internal_charset = boba->sufch[j].charset;
725 fi->codepage = boba->sufch[j].codepage;
726 fi->cptable = boba->sufch[j].cptable;
731 fi->df.dfCharSet = (BYTE)(boba->sufch[j].charset & 0xff);
732 fi->internal_charset = boba->sufch[j].charset;
733 fi->codepage = boba->sufch[j].codepage;
734 fi->cptable = boba->sufch[j].cptable;
737 FIXME("font '%s' has unknown character encoding '%s' in known registry '%s'\n",
738 fullname, lfd->charset_encoding, boba->prefix);
743 FIXME("font '%s' has unknown registry '%s' and character encoding '%s' \n",
744 fullname, lfd->charset_registry, lfd->charset_encoding);
748 WARN("Defaulting to: df.dfCharSet = %d, internal_charset = %d, codepage = %d, cptable = %d\n",
749 fi->df.dfCharSet,fi->internal_charset, fi->codepage, fi->cptable);
752 else if (boba->prefix)
754 WARN("font '%s' has known registry '%s' and no character encoding\n",
756 for( j = 0; boba->sufch[j].psuffix; j++ )
758 fi->df.dfCharSet = (BYTE)(boba->sufch[j].charset & 0xff);
759 fi->internal_charset = boba->sufch[j].charset;
760 fi->codepage = boba->sufch[j].codepage;
761 fi->cptable = boba->sufch[j].cptable;
767 WARN("font '%s' has unknown character set '%s'\n", fullname, lpstr);
771 /* i - index into fETTable
772 * j - index into suffix array for fETTable[i]
774 * 254 - found encoding prefix, unknown suffix
775 * 255 - no encoding match at all.
777 fi->fi_encoding = 256 * (UINT16)i + (UINT16)j;
783 /*************************************************************************
786 * make a matrix suitable for LFD based on theta radians
788 static void LFD_AngleMatrix( char* buffer, int h, double theta)
791 matrix[0] = h*cos(theta);
792 matrix[1] = h*sin(theta);
793 matrix[2] = -h*sin(theta);
794 matrix[3] = h*cos(theta);
795 sprintf(buffer, "[%+f%+f%+f%+f]", matrix[0], matrix[1], matrix[2], matrix[3]);
798 /*************************************************************************
801 * Note: uRelax is a treatment not a cure. Font mapping algorithm
802 * should be bulletproof enough to allow us to avoid hacks like
803 * this despite LFD being so braindead.
805 static BOOL LFD_ComposeLFD( const fontObject* fo,
806 INT height, LPSTR lpLFD, UINT uRelax )
810 char h_string[64], resx_string[64], resy_string[64];
813 /* Get the worst case over with first */
815 /* RealizeFont() will call us repeatedly with increasing uRelax
816 * until XLoadFont() succeeds.
817 * to avoid an infinite loop; these will always match
822 sprintf( lpLFD, "-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-1" );
824 sprintf( lpLFD, "-*-*-*-*-*-*-*-*-*-*-*-*-*-*" );
828 /* read foundry + family from fo */
829 aLFD.foundry = fo->fr->resource->foundry;
830 aLFD.family = fo->fr->resource->family;
833 switch( fo->fi->df.dfWeight )
836 aLFD.weight = "bold"; break;
838 if( fo->fi->fi_flags & FI_FW_BOOK )
839 aLFD.weight = "book";
841 aLFD.weight = "medium";
844 aLFD.weight = "demi";
845 if( !( fo->fi->fi_flags & FI_FW_DEMI) )
846 aLFD.weight = "bold";
849 aLFD.weight = "black"; break;
851 aLFD.weight = "light"; break;
857 if( fo->fi->df.dfItalic )
858 if( fo->fi->fi_flags & FI_OBLIQUE )
863 aLFD.slant = (uRelax < 1) ? "r" : any;
866 if( fo->fi->fi_flags & FI_NORMAL )
867 aLFD.set_width = "normal";
869 aLFD.set_width = any;
872 aLFD.add_style = any;
876 * FIXME: fill in lpXForm and lpPixmap for rotated fonts
878 if( fo->fo_flags & FO_SYNTH_HEIGHT )
879 h = fo->fi->lfd_height;
882 h = (fo->fi->lfd_height * height + (fo->fi->df.dfPixHeight>>1));
883 h /= fo->fi->df.dfPixHeight;
885 if (h < MIN_FONT_SIZE) /* Resist rounding down to 0 */
887 else if (h > MAX_FONT_SIZE) /* Sanity check as huge fonts can lock up the font server */
889 WARN("Huge font size %d pixels has been reduced to %d\n", h, MAX_FONT_SIZE);
894 /* handle rotated fonts */
895 if (fo->lf.lfEscapement) {
896 /* escapement is in tenths of degrees, theta is in radians */
897 double theta = M_PI*fo->lf.lfEscapement/1800.;
898 LFD_AngleMatrix(h_string, h, theta);
902 sprintf(h_string, "%d", h);
905 sprintf(h_string, "%d", fo->fi->lfd_height);
907 aLFD.pixel_size = h_string;
908 aLFD.point_size = any;
910 /* resolution_x,y, average width */
911 /* FOX ME - Why do some font servers ignore average width ?
912 * so that you have to mess around with res_y
914 aLFD.average_width = any;
917 sprintf(resx_string, "%d", fo->fi->lfd_resolution);
918 aLFD.resolution_x = resx_string;
920 strcpy(resy_string, resx_string);
921 if( uRelax == 0 && XTextCaps & TC_SF_X_YINDEP )
923 if( fo->lf.lfWidth && !(fo->fo_flags & FO_SYNTH_WIDTH))
925 int resy = 0.5 + fo->fi->lfd_resolution *
926 (fo->fi->df.dfAvgWidth * height) /
927 (fo->lf.lfWidth * fo->fi->df.dfPixHeight) ;
928 sprintf(resy_string, "%d", resy);
932 /* FIXME - synth width */
935 aLFD.resolution_y = resy_string;
939 aLFD.resolution_x = aLFD.resolution_y = any;
946 if( fo->fi->fi_flags & FI_FIXEDPITCH )
947 w = ( fo->fi->fi_flags & FI_FIXEDEX ) ? "c" : "m";
949 w = ( fo->fi->fi_flags & FI_VARIABLEPITCH ) ? "p" : any;
951 aLFD.spacing = (uRelax <= 1) ? w : any;
958 fontEncodingTemplate* boba = fETTable;
960 for(i = fo->fi->fi_encoding >> 8; i; i--) boba = boba->next;
961 aLFD.charset_registry = boba->prefix ? boba->prefix : any;
963 i = fo->fi->fi_encoding & 255;
967 aLFD.charset_encoding = boba->sufch[i].psuffix;
971 aLFD.charset_encoding = any;
974 case 255: /* no suffix - it ends eg "-ascii" */
975 aLFD.charset_encoding = NULL;
981 aLFD.charset_registry = any;
982 aLFD.charset_encoding = any;
985 LFD_UnParse(lpLFD, MAX_LFD_LENGTH, &aLFD);
987 TRACE("\tLFD(uRelax=%d): %s\n", uRelax, lpLFD );
992 /***********************************************************************
995 * font info - http://www.microsoft.com/kb/articles/q65/1/23.htm
996 * Windows font metrics - http://www.microsoft.com/kb/articles/q32/6/67.htm
998 static void XFONT_GetLeading( const LPIFONTINFO16 pFI, const XFontStruct* x_fs,
999 INT16* pIL, INT16* pEL, const XFONTTRANS *XFT )
1001 unsigned long height;
1002 unsigned min = (unsigned char)pFI->dfFirstChar;
1003 BOOL bIsLatin = IS_LATIN_CHARSET(pFI->dfCharSet);
1008 Atom RAW_CAP_HEIGHT = TSXInternAtom(gdi_display, "RAW_CAP_HEIGHT", TRUE);
1009 if(TSXGetFontProperty((XFontStruct*)x_fs, RAW_CAP_HEIGHT, &height))
1010 *pIL = XFT->ascent -
1011 (INT)(XFT->pixelsize / 1000.0 * height);
1017 if( TSXGetFontProperty((XFontStruct*)x_fs, XA_CAP_HEIGHT, &height) == FALSE )
1019 if( x_fs->per_char )
1021 height = x_fs->per_char['X' - min].ascent;
1023 if (x_fs->ascent >= x_fs->max_bounds.ascent)
1024 height = x_fs->max_bounds.ascent;
1027 height = x_fs->ascent;
1029 *pEL = x_fs->max_bounds.ascent - height;
1032 height = x_fs->min_bounds.ascent;
1035 *pIL = x_fs->ascent - height;
1038 /***********************************************************************
1041 static int XFONT_CharWidth(const XFontStruct* x_fs,
1042 const XFONTTRANS *XFT, int ch)
1045 return x_fs->per_char[ch].width;
1047 return x_fs->per_char[ch].attributes * XFT->pixelsize / 1000.0;
1050 /***********************************************************************
1051 * XFONT_GetAvgCharWidth
1053 static INT XFONT_GetAvgCharWidth( LPIFONTINFO16 pFI, const XFontStruct* x_fs,
1054 const XFONTTRANS *XFT)
1056 unsigned min = (unsigned char)pFI->dfFirstChar;
1057 unsigned max = (unsigned char)pFI->dfLastChar;
1061 if( x_fs->per_char )
1063 int width = 0, chars = 0, j;
1064 if( IS_LATIN_CHARSET(pFI->dfCharSet) ||
1065 pFI->dfCharSet == DEFAULT_CHARSET )
1067 /* FIXME - should use a weighted average */
1068 for( j = 0; j < 26; j++ )
1069 width += XFONT_CharWidth(x_fs, XFT, 'a' + j - min) +
1070 XFONT_CharWidth(x_fs, XFT, 'A' + j - min);
1073 else /* unweighted average of everything */
1075 for( j = 0, max -= min; j <= max; j++ )
1076 if( !CI_NONEXISTCHAR(x_fs->per_char + j) )
1078 width += XFONT_CharWidth(x_fs, XFT, j);
1082 if (chars) avg = (width + (chars>>1))/ chars;
1083 else avg = 0; /* No characters exist at all */
1085 else /* uniform width */
1086 avg = x_fs->min_bounds.width;
1091 /***********************************************************************
1092 * XFONT_GetMaxCharWidth
1094 static INT XFONT_GetMaxCharWidth(const XFontStruct* xfs, const XFONTTRANS *XFT)
1096 unsigned min = (unsigned char)xfs->min_char_or_byte2;
1097 unsigned max = (unsigned char)xfs->max_char_or_byte2;
1100 if(!XFT || !xfs->per_char)
1101 return abs(xfs->max_bounds.width);
1103 for( j = 0, maxwidth = 0, max -= min; j <= max; j++ )
1104 if( !CI_NONEXISTCHAR(xfs->per_char + j) )
1105 if(maxwidth < xfs->per_char[j].attributes)
1106 maxwidth = xfs->per_char[j].attributes;
1108 maxwidth *= XFT->pixelsize / 1000.0;
1112 /***********************************************************************
1113 * XFONT_SetFontMetric
1117 * Initializes IFONTINFO16.
1119 static void XFONT_SetFontMetric(fontInfo* fi, const fontResource* fr, XFontStruct* xfs)
1122 fi->df.dfFirstChar = (BYTE)(min = xfs->min_char_or_byte2);
1123 fi->df.dfLastChar = (BYTE)(max = xfs->max_char_or_byte2);
1125 fi->df.dfDefaultChar = (BYTE)xfs->default_char;
1126 fi->df.dfBreakChar = (BYTE)(( ' ' < min || ' ' > max) ? xfs->default_char: ' ');
1128 fi->df.dfPixHeight = (INT16)((fi->df.dfAscent = (INT16)xfs->ascent) + xfs->descent);
1129 fi->df.dfPixWidth = (xfs->per_char) ? 0 : xfs->min_bounds.width;
1131 XFONT_GetLeading( &fi->df, xfs, &fi->df.dfInternalLeading, &fi->df.dfExternalLeading, NULL );
1132 fi->df.dfAvgWidth = (INT16)XFONT_GetAvgCharWidth(&fi->df, xfs, NULL );
1133 fi->df.dfMaxWidth = (INT16)XFONT_GetMaxCharWidth(xfs, NULL);
1135 if( xfs->min_bounds.width != xfs->max_bounds.width )
1136 fi->df.dfPitchAndFamily |= TMPF_FIXED_PITCH; /* au contraire! */
1137 if( fi->fi_flags & FI_SCALABLE )
1139 fi->df.dfType = DEVICE_FONTTYPE;
1140 fi->df.dfPitchAndFamily |= TMPF_DEVICE;
1142 else if( fi->fi_flags & FI_TRUETYPE )
1143 fi->df.dfType = TRUETYPE_FONTTYPE;
1145 fi->df.dfType = RASTER_FONTTYPE;
1147 fi->df.dfFace = fr->lfFaceName;
1150 /***********************************************************************
1151 * XFONT_GetFontMetric
1153 * Retrieve font metric info (enumeration).
1155 static UINT XFONT_GetFontMetric( const fontInfo* pfi,
1156 const LPENUMLOGFONTEXW pLF,
1157 const LPNEWTEXTMETRICEXW pTM )
1159 memset( pLF, 0, sizeof(*pLF) );
1160 memset( pTM, 0, sizeof(*pTM) );
1162 #define plf ((LPLOGFONTW)pLF)
1163 #define ptm ((LPNEWTEXTMETRICW)pTM)
1164 plf->lfHeight = ptm->tmHeight = pfi->df.dfPixHeight;
1165 plf->lfWidth = ptm->tmAveCharWidth = pfi->df.dfAvgWidth;
1166 plf->lfWeight = ptm->tmWeight = pfi->df.dfWeight;
1167 plf->lfItalic = ptm->tmItalic = pfi->df.dfItalic;
1168 plf->lfUnderline = ptm->tmUnderlined = pfi->df.dfUnderline;
1169 plf->lfStrikeOut = ptm->tmStruckOut = pfi->df.dfStrikeOut;
1170 plf->lfCharSet = ptm->tmCharSet = pfi->df.dfCharSet;
1172 /* convert pitch values */
1174 ptm->tmPitchAndFamily = pfi->df.dfPitchAndFamily;
1175 plf->lfPitchAndFamily = (pfi->df.dfPitchAndFamily & 0xF1) + 1;
1177 MultiByteToWideChar(CP_ACP, 0, pfi->df.dfFace, -1,
1178 plf->lfFaceName, LF_FACESIZE);
1180 /* FIXME: fill in rest of plF values */
1181 strcpyW(pLF->elfFullName, plf->lfFaceName);
1182 MultiByteToWideChar(CP_ACP, 0, "Regular", -1,
1183 pLF->elfStyle, LF_FACESIZE);
1184 MultiByteToWideChar(CP_ACP, 0, plf->lfCharSet == SYMBOL_CHARSET ?
1185 "Symbol" : "Roman", -1,
1186 pLF->elfScript, LF_FACESIZE);
1190 ptm->tmAscent = pfi->df.dfAscent;
1191 ptm->tmDescent = ptm->tmHeight - ptm->tmAscent;
1192 ptm->tmInternalLeading = pfi->df.dfInternalLeading;
1193 ptm->tmMaxCharWidth = pfi->df.dfMaxWidth;
1194 ptm->tmDigitizedAspectX = pfi->df.dfHorizRes;
1195 ptm->tmDigitizedAspectY = pfi->df.dfVertRes;
1197 ptm->tmFirstChar = pfi->df.dfFirstChar;
1198 ptm->tmLastChar = pfi->df.dfLastChar;
1199 ptm->tmDefaultChar = pfi->df.dfDefaultChar;
1200 ptm->tmBreakChar = pfi->df.dfBreakChar;
1202 TRACE("Calling Enum proc with FaceName %s FullName %s\n",
1203 debugstr_w(pLF->elfLogFont.lfFaceName),
1204 debugstr_w(pLF->elfFullName));
1206 TRACE("CharSet = %d type = %d\n", ptm->tmCharSet, pfi->df.dfType);
1207 /* return font type */
1208 return pfi->df.dfType;
1213 /***********************************************************************
1218 * dfPitchAndFamily flags for some common typefaces.
1220 static BYTE XFONT_FixupFlags( LPCSTR lfFaceName )
1222 switch( lfFaceName[0] )
1225 case 'A': if(!strncasecmp(lfFaceName, "Arial", 5) )
1229 case 'H': if(!strcasecmp(lfFaceName, "Helvetica") )
1233 case 'C': if(!strncasecmp(lfFaceName, "Courier", 7))
1236 if (!strcasecmp(lfFaceName, "Charter") )
1240 case 'P': if( !strcasecmp(lfFaceName,"Palatino") )
1244 case 'T': if(!strncasecmp(lfFaceName, "Times", 5) )
1248 case 'U': if(!strcasecmp(lfFaceName, "Utopia") )
1252 case 'Z': if(!strcasecmp(lfFaceName, "Zapf Dingbats") )
1253 return FF_DECORATIVE;
1258 /***********************************************************************
1259 * XFONT_SameFoundryAndFamily
1263 static BOOL XFONT_SameFoundryAndFamily( const LFD* lfd1, const LFD* lfd2 )
1265 return ( !strcasecmp( lfd1->foundry, lfd2->foundry ) &&
1266 !strcasecmp( lfd1->family, lfd2->family ) );
1269 /***********************************************************************
1270 * XFONT_InitialCapitals
1274 * Upper case first letters of words & remove multiple spaces
1276 static void XFONT_InitialCapitals(LPSTR lpch)
1282 for( i = 0, up = TRUE; *lpch; lpch++, i++ )
1284 if( isspace(*lpch) )
1286 if (!up) /* Not already got one */
1292 else if( isalpha(*lpch) && up )
1294 *lpstr++ = toupper(*lpch);
1304 /* Remove possible trailing space */
1311 /***********************************************************************
1312 * XFONT_WindowsNames
1316 * Build generic Windows aliases for X font names.
1318 * -misc-fixed- -> "Fixed"
1319 * -sony-fixed- -> "Sony Fixed", etc...
1321 static void XFONT_WindowsNames(void)
1325 for( fr = fontList; fr ; fr = fr->next )
1330 if( fr->fr_flags & FR_NAMESET ) continue; /* skip already assigned */
1332 for( pfr = fontList; pfr != fr ; pfr = pfr->next )
1333 if( pfr->fr_flags & FR_NAMESET )
1335 if (!strcasecmp( pfr->resource->family, fr->resource->family))
1339 lpch = fr->lfFaceName;
1340 snprintf( fr->lfFaceName, sizeof(fr->lfFaceName), "%s %s",
1341 /* prepend vendor name */
1342 (pfr==fr) ? "" : fr->resource->foundry,
1343 fr->resource->family);
1344 XFONT_InitialCapitals(fr->lfFaceName);
1346 BYTE bFamilyStyle = XFONT_FixupFlags( fr->lfFaceName );
1350 for( fi = fr->fi ; fi ; fi = fi->next )
1351 fi->df.dfPitchAndFamily |= bFamilyStyle;
1355 TRACE("typeface '%s'\n", fr->lfFaceName);
1357 fr->fr_flags |= FR_NAMESET;
1361 /***********************************************************************
1362 * XFONT_LoadDefaultLFD
1364 * Move lfd to the head of fontList to make it more likely to be matched
1366 static void XFONT_LoadDefaultLFD(LFD* lfd, LPCSTR fonttype)
1369 fontResource *fr, *pfr;
1370 for( fr = NULL, pfr = fontList; pfr; pfr = pfr->next )
1372 if( XFONT_SameFoundryAndFamily(pfr->resource, lfd) )
1376 fr->next = pfr->next;
1377 pfr->next = fontList;
1385 WARN("Default %sfont '-%s-%s-' not available\n", fonttype,
1386 lfd->foundry, lfd->family);
1390 /***********************************************************************
1393 static void XFONT_LoadDefault(LPCSTR ini, LPCSTR fonttype)
1395 char buffer[MAX_LFD_LENGTH];
1397 if( PROFILE_GetWineIniString( INIFontSection, ini, "", buffer, sizeof buffer ) )
1403 while( *pch && isspace(*pch) ) pch++;
1405 TRACE("Using '%s' as default %sfont\n", pch, fonttype);
1406 lfd = LFD_Parse(pch);
1407 if (lfd && lfd->foundry && lfd->family)
1408 XFONT_LoadDefaultLFD(lfd, fonttype);
1410 WARN("Ini section [%s]%s is malformed\n", INIFontSection, ini);
1411 HeapFree(GetProcessHeap(), 0, lfd);
1416 /***********************************************************************
1417 * XFONT_LoadDefaults
1419 static void XFONT_LoadDefaults(void)
1421 XFONT_LoadDefault(INIDefaultFixed, "fixed ");
1422 XFONT_LoadDefault(INIDefault, "");
1425 /***********************************************************************
1428 static fontAlias* XFONT_CreateAlias( LPCSTR lpTypeFace, LPCSTR lpAlias )
1431 fontAlias *pfa, *prev = NULL;
1433 for(pfa = aliasTable; pfa; pfa = pfa->next)
1435 /* check if we already got one */
1436 if( !strcasecmp( pfa->faTypeFace, lpAlias ) )
1438 TRACE("redundant alias '%s' -> '%s'\n",
1439 lpAlias, lpTypeFace );
1445 j = strlen(lpTypeFace) + 1;
1446 pfa = HeapAlloc( GetProcessHeap(), 0, sizeof(fontAlias) +
1447 j + strlen(lpAlias) + 1 );
1456 pfa->faTypeFace = (LPSTR)(pfa + 1);
1457 strcpy( pfa->faTypeFace, lpTypeFace );
1458 pfa->faAlias = pfa->faTypeFace + j;
1459 strcpy( pfa->faAlias, lpAlias );
1461 TRACE("added alias '%s' for '%s'\n", lpAlias, lpTypeFace );
1469 /***********************************************************************
1472 static void XFONT_LoadAlias(const LFD* lfd, LPCSTR lpAlias, BOOL bSubst)
1474 fontResource *fr, *frMatch = NULL;
1475 if (!lfd->foundry || ! lfd->family)
1477 WARN("Malformed font resource for alias '%s'\n", lpAlias);
1480 for (fr = fontList; fr ; fr = fr->next)
1482 if(!strcasecmp(fr->resource->family, lpAlias))
1484 /* alias is not needed since the real font is present */
1485 TRACE("Ignoring font alias '%s' as it is already available as a real font\n", lpAlias);
1488 if( XFONT_SameFoundryAndFamily( fr->resource, lfd ) )
1499 fontAlias *pfa, *prev = NULL;
1501 for(pfa = aliasTable; pfa; pfa = pfa->next)
1503 /* Remove lpAlias from aliasTable - we should free the old entry */
1504 if(!strcmp(lpAlias, pfa->faAlias))
1507 prev->next = pfa->next;
1509 aliasTable = pfa->next;
1512 /* Update any references to the substituted font in aliasTable */
1513 if(!strcmp(frMatch->lfFaceName, pfa->faTypeFace))
1514 pfa->faTypeFace = HEAP_strdupA( GetProcessHeap(), 0, lpAlias );
1518 TRACE("\tsubstituted '%s' with '%s'\n", frMatch->lfFaceName, lpAlias );
1520 lstrcpynA( frMatch->lfFaceName, lpAlias, LF_FACESIZE );
1521 frMatch->fr_flags |= FR_NAMESET;
1525 /* create new entry in the alias table */
1526 XFONT_CreateAlias( frMatch->lfFaceName, lpAlias );
1531 WARN("Font alias '-%s-%s-' is not available\n", lfd->foundry, lfd->family);
1535 /***********************************************************************
1540 * Create font aliases for some standard windows fonts using user's
1541 * default choice of (sans-)serif fonts
1543 * Read user-defined aliases from wine.conf. Format is as follows
1545 * Alias# = [Windows font name],[LFD font name], <substitute original name>
1548 * Alias0 = Arial, -adobe-helvetica-
1549 * Alias1 = Times New Roman, -bitstream-courier-, 1
1552 * Note that from 970817 and on we have built-in alias templates that take
1553 * care of the necessary Windows typefaces.
1561 static void XFONT_LoadAliases(void)
1564 char buffer[MAX_LFD_LENGTH];
1568 /* built-ins first */
1569 PROFILE_GetWineIniString( INIFontSection, INIDefaultSerif,
1570 "-bitstream-charter-", buffer, sizeof buffer );
1571 TRACE("Using '%s' as default serif font\n", buffer);
1572 lfd = LFD_Parse(buffer);
1573 /* NB XFONT_InitialCapitals should not change these standard aliases */
1576 XFONT_LoadAlias( lfd, "Tms Roman", FALSE);
1577 XFONT_LoadAlias( lfd, "MS Serif", FALSE);
1578 XFONT_LoadAlias( lfd, "Times New Roman", FALSE);
1580 XFONT_LoadDefaultLFD( lfd, "serif ");
1581 HeapFree(GetProcessHeap(), 0, lfd);
1584 PROFILE_GetWineIniString( INIFontSection, INIDefaultSansSerif,
1585 "-adobe-helvetica-", buffer, sizeof buffer);
1586 TRACE("Using '%s' as default sans serif font\n", buffer);
1587 lfd = LFD_Parse(buffer);
1590 XFONT_LoadAlias( lfd, "Helv", FALSE);
1591 XFONT_LoadAlias( lfd, "MS Sans Serif", FALSE);
1592 XFONT_LoadAlias( lfd, "MS Shell Dlg", FALSE);
1593 XFONT_LoadAlias( lfd, "Arial", FALSE);
1595 XFONT_LoadDefaultLFD( lfd, "sans serif ");
1596 HeapFree(GetProcessHeap(), 0, lfd);
1599 /* then user specified aliases */
1602 BOOL bHaveAlias, bSubst;
1603 char subsection[32];
1604 snprintf( subsection, sizeof subsection, "%s%i", INIAliasSection, i++ );
1606 bHaveAlias = PROFILE_GetWineIniString( INIFontSection,
1607 subsection, "", buffer, sizeof buffer);
1611 XFONT_InitialCapitals(buffer);
1612 lpResource = PROFILE_GetStringItem( buffer );
1613 bSubst = (PROFILE_GetStringItem( lpResource )) ? TRUE : FALSE;
1614 if( lpResource && *lpResource )
1616 lfd = LFD_Parse(lpResource);
1619 XFONT_LoadAlias(lfd, buffer, bSubst);
1620 HeapFree(GetProcessHeap(), 0, lfd);
1624 WARN("malformed font alias '%s'\n", buffer );
1629 /***********************************************************************
1632 * Convert an (potential) alias into a real windows name
1635 static LPCSTR XFONT_UnAlias(char* font)
1640 XFONT_InitialCapitals(font); /* to remove extra white space */
1642 for( fa = aliasTable; fa; fa = fa->next )
1643 /* use case insensitive matching to handle eg "MS Sans Serif" */
1644 if( !strcasecmp( fa->faAlias, font ) )
1646 TRACE("found alias '%s'->%s'\n", font, fa->faTypeFace );
1647 strcpy(font, fa->faTypeFace);
1655 /***********************************************************************
1656 * XFONT_RemoveFontResource
1658 * Caller should check if the font resource is in use. If it is it should
1659 * set FR_REMOVED flag to delay removal until the resource is not in use
1662 void XFONT_RemoveFontResource( fontResource** ppfr )
1664 fontResource* pfr = *ppfr;
1668 /* FIXME - if fonts were read from a cache, these HeapFrees will fail */
1671 pfi = pfr->fi->next;
1672 HeapFree( GetProcessHeap(), 0, pfr->fi );
1675 HeapFree( GetProcessHeap(), 0, pfr );
1680 /***********************************************************************
1685 * Removes specified fonts from the font table to prevent Wine from
1688 * Ignore# = [LFD font name]
1691 * Ignore0 = -misc-nil-
1692 * Ignore1 = -sun-open look glyph-
1696 static void XFONT_LoadIgnore(char* lfdname)
1698 fontResource** ppfr;
1700 LFD* lfd = LFD_Parse(lfdname);
1701 if (lfd && lfd->foundry && lfd->family)
1703 for( ppfr = &fontList; *ppfr ; ppfr = &((*ppfr)->next))
1705 if( XFONT_SameFoundryAndFamily( (*ppfr)->resource, lfd) )
1707 TRACE("Ignoring '-%s-%s-'\n",
1708 (*ppfr)->resource->foundry, (*ppfr)->resource->family );
1710 XFONT_RemoveFontResource( ppfr );
1716 WARN("Malformed font resource\n");
1718 HeapFree(GetProcessHeap(), 0, lfd);
1721 static void XFONT_LoadIgnores(void)
1724 char subsection[32];
1725 char buffer[MAX_LFD_LENGTH];
1727 /* Standard one that noone wants */
1728 strcpy(buffer, "-misc-nil-");
1729 XFONT_LoadIgnore(buffer);
1731 /* Others from INI file */
1734 sprintf( subsection, "%s%i", INIIgnoreSection, i++ );
1736 if( PROFILE_GetWineIniString( INIFontSection,
1737 subsection, "", buffer, sizeof buffer) )
1740 while( *pch && isspace(*pch) ) pch++;
1741 XFONT_LoadIgnore(pch);
1749 /***********************************************************************
1750 * XFONT_UserMetricsCache
1752 * Returns expanded name for the cachedmetrics file.
1753 * Now it also appends the current value of the $DISPLAY variable.
1755 static char* XFONT_UserMetricsCache( char* buffer, int* buf_size )
1757 const char *confdir = get_config_dir();
1758 const char *display_name = XDisplayName(NULL);
1759 int len = strlen(confdir) + strlen(INIFontMetrics) + strlen(display_name) + 2;
1761 if ((len > *buf_size) &&
1762 !(buffer = HeapReAlloc( GetProcessHeap(), 0, buffer, *buf_size = len )))
1764 ERR("out of memory\n");
1768 sprintf( buffer, "%s/%s%s", confdir, INIFontMetrics, display_name );
1773 /***********************************************************************
1776 * Compare two fonts (only parameters set by the XFONT_InitFontInfo()).
1778 static INT XFONT_IsSubset(const fontInfo* match, const fontInfo* fi)
1782 /* 0 - keep both, 1 - keep match, -1 - keep fi */
1784 /* Compare dfItalic, Underline, Strikeout, Weight, Charset */
1785 m = (BYTE*)&fi->df.dfPixWidth - (BYTE*)&fi->df.dfItalic;
1786 if( memcmp(&match->df.dfItalic, &fi->df.dfItalic, m )) return 0;
1788 if( (!((fi->fi_flags & FI_SCALABLE) + (match->fi_flags & FI_SCALABLE))
1789 && fi->lfd_height != match->lfd_height) ||
1790 (!((fi->fi_flags & FI_POLYWEIGHT) + (match->fi_flags & FI_POLYWEIGHT))
1791 && fi->df.dfWeight != match->df.dfWeight) ) return 0;
1793 m = (int)(match->fi_flags & (FI_POLYWEIGHT | FI_SCALABLE)) -
1794 (int)(fi->fi_flags & (FI_SCALABLE | FI_POLYWEIGHT));
1796 if( m == (FI_POLYWEIGHT - FI_SCALABLE) ||
1797 m == (FI_SCALABLE - FI_POLYWEIGHT) ) return 0; /* keep both */
1798 else if( m >= 0 ) return 1; /* 'match' is better */
1800 return -1; /* 'fi' is better */
1803 /***********************************************************************
1806 * REMOVE_SUBSETS - attach new fi and purge subsets
1807 * UNMARK_SUBSETS - remove subset flags from all fi entries
1809 static void XFONT_CheckFIList( fontResource* fr, fontInfo* fi, int action)
1812 fontInfo* pfi, *prev;
1814 for( prev = NULL, pfi = fr->fi; pfi; )
1816 if( action == REMOVE_SUBSETS )
1818 if( pfi->fi_flags & FI_SUBSET )
1820 fontInfo* subset = pfi;
1824 if( prev ) prev->next = pfi = pfi->next;
1825 else fr->fi = pfi = pfi->next;
1826 HeapFree( GetProcessHeap(), 0, subset );
1830 else pfi->fi_flags &= ~FI_SUBSET;
1836 if( action == REMOVE_SUBSETS ) /* also add the superset */
1838 if( fi->fi_flags & FI_SCALABLE )
1843 else if( prev ) prev->next = fi; else fr->fi = fi;
1847 if( i ) TRACE("\t purged %i subsets [%i]\n", i , fr->fi_count);
1850 /***********************************************************************
1853 static fontResource* XFONT_FindFIList( fontResource* pfr, const char* pTypeFace )
1857 if( !strcasecmp( pfr->lfFaceName, pTypeFace ) ) break;
1860 /* Give the app back the font name it asked for. Encarta checks this. */
1861 if (pfr) strcpy(pfr->lfFaceName,pTypeFace);
1865 /***********************************************************************
1866 * XFONT_FixupPointSize
1868 static void XFONT_FixupPointSize(fontInfo* fi)
1871 df.dfHorizRes = df.dfVertRes = fi->lfd_resolution;
1872 df.dfPoints = (INT16)
1873 (((INT)(df.dfPixHeight - df.dfInternalLeading) * 72 + (df.dfVertRes >> 1)) /
1878 /***********************************************************************
1879 * XFONT_BuildMetrics
1881 * Build font metrics from X font
1883 static int XFONT_BuildMetrics(char** x_pattern, int res, unsigned x_checksum, int x_count)
1886 fontInfo* fi = NULL;
1887 fontResource* fr, *pfr;
1890 MESSAGE("Building font metrics. This may take some time...\n");
1891 for( i = 0; i < x_count; i++ )
1896 char buffer[MAX_LFD_LENGTH];
1901 typeface = HEAP_strdupA(GetProcessHeap(), 0, x_pattern[i]);
1905 lfd = LFD_Parse(typeface);
1908 HeapFree(GetProcessHeap(), 0, typeface);
1912 /* find a family to insert into */
1914 for( pfr = NULL, fr = fontList; fr; fr = fr->next )
1916 if( XFONT_SameFoundryAndFamily(fr->resource, lfd))
1921 if( !fi ) fi = (fontInfo*) HeapAlloc(GetProcessHeap(), 0, sizeof(fontInfo));
1923 if( !LFD_InitFontInfo( fi, lfd, x_pattern[i]) )
1926 if( !fr ) /* add new family */
1929 fr = (fontResource*) HeapAlloc(GetProcessHeap(), 0, sizeof(fontResource));
1932 memset(fr, 0, sizeof(fontResource));
1934 fr->resource = (LFD*) HeapAlloc(GetProcessHeap(), 0, sizeof(LFD));
1935 memset(fr->resource, 0, sizeof(LFD));
1937 TRACE("family: -%s-%s-\n", lfd->foundry, lfd->family );
1938 fr->resource->foundry = HEAP_strdupA(GetProcessHeap(), 0, lfd->foundry);
1939 fr->resource->family = HEAP_strdupA(GetProcessHeap(), 0, lfd->family);
1940 fr->resource->weight = "";
1942 if( pfr ) pfr->next = fr;
1946 WARN("Not enough memory for a new font family\n");
1949 /* check if we already have something better than "fi" */
1951 for( pfi = fr->fi, j = 0; pfi && j <= 0; pfi = pfi->next )
1952 if( (j = XFONT_IsSubset( pfi, fi )) < 0 )
1953 pfi->fi_flags |= FI_SUBSET; /* superseded by "fi" */
1954 if( j > 0 ) goto nextfont;
1956 /* add new font instance "fi" to the "fr" font resource */
1958 if( fi->fi_flags & FI_SCALABLE )
1961 char pxl_string[4], res_string[4];
1962 /* set scalable font height to get an basis for extrapolation */
1964 fi->lfd_height = DEF_SCALABLE_HEIGHT;
1965 fi->lfd_resolution = res;
1967 sprintf(pxl_string, "%d", fi->lfd_height);
1968 sprintf(res_string, "%d", fi->lfd_resolution);
1971 lfd1.pixel_size = pxl_string;
1972 lfd1.point_size = "*";
1973 lfd1.resolution_x = res_string;
1974 lfd1.resolution_y = res_string;
1976 LFD_UnParse(buffer, sizeof buffer, &lfd1);
1980 else lpstr = x_pattern[i];
1982 if( (x_fs = TSXLoadQueryFont(gdi_display, lpstr)) )
1984 XFONT_SetFontMetric( fi, fr, x_fs );
1985 TSXFreeFont( gdi_display, x_fs );
1987 XFONT_FixupPointSize(fi);
1989 TRACE("\t[% 2ipt] '%s'\n", fi->df.dfPoints, x_pattern[i] );
1991 XFONT_CheckFIList( fr, fi, REMOVE_SUBSETS );
1992 fi = NULL; /* preventing reuse */
1996 ERR("failed to load %s\n", lpstr );
1998 XFONT_CheckFIList( fr, fi, UNMARK_SUBSETS );
2001 HeapFree(GetProcessHeap(), 0, lfd);
2002 HeapFree(GetProcessHeap(), 0, typeface);
2004 if( fi ) HeapFree(GetProcessHeap(), 0, fi);
2006 /* Scan through the font list and remove FontResorce(s) (fr)
2007 * that have no associated Fontinfo(s) (fi).
2008 * This code is necessary because XFONT_ReadCachedMetrics
2009 * assumes that there is at least one fi associated with a fr.
2010 * This assumption is invalid for TT font
2011 * -altsys-ms outlook-medium-r-normal--0-0-0-0-p-0-microsoft-symbol.
2016 while (!fr->fi_count)
2018 fontList = fr->next;
2020 HeapFree(GetProcessHeap(), 0, fr->resource);
2021 HeapFree(GetProcessHeap(), 0, fr);
2031 if (!fr->next->fi_count)
2034 fr->next = fr->next->next;
2036 HeapFree(GetProcessHeap(), 0, pfr->resource);
2037 HeapFree(GetProcessHeap(), 0, pfr);
2048 /***********************************************************************
2049 * XFONT_ReadCachedMetrics
2053 static BOOL XFONT_ReadCachedMetrics( int fd, int res, unsigned x_checksum, int x_count )
2060 /* read checksums */
2061 read( fd, &u, sizeof(unsigned) );
2062 read( fd, &i, sizeof(int) );
2064 if( u == x_checksum && i == x_count )
2066 off_t length, offset = 3 * sizeof(int);
2068 /* read total size */
2069 read( fd, &i, sizeof(int) );
2070 length = lseek( fd, 0, SEEK_END );
2072 if( length == (i + offset) )
2074 lseek( fd, offset, SEEK_SET );
2075 fontList = (fontResource*)HeapAlloc( GetProcessHeap(), 0, i);
2078 fontResource* pfr = fontList;
2079 fontInfo* pfi = NULL;
2081 TRACE("Reading cached font metrics:\n");
2083 read( fd, fontList, i); /* read all metrics at once */
2084 while( offset < length )
2086 offset += sizeof(fontResource) + sizeof(fontInfo);
2087 pfr->fi = pfi = (fontInfo*)(pfr + 1);
2091 if( offset > length ||
2092 pfi->cptable >= (UINT16)X11DRV_CPTABLE_COUNT ||
2093 (int)(pfi->next) != j++ ) goto fail;
2095 if( pfi->df.dfPixHeight == 0 ) goto fail;
2097 pfi->df.dfFace = pfr->lfFaceName;
2098 if( pfi->fi_flags & FI_SCALABLE )
2100 /* we can pretend we got this font for any resolution */
2101 pfi->lfd_resolution = res;
2102 XFONT_FixupPointSize(pfi);
2104 pfi->next = pfi + 1;
2106 if( j > pfr->fi_count ) break;
2109 offset += sizeof(fontInfo);
2114 pfr->next = (fontResource*)(pfi + 1);
2119 if( pfr->next == NULL &&
2120 *(int*)(pfi + 1) == X_FMC_MAGIC )
2122 /* read LFD stubs */
2123 char* lpch = (char*)((int*)(pfi + 1) + 1);
2124 offset += sizeof(int);
2125 for( pfr = fontList; pfr; pfr = pfr->next )
2127 size_t len = strlen(lpch) + 1;
2128 TRACE("\t%s, %i instances\n", lpch, pfr->fi_count );
2129 pfr->resource = LFD_Parse(lpch);
2132 if (offset > length)
2142 if( fontList ) HeapFree( GetProcessHeap(), 0, fontList );
2149 /***********************************************************************
2150 * XFONT_WriteCachedMetrics
2154 static BOOL XFONT_WriteCachedMetrics( int fd, unsigned x_checksum, int x_count, int n_ff )
2162 char buffer[MAX_LFD_LENGTH];
2164 /* font metrics file:
2168 * +0008 total size to load
2169 * +000C prepackaged font metrics
2172 * +...x + 4 LFD stubs
2175 write( fd, &x_checksum, sizeof(unsigned) );
2176 write( fd, &x_count, sizeof(int) );
2178 for( j = i = 0, pfr = fontList; pfr; pfr = pfr->next )
2180 LFD_UnParse(buffer, sizeof buffer, pfr->resource);
2181 i += strlen( buffer) + 1;
2184 i += n_ff * sizeof(fontResource) + j * sizeof(fontInfo) + sizeof(int);
2185 write( fd, &i, sizeof(int) );
2187 TRACE("Writing font cache:\n");
2189 for( pfr = fontList; pfr; pfr = pfr->next )
2193 TRACE("\t-%s-%s-, %i instances\n", pfr->resource->foundry, pfr->resource->family, pfr->fi_count );
2195 i = write( fd, pfr, sizeof(fontResource) );
2196 if( i == sizeof(fontResource) )
2198 for( k = 1, pfi = pfr->fi; pfi; pfi = pfi->next )
2202 fi.df.dfFace = NULL;
2203 fi.next = (fontInfo*)k; /* loader checks this */
2205 j = write( fd, &fi, sizeof(fi) );
2208 if( j == sizeof(fontInfo) ) continue;
2212 if( i == sizeof(fontResource) && j == sizeof(fontInfo) )
2214 i = j = X_FMC_MAGIC;
2215 write( fd, &i, sizeof(int) );
2216 for( pfr = fontList; pfr && i == j; pfr = pfr->next )
2218 LFD_UnParse(buffer, sizeof buffer, pfr->resource);
2219 i = strlen( buffer ) + 1;
2220 j = write( fd, buffer, i );
2229 /***********************************************************************
2230 * XFONT_GetPointResolution()
2234 * Here we initialize DefResolution which is used in the
2235 * XFONT_Match() penalty function. We also load the point
2236 * resolution value (higher values result in larger fonts).
2238 static int XFONT_GetPointResolution( DeviceCaps* pDevCaps )
2240 int i, j, point_resolution, num = 3;
2241 int allowed_xfont_resolutions[3] = { 72, 75, 100 };
2242 int best = 0, best_diff = 65536;
2244 point_resolution = PROFILE_GetWineIniInt( INIFontSection, INIResolution, 0 );
2245 if( !point_resolution )
2246 point_resolution = pDevCaps->logPixelsY;
2248 pDevCaps->logPixelsX = pDevCaps->logPixelsY = point_resolution;
2251 /* FIXME We can only really guess at a best DefResolution
2252 * - this should be configurable
2254 for( i = best = 0; i < num; i++ )
2256 j = abs( point_resolution - allowed_xfont_resolutions[i] );
2263 DefResolution = allowed_xfont_resolutions[best];
2265 /* FIXME - do win95,nt40,... do this as well ? */
2266 if (TWEAK_WineLook == WIN98_LOOK)
2268 /* Lie about the screen size, so that eg MM_LOMETRIC becomes MM_logical_LOMETRIC */
2270 denom = pDevCaps->logPixelsX * 10;
2271 pDevCaps->horzSize = (pDevCaps->horzRes * 254 + (denom>>1)) / denom;
2272 denom = pDevCaps->logPixelsY * 10;
2273 pDevCaps->vertSize = (pDevCaps->vertRes * 254 + (denom>>1)) / denom;
2276 return point_resolution;
2280 /***********************************************************************
2283 * Compute the matching score between the logical font and the device font.
2285 * contributions from highest to lowest:
2289 * family flags (only when the facename is not present)
2291 * weight, italics, underlines, strikeouts
2293 * NOTE: you can experiment with different penalty weights to see what happens.
2294 * http://premium.microsoft.com/msdn/library/techart/f365/f36b/f37b/d38b/sa8bf.htm
2296 static UINT XFONT_Match( fontMatch* pfm )
2298 fontInfo* pfi = pfm->pfi; /* device font to match */
2299 LPLOGFONT16 plf = pfm->plf; /* wanted logical font */
2301 BOOL bR6 = pfm->flags & FO_MATCH_XYINDEP; /* from TextCaps */
2302 BOOL bScale = pfi->fi_flags & FI_SCALABLE;
2305 TRACE("\t[ %-2ipt h=%-3i w=%-3i %s%s]\n", pfi->df.dfPoints,
2306 pfi->df.dfPixHeight, pfi->df.dfAvgWidth,
2307 (pfi->df.dfWeight > FW_NORMAL) ? "Bold " : "Normal ",
2308 (pfi->df.dfItalic) ? "Italic" : "" );
2310 pfm->flags &= FO_MATCH_MASK;
2313 /* pfm->internal_charset: given(required) charset */
2314 /* pfi->internal_charset: charset of this font */
2315 if (pfi->internal_charset == DEFAULT_CHARSET)
2317 /* special case(unicode font) */
2318 /* priority: unmatched charset < unicode < matched charset */
2323 if( pfm->internal_charset == DEFAULT_CHARSET )
2326 if (pfi->internal_charset != ANSI_CHARSET)
2329 if ( pfi->codepage != GetACP() )
2332 else if (pfm->internal_charset != pfi->internal_charset)
2334 if ( pfi->internal_charset & 0xff00 )
2335 penalty += 0x1000; /* internal charset - should not be used */
2344 if( plf->lfHeight > 0 )
2346 int h = pfi->df.dfPixHeight;
2347 d = h - plf->lfHeight;
2348 height = plf->lfHeight;
2352 int h = pfi->df.dfPixHeight - pfi->df.dfInternalLeading;
2355 d = h + plf->lfHeight;
2356 height = (-plf->lfHeight * pfi->df.dfPixHeight) / h;
2360 ERR("PixHeight == InternalLeading\n");
2361 penalty += 0x1000; /* dont want this */
2367 pfm->height = 1; /* Very small */
2371 pfm->height = height;
2372 else if( (plf->lfQuality != PROOF_QUALITY) && bR6 )
2374 if( d > 0 ) /* do not shrink raster fonts */
2376 pfm->height = pfi->df.dfPixHeight;
2377 penalty += (pfi->df.dfPixHeight - height) * 0x4;
2379 else /* expand only in integer multiples */
2381 pfm->height = height - height%pfi->df.dfPixHeight;
2382 penalty += (height - pfm->height + 1) * height / pfi->df.dfPixHeight;
2385 else /* can't be scaled at all */
2387 if( plf->lfQuality != PROOF_QUALITY) pfm->flags |= FO_SYNTH_HEIGHT;
2388 pfm->height = pfi->df.dfPixHeight;
2389 penalty += (d > 0)? d * 0x8 : -d * 0x10;
2393 pfm->height = pfi->df.dfPixHeight;
2395 /* Pitch and Family */
2396 if( pfm->flags & FO_MATCH_PAF ) {
2397 int family = plf->lfPitchAndFamily & FF_FAMILY;
2399 /* TMPF_FIXED_PITCH means exactly the opposite */
2400 if( plf->lfPitchAndFamily & FIXED_PITCH ) {
2401 if( pfi->df.dfPitchAndFamily & TMPF_FIXED_PITCH ) penalty += 0x100;
2402 } else /* Variable is the default */
2403 if( !(pfi->df.dfPitchAndFamily & TMPF_FIXED_PITCH) ) penalty += 0x2;
2405 if (family != FF_DONTCARE && family != (pfi->df.dfPitchAndFamily & FF_FAMILY) )
2413 if( bR6 || bScale ) h = 0;
2416 /* FIXME: not complete */
2418 pfm->flags |= FO_SYNTH_WIDTH;
2419 h = abs(plf->lfWidth - (pfm->height * pfi->df.dfAvgWidth)/pfi->df.dfPixHeight);
2421 penalty += h * ( d ) ? 0x2 : 0x1 ;
2423 else if( !(pfi->fi_flags & FI_NORMAL) ) penalty++;
2426 if( plf->lfWeight != FW_DONTCARE )
2428 penalty += abs(plf->lfWeight - pfi->df.dfWeight) / 40;
2429 if( plf->lfWeight > pfi->df.dfWeight ) pfm->flags |= FO_SYNTH_BOLD;
2430 } else if( pfi->df.dfWeight >= FW_BOLD ) penalty++; /* choose normal by default */
2433 if( plf->lfItalic != pfi->df.dfItalic )
2436 pfm->flags |= FO_SYNTH_ITALIC;
2439 if( plf->lfUnderline ) pfm->flags |= FO_SYNTH_UNDERLINE;
2442 if( plf->lfStrikeOut ) pfm->flags |= FO_SYNTH_STRIKEOUT;
2445 if( penalty && !bScale && pfi->lfd_resolution != DefResolution )
2448 TRACE(" returning %i\n", penalty );
2453 /***********************************************************************
2456 * Scan a particular font resource for the best match.
2458 static UINT XFONT_MatchFIList( fontMatch* pfm )
2460 BOOL skipRaster = (pfm->flags & FO_MATCH_NORASTER);
2461 UINT current_score, score = (UINT)(-1);
2462 fontMatch fm = *pfm;
2464 for( fm.pfi = pfm->pfr->fi; fm.pfi && score; fm.pfi = fm.pfi->next)
2466 if( skipRaster && !(fm.pfi->fi_flags & FI_SCALABLE) )
2469 current_score = XFONT_Match( &fm );
2470 if( score > current_score )
2473 score = current_score;
2479 /***********************************************************************
2480 * XFONT_MatchDeviceFont
2482 * Scan font resource tree.
2485 static void XFONT_MatchDeviceFont( fontResource* start, fontMatch* pfm)
2487 fontMatch fm = *pfm;
2488 UINT current_score, score = (UINT)(-1);
2489 fontResource** ppfr;
2491 TRACE("(%u) '%s' h=%i weight=%i %s\n",
2492 pfm->plf->lfCharSet, pfm->plf->lfFaceName, pfm->plf->lfHeight,
2493 pfm->plf->lfWeight, (pfm->plf->lfItalic) ? "Italic" : "" );
2496 if( fm.plf->lfFaceName[0] )
2498 fm.pfr = XFONT_FindFIList( start, fm.plf->lfFaceName);
2499 if( fm.pfr ) /* match family */
2501 TRACE("found facename '%s'\n", fm.pfr->lfFaceName );
2503 if( fm.pfr->fr_flags & FR_REMOVED )
2507 XFONT_MatchFIList( &fm );
2514 /* get charset if lfFaceName is one of known facenames. */
2516 const struct CharsetBindingInfo* pcharsetbindings;
2518 pcharsetbindings = &charsetbindings[0];
2519 while ( pcharsetbindings->pszFaceName != NULL )
2521 if ( !strcmp( pcharsetbindings->pszFaceName,
2522 fm.plf->lfFaceName ) )
2524 fm.internal_charset = pcharsetbindings->charset;
2527 pcharsetbindings ++;
2529 TRACE( "%s charset %u\n", fm.plf->lfFaceName, fm.internal_charset );
2533 /* match all available fonts */
2535 fm.flags |= FO_MATCH_PAF;
2536 for( ppfr = &fontList; *ppfr && score; ppfr = &(*ppfr)->next )
2538 if( (*ppfr)->fr_flags & FR_REMOVED )
2540 if( (*ppfr)->fo_count == 0 )
2541 XFONT_RemoveFontResource( ppfr );
2547 TRACE("%s\n", fm.pfr->lfFaceName );
2549 current_score = XFONT_MatchFIList( &fm );
2550 if( current_score < score )
2552 score = current_score;
2559 /***********************************************************************
2562 static void XFONT_GrowFreeList(int start, int end)
2564 /* add all entries from 'start' up to and including 'end' */
2566 memset( fontCache + start, 0, (end - start + 1) * sizeof(fontObject) );
2568 fontCache[end].lru = fontLF;
2569 fontCache[end].count = -1;
2571 while( start < end )
2573 fontCache[start].count = -1;
2574 fontCache[start].lru = start + 1;
2579 static fontObject* XFONT_LookupCachedFont( const LPLOGFONT16 plf, UINT16* checksum )
2581 UINT16 cs = __lfCheckSum( plf );
2582 int i = fontMRU, prev = -1;
2587 if( fontCache[i].lfchecksum == cs &&
2588 !(fontCache[i].fo_flags & FO_REMOVED) )
2590 /* FIXME: something more intelligent here ? */
2592 if( !memcmp( plf, &fontCache[i].lf,
2593 sizeof(LOGFONT16) - LF_FACESIZE ) &&
2594 !strcmp( plf->lfFaceName, fontCache[i].lf.lfFaceName) )
2596 /* remove temporarily from the lru list */
2598 fontCache[prev].lru = fontCache[i].lru;
2600 fontMRU = (INT16)fontCache[i].lru;
2601 return (fontCache + i);
2605 i = (INT16)fontCache[i].lru;
2610 static fontObject* XFONT_GetCacheEntry(void)
2616 int prev_i, prev_j, j;
2618 TRACE("font cache is full\n");
2620 /* lookup the least recently used font */
2622 for( prev_i = prev_j = j = -1, i = fontMRU; i >= 0; i = (INT16)fontCache[i].lru )
2624 if( fontCache[i].count <= 0 &&
2625 !(fontCache[i].fo_flags & FO_SYSTEM) )
2633 if( j >= 0 ) /* unload font */
2635 /* detach from the lru list */
2637 TRACE("\tfreeing entry %i\n", j );
2639 fontCache[j].fr->fo_count--;
2642 fontCache[prev_j].lru = fontCache[j].lru;
2643 else fontMRU = (INT16)fontCache[j].lru;
2645 /* FIXME: lpXForm, lpPixmap */
2646 if(fontCache[j].lpX11Trans)
2647 HeapFree( GetProcessHeap(), 0, fontCache[j].lpX11Trans );
2649 TSXFreeFont( gdi_display, fontCache[j].fs );
2651 memset( fontCache + j, 0, sizeof(fontObject) );
2652 return (fontCache + j);
2654 else /* expand cache */
2656 fontObject* newCache;
2658 prev_i = fontCacheSize + FONTCACHE;
2660 TRACE("\tgrowing font cache from %i to %i\n", fontCacheSize, prev_i );
2662 if( (newCache = (fontObject*)HeapReAlloc(GetProcessHeap(), 0,
2663 fontCache, prev_i)) )
2666 fontCacheSize = prev_i;
2667 fontCache = newCache;
2668 XFONT_GrowFreeList( i, fontCacheSize - 1);
2674 /* detach from the free list */
2677 fontLF = (INT16)fontCache[i].lru;
2678 fontCache[i].count = 0;
2679 return (fontCache + i);
2682 static int XFONT_ReleaseCacheEntry(const fontObject* pfo)
2684 UINT u = (UINT)(pfo - fontCache);
2688 if( u < fontCacheSize )
2690 ret = --fontCache[u].count;
2693 for ( i = 0; i < X11FONT_REFOBJS_MAX; i++ )
2695 if( CHECK_PFONT(pfo->prefobjs[i]) )
2696 XFONT_ReleaseCacheEntry(__PFONT(pfo->prefobjs[i]));
2706 /***********************************************************************
2709 * Initialize font resource list and allocate font cache.
2711 BOOL X11DRV_FONT_Init( DeviceCaps* pDevCaps )
2714 unsigned x_checksum;
2715 int i,res, x_count, fd, buf_size;
2718 res = XFONT_GetPointResolution( pDevCaps );
2720 x_pattern = TSXListFonts(gdi_display, "*", MAX_FONTS, &x_count );
2722 TRACE("Font Mapper: initializing %i fonts [logical dpi=%i, default dpi=%i]\n",
2723 x_count, res, DefResolution);
2724 if (x_count == MAX_FONTS)
2725 MESSAGE("There may be more fonts available - try increasing the value of MAX_FONTS\n");
2727 for( i = x_checksum = 0; i < x_count; i++ )
2731 printf("%i\t: %s\n", i, x_pattern[i] );
2734 j = strlen( x_pattern[i] );
2735 if( j ) x_checksum ^= __genericCheckSum( x_pattern[i], j );
2737 x_checksum |= X_PFONT_MAGIC;
2739 buffer = HeapAlloc( GetProcessHeap(), 0, buf_size );
2741 /* deal with systemwide font metrics cache */
2743 if( PROFILE_GetWineIniString( INIFontSection, INIGlobalMetrics, "", buffer, buf_size ) )
2745 fd = open( buffer, O_RDONLY );
2746 XFONT_ReadCachedMetrics(fd, DefResolution, x_checksum, x_count);
2748 if (fontList == NULL)
2751 buffer = XFONT_UserMetricsCache( buffer, &buf_size );
2754 fd = open( buffer, O_RDONLY );
2755 XFONT_ReadCachedMetrics(fd, DefResolution, x_checksum, x_count);
2759 if( fontList == NULL ) /* build metrics from scratch */
2761 int n_ff = XFONT_BuildMetrics(x_pattern, DefResolution, x_checksum, x_count);
2762 if( buffer[0] ) /* update cached metrics */
2764 fd = open( buffer, O_CREAT | O_TRUNC | O_RDWR, 0644 ); /* -rw-r--r-- */
2765 if( XFONT_WriteCachedMetrics( fd, x_checksum, x_count, n_ff ) == FALSE )
2767 WARN("Unable to write to fontcache '%s'\n", buffer);
2768 if( fd >= 0) remove( buffer ); /* couldn't write entire file */
2773 TSXFreeFontNames(x_pattern);
2775 /* check if we're dealing with X11 R6 server */
2778 strcpy(buffer, "-*-*-*-*-normal-*-[12 0 0 12]-*-72-*-*-*-iso8859-1");
2779 if( (x_fs = TSXLoadQueryFont(gdi_display, buffer)) )
2781 XTextCaps |= TC_SF_X_YINDEP;
2782 TSXFreeFont(gdi_display, x_fs);
2785 HeapFree(GetProcessHeap(), 0, buffer);
2787 XFONT_WindowsNames();
2788 XFONT_LoadAliases();
2789 XFONT_LoadDefaults();
2790 XFONT_LoadIgnores();
2792 /* fontList initialization is over, allocate X font cache */
2794 fontCache = (fontObject*) HeapAlloc(GetProcessHeap(), 0, fontCacheSize * sizeof(fontObject));
2795 XFONT_GrowFreeList(0, fontCacheSize - 1);
2799 /* update text caps parameter */
2801 pDevCaps->textCaps = XTextCaps;
2803 RAW_ASCENT = TSXInternAtom(gdi_display, "RAW_ASCENT", TRUE);
2804 RAW_DESCENT = TSXInternAtom(gdi_display, "RAW_DESCENT", TRUE);
2809 /**********************************************************************
2812 static BOOL XFONT_SetX11Trans( fontObject *pfo )
2818 TSXGetFontProperty( pfo->fs, XA_FONT, &nameAtom );
2819 fontName = TSXGetAtomName( gdi_display, nameAtom );
2820 lfd = LFD_Parse(fontName);
2827 if (lfd->pixel_size[0] != '[') {
2828 HeapFree(GetProcessHeap(), 0, lfd);
2833 #define PX pfo->lpX11Trans
2835 sscanf(lfd->pixel_size, "[%f%f%f%f]", &PX->a, &PX->b, &PX->c, &PX->d);
2837 HeapFree(GetProcessHeap(), 0, lfd);
2839 TSXGetFontProperty( pfo->fs, RAW_ASCENT, &PX->RAW_ASCENT );
2840 TSXGetFontProperty( pfo->fs, RAW_DESCENT, &PX->RAW_DESCENT );
2842 PX->pixelsize = hypot(PX->a, PX->b);
2843 PX->ascent = PX->pixelsize / 1000.0 * PX->RAW_ASCENT;
2844 PX->descent = PX->pixelsize / 1000.0 * PX->RAW_DESCENT;
2846 TRACE("[%f %f %f %f] RA = %ld RD = %ld\n",
2847 PX->a, PX->b, PX->c, PX->d,
2848 PX->RAW_ASCENT, PX->RAW_DESCENT);
2854 /***********************************************************************
2855 * X Device Font Objects
2857 static X_PHYSFONT XFONT_RealizeFont( const LPLOGFONT16 plf,
2858 LPCSTR* faceMatched, BOOL bSubFont,
2859 WORD internal_charset,
2860 WORD* pcharsetMatched )
2866 pfo = XFONT_LookupCachedFont( plf, &checksum );
2877 fm.internal_charset = internal_charset;
2879 if( XTextCaps & TC_SF_X_YINDEP ) fm.flags = FO_MATCH_XYINDEP;
2881 /* allocate new font cache entry */
2883 if( (pfo = XFONT_GetCacheEntry()) )
2885 /* initialize entry and load font */
2886 char lpLFD[MAX_LFD_LENGTH];
2887 UINT uRelaxLevel = 0;
2889 if(abs(plf->lfHeight) > MAX_FONT_SIZE) {
2891 "plf->lfHeight = %d, Creating a 100 pixel font and rescaling metrics \n",
2893 pfo->rescale = fabs(plf->lfHeight / 100.0);
2894 if(plf->lfHeight > 0) plf->lfHeight = 100;
2895 else plf->lfHeight = -100;
2899 XFONT_MatchDeviceFont( fontList, &fm );
2902 pfo->fr->fo_count++;
2903 pfo->fo_flags = fm.flags & ~FO_MATCH_MASK;
2906 pfo->lfchecksum = checksum;
2910 LFD_ComposeLFD( pfo, fm.height, lpLFD, uRelaxLevel++ );
2911 if( (pfo->fs = TSXLoadQueryFont( gdi_display, lpLFD )) ) break;
2912 } while( uRelaxLevel );
2915 if(pfo->lf.lfEscapement != 0) {
2916 pfo->lpX11Trans = HeapAlloc(GetProcessHeap(), 0, sizeof(XFONTTRANS));
2917 if(!XFONT_SetX11Trans( pfo )) {
2918 HeapFree(GetProcessHeap(), 0, pfo->lpX11Trans);
2919 pfo->lpX11Trans = NULL;
2922 XFONT_GetLeading( &pfo->fi->df, pfo->fs,
2923 &pfo->foInternalLeading, NULL, pfo->lpX11Trans );
2924 pfo->foAvgCharWidth = (INT16)XFONT_GetAvgCharWidth(&pfo->fi->df, pfo->fs, pfo->lpX11Trans );
2925 pfo->foMaxCharWidth = (INT16)XFONT_GetMaxCharWidth(pfo->fs, pfo->lpX11Trans);
2927 /* FIXME: If we've got a soft font or
2928 * there are FO_SYNTH_... flags for the
2929 * non PROOF_QUALITY request, the engine
2930 * should rasterize characters into mono
2931 * pixmaps and store them in the pfo->lpPixmap
2932 * array (pfo->fs should be updated as well).
2933 * array (pfo->fs should be updated as well).
2934 * X11DRV_ExtTextOut() must be heavily modified
2935 * to support pixmap blitting and FO_SYNTH_...
2939 pfo->lpPixmap = NULL;
2941 for ( i = 0; i < X11FONT_REFOBJS_MAX; i++ )
2942 pfo->prefobjs[i] = (X_PHYSFONT)0xffffffff; /* invalid value */
2944 /* special treatment for DBCS that needs multiple fonts */
2945 /* All member of pfo must be set correctly. */
2946 if ( bSubFont == FALSE )
2949 WORD charsetMatchedSub;
2951 LPCSTR faceMatchedSub;
2953 for ( i = 0; i < X11FONT_REFOBJS_MAX; i++ )
2955 charset_sub = X11DRV_cptable[pfo->fi->cptable].
2956 penum_subfont_charset( i );
2957 if ( charset_sub == DEFAULT_CHARSET ) break;
2961 lfSub.lfHeight = pfo->fi->df.dfPixHeight;
2962 if ( plf->lfHeight < 0 )
2963 lfSub.lfHeight = - lfSub.lfHeight;
2964 lfSub.lfCharSet = (BYTE)(charset_sub & 0xff);
2965 lfSub.lfFaceName[0] = '\0'; /* FIXME? */
2966 /* this font has sub font */
2967 if ( i == 0 ) pfo->prefobjs[0] = (X_PHYSFONT)0;
2969 XFONT_RealizeFont( &lfSub, &faceMatchedSub,
2971 &charsetMatchedSub );
2972 /* FIXME: check charsetMatchedSub */
2977 if( !pfo ) /* couldn't get a new entry, get one of the cached fonts */
2979 UINT current_score, score = (UINT)(-1);
2981 i = index = fontMRU;
2982 fm.flags |= FO_MATCH_PAF;
2985 pfo = fontCache + i;
2986 fm.pfr = pfo->fr; fm.pfi = pfo->fi;
2988 current_score = XFONT_Match( &fm );
2989 if( current_score < score ) index = i;
2993 pfo = fontCache + index;
2998 /* attach at the head of the lru list */
3000 index = fontMRU = (pfo - fontCache);
3005 TRACE("physfont %i\n", index);
3006 *faceMatched = pfo->fi->df.dfFace;
3007 *pcharsetMatched = pfo->fi->internal_charset;
3009 return (X_PHYSFONT)(X_PFONT_MAGIC | index);
3012 /***********************************************************************
3013 * XFONT_GetFontObject
3015 fontObject* XFONT_GetFontObject( X_PHYSFONT pFont )
3017 if( CHECK_PFONT(pFont) ) return __PFONT(pFont);
3021 /***********************************************************************
3022 * XFONT_GetFontStruct
3024 XFontStruct* XFONT_GetFontStruct( X_PHYSFONT pFont )
3026 if( CHECK_PFONT(pFont) ) return __PFONT(pFont)->fs;
3030 /***********************************************************************
3033 LPIFONTINFO16 XFONT_GetFontInfo( X_PHYSFONT pFont )
3035 if( CHECK_PFONT(pFont) ) return &(__PFONT(pFont)->fi->df);
3041 /* X11DRV Interface ****************************************************
3043 * Exposed via the dc->funcs dispatch table. *
3045 ***********************************************************************/
3046 /***********************************************************************
3047 * X11DRV_FONT_SelectObject
3049 HFONT X11DRV_FONT_SelectObject( DC* dc, HFONT hfont, FONTOBJ* font )
3051 HFONT hPrevFont = 0;
3053 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
3055 EnterCriticalSection( &crtsc_fonts_X11 );
3057 if( CHECK_PFONT(physDev->font) )
3058 XFONT_ReleaseCacheEntry( __PFONT(physDev->font) );
3060 FONT_LogFontWTo16(&font->logfont, &lf);
3062 /* Make sure we don't change the sign when converting to device coords */
3063 /* FIXME - check that the other drivers do this correctly */
3066 lf.lfWidth = GDI_ROUND((FLOAT)lf.lfWidth * fabs(dc->xformWorld2Vport.eM11));
3067 if (lf.lfWidth == 0)
3068 lf.lfWidth = 1; /* Minimum width */
3072 lf.lfHeight = GDI_ROUND((FLOAT)lf.lfHeight * fabs(dc->xformWorld2Vport.eM22));
3074 if (lf.lfHeight == 0)
3075 lf.lfHeight = MIN_FONT_SIZE;
3078 lf.lfHeight = -(DEF_POINT_SIZE * dc->devCaps->logPixelsY + (72>>1)) / 72;
3081 /* Fixup aliases before passing to RealizeFont */
3082 /* alias = Windows name in the alias table */
3083 LPCSTR alias = XFONT_UnAlias( lf.lfFaceName );
3085 WORD charsetMatched;
3087 TRACE("hfont=%04x\n", hfont); /* to connect with the trace from RealizeFont */
3088 physDev->font = XFONT_RealizeFont( &lf, &faceMatched,
3089 FALSE, lf.lfCharSet,
3092 /* set face to the requested facename if it matched
3093 * so that GetTextFace can get the correct face name
3095 if (alias && !strcmp(faceMatched, lf.lfFaceName))
3096 MultiByteToWideChar(CP_ACP, 0, alias, -1,
3097 font->logfont.lfFaceName, LF_FACESIZE);
3099 MultiByteToWideChar(CP_ACP, 0, faceMatched, -1,
3100 font->logfont.lfFaceName, LF_FACESIZE);
3103 * In X, some encodings may have the same lfFaceName.
3105 * -misc-fixed-*-iso8859-1
3106 * -misc-fixed-*-jisx0208.1990-0
3107 * so charset should be saved...
3109 font->logfont.lfCharSet = charsetMatched;
3112 hPrevFont = dc->hFont;
3115 LeaveCriticalSection( &crtsc_fonts_X11 );
3121 /***********************************************************************
3123 * X11DRV_EnumDeviceFonts
3125 BOOL X11DRV_EnumDeviceFonts( HDC hdc, LPLOGFONTW plf,
3126 DEVICEFONTENUMPROC proc, LPARAM lp )
3129 NEWTEXTMETRICEXW tm;
3130 fontResource* pfr = fontList;
3135 FONT_LogFontWTo16(plf, &lf16);
3137 if( lf16.lfFaceName[0] )
3139 /* enum all entries in this resource */
3140 pfr = XFONT_FindFIList( pfr, lf16.lfFaceName );
3144 for( pfi = pfr->fi; pfi; pfi = pfi->next )
3146 /* Note: XFONT_GetFontMetric() will have to
3147 release the crit section, font list will
3148 have to be retraversed on return */
3150 if(lf16.lfCharSet == DEFAULT_CHARSET ||
3151 lf16.lfCharSet == pfi->df.dfCharSet) {
3152 if( (b = (*proc)( &lf, &tm,
3153 XFONT_GetFontMetric( pfi, &lf, &tm ), lp )) )
3160 else /* enum first entry in each resource */
3161 for( ; pfr ; pfr = pfr->next )
3165 if( (b = (*proc)( &lf, &tm,
3166 XFONT_GetFontMetric( pfr->fi, &lf, &tm ), lp )) )
3175 /***********************************************************************
3176 * X11DRV_GetTextMetrics
3178 BOOL X11DRV_GetTextMetrics(DC *dc, TEXTMETRICW *metrics)
3180 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
3183 if( CHECK_PFONT(physDev->font) )
3185 fontObject* pfo = __PFONT(physDev->font);
3186 X11DRV_cptable[pfo->fi->cptable].pGetTextMetricsA( pfo, &tmA );
3187 FONT_TextMetricAToW(&tmA, metrics);
3194 /***********************************************************************
3195 * X11DRV_GetCharWidth
3197 BOOL X11DRV_GetCharWidth( DC *dc, UINT firstChar, UINT lastChar,
3200 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
3201 fontObject* pfo = XFONT_GetFontObject( physDev->font );
3207 if (pfo->fs->per_char == NULL)
3208 for (i = firstChar; i <= lastChar; i++)
3210 *buffer++ = pfo->fs->min_bounds.attributes *
3211 pfo->lpX11Trans->pixelsize / 1000.0 * pfo->rescale;
3213 *buffer++ = pfo->fs->min_bounds.width * pfo->rescale;
3216 XCharStruct *cs, *def;
3217 static XCharStruct __null_char = { 0, 0, 0, 0, 0, 0 };
3219 CI_GET_CHAR_INFO(pfo->fs, pfo->fs->default_char, &__null_char,
3222 for (i = firstChar; i <= lastChar; i++)
3224 if (i >= pfo->fs->min_char_or_byte2 &&
3225 i <= pfo->fs->max_char_or_byte2)
3227 cs = &pfo->fs->per_char[(i - pfo->fs->min_char_or_byte2)];
3228 if (CI_NONEXISTCHAR(cs)) cs = def;
3231 *buffer++ = max(cs->attributes, 0) *
3232 pfo->lpX11Trans->pixelsize / 1000.0 * pfo->rescale;
3234 *buffer++ = max(cs->width, 0 ) * pfo->rescale;