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>
33 #include "debugtools.h"
34 #include "user.h" /* for TWEAK_WineLook (FIXME) */
38 DEFAULT_DEBUG_CHANNEL(font);
40 #define X_PFONT_MAGIC (0xFADE0000)
41 #define X_FMC_MAGIC (0x0000CAFE)
43 #define MAX_FONTS 1024*16
44 #define MAX_LFD_LENGTH 256
48 #define DEF_POINT_SIZE 8 /* CreateFont(0 .. ) gets this */
49 #define DEF_SCALABLE_HEIGHT 100 /* pixels */
50 #define MIN_FONT_SIZE 2 /* Min size in pixels */
51 #define MAX_FONT_SIZE 1000 /* Max size in pixels */
53 #define REMOVE_SUBSETS 1
54 #define UNMARK_SUBSETS 0
57 #define FF_FAMILY (FF_MODERN | FF_SWISS | FF_ROMAN | FF_DECORATIVE | FF_SCRIPT)
59 typedef struct __fontAlias
63 struct __fontAlias* next;
66 static fontAlias *aliasTable = NULL;
68 UINT16 XTextCaps = TC_OP_CHARACTER | TC_OP_STROKE |
69 TC_CP_STROKE | TC_CR_ANY |
70 TC_SA_DOUBLE | TC_SA_INTEGER | TC_SA_CONTIN |
71 TC_UA_ABLE | TC_SO_ABLE | TC_RA_ABLE;
73 /* X11R6 adds TC_SF_X_YINDEP, maybe more... */
75 static const char* INIFontMetrics = "/cachedmetrics.";
76 static const char* INIFontSection = "fonts";
77 static const char* INIAliasSection = "Alias";
78 static const char* INIIgnoreSection = "Ignore";
79 static const char* INIDefault = "Default";
80 static const char* INIDefaultFixed = "DefaultFixed";
81 static const char* INIResolution = "Resolution";
82 static const char* INIGlobalMetrics = "FontMetrics";
83 static const char* INIDefaultSerif = "DefaultSerif";
84 static const char* INIDefaultSansSerif = "DefaultSansSerif";
87 /* FIXME - are there any more Latin charsets ? */
88 /* FIXME - RUSSIAN, ARABIC, GREEK, HEBREW are NOT Latin */
89 #define IS_LATIN_CHARSET(ch) \
90 ((ch)==ANSI_CHARSET ||\
92 (ch)==ISO3_CHARSET ||\
93 (ch)==ISO4_CHARSET ||\
94 (ch)==RUSSIAN_CHARSET ||\
95 (ch)==ARABIC_CHARSET ||\
96 (ch)==GREEK_CHARSET ||\
97 (ch)==HEBREW_CHARSET ||\
98 (ch)==TURKISH_CHARSET ||\
99 (ch)==ISO10_CHARSET ||\
100 (ch)==BALTIC_CHARSET ||\
101 (ch)==CELTIC_CHARSET)
103 /* suffix-charset mapping tables - must be less than 254 entries long */
105 typedef struct __sufch
108 WORD charset; /* hibyte != 0 means *internal* charset */
113 static const SuffixCharset sufch_ansi[] = {
114 { "0", ANSI_CHARSET, 1252, X11DRV_CPTABLE_SBCS },
115 { NULL, ANSI_CHARSET, 1252, X11DRV_CPTABLE_SBCS }};
117 static const SuffixCharset sufch_iso646[] = {
118 { "irv", ANSI_CHARSET, 1252, X11DRV_CPTABLE_SBCS },
119 { NULL, ANSI_CHARSET, 1252, X11DRV_CPTABLE_SBCS }};
121 static const SuffixCharset sufch_iso8859[] = {
122 { "1", ANSI_CHARSET, 28591, X11DRV_CPTABLE_SBCS },
123 { "2", EE_CHARSET, 28592, X11DRV_CPTABLE_SBCS },
124 { "3", ISO3_CHARSET, 28593, X11DRV_CPTABLE_SBCS },
125 { "4", ISO4_CHARSET, 28594, X11DRV_CPTABLE_SBCS },
126 { "5", RUSSIAN_CHARSET, 28595, X11DRV_CPTABLE_SBCS },
127 { "6", ARABIC_CHARSET, 28596, X11DRV_CPTABLE_SBCS },
128 { "7", GREEK_CHARSET, 28597, X11DRV_CPTABLE_SBCS },
129 { "8", HEBREW_CHARSET, 28598, X11DRV_CPTABLE_SBCS },
130 { "9", TURKISH_CHARSET, 28599, X11DRV_CPTABLE_SBCS },
131 { "10", ISO10_CHARSET, 28600, X11DRV_CPTABLE_SBCS },
132 { "11", THAI_CHARSET, 874, X11DRV_CPTABLE_SBCS }, /* FIXME */
133 { "12", SYMBOL_CHARSET, CP_SYMBOL, X11DRV_CPTABLE_SBCS },
134 { "13", BALTIC_CHARSET, 28603, X11DRV_CPTABLE_SBCS },
135 { "14", CELTIC_CHARSET, 28604, X11DRV_CPTABLE_SBCS },
136 { "15", ANSI_CHARSET, 28605, X11DRV_CPTABLE_SBCS },
137 { NULL, ANSI_CHARSET, 1252, X11DRV_CPTABLE_SBCS }};
139 static const SuffixCharset sufch_microsoft[] = {
140 { "cp1250", EE_CHARSET, 1250, X11DRV_CPTABLE_SBCS },
141 { "cp1251", RUSSIAN_CHARSET, 1251, X11DRV_CPTABLE_SBCS },
142 { "cp1252", ANSI_CHARSET, 1252, X11DRV_CPTABLE_SBCS },
143 { "cp1253", GREEK_CHARSET, 1253, X11DRV_CPTABLE_SBCS },
144 { "cp1254", TURKISH_CHARSET, 1254, X11DRV_CPTABLE_SBCS },
145 { "cp1255", HEBREW_CHARSET, 1255, X11DRV_CPTABLE_SBCS },
146 { "cp1256", ARABIC_CHARSET, 1256, X11DRV_CPTABLE_SBCS },
147 { "cp1257", BALTIC_CHARSET, 1257, X11DRV_CPTABLE_SBCS },
148 { "fontspecific", SYMBOL_CHARSET, CP_SYMBOL, X11DRV_CPTABLE_SBCS },
149 { "symbol", SYMBOL_CHARSET, CP_SYMBOL, X11DRV_CPTABLE_SBCS },
150 { NULL, ANSI_CHARSET, 1252, X11DRV_CPTABLE_SBCS }};
152 static const SuffixCharset sufch_tcvn[] = {
153 { "0", TCVN_CHARSET, 1252, X11DRV_CPTABLE_SBCS }, /* FIXME */
154 { NULL, TCVN_CHARSET, 1252, X11DRV_CPTABLE_SBCS }};
156 static const SuffixCharset sufch_tis620[] = {
157 { "0", THAI_CHARSET, 874, X11DRV_CPTABLE_SBCS }, /* FIXME */
158 { NULL, THAI_CHARSET, 874, X11DRV_CPTABLE_SBCS }};
160 static const SuffixCharset sufch_viscii[] = {
161 { "1", VISCII_CHARSET, 1252, X11DRV_CPTABLE_SBCS }, /* FIXME */
162 { NULL, VISCII_CHARSET, 1252, X11DRV_CPTABLE_SBCS }};
164 static const SuffixCharset sufch_windows[] = {
165 { "1250", EE_CHARSET, 1250, X11DRV_CPTABLE_SBCS },
166 { "1251", RUSSIAN_CHARSET, 1251, X11DRV_CPTABLE_SBCS },
167 { "1252", ANSI_CHARSET, 1252, X11DRV_CPTABLE_SBCS },
168 { "1253", GREEK_CHARSET, 1253, X11DRV_CPTABLE_SBCS },
169 { "1254", TURKISH_CHARSET, 1254, X11DRV_CPTABLE_SBCS },
170 { "1255", HEBREW_CHARSET, 1255, X11DRV_CPTABLE_SBCS },
171 { "1256", ARABIC_CHARSET, 1256, X11DRV_CPTABLE_SBCS },
172 { "1257", BALTIC_CHARSET, 1257, X11DRV_CPTABLE_SBCS },
173 { NULL, ANSI_CHARSET, 1252, X11DRV_CPTABLE_SBCS }};
175 static const SuffixCharset sufch_koi8[] = {
176 { "r", RUSSIAN_CHARSET, 20866, X11DRV_CPTABLE_SBCS },
177 { "ru", RUSSIAN_CHARSET, 20866, X11DRV_CPTABLE_SBCS },
178 { "u", RUSSIAN_CHARSET, 20866, X11DRV_CPTABLE_SBCS },
179 { NULL, RUSSIAN_CHARSET, 20866, X11DRV_CPTABLE_SBCS }};
181 static const SuffixCharset sufch_jisx0201[] = {
182 { "0", X11FONT_JISX0201_CHARSET, 932, X11DRV_CPTABLE_SBCS },
183 { NULL, X11FONT_JISX0201_CHARSET, 932, X11DRV_CPTABLE_SBCS }};
185 static const SuffixCharset sufch_jisx0208[] = {
186 { "0", SHIFTJIS_CHARSET, 932, X11DRV_CPTABLE_CP932 },
187 { NULL, SHIFTJIS_CHARSET, 932, X11DRV_CPTABLE_CP932 }};
189 static const SuffixCharset sufch_jisx0212[] = {
190 { "0", X11FONT_JISX0212_CHARSET, 932, X11DRV_CPTABLE_CP932 },
191 { NULL, X11FONT_JISX0212_CHARSET, 932, X11DRV_CPTABLE_CP932 }};
193 static const SuffixCharset sufch_ksc5601[] = {
194 { "0", HANGEUL_CHARSET, 949, X11DRV_CPTABLE_CP949 },
195 { NULL, HANGEUL_CHARSET, 949, X11DRV_CPTABLE_CP949 }};
197 static const SuffixCharset sufch_gb2312[] = {
198 { "0", GB2312_CHARSET, 936, X11DRV_CPTABLE_CP936 },
199 { NULL, GB2312_CHARSET, 936, X11DRV_CPTABLE_CP936 }};
201 static const SuffixCharset sufch_big5[] = {
202 { "0", CHINESEBIG5_CHARSET, 950, X11DRV_CPTABLE_CP950 },
203 { NULL, CHINESEBIG5_CHARSET, 950, X11DRV_CPTABLE_CP950 }};
205 static const SuffixCharset sufch_unicode[] = {
206 { "0", DEFAULT_CHARSET, 0, X11DRV_CPTABLE_UNICODE },
207 { NULL, DEFAULT_CHARSET, 0, X11DRV_CPTABLE_UNICODE }};
209 static const SuffixCharset sufch_iso10646[] = {
210 { "1", DEFAULT_CHARSET, 0, X11DRV_CPTABLE_UNICODE },
211 { NULL, DEFAULT_CHARSET, 0, X11DRV_CPTABLE_UNICODE }};
213 /* Each of these must be matched explicitly */
214 static const SuffixCharset sufch_any[] = {
215 { "fontspecific", SYMBOL_CHARSET, CP_SYMBOL, X11DRV_CPTABLE_SBCS },
216 { NULL, 0, 0, X11DRV_CPTABLE_SBCS }};
222 const SuffixCharset* sufch;
224 } fontEncodingTemplate;
226 /* Note: we can attach additional encoding mappings to the end
227 * of this table at runtime.
229 static fontEncodingTemplate __fETTable[] = {
230 { "ansi", sufch_ansi, &__fETTable[1] },
231 { "ascii", sufch_ansi, &__fETTable[2] },
232 { "iso646.1991", sufch_iso646, &__fETTable[3] },
233 { "iso8859", sufch_iso8859, &__fETTable[4] },
234 { "microsoft", sufch_microsoft, &__fETTable[5] },
235 { "tcvn", sufch_tcvn, &__fETTable[6] },
236 { "tis620.2533", sufch_tis620, &__fETTable[7] },
237 { "viscii1.1", sufch_viscii, &__fETTable[8] },
238 { "windows", sufch_windows, &__fETTable[9] },
239 { "koi8", sufch_koi8, &__fETTable[10]},
240 { "jisx0201.1976",sufch_jisx0201, &__fETTable[11]},
241 { "jisc6226.1978",sufch_jisx0208, &__fETTable[12]},
242 { "jisx0208.1983",sufch_jisx0208, &__fETTable[13]},
243 { "jisx0208.1990",sufch_jisx0208, &__fETTable[14]},
244 { "jisx0212.1990",sufch_jisx0212, &__fETTable[15]},
245 { "ksc5601.1987", sufch_ksc5601, &__fETTable[16]},
246 { "gb2312.1980", sufch_gb2312, &__fETTable[17]},
247 { "big5.et", sufch_big5, &__fETTable[18]},
248 { "unicode", sufch_unicode, &__fETTable[19]},
249 { "iso10646", sufch_iso10646, &__fETTable[20]},
250 { "cp", sufch_windows, &__fETTable[21]},
251 /* NULL prefix matches anything so put it last */
252 { NULL, sufch_any, NULL },
254 static fontEncodingTemplate* fETTable = __fETTable;
256 /* a charset database for known facenames */
257 struct CharsetBindingInfo
259 const char* pszFaceName;
262 static const struct CharsetBindingInfo charsetbindings[] =
264 /* special facenames */
265 { "System", DEFAULT_CHARSET },
266 { "FixedSys", DEFAULT_CHARSET },
268 /* known facenames */
269 { "MS Serif", ANSI_CHARSET },
270 { "MS Sans Serif", ANSI_CHARSET },
271 { "Courier", ANSI_CHARSET },
272 { "Symbol", SYMBOL_CHARSET },
274 { "Arial", ANSI_CHARSET },
275 { "Arial Greek", GREEK_CHARSET },
276 { "Arial Tur", TURKISH_CHARSET },
277 { "Arial Baltic", BALTIC_CHARSET },
278 { "Arial CE", EASTEUROPE_CHARSET },
279 { "Arial Cyr", RUSSIAN_CHARSET },
280 { "Courier New", ANSI_CHARSET },
281 { "Courier New Greek", GREEK_CHARSET },
282 { "Courier New Tur", TURKISH_CHARSET },
283 { "Courier New Baltic", BALTIC_CHARSET },
284 { "Courier New CE", EASTEUROPE_CHARSET },
285 { "Courier New Cyr", RUSSIAN_CHARSET },
286 { "Times New Roman", ANSI_CHARSET },
287 { "Times New Roman Greek", GREEK_CHARSET },
288 { "Times New Roman Tur", TURKISH_CHARSET },
289 { "Times New Roman Baltic", BALTIC_CHARSET },
290 { "Times New Roman CE", EASTEUROPE_CHARSET },
291 { "Times New Roman Cyr", RUSSIAN_CHARSET },
293 { "\x82\x6c\x82\x72 \x83\x53\x83\x56\x83\x62\x83\x4e",
294 SHIFTJIS_CHARSET }, /* MS gothic */
295 { "\x82\x6c\x82\x72 \x82\x6f\x83\x53\x83\x56\x83\x62\x83\x4e",
296 SHIFTJIS_CHARSET }, /* MS P gothic */
297 { "\x82\x6c\x82\x72 \x96\xbe\x92\xa9",
298 SHIFTJIS_CHARSET }, /* MS mincho */
299 { "\x82\x6c\x82\x72 \x82\x6f\x96\xbe\x92\xa9",
300 SHIFTJIS_CHARSET }, /* MS P mincho */
301 { "GulimChe", HANGEUL_CHARSET },
302 { "MS Song", GB2312_CHARSET },
303 { "MS Hei", GB2312_CHARSET },
309 static int DefResolution = 0;
311 static CRITICAL_SECTION crtsc_fonts_X11 = CRITICAL_SECTION_INIT;
313 static fontResource* fontList = NULL;
314 static fontObject* fontCache = NULL; /* array */
315 static int fontCacheSize = FONTCACHE;
316 static int fontLF = -1, fontMRU = -1; /* last free, most recently used */
318 #define __PFONT(pFont) ( fontCache + ((UINT)(pFont) & 0x0000FFFF) )
319 #define CHECK_PFONT(pFont) ( (((UINT)(pFont) & 0xFFFF0000) == X_PFONT_MAGIC) &&\
320 (((UINT)(pFont) & 0x0000FFFF) < fontCacheSize) )
322 static Atom RAW_ASCENT;
323 static Atom RAW_DESCENT;
325 /***********************************************************************
326 * Helper macros from X distribution
329 #define CI_NONEXISTCHAR(cs) (((cs)->width == 0) && \
330 (((cs)->rbearing|(cs)->lbearing| \
331 (cs)->ascent|(cs)->descent) == 0))
333 #define CI_GET_CHAR_INFO(fs,col,def,cs) \
336 if (col >= fs->min_char_or_byte2 && col <= fs->max_char_or_byte2) { \
337 if (fs->per_char == NULL) { \
338 cs = &fs->min_bounds; \
340 cs = &fs->per_char[(col - fs->min_char_or_byte2)]; \
341 if (CI_NONEXISTCHAR(cs)) cs = def; \
346 #define CI_GET_DEFAULT_INFO(fs,cs) \
347 CI_GET_CHAR_INFO(fs, fs->default_char, NULL, cs)
349 /***********************************************************************
352 static UINT16 __lfCheckSum( LPLOGFONT16 plf )
354 CHAR font[LF_FACESIZE];
360 for (i = 0; i < 9; i++) checksum ^= *ptr++;
361 for (i = 0; i < LF_FACESIZE; i++)
363 font[i] = tolower(plf->lfFaceName[i]);
364 if (!font[i] || font[i] == ' ') break;
366 for (ptr = (UINT16 *)font, i >>= 1; i > 0; i-- ) checksum ^= *ptr++;
370 static UINT16 __genericCheckSum( const void *ptr, int size )
372 unsigned int checksum = 0;
373 const char *p = (const char *)ptr;
375 checksum ^= (checksum << 3) + (checksum >> 29) + *p++;
377 return checksum & 0xffff;
380 /*************************************************************************
381 * LFD parse/compose routines
383 * NB. LFD_Parse will use lpFont for its own ends, so if you want to keep it
386 * These functions also do TILDE to HYPHEN conversion
388 static LFD* LFD_Parse(LPSTR lpFont)
391 char *lpch = lpFont, *lfd_fld[LFD_FIELDS], *field_start;
395 WARN("font '%s' doesn't begin with '%c'\n", lpFont, HYPHEN);
399 field_start = ++lpch;
400 for( i = 0; i < LFD_FIELDS; )
405 lfd_fld[i] = field_start;
407 field_start = ++lpch;
411 lfd_fld[i] = field_start;
415 else if (*lpch == TILDE)
423 /* Fill in the empty fields with NULLS */
424 for (; i< LFD_FIELDS; i++)
427 WARN("Extra ignored in font '%s'\n", lpFont);
429 lfd = HeapAlloc( GetProcessHeap(), 0, sizeof(LFD) );
432 lfd->foundry = lfd_fld[0];
433 lfd->family = lfd_fld[1];
434 lfd->weight = lfd_fld[2];
435 lfd->slant = lfd_fld[3];
436 lfd->set_width = lfd_fld[4];
437 lfd->add_style = lfd_fld[5];
438 lfd->pixel_size = lfd_fld[6];
439 lfd->point_size = lfd_fld[7];
440 lfd->resolution_x = lfd_fld[8];
441 lfd->resolution_y = lfd_fld[9];
442 lfd->spacing = lfd_fld[10];
443 lfd->average_width = lfd_fld[11];
444 lfd->charset_registry = lfd_fld[12];
445 lfd->charset_encoding = lfd_fld[13];
451 static void LFD_UnParse(LPSTR dp, UINT buf_size, LFD* lfd)
453 const char* lfd_fld[LFD_FIELDS];
457 return; /* Dont be silly */
459 lfd_fld[0] = lfd->foundry;
460 lfd_fld[1] = lfd->family;
461 lfd_fld[2] = lfd->weight ;
462 lfd_fld[3] = lfd->slant ;
463 lfd_fld[4] = lfd->set_width ;
464 lfd_fld[5] = lfd->add_style;
465 lfd_fld[6] = lfd->pixel_size;
466 lfd_fld[7] = lfd->point_size;
467 lfd_fld[8] = lfd->resolution_x;
468 lfd_fld[9] = lfd->resolution_y ;
469 lfd_fld[10] = lfd->spacing ;
470 lfd_fld[11] = lfd->average_width ;
471 lfd_fld[12] = lfd->charset_registry ;
472 lfd_fld[13] = lfd->charset_encoding ;
474 buf_size--; /* Room for the terminator */
476 for (i = 0; i < LFD_FIELDS; i++)
478 const char* sp = lfd_fld[i];
479 if (!sp || !buf_size)
484 while (buf_size > 0 && *sp)
486 *dp = (*sp == HYPHEN) ? TILDE : *sp;
495 static void LFD_GetWeight( fontInfo* fi, LPCSTR lpStr)
497 int j = strlen(lpStr);
498 if( j == 1 && *lpStr == '0')
499 fi->fi_flags |= FI_POLYWEIGHT;
502 if( !strcasecmp( "bold", lpStr) )
503 fi->df.dfWeight = FW_BOLD;
504 else if( !strcasecmp( "demi", lpStr) )
506 fi->fi_flags |= FI_FW_DEMI;
507 fi->df.dfWeight = FW_DEMIBOLD;
509 else if( !strcasecmp( "book", lpStr) )
511 fi->fi_flags |= FI_FW_BOOK;
512 fi->df.dfWeight = FW_REGULAR;
517 if( !strcasecmp( "light", lpStr) )
518 fi->df.dfWeight = FW_LIGHT;
519 else if( !strcasecmp( "black", lpStr) )
520 fi->df.dfWeight = FW_BLACK;
522 else if( j == 6 && !strcasecmp( "medium", lpStr) )
523 fi->df.dfWeight = FW_REGULAR;
524 else if( j == 8 && !strcasecmp( "demibold", lpStr) )
525 fi->df.dfWeight = FW_DEMIBOLD;
527 fi->df.dfWeight = FW_DONTCARE; /* FIXME: try to get something
528 * from the weight property */
531 static BOOL LFD_GetSlant( fontInfo* fi, LPCSTR lpStr)
533 int l = strlen(lpStr);
536 switch( tolower( *lpStr ) )
538 case '0': fi->fi_flags |= FI_POLYSLANT; /* haven't seen this one yet */
540 case 'r': fi->df.dfItalic = 0;
543 fi->fi_flags |= FI_OBLIQUE;
544 case 'i': fi->df.dfItalic = 1;
552 static void LFD_GetStyle( fontInfo* fi, LPCSTR lpstr, int dec_style_check)
554 int j = strlen(lpstr);
555 if( j > 3 ) /* find out is there "sans" or "script" */
559 if( strstr(lpstr, "sans") )
561 fi->df.dfPitchAndFamily |= FF_SWISS;
564 if( strstr(lpstr, "script") )
566 fi->df.dfPitchAndFamily |= FF_SCRIPT;
569 if( !j && dec_style_check )
570 fi->df.dfPitchAndFamily |= FF_DECORATIVE;
574 /*************************************************************************
579 * Fill in some fields in the fontInfo struct.
581 static int LFD_InitFontInfo( fontInfo* fi, const LFD* lfd, LPCSTR fullname )
583 int i, j, dec_style_check, scalability;
584 fontEncodingTemplate* boba;
585 const char* ridiculous = "font '%s' has ridiculous %s\n";
588 if (!lfd->charset_registry)
590 WARN("font '%s' does not have enough fields\n", fullname);
594 memset(fi, 0, sizeof(fontInfo) );
597 LFD_GetWeight( fi, lfd->weight);
600 dec_style_check = LFD_GetSlant( fi, lfd->slant);
603 lpstr = lfd->set_width;
604 if( strcasecmp( "normal", lpstr) ) /* XXX 'narrow', 'condensed', etc... */
605 dec_style_check = TRUE;
607 fi->fi_flags |= FI_NORMAL;
610 LFD_GetStyle(fi, lfd->add_style, dec_style_check);
612 /* pixel & decipoint height, and res_x & y */
616 j = strlen(lfd->pixel_size);
617 if( j == 0 || j > 3 )
619 WARN(ridiculous, fullname, "pixel_size");
622 if( !(fi->lfd_height = atoi(lfd->pixel_size)) )
625 j = strlen(lfd->point_size);
626 if( j == 0 || j > 3 )
628 WARN(ridiculous, fullname, "point_size");
631 if( !(atoi(lfd->point_size)) )
634 j = strlen(lfd->resolution_x);
635 if( j == 0 || j > 3 )
637 WARN(ridiculous, fullname, "resolution_x");
640 if( !(fi->lfd_resolution = atoi(lfd->resolution_x)) )
643 j = strlen(lfd->resolution_y);
644 if( j == 0 || j > 3 )
646 WARN(ridiculous, fullname, "resolution_y");
649 if( !(atoi(lfd->resolution_y)) )
652 /* Check scalability */
657 case 4: /* Scalable */
658 fi->fi_flags |= FI_SCALABLE;
661 /* #$%^!!! X11R6 mutant garbage (scalable bitmap) */
662 TRACE("Skipping scalable bitmap '%s'\n", fullname);
665 WARN("Font '%s' has weird scalability\n", fullname);
670 lpstr = lfd->spacing;
674 WARN("font '%s' has no spacing\n", fullname);
677 case 'p': fi->fi_flags |= FI_VARIABLEPITCH;
679 case 'c': fi->df.dfPitchAndFamily |= FF_MODERN;
680 fi->fi_flags |= FI_FIXEDEX;
682 case 'm': fi->fi_flags |= FI_FIXEDPITCH;
685 /* Of course this line does nothing */
686 fi->df.dfPitchAndFamily |= DEFAULT_PITCH | FF_DONTCARE;
689 /* average width - */
690 lpstr = lfd->average_width;
692 if( j == 0 || j > 3 )
694 WARN(ridiculous, fullname, "average_width");
698 if( !(atoi(lpstr)) && !scalability )
700 WARN("font '%s' has average_width 0 but is not scalable!!\n", fullname);
704 /* charset registry, charset encoding - */
705 lpstr = lfd->charset_registry;
706 if( strstr(lpstr, "ksc") ||
707 strstr(lpstr, "gb2312") ||
708 strstr(lpstr, "big5") )
710 FIXME("DBCS fonts like '%s' are not working correctly now.\n", fullname);
713 fi->df.dfCharSet = ANSI_CHARSET;
715 for( i = 0, boba = fETTable; boba; boba = boba->next, i++ )
717 if (!boba->prefix || !strcasecmp(lpstr, boba->prefix))
719 if (lfd->charset_encoding)
721 for( j = 0; boba->sufch[j].psuffix; j++ )
723 if( !strcasecmp(lfd->charset_encoding, boba->sufch[j].psuffix ))
725 fi->df.dfCharSet = (BYTE)(boba->sufch[j].charset & 0xff);
726 fi->internal_charset = boba->sufch[j].charset;
727 fi->codepage = boba->sufch[j].codepage;
728 fi->cptable = boba->sufch[j].cptable;
733 fi->df.dfCharSet = (BYTE)(boba->sufch[j].charset & 0xff);
734 fi->internal_charset = boba->sufch[j].charset;
735 fi->codepage = boba->sufch[j].codepage;
736 fi->cptable = boba->sufch[j].cptable;
739 FIXME("font '%s' has unknown character encoding '%s' in known registry '%s'\n",
740 fullname, lfd->charset_encoding, boba->prefix);
745 FIXME("font '%s' has unknown registry '%s' and character encoding '%s' \n",
746 fullname, lfd->charset_registry, lfd->charset_encoding);
750 WARN("Defaulting to: df.dfCharSet = %d, internal_charset = %d, codepage = %d, cptable = %d\n",
751 fi->df.dfCharSet,fi->internal_charset, fi->codepage, fi->cptable);
754 else if (boba->prefix)
756 WARN("font '%s' has known registry '%s' and no character encoding\n",
758 for( j = 0; boba->sufch[j].psuffix; j++ )
760 fi->df.dfCharSet = (BYTE)(boba->sufch[j].charset & 0xff);
761 fi->internal_charset = boba->sufch[j].charset;
762 fi->codepage = boba->sufch[j].codepage;
763 fi->cptable = boba->sufch[j].cptable;
769 WARN("font '%s' has unknown character set '%s'\n", fullname, lpstr);
773 /* i - index into fETTable
774 * j - index into suffix array for fETTable[i]
776 * 254 - found encoding prefix, unknown suffix
777 * 255 - no encoding match at all.
779 fi->fi_encoding = 256 * (UINT16)i + (UINT16)j;
785 /*************************************************************************
788 * make a matrix suitable for LFD based on theta radians
790 static void LFD_AngleMatrix( char* buffer, int h, double theta)
793 matrix[0] = h*cos(theta);
794 matrix[1] = h*sin(theta);
795 matrix[2] = -h*sin(theta);
796 matrix[3] = h*cos(theta);
797 sprintf(buffer, "[%+f%+f%+f%+f]", matrix[0], matrix[1], matrix[2], matrix[3]);
800 /*************************************************************************
803 * Note: uRelax is a treatment not a cure. Font mapping algorithm
804 * should be bulletproof enough to allow us to avoid hacks like
805 * this despite LFD being so braindead.
807 static BOOL LFD_ComposeLFD( const fontObject* fo,
808 INT height, LPSTR lpLFD, UINT uRelax )
812 char h_string[64], resx_string[64], resy_string[64];
815 /* Get the worst case over with first */
817 /* RealizeFont() will call us repeatedly with increasing uRelax
818 * until XLoadFont() succeeds.
819 * to avoid an infinite loop; these will always match
824 sprintf( lpLFD, "-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-1" );
826 sprintf( lpLFD, "-*-*-*-*-*-*-*-*-*-*-*-*-*-*" );
830 /* read foundry + family from fo */
831 aLFD.foundry = fo->fr->resource->foundry;
832 aLFD.family = fo->fr->resource->family;
835 switch( fo->fi->df.dfWeight )
838 aLFD.weight = "bold"; break;
840 if( fo->fi->fi_flags & FI_FW_BOOK )
841 aLFD.weight = "book";
843 aLFD.weight = "medium";
846 aLFD.weight = "demi";
847 if( !( fo->fi->fi_flags & FI_FW_DEMI) )
848 aLFD.weight = "bold";
851 aLFD.weight = "black"; break;
853 aLFD.weight = "light"; break;
859 if( fo->fi->df.dfItalic )
860 if( fo->fi->fi_flags & FI_OBLIQUE )
865 aLFD.slant = (uRelax < 1) ? "r" : any;
868 if( fo->fi->fi_flags & FI_NORMAL )
869 aLFD.set_width = "normal";
871 aLFD.set_width = any;
874 aLFD.add_style = any;
878 * FIXME: fill in lpXForm and lpPixmap for rotated fonts
880 if( fo->fo_flags & FO_SYNTH_HEIGHT )
881 h = fo->fi->lfd_height;
884 h = (fo->fi->lfd_height * height + (fo->fi->df.dfPixHeight>>1));
885 h /= fo->fi->df.dfPixHeight;
887 if (h < MIN_FONT_SIZE) /* Resist rounding down to 0 */
889 else if (h > MAX_FONT_SIZE) /* Sanity check as huge fonts can lock up the font server */
891 WARN("Huge font size %d pixels has been reduced to %d\n", h, MAX_FONT_SIZE);
896 /* handle rotated fonts */
897 if (fo->lf.lfEscapement) {
898 /* escapement is in tenths of degrees, theta is in radians */
899 double theta = M_PI*fo->lf.lfEscapement/1800.;
900 LFD_AngleMatrix(h_string, h, theta);
904 sprintf(h_string, "%d", h);
907 sprintf(h_string, "%d", fo->fi->lfd_height);
909 aLFD.pixel_size = h_string;
910 aLFD.point_size = any;
912 /* resolution_x,y, average width */
913 /* FOX ME - Why do some font servers ignore average width ?
914 * so that you have to mess around with res_y
916 aLFD.average_width = any;
919 sprintf(resx_string, "%d", fo->fi->lfd_resolution);
920 aLFD.resolution_x = resx_string;
922 strcpy(resy_string, resx_string);
923 if( uRelax == 0 && XTextCaps & TC_SF_X_YINDEP )
925 if( fo->lf.lfWidth && !(fo->fo_flags & FO_SYNTH_WIDTH))
927 int resy = 0.5 + fo->fi->lfd_resolution *
928 (fo->fi->df.dfAvgWidth * height) /
929 (fo->lf.lfWidth * fo->fi->df.dfPixHeight) ;
930 sprintf(resy_string, "%d", resy);
934 /* FIXME - synth width */
937 aLFD.resolution_y = resy_string;
941 aLFD.resolution_x = aLFD.resolution_y = any;
948 if( fo->fi->fi_flags & FI_FIXEDPITCH )
949 w = ( fo->fi->fi_flags & FI_FIXEDEX ) ? "c" : "m";
951 w = ( fo->fi->fi_flags & FI_VARIABLEPITCH ) ? "p" : any;
953 aLFD.spacing = (uRelax <= 1) ? w : any;
960 fontEncodingTemplate* boba = fETTable;
962 for(i = fo->fi->fi_encoding >> 8; i; i--) boba = boba->next;
963 aLFD.charset_registry = boba->prefix ? boba->prefix : any;
965 i = fo->fi->fi_encoding & 255;
969 aLFD.charset_encoding = boba->sufch[i].psuffix;
973 aLFD.charset_encoding = any;
976 case 255: /* no suffix - it ends eg "-ascii" */
977 aLFD.charset_encoding = NULL;
983 aLFD.charset_registry = any;
984 aLFD.charset_encoding = any;
987 LFD_UnParse(lpLFD, MAX_LFD_LENGTH, &aLFD);
989 TRACE("\tLFD(uRelax=%d): %s\n", uRelax, lpLFD );
994 /***********************************************************************
997 * font info - http://www.microsoft.com/kb/articles/q65/1/23.htm
998 * Windows font metrics - http://www.microsoft.com/kb/articles/q32/6/67.htm
1000 static void XFONT_GetLeading( const LPIFONTINFO16 pFI, const XFontStruct* x_fs,
1001 INT16* pIL, INT16* pEL, const XFONTTRANS *XFT )
1003 unsigned long height;
1004 unsigned min = (unsigned char)pFI->dfFirstChar;
1005 BOOL bIsLatin = IS_LATIN_CHARSET(pFI->dfCharSet);
1010 Atom RAW_CAP_HEIGHT = TSXInternAtom(gdi_display, "RAW_CAP_HEIGHT", TRUE);
1011 if(TSXGetFontProperty((XFontStruct*)x_fs, RAW_CAP_HEIGHT, &height))
1012 *pIL = XFT->ascent -
1013 (INT)(XFT->pixelsize / 1000.0 * height);
1019 if( TSXGetFontProperty((XFontStruct*)x_fs, XA_CAP_HEIGHT, &height) == FALSE )
1021 if( x_fs->per_char )
1023 height = x_fs->per_char['X' - min].ascent;
1025 if (x_fs->ascent >= x_fs->max_bounds.ascent)
1026 height = x_fs->max_bounds.ascent;
1029 height = x_fs->ascent;
1031 *pEL = x_fs->max_bounds.ascent - height;
1034 height = x_fs->min_bounds.ascent;
1037 *pIL = x_fs->ascent - height;
1040 /***********************************************************************
1043 static int XFONT_CharWidth(const XFontStruct* x_fs,
1044 const XFONTTRANS *XFT, int ch)
1047 return x_fs->per_char[ch].width;
1049 return x_fs->per_char[ch].attributes * XFT->pixelsize / 1000.0;
1052 /***********************************************************************
1053 * XFONT_GetAvgCharWidth
1055 static INT XFONT_GetAvgCharWidth( LPIFONTINFO16 pFI, const XFontStruct* x_fs,
1056 const XFONTTRANS *XFT)
1058 unsigned min = (unsigned char)pFI->dfFirstChar;
1059 unsigned max = (unsigned char)pFI->dfLastChar;
1063 if( x_fs->per_char )
1065 int width = 0, chars = 0, j;
1066 if( IS_LATIN_CHARSET(pFI->dfCharSet) ||
1067 pFI->dfCharSet == DEFAULT_CHARSET )
1069 /* FIXME - should use a weighted average */
1070 for( j = 0; j < 26; j++ )
1071 width += XFONT_CharWidth(x_fs, XFT, 'a' + j - min) +
1072 XFONT_CharWidth(x_fs, XFT, 'A' + j - min);
1075 else /* unweighted average of everything */
1077 for( j = 0, max -= min; j <= max; j++ )
1078 if( !CI_NONEXISTCHAR(x_fs->per_char + j) )
1080 width += XFONT_CharWidth(x_fs, XFT, j);
1084 if (chars) avg = (width + (chars>>1))/ chars;
1085 else avg = 0; /* No characters exist at all */
1087 else /* uniform width */
1088 avg = x_fs->min_bounds.width;
1093 /***********************************************************************
1094 * XFONT_GetMaxCharWidth
1096 static INT XFONT_GetMaxCharWidth(const XFontStruct* xfs, const XFONTTRANS *XFT)
1098 unsigned min = (unsigned char)xfs->min_char_or_byte2;
1099 unsigned max = (unsigned char)xfs->max_char_or_byte2;
1102 if(!XFT || !xfs->per_char)
1103 return abs(xfs->max_bounds.width);
1105 for( j = 0, maxwidth = 0, max -= min; j <= max; j++ )
1106 if( !CI_NONEXISTCHAR(xfs->per_char + j) )
1107 if(maxwidth < xfs->per_char[j].attributes)
1108 maxwidth = xfs->per_char[j].attributes;
1110 maxwidth *= XFT->pixelsize / 1000.0;
1114 /***********************************************************************
1115 * XFONT_SetFontMetric
1119 * Initializes IFONTINFO16.
1121 static void XFONT_SetFontMetric(fontInfo* fi, const fontResource* fr, XFontStruct* xfs)
1124 fi->df.dfFirstChar = (BYTE)(min = xfs->min_char_or_byte2);
1125 fi->df.dfLastChar = (BYTE)(max = xfs->max_char_or_byte2);
1127 fi->df.dfDefaultChar = (BYTE)xfs->default_char;
1128 fi->df.dfBreakChar = (BYTE)(( ' ' < min || ' ' > max) ? xfs->default_char: ' ');
1130 fi->df.dfPixHeight = (INT16)((fi->df.dfAscent = (INT16)xfs->ascent) + xfs->descent);
1131 fi->df.dfPixWidth = (xfs->per_char) ? 0 : xfs->min_bounds.width;
1133 XFONT_GetLeading( &fi->df, xfs, &fi->df.dfInternalLeading, &fi->df.dfExternalLeading, NULL );
1134 fi->df.dfAvgWidth = (INT16)XFONT_GetAvgCharWidth(&fi->df, xfs, NULL );
1135 fi->df.dfMaxWidth = (INT16)XFONT_GetMaxCharWidth(xfs, NULL);
1137 if( xfs->min_bounds.width != xfs->max_bounds.width )
1138 fi->df.dfPitchAndFamily |= TMPF_FIXED_PITCH; /* au contraire! */
1139 if( fi->fi_flags & FI_SCALABLE )
1141 fi->df.dfType = DEVICE_FONTTYPE;
1142 fi->df.dfPitchAndFamily |= TMPF_DEVICE;
1144 else if( fi->fi_flags & FI_TRUETYPE )
1145 fi->df.dfType = TRUETYPE_FONTTYPE;
1147 fi->df.dfType = RASTER_FONTTYPE;
1149 fi->df.dfFace = fr->lfFaceName;
1152 /***********************************************************************
1153 * XFONT_GetFontMetric
1155 * Retrieve font metric info (enumeration).
1157 static UINT XFONT_GetFontMetric( const fontInfo* pfi,
1158 const LPENUMLOGFONTEXW pLF,
1159 const LPNEWTEXTMETRICEXW pTM )
1161 memset( pLF, 0, sizeof(*pLF) );
1162 memset( pTM, 0, sizeof(*pTM) );
1164 #define plf ((LPLOGFONTW)pLF)
1165 #define ptm ((LPNEWTEXTMETRICW)pTM)
1166 plf->lfHeight = ptm->tmHeight = pfi->df.dfPixHeight;
1167 plf->lfWidth = ptm->tmAveCharWidth = pfi->df.dfAvgWidth;
1168 plf->lfWeight = ptm->tmWeight = pfi->df.dfWeight;
1169 plf->lfItalic = ptm->tmItalic = pfi->df.dfItalic;
1170 plf->lfUnderline = ptm->tmUnderlined = pfi->df.dfUnderline;
1171 plf->lfStrikeOut = ptm->tmStruckOut = pfi->df.dfStrikeOut;
1172 plf->lfCharSet = ptm->tmCharSet = pfi->df.dfCharSet;
1174 /* convert pitch values */
1176 ptm->tmPitchAndFamily = pfi->df.dfPitchAndFamily;
1177 plf->lfPitchAndFamily = (pfi->df.dfPitchAndFamily & 0xF1) + 1;
1179 MultiByteToWideChar(CP_ACP, 0, pfi->df.dfFace, -1,
1180 plf->lfFaceName, LF_FACESIZE);
1182 /* FIXME: fill in rest of plF values */
1183 strcpyW(pLF->elfFullName, plf->lfFaceName);
1184 MultiByteToWideChar(CP_ACP, 0, "Regular", -1,
1185 pLF->elfStyle, LF_FACESIZE);
1186 MultiByteToWideChar(CP_ACP, 0, plf->lfCharSet == SYMBOL_CHARSET ?
1187 "Symbol" : "Roman", -1,
1188 pLF->elfScript, LF_FACESIZE);
1192 ptm->tmAscent = pfi->df.dfAscent;
1193 ptm->tmDescent = ptm->tmHeight - ptm->tmAscent;
1194 ptm->tmInternalLeading = pfi->df.dfInternalLeading;
1195 ptm->tmMaxCharWidth = pfi->df.dfMaxWidth;
1196 ptm->tmDigitizedAspectX = pfi->df.dfHorizRes;
1197 ptm->tmDigitizedAspectY = pfi->df.dfVertRes;
1199 ptm->tmFirstChar = pfi->df.dfFirstChar;
1200 ptm->tmLastChar = pfi->df.dfLastChar;
1201 ptm->tmDefaultChar = pfi->df.dfDefaultChar;
1202 ptm->tmBreakChar = pfi->df.dfBreakChar;
1204 TRACE("Calling Enum proc with FaceName '%s' FullName '%s'\n",
1205 debugstr_w(pLF->elfLogFont.lfFaceName),
1206 debugstr_w(pLF->elfFullName));
1208 TRACE("CharSet = %d type = %d\n", ptm->tmCharSet, pfi->df.dfType);
1209 /* return font type */
1210 return pfi->df.dfType;
1215 /***********************************************************************
1220 * dfPitchAndFamily flags for some common typefaces.
1222 static BYTE XFONT_FixupFlags( LPCSTR lfFaceName )
1224 switch( lfFaceName[0] )
1227 case 'A': if(!strncasecmp(lfFaceName, "Arial", 5) )
1231 case 'H': if(!strcasecmp(lfFaceName, "Helvetica") )
1235 case 'C': if(!strncasecmp(lfFaceName, "Courier", 7))
1238 if (!strcasecmp(lfFaceName, "Charter") )
1242 case 'P': if( !strcasecmp(lfFaceName,"Palatino") )
1246 case 'T': if(!strncasecmp(lfFaceName, "Times", 5) )
1250 case 'U': if(!strcasecmp(lfFaceName, "Utopia") )
1254 case 'Z': if(!strcasecmp(lfFaceName, "Zapf Dingbats") )
1255 return FF_DECORATIVE;
1260 /***********************************************************************
1261 * XFONT_SameFoundryAndFamily
1265 static BOOL XFONT_SameFoundryAndFamily( const LFD* lfd1, const LFD* lfd2 )
1267 return ( !strcasecmp( lfd1->foundry, lfd2->foundry ) &&
1268 !strcasecmp( lfd1->family, lfd2->family ) );
1271 /***********************************************************************
1272 * XFONT_InitialCapitals
1276 * Upper case first letters of words & remove multiple spaces
1278 static void XFONT_InitialCapitals(LPSTR lpch)
1284 for( i = 0, up = TRUE; *lpch; lpch++, i++ )
1286 if( isspace(*lpch) )
1288 if (!up) /* Not already got one */
1294 else if( isalpha(*lpch) && up )
1296 *lpstr++ = toupper(*lpch);
1306 /* Remove possible trailing space */
1313 /***********************************************************************
1314 * XFONT_WindowsNames
1318 * Build generic Windows aliases for X font names.
1320 * -misc-fixed- -> "Fixed"
1321 * -sony-fixed- -> "Sony Fixed", etc...
1323 static void XFONT_WindowsNames(void)
1327 for( fr = fontList; fr ; fr = fr->next )
1332 if( fr->fr_flags & FR_NAMESET ) continue; /* skip already assigned */
1334 for( pfr = fontList; pfr != fr ; pfr = pfr->next )
1335 if( pfr->fr_flags & FR_NAMESET )
1337 if (!strcasecmp( pfr->resource->family, fr->resource->family))
1341 lpch = fr->lfFaceName;
1342 snprintf( fr->lfFaceName, sizeof(fr->lfFaceName), "%s %s",
1343 /* prepend vendor name */
1344 (pfr==fr) ? "" : fr->resource->foundry,
1345 fr->resource->family);
1346 XFONT_InitialCapitals(fr->lfFaceName);
1348 BYTE bFamilyStyle = XFONT_FixupFlags( fr->lfFaceName );
1352 for( fi = fr->fi ; fi ; fi = fi->next )
1353 fi->df.dfPitchAndFamily |= bFamilyStyle;
1357 TRACE("typeface '%s'\n", fr->lfFaceName);
1359 fr->fr_flags |= FR_NAMESET;
1363 /***********************************************************************
1364 * XFONT_LoadDefaultLFD
1366 * Move lfd to the head of fontList to make it more likely to be matched
1368 static void XFONT_LoadDefaultLFD(LFD* lfd, LPCSTR fonttype)
1371 fontResource *fr, *pfr;
1372 for( fr = NULL, pfr = fontList; pfr; pfr = pfr->next )
1374 if( XFONT_SameFoundryAndFamily(pfr->resource, lfd) )
1378 fr->next = pfr->next;
1379 pfr->next = fontList;
1387 WARN("Default %sfont '-%s-%s-' not available\n", fonttype,
1388 lfd->foundry, lfd->family);
1392 /***********************************************************************
1395 static void XFONT_LoadDefault(LPCSTR ini, LPCSTR fonttype)
1397 char buffer[MAX_LFD_LENGTH];
1399 if( PROFILE_GetWineIniString( INIFontSection, ini, "", buffer, sizeof buffer ) )
1405 while( *pch && isspace(*pch) ) pch++;
1407 TRACE("Using '%s' as default %sfont\n", pch, fonttype);
1408 lfd = LFD_Parse(pch);
1409 if (lfd && lfd->foundry && lfd->family)
1410 XFONT_LoadDefaultLFD(lfd, fonttype);
1412 WARN("Ini section [%s]%s is malformed\n", INIFontSection, ini);
1413 HeapFree(GetProcessHeap(), 0, lfd);
1418 /***********************************************************************
1419 * XFONT_LoadDefaults
1421 static void XFONT_LoadDefaults(void)
1423 XFONT_LoadDefault(INIDefaultFixed, "fixed ");
1424 XFONT_LoadDefault(INIDefault, "");
1427 /***********************************************************************
1430 static fontAlias* XFONT_CreateAlias( LPCSTR lpTypeFace, LPCSTR lpAlias )
1433 fontAlias *pfa, *prev = NULL;
1435 for(pfa = aliasTable; pfa; pfa = pfa->next)
1437 /* check if we already got one */
1438 if( !strcasecmp( pfa->faTypeFace, lpAlias ) )
1440 TRACE("redundant alias '%s' -> '%s'\n",
1441 lpAlias, lpTypeFace );
1447 j = strlen(lpTypeFace) + 1;
1448 pfa = HeapAlloc( GetProcessHeap(), 0, sizeof(fontAlias) +
1449 j + strlen(lpAlias) + 1 );
1458 pfa->faTypeFace = (LPSTR)(pfa + 1);
1459 strcpy( pfa->faTypeFace, lpTypeFace );
1460 pfa->faAlias = pfa->faTypeFace + j;
1461 strcpy( pfa->faAlias, lpAlias );
1463 TRACE("added alias '%s' for '%s'\n", lpAlias, lpTypeFace );
1471 /***********************************************************************
1474 static void XFONT_LoadAlias(const LFD* lfd, LPCSTR lpAlias, BOOL bSubst)
1476 fontResource *fr, *frMatch = NULL;
1477 if (!lfd->foundry || ! lfd->family)
1479 WARN("Malformed font resource for alias '%s'\n", lpAlias);
1482 for (fr = fontList; fr ; fr = fr->next)
1484 if(!strcasecmp(fr->resource->family, lpAlias))
1486 /* alias is not needed since the real font is present */
1487 TRACE("Ignoring font alias '%s' as it is already available as a real font\n", lpAlias);
1490 if( XFONT_SameFoundryAndFamily( fr->resource, lfd ) )
1501 fontAlias *pfa, *prev = NULL;
1503 for(pfa = aliasTable; pfa; pfa = pfa->next)
1505 /* Remove lpAlias from aliasTable - we should free the old entry */
1506 if(!strcmp(lpAlias, pfa->faAlias))
1509 prev->next = pfa->next;
1511 aliasTable = pfa->next;
1514 /* Update any references to the substituted font in aliasTable */
1515 if(!strcmp(frMatch->lfFaceName, pfa->faTypeFace))
1516 pfa->faTypeFace = HEAP_strdupA( GetProcessHeap(), 0, lpAlias );
1520 TRACE("\tsubstituted '%s' with '%s'\n", frMatch->lfFaceName, lpAlias );
1522 lstrcpynA( frMatch->lfFaceName, lpAlias, LF_FACESIZE );
1523 frMatch->fr_flags |= FR_NAMESET;
1527 /* create new entry in the alias table */
1528 XFONT_CreateAlias( frMatch->lfFaceName, lpAlias );
1533 WARN("Font alias '-%s-%s-' is not available\n", lfd->foundry, lfd->family);
1537 /***********************************************************************
1542 * Create font aliases for some standard windows fonts using user's
1543 * default choice of (sans-)serif fonts
1545 * Read user-defined aliases from wine.conf. Format is as follows
1547 * Alias# = [Windows font name],[LFD font name], <substitute original name>
1550 * Alias0 = Arial, -adobe-helvetica-
1551 * Alias1 = Times New Roman, -bitstream-courier-, 1
1554 * Note that from 970817 and on we have built-in alias templates that take
1555 * care of the necessary Windows typefaces.
1563 static void XFONT_LoadAliases(void)
1566 char buffer[MAX_LFD_LENGTH];
1570 /* built-ins first */
1571 PROFILE_GetWineIniString( INIFontSection, INIDefaultSerif,
1572 "-bitstream-charter-", buffer, sizeof buffer );
1573 TRACE("Using '%s' as default serif font\n", buffer);
1574 lfd = LFD_Parse(buffer);
1575 /* NB XFONT_InitialCapitals should not change these standard aliases */
1578 XFONT_LoadAlias( lfd, "Tms Roman", FALSE);
1579 XFONT_LoadAlias( lfd, "MS Serif", FALSE);
1580 XFONT_LoadAlias( lfd, "Times New Roman", FALSE);
1582 XFONT_LoadDefaultLFD( lfd, "serif ");
1583 HeapFree(GetProcessHeap(), 0, lfd);
1586 PROFILE_GetWineIniString( INIFontSection, INIDefaultSansSerif,
1587 "-adobe-helvetica-", buffer, sizeof buffer);
1588 TRACE("Using '%s' as default sans serif font\n", buffer);
1589 lfd = LFD_Parse(buffer);
1592 XFONT_LoadAlias( lfd, "Helv", FALSE);
1593 XFONT_LoadAlias( lfd, "MS Sans Serif", FALSE);
1594 XFONT_LoadAlias( lfd, "MS Shell Dlg", FALSE);
1595 XFONT_LoadAlias( lfd, "Arial", FALSE);
1597 XFONT_LoadDefaultLFD( lfd, "sans serif ");
1598 HeapFree(GetProcessHeap(), 0, lfd);
1601 /* then user specified aliases */
1604 BOOL bHaveAlias, bSubst;
1605 char subsection[32];
1606 snprintf( subsection, sizeof subsection, "%s%i", INIAliasSection, i++ );
1608 bHaveAlias = PROFILE_GetWineIniString( INIFontSection,
1609 subsection, "", buffer, sizeof buffer);
1613 XFONT_InitialCapitals(buffer);
1614 lpResource = PROFILE_GetStringItem( buffer );
1615 bSubst = (PROFILE_GetStringItem( lpResource )) ? TRUE : FALSE;
1616 if( lpResource && *lpResource )
1618 lfd = LFD_Parse(lpResource);
1621 XFONT_LoadAlias(lfd, buffer, bSubst);
1622 HeapFree(GetProcessHeap(), 0, lfd);
1626 WARN("malformed font alias '%s'\n", buffer );
1631 /***********************************************************************
1634 * Convert an (potential) alias into a real windows name
1637 static LPCSTR XFONT_UnAlias(char* font)
1642 XFONT_InitialCapitals(font); /* to remove extra white space */
1644 for( fa = aliasTable; fa; fa = fa->next )
1645 /* use case insensitive matching to handle eg "MS Sans Serif" */
1646 if( !strcasecmp( fa->faAlias, font ) )
1648 TRACE("found alias '%s'->%s'\n", font, fa->faTypeFace );
1649 strcpy(font, fa->faTypeFace);
1657 /***********************************************************************
1658 * XFONT_RemoveFontResource
1660 * Caller should check if the font resource is in use. If it is it should
1661 * set FR_REMOVED flag to delay removal until the resource is not in use
1664 void XFONT_RemoveFontResource( fontResource** ppfr )
1666 fontResource* pfr = *ppfr;
1670 /* FIXME - if fonts were read from a cache, these HeapFrees will fail */
1673 pfi = pfr->fi->next;
1674 HeapFree( GetProcessHeap(), 0, pfr->fi );
1677 HeapFree( GetProcessHeap(), 0, pfr );
1682 /***********************************************************************
1687 * Removes specified fonts from the font table to prevent Wine from
1690 * Ignore# = [LFD font name]
1693 * Ignore0 = -misc-nil-
1694 * Ignore1 = -sun-open look glyph-
1698 static void XFONT_LoadIgnore(char* lfdname)
1700 fontResource** ppfr;
1702 LFD* lfd = LFD_Parse(lfdname);
1703 if (lfd && lfd->foundry && lfd->family)
1705 for( ppfr = &fontList; *ppfr ; ppfr = &((*ppfr)->next))
1707 if( XFONT_SameFoundryAndFamily( (*ppfr)->resource, lfd) )
1709 TRACE("Ignoring '-%s-%s-'\n",
1710 (*ppfr)->resource->foundry, (*ppfr)->resource->family );
1712 XFONT_RemoveFontResource( ppfr );
1718 WARN("Malformed font resource\n");
1720 HeapFree(GetProcessHeap(), 0, lfd);
1723 static void XFONT_LoadIgnores(void)
1726 char subsection[32];
1727 char buffer[MAX_LFD_LENGTH];
1729 /* Standard one that noone wants */
1730 strcpy(buffer, "-misc-nil-");
1731 XFONT_LoadIgnore(buffer);
1733 /* Others from INI file */
1736 sprintf( subsection, "%s%i", INIIgnoreSection, i++ );
1738 if( PROFILE_GetWineIniString( INIFontSection,
1739 subsection, "", buffer, sizeof buffer) )
1742 while( *pch && isspace(*pch) ) pch++;
1743 XFONT_LoadIgnore(pch);
1751 /***********************************************************************
1752 * XFONT_UserMetricsCache
1754 * Returns expanded name for the cachedmetrics file.
1755 * Now it also appends the current value of the $DISPLAY variable.
1757 static char* XFONT_UserMetricsCache( char* buffer, int* buf_size )
1759 const char *confdir = get_config_dir();
1760 const char *display_name = XDisplayName(NULL);
1761 int len = strlen(confdir) + strlen(INIFontMetrics) + strlen(display_name) + 2;
1763 if ((len > *buf_size) &&
1764 !(buffer = HeapReAlloc( GetProcessHeap(), 0, buffer, *buf_size = len )))
1766 ERR("out of memory\n");
1770 sprintf( buffer, "%s/%s%s", confdir, INIFontMetrics, display_name );
1775 /***********************************************************************
1778 * Compare two fonts (only parameters set by the XFONT_InitFontInfo()).
1780 static INT XFONT_IsSubset(const fontInfo* match, const fontInfo* fi)
1784 /* 0 - keep both, 1 - keep match, -1 - keep fi */
1786 /* Compare dfItalic, Underline, Strikeout, Weight, Charset */
1787 m = (BYTE*)&fi->df.dfPixWidth - (BYTE*)&fi->df.dfItalic;
1788 if( memcmp(&match->df.dfItalic, &fi->df.dfItalic, m )) return 0;
1790 if( (!((fi->fi_flags & FI_SCALABLE) + (match->fi_flags & FI_SCALABLE))
1791 && fi->lfd_height != match->lfd_height) ||
1792 (!((fi->fi_flags & FI_POLYWEIGHT) + (match->fi_flags & FI_POLYWEIGHT))
1793 && fi->df.dfWeight != match->df.dfWeight) ) return 0;
1795 m = (int)(match->fi_flags & (FI_POLYWEIGHT | FI_SCALABLE)) -
1796 (int)(fi->fi_flags & (FI_SCALABLE | FI_POLYWEIGHT));
1798 if( m == (FI_POLYWEIGHT - FI_SCALABLE) ||
1799 m == (FI_SCALABLE - FI_POLYWEIGHT) ) return 0; /* keep both */
1800 else if( m >= 0 ) return 1; /* 'match' is better */
1802 return -1; /* 'fi' is better */
1805 /***********************************************************************
1808 * REMOVE_SUBSETS - attach new fi and purge subsets
1809 * UNMARK_SUBSETS - remove subset flags from all fi entries
1811 static void XFONT_CheckFIList( fontResource* fr, fontInfo* fi, int action)
1814 fontInfo* pfi, *prev;
1816 for( prev = NULL, pfi = fr->fi; pfi; )
1818 if( action == REMOVE_SUBSETS )
1820 if( pfi->fi_flags & FI_SUBSET )
1822 fontInfo* subset = pfi;
1826 if( prev ) prev->next = pfi = pfi->next;
1827 else fr->fi = pfi = pfi->next;
1828 HeapFree( GetProcessHeap(), 0, subset );
1832 else pfi->fi_flags &= ~FI_SUBSET;
1838 if( action == REMOVE_SUBSETS ) /* also add the superset */
1840 if( fi->fi_flags & FI_SCALABLE )
1845 else if( prev ) prev->next = fi; else fr->fi = fi;
1849 if( i ) TRACE("\t purged %i subsets [%i]\n", i , fr->fi_count);
1852 /***********************************************************************
1855 static fontResource* XFONT_FindFIList( fontResource* pfr, const char* pTypeFace )
1859 if( !strcasecmp( pfr->lfFaceName, pTypeFace ) ) break;
1862 /* Give the app back the font name it asked for. Encarta checks this. */
1863 if (pfr) strcpy(pfr->lfFaceName,pTypeFace);
1867 /***********************************************************************
1868 * XFONT_FixupPointSize
1870 static void XFONT_FixupPointSize(fontInfo* fi)
1873 df.dfHorizRes = df.dfVertRes = fi->lfd_resolution;
1874 df.dfPoints = (INT16)
1875 (((INT)(df.dfPixHeight - df.dfInternalLeading) * 72 + (df.dfVertRes >> 1)) /
1880 /***********************************************************************
1881 * XFONT_BuildMetrics
1883 * Build font metrics from X font
1885 static int XFONT_BuildMetrics(char** x_pattern, int res, unsigned x_checksum, int x_count)
1888 fontInfo* fi = NULL;
1889 fontResource* fr, *pfr;
1892 MESSAGE("Building font metrics. This may take some time...\n");
1893 for( i = 0; i < x_count; i++ )
1898 char buffer[MAX_LFD_LENGTH];
1903 typeface = HEAP_strdupA(GetProcessHeap(), 0, x_pattern[i]);
1907 lfd = LFD_Parse(typeface);
1910 HeapFree(GetProcessHeap(), 0, typeface);
1914 /* find a family to insert into */
1916 for( pfr = NULL, fr = fontList; fr; fr = fr->next )
1918 if( XFONT_SameFoundryAndFamily(fr->resource, lfd))
1923 if( !fi ) fi = (fontInfo*) HeapAlloc(GetProcessHeap(), 0, sizeof(fontInfo));
1925 if( !LFD_InitFontInfo( fi, lfd, x_pattern[i]) )
1928 if( !fr ) /* add new family */
1931 fr = (fontResource*) HeapAlloc(GetProcessHeap(), 0, sizeof(fontResource));
1934 memset(fr, 0, sizeof(fontResource));
1936 fr->resource = (LFD*) HeapAlloc(GetProcessHeap(), 0, sizeof(LFD));
1937 memset(fr->resource, 0, sizeof(LFD));
1939 TRACE("family: -%s-%s-\n", lfd->foundry, lfd->family );
1940 fr->resource->foundry = HEAP_strdupA(GetProcessHeap(), 0, lfd->foundry);
1941 fr->resource->family = HEAP_strdupA(GetProcessHeap(), 0, lfd->family);
1942 fr->resource->weight = "";
1944 if( pfr ) pfr->next = fr;
1948 WARN("Not enough memory for a new font family\n");
1951 /* check if we already have something better than "fi" */
1953 for( pfi = fr->fi, j = 0; pfi && j <= 0; pfi = pfi->next )
1954 if( (j = XFONT_IsSubset( pfi, fi )) < 0 )
1955 pfi->fi_flags |= FI_SUBSET; /* superseded by "fi" */
1956 if( j > 0 ) goto nextfont;
1958 /* add new font instance "fi" to the "fr" font resource */
1960 if( fi->fi_flags & FI_SCALABLE )
1963 char pxl_string[4], res_string[4];
1964 /* set scalable font height to get an basis for extrapolation */
1966 fi->lfd_height = DEF_SCALABLE_HEIGHT;
1967 fi->lfd_resolution = res;
1969 sprintf(pxl_string, "%d", fi->lfd_height);
1970 sprintf(res_string, "%d", fi->lfd_resolution);
1973 lfd1.pixel_size = pxl_string;
1974 lfd1.point_size = "*";
1975 lfd1.resolution_x = res_string;
1976 lfd1.resolution_y = res_string;
1978 LFD_UnParse(buffer, sizeof buffer, &lfd1);
1982 else lpstr = x_pattern[i];
1984 if( (x_fs = TSXLoadQueryFont(gdi_display, lpstr)) )
1986 XFONT_SetFontMetric( fi, fr, x_fs );
1987 TSXFreeFont( gdi_display, x_fs );
1989 XFONT_FixupPointSize(fi);
1991 TRACE("\t[% 2ipt] '%s'\n", fi->df.dfPoints, x_pattern[i] );
1993 XFONT_CheckFIList( fr, fi, REMOVE_SUBSETS );
1994 fi = NULL; /* preventing reuse */
1998 ERR("failed to load %s\n", lpstr );
2000 XFONT_CheckFIList( fr, fi, UNMARK_SUBSETS );
2003 HeapFree(GetProcessHeap(), 0, lfd);
2004 HeapFree(GetProcessHeap(), 0, typeface);
2006 if( fi ) HeapFree(GetProcessHeap(), 0, fi);
2008 /* Scan through the font list and remove FontResorce(s) (fr)
2009 * that have no associated Fontinfo(s) (fi).
2010 * This code is necessary because XFONT_ReadCachedMetrics
2011 * assumes that there is at least one fi associated with a fr.
2012 * This assumption is invalid for TT font
2013 * -altsys-ms outlook-medium-r-normal--0-0-0-0-p-0-microsoft-symbol.
2018 while (!fr->fi_count)
2020 fontList = fr->next;
2022 HeapFree(GetProcessHeap(), 0, fr->resource);
2023 HeapFree(GetProcessHeap(), 0, fr);
2033 if (!fr->next->fi_count)
2036 fr->next = fr->next->next;
2038 HeapFree(GetProcessHeap(), 0, pfr->resource);
2039 HeapFree(GetProcessHeap(), 0, pfr);
2050 /***********************************************************************
2051 * XFONT_ReadCachedMetrics
2055 static BOOL XFONT_ReadCachedMetrics( int fd, int res, unsigned x_checksum, int x_count )
2062 /* read checksums */
2063 read( fd, &u, sizeof(unsigned) );
2064 read( fd, &i, sizeof(int) );
2066 if( u == x_checksum && i == x_count )
2068 off_t length, offset = 3 * sizeof(int);
2070 /* read total size */
2071 read( fd, &i, sizeof(int) );
2072 length = lseek( fd, 0, SEEK_END );
2074 if( length == (i + offset) )
2076 lseek( fd, offset, SEEK_SET );
2077 fontList = (fontResource*)HeapAlloc( GetProcessHeap(), 0, i);
2080 fontResource* pfr = fontList;
2081 fontInfo* pfi = NULL;
2083 TRACE("Reading cached font metrics:\n");
2085 read( fd, fontList, i); /* read all metrics at once */
2086 while( offset < length )
2088 offset += sizeof(fontResource) + sizeof(fontInfo);
2089 pfr->fi = pfi = (fontInfo*)(pfr + 1);
2093 if( offset > length ||
2094 pfi->cptable >= (UINT16)X11DRV_CPTABLE_COUNT ||
2095 (int)(pfi->next) != j++ ) goto fail;
2097 if( pfi->df.dfPixHeight == 0 ) goto fail;
2099 pfi->df.dfFace = pfr->lfFaceName;
2100 if( pfi->fi_flags & FI_SCALABLE )
2102 /* we can pretend we got this font for any resolution */
2103 pfi->lfd_resolution = res;
2104 XFONT_FixupPointSize(pfi);
2106 pfi->next = pfi + 1;
2108 if( j > pfr->fi_count ) break;
2111 offset += sizeof(fontInfo);
2116 pfr->next = (fontResource*)(pfi + 1);
2121 if( pfr->next == NULL &&
2122 *(int*)(pfi + 1) == X_FMC_MAGIC )
2124 /* read LFD stubs */
2125 char* lpch = (char*)((int*)(pfi + 1) + 1);
2126 offset += sizeof(int);
2127 for( pfr = fontList; pfr; pfr = pfr->next )
2129 size_t len = strlen(lpch) + 1;
2130 TRACE("\t%s, %i instances\n", lpch, pfr->fi_count );
2131 pfr->resource = LFD_Parse(lpch);
2134 if (offset > length)
2144 if( fontList ) HeapFree( GetProcessHeap(), 0, fontList );
2151 /***********************************************************************
2152 * XFONT_WriteCachedMetrics
2156 static BOOL XFONT_WriteCachedMetrics( int fd, unsigned x_checksum, int x_count, int n_ff )
2164 char buffer[MAX_LFD_LENGTH];
2166 /* font metrics file:
2170 * +0008 total size to load
2171 * +000C prepackaged font metrics
2174 * +...x + 4 LFD stubs
2177 write( fd, &x_checksum, sizeof(unsigned) );
2178 write( fd, &x_count, sizeof(int) );
2180 for( j = i = 0, pfr = fontList; pfr; pfr = pfr->next )
2182 LFD_UnParse(buffer, sizeof buffer, pfr->resource);
2183 i += strlen( buffer) + 1;
2186 i += n_ff * sizeof(fontResource) + j * sizeof(fontInfo) + sizeof(int);
2187 write( fd, &i, sizeof(int) );
2189 TRACE("Writing font cache:\n");
2191 for( pfr = fontList; pfr; pfr = pfr->next )
2195 TRACE("\t-%s-%s-, %i instances\n", pfr->resource->foundry, pfr->resource->family, pfr->fi_count );
2197 i = write( fd, pfr, sizeof(fontResource) );
2198 if( i == sizeof(fontResource) )
2200 for( k = 1, pfi = pfr->fi; pfi; pfi = pfi->next )
2204 fi.df.dfFace = NULL;
2205 fi.next = (fontInfo*)k; /* loader checks this */
2207 j = write( fd, &fi, sizeof(fi) );
2210 if( j == sizeof(fontInfo) ) continue;
2214 if( i == sizeof(fontResource) && j == sizeof(fontInfo) )
2216 i = j = X_FMC_MAGIC;
2217 write( fd, &i, sizeof(int) );
2218 for( pfr = fontList; pfr && i == j; pfr = pfr->next )
2220 LFD_UnParse(buffer, sizeof buffer, pfr->resource);
2221 i = strlen( buffer ) + 1;
2222 j = write( fd, buffer, i );
2231 /***********************************************************************
2232 * XFONT_GetPointResolution()
2236 * Here we initialize DefResolution which is used in the
2237 * XFONT_Match() penalty function. We also load the point
2238 * resolution value (higher values result in larger fonts).
2240 static int XFONT_GetPointResolution( DeviceCaps* pDevCaps )
2242 int i, j, point_resolution, num = 3;
2243 int allowed_xfont_resolutions[3] = { 72, 75, 100 };
2244 int best = 0, best_diff = 65536;
2246 point_resolution = PROFILE_GetWineIniInt( INIFontSection, INIResolution, 0 );
2247 if( !point_resolution )
2248 point_resolution = pDevCaps->logPixelsY;
2250 pDevCaps->logPixelsX = pDevCaps->logPixelsY = point_resolution;
2253 /* FIXME We can only really guess at a best DefResolution
2254 * - this should be configurable
2256 for( i = best = 0; i < num; i++ )
2258 j = abs( point_resolution - allowed_xfont_resolutions[i] );
2265 DefResolution = allowed_xfont_resolutions[best];
2267 /* FIXME - do win95,nt40,... do this as well ? */
2268 if (TWEAK_WineLook == WIN98_LOOK)
2270 /* Lie about the screen size, so that eg MM_LOMETRIC becomes MM_logical_LOMETRIC */
2272 denom = pDevCaps->logPixelsX * 10;
2273 pDevCaps->horzSize = (pDevCaps->horzRes * 254 + (denom>>1)) / denom;
2274 denom = pDevCaps->logPixelsY * 10;
2275 pDevCaps->vertSize = (pDevCaps->vertRes * 254 + (denom>>1)) / denom;
2278 return point_resolution;
2282 /***********************************************************************
2285 * Compute the matching score between the logical font and the device font.
2287 * contributions from highest to lowest:
2291 * family flags (only when the facename is not present)
2293 * weight, italics, underlines, strikeouts
2295 * NOTE: you can experiment with different penalty weights to see what happens.
2296 * http://premium.microsoft.com/msdn/library/techart/f365/f36b/f37b/d38b/sa8bf.htm
2298 static UINT XFONT_Match( fontMatch* pfm )
2300 fontInfo* pfi = pfm->pfi; /* device font to match */
2301 LPLOGFONT16 plf = pfm->plf; /* wanted logical font */
2303 BOOL bR6 = pfm->flags & FO_MATCH_XYINDEP; /* from TextCaps */
2304 BOOL bScale = pfi->fi_flags & FI_SCALABLE;
2307 TRACE("\t[ %-2ipt h=%-3i w=%-3i %s%s]\n", pfi->df.dfPoints,
2308 pfi->df.dfPixHeight, pfi->df.dfAvgWidth,
2309 (pfi->df.dfWeight > FW_NORMAL) ? "Bold " : "Normal ",
2310 (pfi->df.dfItalic) ? "Italic" : "" );
2312 pfm->flags &= FO_MATCH_MASK;
2315 /* pfm->internal_charset: given(required) charset */
2316 /* pfi->internal_charset: charset of this font */
2317 if (pfi->internal_charset == DEFAULT_CHARSET)
2319 /* special case(unicode font) */
2320 /* priority: unmatched charset < unicode < matched charset */
2325 if( pfm->internal_charset == DEFAULT_CHARSET )
2328 if (pfi->internal_charset != ANSI_CHARSET)
2331 if ( pfi->codepage != GetACP() )
2334 else if (pfm->internal_charset != pfi->internal_charset)
2336 if ( pfi->internal_charset & 0xff00 )
2337 penalty += 0x1000; /* internal charset - should not be used */
2346 if( plf->lfHeight > 0 )
2348 int h = pfi->df.dfPixHeight;
2349 d = h - plf->lfHeight;
2350 height = plf->lfHeight;
2354 int h = pfi->df.dfPixHeight - pfi->df.dfInternalLeading;
2357 d = h + plf->lfHeight;
2358 height = (-plf->lfHeight * pfi->df.dfPixHeight) / h;
2362 ERR("PixHeight == InternalLeading\n");
2363 penalty += 0x1000; /* dont want this */
2369 pfm->height = 1; /* Very small */
2373 pfm->height = height;
2374 else if( (plf->lfQuality != PROOF_QUALITY) && bR6 )
2376 if( d > 0 ) /* do not shrink raster fonts */
2378 pfm->height = pfi->df.dfPixHeight;
2379 penalty += (pfi->df.dfPixHeight - height) * 0x4;
2381 else /* expand only in integer multiples */
2383 pfm->height = height - height%pfi->df.dfPixHeight;
2384 penalty += (height - pfm->height + 1) * height / pfi->df.dfPixHeight;
2387 else /* can't be scaled at all */
2389 if( plf->lfQuality != PROOF_QUALITY) pfm->flags |= FO_SYNTH_HEIGHT;
2390 pfm->height = pfi->df.dfPixHeight;
2391 penalty += (d > 0)? d * 0x8 : -d * 0x10;
2395 pfm->height = pfi->df.dfPixHeight;
2397 /* Pitch and Family */
2398 if( pfm->flags & FO_MATCH_PAF ) {
2399 int family = plf->lfPitchAndFamily & FF_FAMILY;
2401 /* TMPF_FIXED_PITCH means exactly the opposite */
2402 if( plf->lfPitchAndFamily & FIXED_PITCH ) {
2403 if( pfi->df.dfPitchAndFamily & TMPF_FIXED_PITCH ) penalty += 0x100;
2404 } else /* Variable is the default */
2405 if( !(pfi->df.dfPitchAndFamily & TMPF_FIXED_PITCH) ) penalty += 0x2;
2407 if (family != FF_DONTCARE && family != (pfi->df.dfPitchAndFamily & FF_FAMILY) )
2415 if( bR6 || bScale ) h = 0;
2418 /* FIXME: not complete */
2420 pfm->flags |= FO_SYNTH_WIDTH;
2421 h = abs(plf->lfWidth - (pfm->height * pfi->df.dfAvgWidth)/pfi->df.dfPixHeight);
2423 penalty += h * ( d ) ? 0x2 : 0x1 ;
2425 else if( !(pfi->fi_flags & FI_NORMAL) ) penalty++;
2428 if( plf->lfWeight != FW_DONTCARE )
2430 penalty += abs(plf->lfWeight - pfi->df.dfWeight) / 40;
2431 if( plf->lfWeight > pfi->df.dfWeight ) pfm->flags |= FO_SYNTH_BOLD;
2432 } else if( pfi->df.dfWeight >= FW_BOLD ) penalty++; /* choose normal by default */
2435 if( plf->lfItalic != pfi->df.dfItalic )
2438 pfm->flags |= FO_SYNTH_ITALIC;
2441 if( plf->lfUnderline ) pfm->flags |= FO_SYNTH_UNDERLINE;
2444 if( plf->lfStrikeOut ) pfm->flags |= FO_SYNTH_STRIKEOUT;
2447 if( penalty && !bScale && pfi->lfd_resolution != DefResolution )
2450 TRACE(" returning %i\n", penalty );
2455 /***********************************************************************
2458 * Scan a particular font resource for the best match.
2460 static UINT XFONT_MatchFIList( fontMatch* pfm )
2462 BOOL skipRaster = (pfm->flags & FO_MATCH_NORASTER);
2463 UINT current_score, score = (UINT)(-1);
2464 fontMatch fm = *pfm;
2466 for( fm.pfi = pfm->pfr->fi; fm.pfi && score; fm.pfi = fm.pfi->next)
2468 if( skipRaster && !(fm.pfi->fi_flags & FI_SCALABLE) )
2471 current_score = XFONT_Match( &fm );
2472 if( score > current_score )
2475 score = current_score;
2481 /***********************************************************************
2482 * XFONT_MatchDeviceFont
2484 * Scan font resource tree.
2487 static void XFONT_MatchDeviceFont( fontResource* start, fontMatch* pfm)
2489 fontMatch fm = *pfm;
2490 UINT current_score, score = (UINT)(-1);
2491 fontResource** ppfr;
2493 TRACE("(%u) '%s' h=%i weight=%i %s\n",
2494 pfm->plf->lfCharSet, pfm->plf->lfFaceName, pfm->plf->lfHeight,
2495 pfm->plf->lfWeight, (pfm->plf->lfItalic) ? "Italic" : "" );
2498 if( fm.plf->lfFaceName[0] )
2500 fm.pfr = XFONT_FindFIList( start, fm.plf->lfFaceName);
2501 if( fm.pfr ) /* match family */
2503 TRACE("found facename '%s'\n", fm.pfr->lfFaceName );
2505 if( fm.pfr->fr_flags & FR_REMOVED )
2509 XFONT_MatchFIList( &fm );
2516 /* get charset if lfFaceName is one of known facenames. */
2518 const struct CharsetBindingInfo* pcharsetbindings;
2520 pcharsetbindings = &charsetbindings[0];
2521 while ( pcharsetbindings->pszFaceName != NULL )
2523 if ( !strcmp( pcharsetbindings->pszFaceName,
2524 fm.plf->lfFaceName ) )
2526 fm.internal_charset = pcharsetbindings->charset;
2529 pcharsetbindings ++;
2531 TRACE( "%s charset %u\n", fm.plf->lfFaceName, fm.internal_charset );
2535 /* match all available fonts */
2537 fm.flags |= FO_MATCH_PAF;
2538 for( ppfr = &fontList; *ppfr && score; ppfr = &(*ppfr)->next )
2540 if( (*ppfr)->fr_flags & FR_REMOVED )
2542 if( (*ppfr)->fo_count == 0 )
2543 XFONT_RemoveFontResource( ppfr );
2549 TRACE("%s\n", fm.pfr->lfFaceName );
2551 current_score = XFONT_MatchFIList( &fm );
2552 if( current_score < score )
2554 score = current_score;
2561 /***********************************************************************
2564 static void XFONT_GrowFreeList(int start, int end)
2566 /* add all entries from 'start' up to and including 'end' */
2568 memset( fontCache + start, 0, (end - start + 1) * sizeof(fontObject) );
2570 fontCache[end].lru = fontLF;
2571 fontCache[end].count = -1;
2573 while( start < end )
2575 fontCache[start].count = -1;
2576 fontCache[start].lru = start + 1;
2581 static fontObject* XFONT_LookupCachedFont( const LPLOGFONT16 plf, UINT16* checksum )
2583 UINT16 cs = __lfCheckSum( plf );
2584 int i = fontMRU, prev = -1;
2589 if( fontCache[i].lfchecksum == cs &&
2590 !(fontCache[i].fo_flags & FO_REMOVED) )
2592 /* FIXME: something more intelligent here ? */
2594 if( !memcmp( plf, &fontCache[i].lf,
2595 sizeof(LOGFONT16) - LF_FACESIZE ) &&
2596 !strcmp( plf->lfFaceName, fontCache[i].lf.lfFaceName) )
2598 /* remove temporarily from the lru list */
2600 fontCache[prev].lru = fontCache[i].lru;
2602 fontMRU = (INT16)fontCache[i].lru;
2603 return (fontCache + i);
2607 i = (INT16)fontCache[i].lru;
2612 static fontObject* XFONT_GetCacheEntry(void)
2618 int prev_i, prev_j, j;
2620 TRACE("font cache is full\n");
2622 /* lookup the least recently used font */
2624 for( prev_i = prev_j = j = -1, i = fontMRU; i >= 0; i = (INT16)fontCache[i].lru )
2626 if( fontCache[i].count <= 0 &&
2627 !(fontCache[i].fo_flags & FO_SYSTEM) )
2635 if( j >= 0 ) /* unload font */
2637 /* detach from the lru list */
2639 TRACE("\tfreeing entry %i\n", j );
2641 fontCache[j].fr->fo_count--;
2644 fontCache[prev_j].lru = fontCache[j].lru;
2645 else fontMRU = (INT16)fontCache[j].lru;
2647 /* FIXME: lpXForm, lpPixmap */
2648 if(fontCache[j].lpX11Trans)
2649 HeapFree( GetProcessHeap(), 0, fontCache[j].lpX11Trans );
2651 TSXFreeFont( gdi_display, fontCache[j].fs );
2653 memset( fontCache + j, 0, sizeof(fontObject) );
2654 return (fontCache + j);
2656 else /* expand cache */
2658 fontObject* newCache;
2660 prev_i = fontCacheSize + FONTCACHE;
2662 TRACE("\tgrowing font cache from %i to %i\n", fontCacheSize, prev_i );
2664 if( (newCache = (fontObject*)HeapReAlloc(GetProcessHeap(), 0,
2665 fontCache, prev_i)) )
2668 fontCacheSize = prev_i;
2669 fontCache = newCache;
2670 XFONT_GrowFreeList( i, fontCacheSize - 1);
2676 /* detach from the free list */
2679 fontLF = (INT16)fontCache[i].lru;
2680 fontCache[i].count = 0;
2681 return (fontCache + i);
2684 static int XFONT_ReleaseCacheEntry(const fontObject* pfo)
2686 UINT u = (UINT)(pfo - fontCache);
2690 if( u < fontCacheSize )
2692 ret = --fontCache[u].count;
2695 for ( i = 0; i < X11FONT_REFOBJS_MAX; i++ )
2697 if( CHECK_PFONT(pfo->prefobjs[i]) )
2698 XFONT_ReleaseCacheEntry(__PFONT(pfo->prefobjs[i]));
2708 /***********************************************************************
2711 * Initialize font resource list and allocate font cache.
2713 BOOL X11DRV_FONT_Init( DeviceCaps* pDevCaps )
2716 unsigned x_checksum;
2717 int i,res, x_count, fd, buf_size;
2720 res = XFONT_GetPointResolution( pDevCaps );
2722 x_pattern = TSXListFonts(gdi_display, "*", MAX_FONTS, &x_count );
2724 TRACE("Font Mapper: initializing %i fonts [logical dpi=%i, default dpi=%i]\n",
2725 x_count, res, DefResolution);
2726 if (x_count == MAX_FONTS)
2727 MESSAGE("There may be more fonts available - try increasing the value of MAX_FONTS\n");
2729 for( i = x_checksum = 0; i < x_count; i++ )
2733 printf("%i\t: %s\n", i, x_pattern[i] );
2736 j = strlen( x_pattern[i] );
2737 if( j ) x_checksum ^= __genericCheckSum( x_pattern[i], j );
2739 x_checksum |= X_PFONT_MAGIC;
2741 buffer = HeapAlloc( GetProcessHeap(), 0, buf_size );
2743 /* deal with systemwide font metrics cache */
2745 if( PROFILE_GetWineIniString( INIFontSection, INIGlobalMetrics, "", buffer, buf_size ) )
2747 fd = open( buffer, O_RDONLY );
2748 XFONT_ReadCachedMetrics(fd, DefResolution, x_checksum, x_count);
2750 if (fontList == NULL)
2753 buffer = XFONT_UserMetricsCache( buffer, &buf_size );
2756 fd = open( buffer, O_RDONLY );
2757 XFONT_ReadCachedMetrics(fd, DefResolution, x_checksum, x_count);
2761 if( fontList == NULL ) /* build metrics from scratch */
2763 int n_ff = XFONT_BuildMetrics(x_pattern, DefResolution, x_checksum, x_count);
2764 if( buffer[0] ) /* update cached metrics */
2766 fd = open( buffer, O_CREAT | O_TRUNC | O_RDWR, 0644 ); /* -rw-r--r-- */
2767 if( XFONT_WriteCachedMetrics( fd, x_checksum, x_count, n_ff ) == FALSE )
2769 WARN("Unable to write to fontcache '%s'\n", buffer);
2770 if( fd >= 0) remove( buffer ); /* couldn't write entire file */
2775 TSXFreeFontNames(x_pattern);
2777 /* check if we're dealing with X11 R6 server */
2780 strcpy(buffer, "-*-*-*-*-normal-*-[12 0 0 12]-*-72-*-*-*-iso8859-1");
2781 if( (x_fs = TSXLoadQueryFont(gdi_display, buffer)) )
2783 XTextCaps |= TC_SF_X_YINDEP;
2784 TSXFreeFont(gdi_display, x_fs);
2787 HeapFree(GetProcessHeap(), 0, buffer);
2789 XFONT_WindowsNames();
2790 XFONT_LoadAliases();
2791 XFONT_LoadDefaults();
2792 XFONT_LoadIgnores();
2794 /* fontList initialization is over, allocate X font cache */
2796 fontCache = (fontObject*) HeapAlloc(GetProcessHeap(), 0, fontCacheSize * sizeof(fontObject));
2797 XFONT_GrowFreeList(0, fontCacheSize - 1);
2801 /* update text caps parameter */
2803 pDevCaps->textCaps = XTextCaps;
2805 RAW_ASCENT = TSXInternAtom(gdi_display, "RAW_ASCENT", TRUE);
2806 RAW_DESCENT = TSXInternAtom(gdi_display, "RAW_DESCENT", TRUE);
2811 /**********************************************************************
2814 static BOOL XFONT_SetX11Trans( fontObject *pfo )
2820 TSXGetFontProperty( pfo->fs, XA_FONT, &nameAtom );
2821 fontName = TSXGetAtomName( gdi_display, nameAtom );
2822 lfd = LFD_Parse(fontName);
2829 if (lfd->pixel_size[0] != '[') {
2830 HeapFree(GetProcessHeap(), 0, lfd);
2835 #define PX pfo->lpX11Trans
2837 sscanf(lfd->pixel_size, "[%f%f%f%f]", &PX->a, &PX->b, &PX->c, &PX->d);
2839 HeapFree(GetProcessHeap(), 0, lfd);
2841 TSXGetFontProperty( pfo->fs, RAW_ASCENT, &PX->RAW_ASCENT );
2842 TSXGetFontProperty( pfo->fs, RAW_DESCENT, &PX->RAW_DESCENT );
2844 PX->pixelsize = hypot(PX->a, PX->b);
2845 PX->ascent = PX->pixelsize / 1000.0 * PX->RAW_ASCENT;
2846 PX->descent = PX->pixelsize / 1000.0 * PX->RAW_DESCENT;
2848 TRACE("[%f %f %f %f] RA = %ld RD = %ld\n",
2849 PX->a, PX->b, PX->c, PX->d,
2850 PX->RAW_ASCENT, PX->RAW_DESCENT);
2856 /***********************************************************************
2857 * X Device Font Objects
2859 static X_PHYSFONT XFONT_RealizeFont( const LPLOGFONT16 plf,
2860 LPCSTR* faceMatched, BOOL bSubFont,
2861 WORD internal_charset,
2862 WORD* pcharsetMatched )
2868 pfo = XFONT_LookupCachedFont( plf, &checksum );
2879 fm.internal_charset = internal_charset;
2881 if( XTextCaps & TC_SF_X_YINDEP ) fm.flags = FO_MATCH_XYINDEP;
2883 /* allocate new font cache entry */
2885 if( (pfo = XFONT_GetCacheEntry()) )
2887 /* initialize entry and load font */
2888 char lpLFD[MAX_LFD_LENGTH];
2889 UINT uRelaxLevel = 0;
2891 if(abs(plf->lfHeight) > MAX_FONT_SIZE) {
2893 "plf->lfHeight = %d, Creating a 100 pixel font and rescaling metrics \n",
2895 pfo->rescale = fabs(plf->lfHeight / 100.0);
2896 if(plf->lfHeight > 0) plf->lfHeight = 100;
2897 else plf->lfHeight = -100;
2901 XFONT_MatchDeviceFont( fontList, &fm );
2904 pfo->fr->fo_count++;
2905 pfo->fo_flags = fm.flags & ~FO_MATCH_MASK;
2908 pfo->lfchecksum = checksum;
2912 LFD_ComposeLFD( pfo, fm.height, lpLFD, uRelaxLevel++ );
2913 if( (pfo->fs = TSXLoadQueryFont( gdi_display, lpLFD )) ) break;
2914 } while( uRelaxLevel );
2917 if(pfo->lf.lfEscapement != 0) {
2918 pfo->lpX11Trans = HeapAlloc(GetProcessHeap(), 0, sizeof(XFONTTRANS));
2919 if(!XFONT_SetX11Trans( pfo )) {
2920 HeapFree(GetProcessHeap(), 0, pfo->lpX11Trans);
2921 pfo->lpX11Trans = NULL;
2924 XFONT_GetLeading( &pfo->fi->df, pfo->fs,
2925 &pfo->foInternalLeading, NULL, pfo->lpX11Trans );
2926 pfo->foAvgCharWidth = (INT16)XFONT_GetAvgCharWidth(&pfo->fi->df, pfo->fs, pfo->lpX11Trans );
2927 pfo->foMaxCharWidth = (INT16)XFONT_GetMaxCharWidth(pfo->fs, pfo->lpX11Trans);
2929 /* FIXME: If we've got a soft font or
2930 * there are FO_SYNTH_... flags for the
2931 * non PROOF_QUALITY request, the engine
2932 * should rasterize characters into mono
2933 * pixmaps and store them in the pfo->lpPixmap
2934 * array (pfo->fs should be updated as well).
2935 * array (pfo->fs should be updated as well).
2936 * X11DRV_ExtTextOut() must be heavily modified
2937 * to support pixmap blitting and FO_SYNTH_...
2941 pfo->lpPixmap = NULL;
2943 for ( i = 0; i < X11FONT_REFOBJS_MAX; i++ )
2944 pfo->prefobjs[i] = (X_PHYSFONT)0xffffffff; /* invalid value */
2946 /* special treatment for DBCS that needs multiple fonts */
2947 /* All member of pfo must be set correctly. */
2948 if ( bSubFont == FALSE )
2951 WORD charsetMatchedSub;
2953 LPCSTR faceMatchedSub;
2955 for ( i = 0; i < X11FONT_REFOBJS_MAX; i++ )
2957 charset_sub = X11DRV_cptable[pfo->fi->cptable].
2958 penum_subfont_charset( i );
2959 if ( charset_sub == DEFAULT_CHARSET ) break;
2963 lfSub.lfHeight = pfo->fi->df.dfPixHeight;
2964 if ( plf->lfHeight < 0 )
2965 lfSub.lfHeight = - lfSub.lfHeight;
2966 lfSub.lfCharSet = (BYTE)(charset_sub & 0xff);
2967 lfSub.lfFaceName[0] = '\0'; /* FIXME? */
2968 /* this font has sub font */
2969 if ( i == 0 ) pfo->prefobjs[0] = (X_PHYSFONT)0;
2971 XFONT_RealizeFont( &lfSub, &faceMatchedSub,
2973 &charsetMatchedSub );
2974 /* FIXME: check charsetMatchedSub */
2979 if( !pfo ) /* couldn't get a new entry, get one of the cached fonts */
2981 UINT current_score, score = (UINT)(-1);
2983 i = index = fontMRU;
2984 fm.flags |= FO_MATCH_PAF;
2987 pfo = fontCache + i;
2988 fm.pfr = pfo->fr; fm.pfi = pfo->fi;
2990 current_score = XFONT_Match( &fm );
2991 if( current_score < score ) index = i;
2995 pfo = fontCache + index;
3000 /* attach at the head of the lru list */
3002 index = fontMRU = (pfo - fontCache);
3007 TRACE("physfont %i\n", index);
3008 *faceMatched = pfo->fi->df.dfFace;
3009 *pcharsetMatched = pfo->fi->internal_charset;
3011 return (X_PHYSFONT)(X_PFONT_MAGIC | index);
3014 /***********************************************************************
3015 * XFONT_GetFontObject
3017 fontObject* XFONT_GetFontObject( X_PHYSFONT pFont )
3019 if( CHECK_PFONT(pFont) ) return __PFONT(pFont);
3023 /***********************************************************************
3024 * XFONT_GetFontStruct
3026 XFontStruct* XFONT_GetFontStruct( X_PHYSFONT pFont )
3028 if( CHECK_PFONT(pFont) ) return __PFONT(pFont)->fs;
3032 /***********************************************************************
3035 LPIFONTINFO16 XFONT_GetFontInfo( X_PHYSFONT pFont )
3037 if( CHECK_PFONT(pFont) ) return &(__PFONT(pFont)->fi->df);
3043 /* X11DRV Interface ****************************************************
3045 * Exposed via the dc->funcs dispatch table. *
3047 ***********************************************************************/
3048 /***********************************************************************
3049 * X11DRV_FONT_SelectObject
3051 HFONT X11DRV_FONT_SelectObject( DC* dc, HFONT hfont, FONTOBJ* font )
3053 HFONT hPrevFont = 0;
3055 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
3057 EnterCriticalSection( &crtsc_fonts_X11 );
3059 if( CHECK_PFONT(physDev->font) )
3060 XFONT_ReleaseCacheEntry( __PFONT(physDev->font) );
3062 FONT_LogFontWTo16(&font->logfont, &lf);
3064 /* Make sure we don't change the sign when converting to device coords */
3065 /* FIXME - check that the other drivers do this correctly */
3068 lf.lfWidth = GDI_ROUND((FLOAT)lf.lfWidth * fabs(dc->xformWorld2Vport.eM11));
3069 if (lf.lfWidth == 0)
3070 lf.lfWidth = 1; /* Minimum width */
3074 lf.lfHeight = GDI_ROUND((FLOAT)lf.lfHeight * fabs(dc->xformWorld2Vport.eM22));
3076 if (lf.lfHeight == 0)
3077 lf.lfHeight = MIN_FONT_SIZE;
3080 lf.lfHeight = -(DEF_POINT_SIZE * dc->devCaps->logPixelsY + (72>>1)) / 72;
3083 /* Fixup aliases before passing to RealizeFont */
3084 /* alias = Windows name in the alias table */
3085 LPCSTR alias = XFONT_UnAlias( lf.lfFaceName );
3087 WORD charsetMatched;
3089 TRACE("hfont=%04x\n", hfont); /* to connect with the trace from RealizeFont */
3090 physDev->font = XFONT_RealizeFont( &lf, &faceMatched,
3091 FALSE, lf.lfCharSet,
3094 /* set face to the requested facename if it matched
3095 * so that GetTextFace can get the correct face name
3097 if (alias && !strcmp(faceMatched, lf.lfFaceName))
3098 MultiByteToWideChar(CP_ACP, 0, alias, -1,
3099 font->logfont.lfFaceName, LF_FACESIZE);
3101 MultiByteToWideChar(CP_ACP, 0, faceMatched, -1,
3102 font->logfont.lfFaceName, LF_FACESIZE);
3105 * In X, some encodings may have the same lfFaceName.
3107 * -misc-fixed-*-iso8859-1
3108 * -misc-fixed-*-jisx0208.1990-0
3109 * so charset should be saved...
3111 font->logfont.lfCharSet = charsetMatched;
3114 hPrevFont = dc->hFont;
3117 LeaveCriticalSection( &crtsc_fonts_X11 );
3123 /***********************************************************************
3125 * X11DRV_EnumDeviceFonts
3127 BOOL X11DRV_EnumDeviceFonts( HDC hdc, LPLOGFONTW plf,
3128 DEVICEFONTENUMPROC proc, LPARAM lp )
3131 NEWTEXTMETRICEXW tm;
3132 fontResource* pfr = fontList;
3137 FONT_LogFontWTo16(plf, &lf16);
3139 if( lf16.lfFaceName[0] )
3141 /* enum all entries in this resource */
3142 pfr = XFONT_FindFIList( pfr, lf16.lfFaceName );
3146 for( pfi = pfr->fi; pfi; pfi = pfi->next )
3148 /* Note: XFONT_GetFontMetric() will have to
3149 release the crit section, font list will
3150 have to be retraversed on return */
3152 if(lf16.lfCharSet == DEFAULT_CHARSET ||
3153 lf16.lfCharSet == pfi->df.dfCharSet) {
3154 if( (b = (*proc)( &lf, &tm,
3155 XFONT_GetFontMetric( pfi, &lf, &tm ), lp )) )
3162 else /* enum first entry in each resource */
3163 for( ; pfr ; pfr = pfr->next )
3167 if( (b = (*proc)( &lf, &tm,
3168 XFONT_GetFontMetric( pfr->fi, &lf, &tm ), lp )) )
3177 /***********************************************************************
3178 * X11DRV_GetTextMetrics
3180 BOOL X11DRV_GetTextMetrics(DC *dc, TEXTMETRICW *metrics)
3182 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
3185 if( CHECK_PFONT(physDev->font) )
3187 fontObject* pfo = __PFONT(physDev->font);
3188 X11DRV_cptable[pfo->fi->cptable].pGetTextMetricsA( pfo, &tmA );
3189 FONT_TextMetricAToW(&tmA, metrics);
3196 /***********************************************************************
3197 * X11DRV_GetCharWidth
3199 BOOL X11DRV_GetCharWidth( DC *dc, UINT firstChar, UINT lastChar,
3202 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
3203 fontObject* pfo = XFONT_GetFontObject( physDev->font );
3209 if (pfo->fs->per_char == NULL)
3210 for (i = firstChar; i <= lastChar; i++)
3212 *buffer++ = pfo->fs->min_bounds.attributes *
3213 pfo->lpX11Trans->pixelsize / 1000.0 * pfo->rescale;
3215 *buffer++ = pfo->fs->min_bounds.width * pfo->rescale;
3218 XCharStruct *cs, *def;
3219 static XCharStruct __null_char = { 0, 0, 0, 0, 0, 0 };
3221 CI_GET_CHAR_INFO(pfo->fs, pfo->fs->default_char, &__null_char,
3224 for (i = firstChar; i <= lastChar; i++)
3226 if (i >= pfo->fs->min_char_or_byte2 &&
3227 i <= pfo->fs->max_char_or_byte2)
3229 cs = &pfo->fs->per_char[(i - pfo->fs->min_char_or_byte2)];
3230 if (CI_NONEXISTCHAR(cs)) cs = def;
3233 *buffer++ = max(cs->attributes, 0) *
3234 pfo->lpX11Trans->pixelsize / 1000.0 * pfo->rescale;
3236 *buffer++ = max(cs->width, 0 ) * pfo->rescale;