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>
30 #include "debugtools.h"
31 #include "user.h" /* for TWEAK_WineLook (FIXME) */
33 #include "wine/server.h"
34 #include "wine/unicode.h"
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 static UINT XTextCaps = (TC_OP_CHARACTER | TC_OP_STROKE | TC_CP_STROKE | TC_CR_ANY |
67 TC_SA_DOUBLE | TC_SA_INTEGER | TC_SA_CONTIN |
68 TC_UA_ABLE | TC_SO_ABLE | TC_RA_ABLE);
69 /* X11R6 adds TC_SF_X_YINDEP, maybe more... */
71 static const char* INIFontMetrics = "cachedmetrics.";
72 static const char* INIFontSection = "Software\\Wine\\Wine\\Config\\fonts";
73 static const char* INIAliasSection = "Alias";
74 static const char* INIIgnoreSection = "Ignore";
75 static const char* INIDefault = "Default";
76 static const char* INIDefaultFixed = "DefaultFixed";
77 static const char* INIResolution = "Resolution";
78 static const char* INIGlobalMetrics = "FontMetrics";
79 static const char* INIDefaultSerif = "DefaultSerif";
80 static const char* INIDefaultSansSerif = "DefaultSansSerif";
83 /* FIXME - are there any more Latin charsets ? */
84 /* FIXME - RUSSIAN, ARABIC, GREEK, HEBREW are NOT Latin */
85 #define IS_LATIN_CHARSET(ch) \
86 ((ch)==ANSI_CHARSET ||\
88 (ch)==ISO3_CHARSET ||\
89 (ch)==ISO4_CHARSET ||\
90 (ch)==RUSSIAN_CHARSET ||\
91 (ch)==ARABIC_CHARSET ||\
92 (ch)==GREEK_CHARSET ||\
93 (ch)==HEBREW_CHARSET ||\
94 (ch)==TURKISH_CHARSET ||\
95 (ch)==ISO10_CHARSET ||\
96 (ch)==BALTIC_CHARSET ||\
99 /* suffix-charset mapping tables - must be less than 254 entries long */
101 typedef struct __sufch
104 WORD charset; /* hibyte != 0 means *internal* charset */
109 static const SuffixCharset sufch_ansi[] = {
110 { "0", ANSI_CHARSET, 1252, X11DRV_CPTABLE_SBCS },
111 { NULL, ANSI_CHARSET, 1252, X11DRV_CPTABLE_SBCS }};
113 static const SuffixCharset sufch_iso646[] = {
114 { "irv", ANSI_CHARSET, 1252, X11DRV_CPTABLE_SBCS },
115 { NULL, ANSI_CHARSET, 1252, X11DRV_CPTABLE_SBCS }};
117 static const SuffixCharset sufch_iso8859[] = {
118 { "1", ANSI_CHARSET, 28591, X11DRV_CPTABLE_SBCS },
119 { "2", EE_CHARSET, 28592, X11DRV_CPTABLE_SBCS },
120 { "3", ISO3_CHARSET, 28593, X11DRV_CPTABLE_SBCS },
121 { "4", ISO4_CHARSET, 28594, X11DRV_CPTABLE_SBCS },
122 { "5", RUSSIAN_CHARSET, 28595, X11DRV_CPTABLE_SBCS },
123 { "6", ARABIC_CHARSET, 28596, X11DRV_CPTABLE_SBCS },
124 { "7", GREEK_CHARSET, 28597, X11DRV_CPTABLE_SBCS },
125 { "8", HEBREW_CHARSET, 28598, X11DRV_CPTABLE_SBCS },
126 { "9", TURKISH_CHARSET, 28599, X11DRV_CPTABLE_SBCS },
127 { "10", ISO10_CHARSET, 28600, X11DRV_CPTABLE_SBCS },
128 { "11", THAI_CHARSET, 874, X11DRV_CPTABLE_SBCS }, /* FIXME */
129 { "12", SYMBOL_CHARSET, CP_SYMBOL, X11DRV_CPTABLE_SBCS },
130 { "13", BALTIC_CHARSET, 28603, X11DRV_CPTABLE_SBCS },
131 { "14", CELTIC_CHARSET, 28604, X11DRV_CPTABLE_SBCS },
132 { "15", ANSI_CHARSET, 28605, X11DRV_CPTABLE_SBCS },
133 { NULL, ANSI_CHARSET, 1252, X11DRV_CPTABLE_SBCS }};
135 static const SuffixCharset sufch_microsoft[] = {
136 { "cp1250", EE_CHARSET, 1250, X11DRV_CPTABLE_SBCS },
137 { "cp1251", RUSSIAN_CHARSET, 1251, X11DRV_CPTABLE_SBCS },
138 { "cp1252", ANSI_CHARSET, 1252, X11DRV_CPTABLE_SBCS },
139 { "cp1253", GREEK_CHARSET, 1253, X11DRV_CPTABLE_SBCS },
140 { "cp1254", TURKISH_CHARSET, 1254, X11DRV_CPTABLE_SBCS },
141 { "cp1255", HEBREW_CHARSET, 1255, X11DRV_CPTABLE_SBCS },
142 { "cp1256", ARABIC_CHARSET, 1256, X11DRV_CPTABLE_SBCS },
143 { "cp1257", BALTIC_CHARSET, 1257, X11DRV_CPTABLE_SBCS },
144 { "fontspecific", SYMBOL_CHARSET, CP_SYMBOL, X11DRV_CPTABLE_SYMBOL },
145 { "symbol", SYMBOL_CHARSET, CP_SYMBOL, X11DRV_CPTABLE_SYMBOL },
146 { NULL, ANSI_CHARSET, 1252, X11DRV_CPTABLE_SBCS }};
148 static const SuffixCharset sufch_tcvn[] = {
149 { "0", TCVN_CHARSET, 1252, X11DRV_CPTABLE_SBCS }, /* FIXME */
150 { NULL, TCVN_CHARSET, 1252, X11DRV_CPTABLE_SBCS }};
152 static const SuffixCharset sufch_tis620[] = {
153 { "0", THAI_CHARSET, 874, X11DRV_CPTABLE_SBCS }, /* FIXME */
154 { NULL, THAI_CHARSET, 874, X11DRV_CPTABLE_SBCS }};
156 static const SuffixCharset sufch_viscii[] = {
157 { "1", VISCII_CHARSET, 1252, X11DRV_CPTABLE_SBCS }, /* FIXME */
158 { NULL, VISCII_CHARSET, 1252, X11DRV_CPTABLE_SBCS }};
160 static const SuffixCharset sufch_windows[] = {
161 { "1250", EE_CHARSET, 1250, X11DRV_CPTABLE_SBCS },
162 { "1251", RUSSIAN_CHARSET, 1251, X11DRV_CPTABLE_SBCS },
163 { "1252", ANSI_CHARSET, 1252, X11DRV_CPTABLE_SBCS },
164 { "1253", GREEK_CHARSET, 1253, X11DRV_CPTABLE_SBCS },
165 { "1254", TURKISH_CHARSET, 1254, X11DRV_CPTABLE_SBCS },
166 { "1255", HEBREW_CHARSET, 1255, X11DRV_CPTABLE_SBCS },
167 { "1256", ARABIC_CHARSET, 1256, X11DRV_CPTABLE_SBCS },
168 { "1257", BALTIC_CHARSET, 1257, X11DRV_CPTABLE_SBCS },
169 { NULL, ANSI_CHARSET, 1252, X11DRV_CPTABLE_SBCS }};
171 static const SuffixCharset sufch_koi8[] = {
172 { "r", RUSSIAN_CHARSET, 20866, X11DRV_CPTABLE_SBCS },
173 { "ru", RUSSIAN_CHARSET, 20866, X11DRV_CPTABLE_SBCS },
174 { "u", RUSSIAN_CHARSET, 20866, X11DRV_CPTABLE_SBCS },
175 { NULL, RUSSIAN_CHARSET, 20866, X11DRV_CPTABLE_SBCS }};
177 static const SuffixCharset sufch_jisx0201[] = {
178 { "0", X11FONT_JISX0201_CHARSET, 932, X11DRV_CPTABLE_SBCS },
179 { NULL, X11FONT_JISX0201_CHARSET, 932, X11DRV_CPTABLE_SBCS }};
181 static const SuffixCharset sufch_jisx0208[] = {
182 { "0", SHIFTJIS_CHARSET, 932, X11DRV_CPTABLE_CP932 },
183 { NULL, SHIFTJIS_CHARSET, 932, X11DRV_CPTABLE_CP932 }};
185 static const SuffixCharset sufch_jisx0212[] = {
186 { "0", X11FONT_JISX0212_CHARSET, 932, X11DRV_CPTABLE_CP932 },
187 { NULL, X11FONT_JISX0212_CHARSET, 932, X11DRV_CPTABLE_CP932 }};
189 static const SuffixCharset sufch_ksc5601[] = {
190 { "0", HANGEUL_CHARSET, 949, X11DRV_CPTABLE_CP949 },
191 { NULL, HANGEUL_CHARSET, 949, X11DRV_CPTABLE_CP949 }};
193 static const SuffixCharset sufch_gb2312[] = {
194 { "0", GB2312_CHARSET, 936, X11DRV_CPTABLE_CP936 },
195 { NULL, GB2312_CHARSET, 936, X11DRV_CPTABLE_CP936 }};
197 static const SuffixCharset sufch_big5[] = {
198 { "0", CHINESEBIG5_CHARSET, 950, X11DRV_CPTABLE_CP950 },
199 { NULL, CHINESEBIG5_CHARSET, 950, X11DRV_CPTABLE_CP950 }};
201 static const SuffixCharset sufch_unicode[] = {
202 { "0", DEFAULT_CHARSET, 0, X11DRV_CPTABLE_UNICODE },
203 { NULL, DEFAULT_CHARSET, 0, X11DRV_CPTABLE_UNICODE }};
205 static const SuffixCharset sufch_iso10646[] = {
206 { "1", DEFAULT_CHARSET, 0, X11DRV_CPTABLE_UNICODE },
207 { NULL, DEFAULT_CHARSET, 0, X11DRV_CPTABLE_UNICODE }};
209 static const SuffixCharset sufch_dec[] = {
210 { "dectech", SYMBOL_CHARSET, CP_SYMBOL, X11DRV_CPTABLE_SBCS },
211 { NULL, 0, 0, X11DRV_CPTABLE_SBCS }};
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", sufch_big5, &__fETTable[18]},
248 { "unicode", sufch_unicode, &__fETTable[19]},
249 { "iso10646", sufch_iso10646, &__fETTable[20]},
250 { "cp", sufch_windows, &__fETTable[21]},
251 { "dec", sufch_dec, &__fETTable[22]},
252 /* NULL prefix matches anything so put it last */
253 { NULL, sufch_any, NULL },
255 static fontEncodingTemplate* fETTable = __fETTable;
257 /* a charset database for known facenames */
258 struct CharsetBindingInfo
260 const char* pszFaceName;
263 static const struct CharsetBindingInfo charsetbindings[] =
265 /* special facenames */
266 { "System", DEFAULT_CHARSET },
267 { "FixedSys", DEFAULT_CHARSET },
269 /* known facenames */
270 { "MS Serif", ANSI_CHARSET },
271 { "MS Sans Serif", ANSI_CHARSET },
272 { "Courier", ANSI_CHARSET },
273 { "Symbol", SYMBOL_CHARSET },
275 { "Arial", ANSI_CHARSET },
276 { "Arial Greek", GREEK_CHARSET },
277 { "Arial Tur", TURKISH_CHARSET },
278 { "Arial Baltic", BALTIC_CHARSET },
279 { "Arial CE", EASTEUROPE_CHARSET },
280 { "Arial Cyr", RUSSIAN_CHARSET },
281 { "Courier New", ANSI_CHARSET },
282 { "Courier New Greek", GREEK_CHARSET },
283 { "Courier New Tur", TURKISH_CHARSET },
284 { "Courier New Baltic", BALTIC_CHARSET },
285 { "Courier New CE", EASTEUROPE_CHARSET },
286 { "Courier New Cyr", RUSSIAN_CHARSET },
287 { "Times New Roman", ANSI_CHARSET },
288 { "Times New Roman Greek", GREEK_CHARSET },
289 { "Times New Roman Tur", TURKISH_CHARSET },
290 { "Times New Roman Baltic", BALTIC_CHARSET },
291 { "Times New Roman CE", EASTEUROPE_CHARSET },
292 { "Times New Roman Cyr", RUSSIAN_CHARSET },
294 { "\x82\x6c\x82\x72 \x83\x53\x83\x56\x83\x62\x83\x4e",
295 SHIFTJIS_CHARSET }, /* MS gothic */
296 { "\x82\x6c\x82\x72 \x82\x6f\x83\x53\x83\x56\x83\x62\x83\x4e",
297 SHIFTJIS_CHARSET }, /* MS P gothic */
298 { "\x82\x6c\x82\x72 \x96\xbe\x92\xa9",
299 SHIFTJIS_CHARSET }, /* MS mincho */
300 { "\x82\x6c\x82\x72 \x82\x6f\x96\xbe\x92\xa9",
301 SHIFTJIS_CHARSET }, /* MS P mincho */
302 { "GulimChe", HANGEUL_CHARSET },
303 { "MS Song", GB2312_CHARSET },
304 { "MS Hei", GB2312_CHARSET },
305 { "\xb7\x73\xb2\xd3\xa9\xfa\xc5\xe9", CHINESEBIG5_CHARSET },/*MS Mingliu*/
306 { "\xb2\xd3\xa9\xfa\xc5\xe9", CHINESEBIG5_CHARSET },
312 static int DefResolution = 0;
314 static CRITICAL_SECTION crtsc_fonts_X11 = CRITICAL_SECTION_INIT("crtsc_fonts_X11");
316 static fontResource* fontList = NULL;
317 static fontObject* fontCache = NULL; /* array */
318 static int fontCacheSize = FONTCACHE;
319 static int fontLF = -1, fontMRU = -1; /* last free, most recently used */
321 #define __PFONT(pFont) ( fontCache + ((UINT)(pFont) & 0x0000FFFF) )
322 #define CHECK_PFONT(pFont) ( (((UINT)(pFont) & 0xFFFF0000) == X_PFONT_MAGIC) &&\
323 (((UINT)(pFont) & 0x0000FFFF) < fontCacheSize) )
325 static Atom RAW_ASCENT;
326 static Atom RAW_DESCENT;
328 /***********************************************************************
329 * Helper macros from X distribution
332 #define CI_NONEXISTCHAR(cs) (((cs)->width == 0) && \
333 (((cs)->rbearing|(cs)->lbearing| \
334 (cs)->ascent|(cs)->descent) == 0))
336 #define CI_GET_CHAR_INFO(fs,col,def,cs) \
339 if (col >= fs->min_char_or_byte2 && col <= fs->max_char_or_byte2) { \
340 if (fs->per_char == NULL) { \
341 cs = &fs->min_bounds; \
343 cs = &fs->per_char[(col - fs->min_char_or_byte2)]; \
344 if (CI_NONEXISTCHAR(cs)) cs = def; \
349 #define CI_GET_DEFAULT_INFO(fs,cs) \
350 CI_GET_CHAR_INFO(fs, fs->default_char, NULL, cs)
353 /***********************************************************************
356 inline static BOOL is_stock_font( HFONT font )
359 for (i = OEM_FIXED_FONT; i <= DEFAULT_GUI_FONT; i++)
361 if (i != DEFAULT_PALETTE && font == GetStockObject(i)) return TRUE;
367 /***********************************************************************
370 static UINT16 __lfCheckSum( LPLOGFONT16 plf )
372 CHAR font[LF_FACESIZE];
378 for (i = 0; i < 9; i++) checksum ^= *ptr++;
379 for (i = 0; i < LF_FACESIZE; i++)
381 font[i] = tolower(plf->lfFaceName[i]);
382 if (!font[i] || font[i] == ' ') break;
384 for (ptr = (UINT16 *)font, i >>= 1; i > 0; i-- ) checksum ^= *ptr++;
388 static UINT16 __genericCheckSum( const void *ptr, int size )
390 unsigned int checksum = 0;
391 const char *p = (const char *)ptr;
393 checksum ^= (checksum << 3) + (checksum >> 29) + *p++;
395 return checksum & 0xffff;
398 /*************************************************************************
399 * LFD parse/compose routines
401 * NB. LFD_Parse will use lpFont for its own ends, so if you want to keep it
404 * These functions also do TILDE to HYPHEN conversion
406 static LFD* LFD_Parse(LPSTR lpFont)
409 char *lpch = lpFont, *lfd_fld[LFD_FIELDS], *field_start;
413 WARN("font '%s' doesn't begin with '%c'\n", lpFont, HYPHEN);
417 field_start = ++lpch;
418 for( i = 0; i < LFD_FIELDS; )
423 lfd_fld[i] = field_start;
425 field_start = ++lpch;
429 lfd_fld[i] = field_start;
433 else if (*lpch == TILDE)
441 /* Fill in the empty fields with NULLS */
442 for (; i< LFD_FIELDS; i++)
445 WARN("Extra ignored in font '%s'\n", lpFont);
447 lfd = HeapAlloc( GetProcessHeap(), 0, sizeof(LFD) );
450 lfd->foundry = lfd_fld[0];
451 lfd->family = lfd_fld[1];
452 lfd->weight = lfd_fld[2];
453 lfd->slant = lfd_fld[3];
454 lfd->set_width = lfd_fld[4];
455 lfd->add_style = lfd_fld[5];
456 lfd->pixel_size = lfd_fld[6];
457 lfd->point_size = lfd_fld[7];
458 lfd->resolution_x = lfd_fld[8];
459 lfd->resolution_y = lfd_fld[9];
460 lfd->spacing = lfd_fld[10];
461 lfd->average_width = lfd_fld[11];
462 lfd->charset_registry = lfd_fld[12];
463 lfd->charset_encoding = lfd_fld[13];
469 static void LFD_UnParse(LPSTR dp, UINT buf_size, LFD* lfd)
471 const char* lfd_fld[LFD_FIELDS];
475 return; /* Dont be silly */
477 lfd_fld[0] = lfd->foundry;
478 lfd_fld[1] = lfd->family;
479 lfd_fld[2] = lfd->weight ;
480 lfd_fld[3] = lfd->slant ;
481 lfd_fld[4] = lfd->set_width ;
482 lfd_fld[5] = lfd->add_style;
483 lfd_fld[6] = lfd->pixel_size;
484 lfd_fld[7] = lfd->point_size;
485 lfd_fld[8] = lfd->resolution_x;
486 lfd_fld[9] = lfd->resolution_y ;
487 lfd_fld[10] = lfd->spacing ;
488 lfd_fld[11] = lfd->average_width ;
489 lfd_fld[12] = lfd->charset_registry ;
490 lfd_fld[13] = lfd->charset_encoding ;
492 buf_size--; /* Room for the terminator */
494 for (i = 0; i < LFD_FIELDS; i++)
496 const char* sp = lfd_fld[i];
497 if (!sp || !buf_size)
502 while (buf_size > 0 && *sp)
504 *dp = (*sp == HYPHEN) ? TILDE : *sp;
513 static void LFD_GetWeight( fontInfo* fi, LPCSTR lpStr)
515 int j = strlen(lpStr);
516 if( j == 1 && *lpStr == '0')
517 fi->fi_flags |= FI_POLYWEIGHT;
520 if( !strcasecmp( "bold", lpStr) )
521 fi->df.dfWeight = FW_BOLD;
522 else if( !strcasecmp( "demi", lpStr) )
524 fi->fi_flags |= FI_FW_DEMI;
525 fi->df.dfWeight = FW_DEMIBOLD;
527 else if( !strcasecmp( "book", lpStr) )
529 fi->fi_flags |= FI_FW_BOOK;
530 fi->df.dfWeight = FW_REGULAR;
535 if( !strcasecmp( "light", lpStr) )
536 fi->df.dfWeight = FW_LIGHT;
537 else if( !strcasecmp( "black", lpStr) )
538 fi->df.dfWeight = FW_BLACK;
540 else if( j == 6 && !strcasecmp( "medium", lpStr) )
541 fi->df.dfWeight = FW_REGULAR;
542 else if( j == 8 && !strcasecmp( "demibold", lpStr) )
543 fi->df.dfWeight = FW_DEMIBOLD;
545 fi->df.dfWeight = FW_DONTCARE; /* FIXME: try to get something
546 * from the weight property */
549 static BOOL LFD_GetSlant( fontInfo* fi, LPCSTR lpStr)
551 int l = strlen(lpStr);
554 switch( tolower( *lpStr ) )
556 case '0': fi->fi_flags |= FI_POLYSLANT; /* haven't seen this one yet */
558 case 'r': fi->df.dfItalic = 0;
561 fi->fi_flags |= FI_OBLIQUE;
562 case 'i': fi->df.dfItalic = 1;
570 static void LFD_GetStyle( fontInfo* fi, LPCSTR lpstr, int dec_style_check)
572 int j = strlen(lpstr);
573 if( j > 3 ) /* find out is there "sans" or "script" */
577 if( strstr(lpstr, "sans") )
579 fi->df.dfPitchAndFamily |= FF_SWISS;
582 if( strstr(lpstr, "script") )
584 fi->df.dfPitchAndFamily |= FF_SCRIPT;
587 if( !j && dec_style_check )
588 fi->df.dfPitchAndFamily |= FF_DECORATIVE;
592 /*************************************************************************
597 * Fill in some fields in the fontInfo struct.
599 static int LFD_InitFontInfo( fontInfo* fi, const LFD* lfd, LPCSTR fullname )
601 int i, j, dec_style_check, scalability;
602 fontEncodingTemplate* boba;
603 const char* ridiculous = "font '%s' has ridiculous %s\n";
606 if (!lfd->charset_registry)
608 WARN("font '%s' does not have enough fields\n", fullname);
612 memset(fi, 0, sizeof(fontInfo) );
615 LFD_GetWeight( fi, lfd->weight);
618 dec_style_check = LFD_GetSlant( fi, lfd->slant);
621 lpstr = lfd->set_width;
622 if( strcasecmp( "normal", lpstr) ) /* XXX 'narrow', 'condensed', etc... */
623 dec_style_check = TRUE;
625 fi->fi_flags |= FI_NORMAL;
628 LFD_GetStyle(fi, lfd->add_style, dec_style_check);
630 /* pixel & decipoint height, and res_x & y */
634 j = strlen(lfd->pixel_size);
635 if( j == 0 || j > 3 )
637 WARN(ridiculous, fullname, "pixel_size");
640 if( !(fi->lfd_height = atoi(lfd->pixel_size)) )
643 j = strlen(lfd->point_size);
644 if( j == 0 || j > 3 )
646 WARN(ridiculous, fullname, "point_size");
649 if( !(atoi(lfd->point_size)) )
652 j = strlen(lfd->resolution_x);
653 if( j == 0 || j > 3 )
655 WARN(ridiculous, fullname, "resolution_x");
658 if( !(fi->lfd_resolution = atoi(lfd->resolution_x)) )
661 j = strlen(lfd->resolution_y);
662 if( j == 0 || j > 3 )
664 WARN(ridiculous, fullname, "resolution_y");
667 if( !(atoi(lfd->resolution_y)) )
670 /* Check scalability */
675 case 4: /* Scalable */
676 fi->fi_flags |= FI_SCALABLE;
679 /* #$%^!!! X11R6 mutant garbage (scalable bitmap) */
680 TRACE("Skipping scalable bitmap '%s'\n", fullname);
683 WARN("Font '%s' has weird scalability\n", fullname);
688 lpstr = lfd->spacing;
692 WARN("font '%s' has no spacing\n", fullname);
695 case 'p': fi->fi_flags |= FI_VARIABLEPITCH;
697 case 'c': fi->df.dfPitchAndFamily |= FF_MODERN;
698 fi->fi_flags |= FI_FIXEDEX;
700 case 'm': fi->fi_flags |= FI_FIXEDPITCH;
703 /* Of course this line does nothing */
704 fi->df.dfPitchAndFamily |= DEFAULT_PITCH | FF_DONTCARE;
707 /* average width - */
708 lpstr = lfd->average_width;
710 if( j == 0 || j > 3 )
712 WARN(ridiculous, fullname, "average_width");
716 if( !(atoi(lpstr)) && !scalability )
718 WARN("font '%s' has average_width 0 but is not scalable!!\n", fullname);
722 /* charset registry, charset encoding - */
723 lpstr = lfd->charset_registry;
724 if( strstr(lpstr, "ksc") ||
725 strstr(lpstr, "gb2312") ||
726 strstr(lpstr, "big5") )
728 FIXME("DBCS fonts like '%s' are not working correctly now.\n", fullname);
731 fi->df.dfCharSet = ANSI_CHARSET;
733 for( i = 0, boba = fETTable; boba; boba = boba->next, i++ )
735 if (!boba->prefix || !strcasecmp(lpstr, boba->prefix))
737 if (lfd->charset_encoding)
739 for( j = 0; boba->sufch[j].psuffix; j++ )
741 if( !strcasecmp(lfd->charset_encoding, boba->sufch[j].psuffix ))
743 fi->df.dfCharSet = (BYTE)(boba->sufch[j].charset & 0xff);
744 fi->internal_charset = boba->sufch[j].charset;
745 fi->codepage = boba->sufch[j].codepage;
746 fi->cptable = boba->sufch[j].cptable;
751 fi->df.dfCharSet = (BYTE)(boba->sufch[j].charset & 0xff);
752 fi->internal_charset = boba->sufch[j].charset;
753 fi->codepage = boba->sufch[j].codepage;
754 fi->cptable = boba->sufch[j].cptable;
757 FIXME("font '%s' has unknown character encoding '%s' in known registry '%s'\n",
758 fullname, lfd->charset_encoding, boba->prefix);
763 FIXME("font '%s' has unknown registry '%s' and character encoding '%s' \n",
764 fullname, lfd->charset_registry, lfd->charset_encoding);
768 WARN("Defaulting to: df.dfCharSet = %d, internal_charset = %d, codepage = %d, cptable = %d\n",
769 fi->df.dfCharSet,fi->internal_charset, fi->codepage, fi->cptable);
772 else if (boba->prefix)
774 WARN("font '%s' has known registry '%s' and no character encoding\n",
776 for( j = 0; boba->sufch[j].psuffix; j++ )
778 fi->df.dfCharSet = (BYTE)(boba->sufch[j].charset & 0xff);
779 fi->internal_charset = boba->sufch[j].charset;
780 fi->codepage = boba->sufch[j].codepage;
781 fi->cptable = boba->sufch[j].cptable;
787 WARN("font '%s' has unknown character set '%s'\n", fullname, lpstr);
791 /* i - index into fETTable
792 * j - index into suffix array for fETTable[i]
794 * 254 - found encoding prefix, unknown suffix
795 * 255 - no encoding match at all.
797 fi->fi_encoding = 256 * (UINT16)i + (UINT16)j;
803 /*************************************************************************
806 * make a matrix suitable for LFD based on theta radians
808 static void LFD_AngleMatrix( char* buffer, int h, double theta)
811 matrix[0] = h*cos(theta);
812 matrix[1] = h*sin(theta);
813 matrix[2] = -h*sin(theta);
814 matrix[3] = h*cos(theta);
815 sprintf(buffer, "[%+f%+f%+f%+f]", matrix[0], matrix[1], matrix[2], matrix[3]);
818 /*************************************************************************
821 * Note: uRelax is a treatment not a cure. Font mapping algorithm
822 * should be bulletproof enough to allow us to avoid hacks like
823 * this despite LFD being so braindead.
825 static BOOL LFD_ComposeLFD( const fontObject* fo,
826 INT height, LPSTR lpLFD, UINT uRelax )
830 char h_string[64], resx_string[64], resy_string[64];
833 /* Get the worst case over with first */
835 /* RealizeFont() will call us repeatedly with increasing uRelax
836 * until XLoadFont() succeeds.
837 * to avoid an infinite loop; these will always match
842 sprintf( lpLFD, "-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-1" );
844 sprintf( lpLFD, "-*-*-*-*-*-*-*-*-*-*-*-*-*-*" );
848 /* read foundry + family from fo */
849 aLFD.foundry = fo->fr->resource->foundry;
850 aLFD.family = fo->fr->resource->family;
853 switch( fo->fi->df.dfWeight )
856 aLFD.weight = "bold"; break;
858 if( fo->fi->fi_flags & FI_FW_BOOK )
859 aLFD.weight = "book";
861 aLFD.weight = "medium";
864 aLFD.weight = "demi";
865 if( !( fo->fi->fi_flags & FI_FW_DEMI) )
866 aLFD.weight = "bold";
869 aLFD.weight = "black"; break;
871 aLFD.weight = "light"; break;
877 if( fo->fi->df.dfItalic )
878 if( fo->fi->fi_flags & FI_OBLIQUE )
883 aLFD.slant = (uRelax < 1) ? "r" : any;
886 if( fo->fi->fi_flags & FI_NORMAL )
887 aLFD.set_width = "normal";
889 aLFD.set_width = any;
892 aLFD.add_style = any;
896 * FIXME: fill in lpXForm and lpPixmap for rotated fonts
898 if( fo->fo_flags & FO_SYNTH_HEIGHT )
899 h = fo->fi->lfd_height;
902 h = (fo->fi->lfd_height * height + (fo->fi->df.dfPixHeight>>1));
903 h /= fo->fi->df.dfPixHeight;
905 if (h < MIN_FONT_SIZE) /* Resist rounding down to 0 */
907 else if (h > MAX_FONT_SIZE) /* Sanity check as huge fonts can lock up the font server */
909 WARN("Huge font size %d pixels has been reduced to %d\n", h, MAX_FONT_SIZE);
914 /* handle rotated fonts */
915 if (fo->lf.lfEscapement) {
916 /* escapement is in tenths of degrees, theta is in radians */
917 double theta = M_PI*fo->lf.lfEscapement/1800.;
918 LFD_AngleMatrix(h_string, h, theta);
922 sprintf(h_string, "%d", h);
925 sprintf(h_string, "%d", fo->fi->lfd_height);
927 aLFD.pixel_size = h_string;
928 aLFD.point_size = any;
930 /* resolution_x,y, average width */
931 /* FOX ME - Why do some font servers ignore average width ?
932 * so that you have to mess around with res_y
934 aLFD.average_width = any;
937 sprintf(resx_string, "%d", fo->fi->lfd_resolution);
938 aLFD.resolution_x = resx_string;
940 strcpy(resy_string, resx_string);
941 if( uRelax == 0 && XTextCaps & TC_SF_X_YINDEP )
943 if( fo->lf.lfWidth && !(fo->fo_flags & FO_SYNTH_WIDTH))
945 int resy = 0.5 + fo->fi->lfd_resolution *
946 (fo->fi->df.dfAvgWidth * height) /
947 (fo->lf.lfWidth * fo->fi->df.dfPixHeight) ;
948 sprintf(resy_string, "%d", resy);
952 /* FIXME - synth width */
955 aLFD.resolution_y = resy_string;
959 aLFD.resolution_x = aLFD.resolution_y = any;
966 if( fo->fi->fi_flags & FI_FIXEDPITCH )
967 w = ( fo->fi->fi_flags & FI_FIXEDEX ) ? "c" : "m";
969 w = ( fo->fi->fi_flags & FI_VARIABLEPITCH ) ? "p" : any;
971 aLFD.spacing = (uRelax <= 1) ? w : any;
978 fontEncodingTemplate* boba = fETTable;
980 for(i = fo->fi->fi_encoding >> 8; i; i--) boba = boba->next;
981 aLFD.charset_registry = boba->prefix ? boba->prefix : any;
983 i = fo->fi->fi_encoding & 255;
987 aLFD.charset_encoding = boba->sufch[i].psuffix;
991 aLFD.charset_encoding = any;
994 case 255: /* no suffix - it ends eg "-ascii" */
995 aLFD.charset_encoding = NULL;
1001 aLFD.charset_registry = any;
1002 aLFD.charset_encoding = any;
1005 LFD_UnParse(lpLFD, MAX_LFD_LENGTH, &aLFD);
1007 TRACE("\tLFD(uRelax=%d): %s\n", uRelax, lpLFD );
1012 /***********************************************************************
1015 * font info - http://www.microsoft.com/kb/articles/q65/1/23.htm
1016 * Windows font metrics - http://www.microsoft.com/kb/articles/q32/6/67.htm
1018 static void XFONT_GetLeading( const LPIFONTINFO16 pFI, const XFontStruct* x_fs,
1019 INT16* pIL, INT16* pEL, const XFONTTRANS *XFT )
1021 unsigned long height;
1022 unsigned min = (unsigned char)pFI->dfFirstChar;
1023 BOOL bIsLatin = IS_LATIN_CHARSET(pFI->dfCharSet);
1028 Atom RAW_CAP_HEIGHT = TSXInternAtom(gdi_display, "RAW_CAP_HEIGHT", TRUE);
1029 if(TSXGetFontProperty((XFontStruct*)x_fs, RAW_CAP_HEIGHT, &height))
1030 *pIL = XFT->ascent -
1031 (INT)(XFT->pixelsize / 1000.0 * height);
1037 if( TSXGetFontProperty((XFontStruct*)x_fs, XA_CAP_HEIGHT, &height) == FALSE )
1039 if( x_fs->per_char )
1041 height = x_fs->per_char['X' - min].ascent;
1043 if (x_fs->ascent >= x_fs->max_bounds.ascent)
1044 height = x_fs->max_bounds.ascent;
1047 height = x_fs->ascent;
1049 *pEL = x_fs->max_bounds.ascent - height;
1052 height = x_fs->min_bounds.ascent;
1055 *pIL = x_fs->ascent - height;
1058 /***********************************************************************
1061 static int XFONT_CharWidth(const XFontStruct* x_fs,
1062 const XFONTTRANS *XFT, int ch)
1065 return x_fs->per_char[ch].width;
1067 return x_fs->per_char[ch].attributes * XFT->pixelsize / 1000.0;
1070 /***********************************************************************
1071 * XFONT_GetAvgCharWidth
1073 static INT XFONT_GetAvgCharWidth( LPIFONTINFO16 pFI, const XFontStruct* x_fs,
1074 const XFONTTRANS *XFT)
1076 unsigned min = (unsigned char)pFI->dfFirstChar;
1077 unsigned max = (unsigned char)pFI->dfLastChar;
1081 if( x_fs->per_char )
1083 int width = 0, chars = 0, j;
1084 if( IS_LATIN_CHARSET(pFI->dfCharSet) ||
1085 pFI->dfCharSet == DEFAULT_CHARSET )
1087 /* FIXME - should use a weighted average */
1088 for( j = 0; j < 26; j++ )
1089 width += XFONT_CharWidth(x_fs, XFT, 'a' + j - min) +
1090 XFONT_CharWidth(x_fs, XFT, 'A' + j - min);
1093 else /* unweighted average of everything */
1095 for( j = 0, max -= min; j <= max; j++ )
1096 if( !CI_NONEXISTCHAR(x_fs->per_char + j) )
1098 width += XFONT_CharWidth(x_fs, XFT, j);
1102 if (chars) avg = (width + (chars>>1))/ chars;
1103 else avg = 0; /* No characters exist at all */
1105 else /* uniform width */
1106 avg = x_fs->min_bounds.width;
1111 /***********************************************************************
1112 * XFONT_GetMaxCharWidth
1114 static INT XFONT_GetMaxCharWidth(const XFontStruct* xfs, const XFONTTRANS *XFT)
1116 unsigned min = (unsigned char)xfs->min_char_or_byte2;
1117 unsigned max = (unsigned char)xfs->max_char_or_byte2;
1120 if(!XFT || !xfs->per_char)
1121 return abs(xfs->max_bounds.width);
1123 for( j = 0, maxwidth = 0, max -= min; j <= max; j++ )
1124 if( !CI_NONEXISTCHAR(xfs->per_char + j) )
1125 if(maxwidth < xfs->per_char[j].attributes)
1126 maxwidth = xfs->per_char[j].attributes;
1128 maxwidth *= XFT->pixelsize / 1000.0;
1132 /***********************************************************************
1133 * XFONT_SetFontMetric
1137 * Initializes IFONTINFO16.
1139 static void XFONT_SetFontMetric(fontInfo* fi, const fontResource* fr, XFontStruct* xfs)
1142 fi->df.dfFirstChar = (BYTE)(min = xfs->min_char_or_byte2);
1143 fi->df.dfLastChar = (BYTE)(max = xfs->max_char_or_byte2);
1145 fi->df.dfDefaultChar = (BYTE)xfs->default_char;
1146 fi->df.dfBreakChar = (BYTE)(( ' ' < min || ' ' > max) ? xfs->default_char: ' ');
1148 fi->df.dfPixHeight = (INT16)((fi->df.dfAscent = (INT16)xfs->ascent) + xfs->descent);
1149 fi->df.dfPixWidth = (xfs->per_char) ? 0 : xfs->min_bounds.width;
1151 XFONT_GetLeading( &fi->df, xfs, &fi->df.dfInternalLeading, &fi->df.dfExternalLeading, NULL );
1152 fi->df.dfAvgWidth = (INT16)XFONT_GetAvgCharWidth(&fi->df, xfs, NULL );
1153 fi->df.dfMaxWidth = (INT16)XFONT_GetMaxCharWidth(xfs, NULL);
1155 if( xfs->min_bounds.width != xfs->max_bounds.width )
1156 fi->df.dfPitchAndFamily |= TMPF_FIXED_PITCH; /* au contraire! */
1157 if( fi->fi_flags & FI_SCALABLE )
1159 fi->df.dfType = DEVICE_FONTTYPE;
1160 fi->df.dfPitchAndFamily |= TMPF_DEVICE;
1162 else if( fi->fi_flags & FI_TRUETYPE )
1163 fi->df.dfType = TRUETYPE_FONTTYPE;
1165 fi->df.dfType = RASTER_FONTTYPE;
1167 fi->df.dfFace = fr->lfFaceName;
1170 /***********************************************************************
1171 * XFONT_GetFontMetric
1173 * Retrieve font metric info (enumeration).
1175 static UINT XFONT_GetFontMetric( const fontInfo* pfi,
1176 const LPENUMLOGFONTEXW pLF,
1177 const LPNEWTEXTMETRICEXW pTM )
1179 memset( pLF, 0, sizeof(*pLF) );
1180 memset( pTM, 0, sizeof(*pTM) );
1182 #define plf ((LPLOGFONTW)pLF)
1183 #define ptm ((LPNEWTEXTMETRICW)pTM)
1184 plf->lfHeight = ptm->tmHeight = pfi->df.dfPixHeight;
1185 plf->lfWidth = ptm->tmAveCharWidth = pfi->df.dfAvgWidth;
1186 plf->lfWeight = ptm->tmWeight = pfi->df.dfWeight;
1187 plf->lfItalic = ptm->tmItalic = pfi->df.dfItalic;
1188 plf->lfUnderline = ptm->tmUnderlined = pfi->df.dfUnderline;
1189 plf->lfStrikeOut = ptm->tmStruckOut = pfi->df.dfStrikeOut;
1190 plf->lfCharSet = ptm->tmCharSet = pfi->df.dfCharSet;
1192 /* convert pitch values */
1194 ptm->tmPitchAndFamily = pfi->df.dfPitchAndFamily;
1195 plf->lfPitchAndFamily = (pfi->df.dfPitchAndFamily & 0xF1) + 1;
1197 MultiByteToWideChar(CP_ACP, 0, pfi->df.dfFace, -1,
1198 plf->lfFaceName, LF_FACESIZE);
1200 /* FIXME: fill in rest of plF values */
1201 strcpyW(pLF->elfFullName, plf->lfFaceName);
1202 MultiByteToWideChar(CP_ACP, 0, "Regular", -1,
1203 pLF->elfStyle, LF_FACESIZE);
1204 MultiByteToWideChar(CP_ACP, 0, plf->lfCharSet == SYMBOL_CHARSET ?
1205 "Symbol" : "Roman", -1,
1206 pLF->elfScript, LF_FACESIZE);
1210 ptm->tmAscent = pfi->df.dfAscent;
1211 ptm->tmDescent = ptm->tmHeight - ptm->tmAscent;
1212 ptm->tmInternalLeading = pfi->df.dfInternalLeading;
1213 ptm->tmMaxCharWidth = pfi->df.dfMaxWidth;
1214 ptm->tmDigitizedAspectX = pfi->df.dfHorizRes;
1215 ptm->tmDigitizedAspectY = pfi->df.dfVertRes;
1217 ptm->tmFirstChar = pfi->df.dfFirstChar;
1218 ptm->tmLastChar = pfi->df.dfLastChar;
1219 ptm->tmDefaultChar = pfi->df.dfDefaultChar;
1220 ptm->tmBreakChar = pfi->df.dfBreakChar;
1222 TRACE("Calling Enum proc with FaceName %s FullName %s\n",
1223 debugstr_w(pLF->elfLogFont.lfFaceName),
1224 debugstr_w(pLF->elfFullName));
1226 TRACE("CharSet = %d type = %d\n", ptm->tmCharSet, pfi->df.dfType);
1227 /* return font type */
1228 return pfi->df.dfType;
1233 /***********************************************************************
1238 * dfPitchAndFamily flags for some common typefaces.
1240 static BYTE XFONT_FixupFlags( LPCSTR lfFaceName )
1242 switch( lfFaceName[0] )
1245 case 'A': if(!strncasecmp(lfFaceName, "Arial", 5) )
1249 case 'H': if(!strcasecmp(lfFaceName, "Helvetica") )
1253 case 'C': if(!strncasecmp(lfFaceName, "Courier", 7))
1256 if (!strcasecmp(lfFaceName, "Charter") )
1260 case 'P': if( !strcasecmp(lfFaceName,"Palatino") )
1264 case 'T': if(!strncasecmp(lfFaceName, "Times", 5) )
1268 case 'U': if(!strcasecmp(lfFaceName, "Utopia") )
1272 case 'Z': if(!strcasecmp(lfFaceName, "Zapf Dingbats") )
1273 return FF_DECORATIVE;
1278 /***********************************************************************
1279 * XFONT_SameFoundryAndFamily
1283 static BOOL XFONT_SameFoundryAndFamily( const LFD* lfd1, const LFD* lfd2 )
1285 return ( !strcasecmp( lfd1->foundry, lfd2->foundry ) &&
1286 !strcasecmp( lfd1->family, lfd2->family ) );
1289 /***********************************************************************
1290 * XFONT_InitialCapitals
1294 * Upper case first letters of words & remove multiple spaces
1296 static void XFONT_InitialCapitals(LPSTR lpch)
1302 for( i = 0, up = TRUE; *lpch; lpch++, i++ )
1304 if( isspace(*lpch) )
1306 if (!up) /* Not already got one */
1312 else if( isalpha(*lpch) && up )
1314 *lpstr++ = toupper(*lpch);
1324 /* Remove possible trailing space */
1331 /***********************************************************************
1332 * XFONT_WindowsNames
1336 * Build generic Windows aliases for X font names.
1338 * -misc-fixed- -> "Fixed"
1339 * -sony-fixed- -> "Sony Fixed", etc...
1341 static void XFONT_WindowsNames(void)
1345 for( fr = fontList; fr ; fr = fr->next )
1350 if( fr->fr_flags & FR_NAMESET ) continue; /* skip already assigned */
1352 for( pfr = fontList; pfr != fr ; pfr = pfr->next )
1353 if( pfr->fr_flags & FR_NAMESET )
1355 if (!strcasecmp( pfr->resource->family, fr->resource->family))
1359 lpch = fr->lfFaceName;
1360 snprintf( fr->lfFaceName, sizeof(fr->lfFaceName), "%s %s",
1361 /* prepend vendor name */
1362 (pfr==fr) ? "" : fr->resource->foundry,
1363 fr->resource->family);
1364 XFONT_InitialCapitals(fr->lfFaceName);
1366 BYTE bFamilyStyle = XFONT_FixupFlags( fr->lfFaceName );
1370 for( fi = fr->fi ; fi ; fi = fi->next )
1371 fi->df.dfPitchAndFamily |= bFamilyStyle;
1375 TRACE("typeface '%s'\n", fr->lfFaceName);
1377 fr->fr_flags |= FR_NAMESET;
1381 /***********************************************************************
1382 * XFONT_LoadDefaultLFD
1384 * Move lfd to the head of fontList to make it more likely to be matched
1386 static void XFONT_LoadDefaultLFD(LFD* lfd, LPCSTR fonttype)
1389 fontResource *fr, *pfr;
1390 for( fr = NULL, pfr = fontList; pfr; pfr = pfr->next )
1392 if( XFONT_SameFoundryAndFamily(pfr->resource, lfd) )
1396 fr->next = pfr->next;
1397 pfr->next = fontList;
1405 WARN("Default %sfont '-%s-%s-' not available\n", fonttype,
1406 lfd->foundry, lfd->family);
1410 /***********************************************************************
1413 static void XFONT_LoadDefault(LPCSTR ini, LPCSTR fonttype)
1415 char buffer[MAX_LFD_LENGTH];
1419 if(!RegOpenKeyA(HKEY_LOCAL_MACHINE, INIFontSection, &hkey))
1421 DWORD type, count = sizeof(buffer);
1422 RegQueryValueExA(hkey, ini, 0, &type, buffer, &count);
1429 while( *pch && isspace(*pch) ) pch++;
1431 TRACE("Using '%s' as default %sfont\n", pch, fonttype);
1432 lfd = LFD_Parse(pch);
1433 if (lfd && lfd->foundry && lfd->family)
1434 XFONT_LoadDefaultLFD(lfd, fonttype);
1436 WARN("Ini section [%s]%s is malformed\n", INIFontSection, ini);
1437 HeapFree(GetProcessHeap(), 0, lfd);
1442 /***********************************************************************
1443 * XFONT_LoadDefaults
1445 static void XFONT_LoadDefaults(void)
1447 XFONT_LoadDefault(INIDefaultFixed, "fixed ");
1448 XFONT_LoadDefault(INIDefault, "");
1451 /***********************************************************************
1454 static fontAlias* XFONT_CreateAlias( LPCSTR lpTypeFace, LPCSTR lpAlias )
1457 fontAlias *pfa, *prev = NULL;
1459 for(pfa = aliasTable; pfa; pfa = pfa->next)
1461 /* check if we already got one */
1462 if( !strcasecmp( pfa->faTypeFace, lpAlias ) )
1464 TRACE("redundant alias '%s' -> '%s'\n",
1465 lpAlias, lpTypeFace );
1471 j = strlen(lpTypeFace) + 1;
1472 pfa = HeapAlloc( GetProcessHeap(), 0, sizeof(fontAlias) +
1473 j + strlen(lpAlias) + 1 );
1482 pfa->faTypeFace = (LPSTR)(pfa + 1);
1483 strcpy( pfa->faTypeFace, lpTypeFace );
1484 pfa->faAlias = pfa->faTypeFace + j;
1485 strcpy( pfa->faAlias, lpAlias );
1487 TRACE("added alias '%s' for '%s'\n", lpAlias, lpTypeFace );
1495 /***********************************************************************
1498 static void XFONT_LoadAlias(const LFD* lfd, LPCSTR lpAlias, BOOL bSubst)
1500 fontResource *fr, *frMatch = NULL;
1501 if (!lfd->foundry || ! lfd->family)
1503 WARN("Malformed font resource for alias '%s'\n", lpAlias);
1506 for (fr = fontList; fr ; fr = fr->next)
1508 if(!strcasecmp(fr->resource->family, lpAlias))
1510 /* alias is not needed since the real font is present */
1511 TRACE("Ignoring font alias '%s' as it is already available as a real font\n", lpAlias);
1514 if( XFONT_SameFoundryAndFamily( fr->resource, lfd ) )
1525 fontAlias *pfa, *prev = NULL;
1527 for(pfa = aliasTable; pfa; pfa = pfa->next)
1529 /* Remove lpAlias from aliasTable - we should free the old entry */
1530 if(!strcmp(lpAlias, pfa->faAlias))
1533 prev->next = pfa->next;
1535 aliasTable = pfa->next;
1538 /* Update any references to the substituted font in aliasTable */
1539 if(!strcmp(frMatch->lfFaceName, pfa->faTypeFace))
1541 pfa->faTypeFace = HeapAlloc( GetProcessHeap(), 0, strlen(lpAlias)+1 );
1542 strcpy( pfa->faTypeFace, lpAlias );
1547 TRACE("\tsubstituted '%s' with '%s'\n", frMatch->lfFaceName, lpAlias );
1549 lstrcpynA( frMatch->lfFaceName, lpAlias, LF_FACESIZE );
1550 frMatch->fr_flags |= FR_NAMESET;
1554 /* create new entry in the alias table */
1555 XFONT_CreateAlias( frMatch->lfFaceName, lpAlias );
1560 WARN("Font alias '-%s-%s-' is not available\n", lfd->foundry, lfd->family);
1564 /***********************************************************************
1565 * Just a copy of PROFILE_GetStringItem
1567 * Convenience function that turns a string 'xxx, yyy, zzz' into
1568 * the 'xxx\0 yyy, zzz' and returns a pointer to the 'yyy, zzz'.
1570 static char *XFONT_GetStringItem( char *start )
1572 #define XFONT_isspace(c) (isspace(c) || (c == '\r') || (c == 0x1a))
1575 for (lpchX = start, lpch = NULL; *lpchX != '\0'; lpchX++ )
1579 if( lpch ) *lpch = '\0'; else *lpchX = '\0';
1581 if( !XFONT_isspace(*lpchX) ) return lpchX;
1583 else if( XFONT_isspace( *lpchX ) && !lpch ) lpch = lpchX;
1586 if( lpch ) *lpch = '\0';
1588 #undef XFONT_isspace
1591 /***********************************************************************
1596 * Create font aliases for some standard windows fonts using user's
1597 * default choice of (sans-)serif fonts
1599 * Read user-defined aliases from wine.conf. Format is as follows
1601 * Alias# = [Windows font name],[LFD font name], <substitute original name>
1604 * Alias0 = Arial, -adobe-helvetica-
1605 * Alias1 = Times New Roman, -bitstream-courier-, 1
1608 * Note that from 970817 and on we have built-in alias templates that take
1609 * care of the necessary Windows typefaces.
1617 static void XFONT_LoadAliases(void)
1620 char buffer[MAX_LFD_LENGTH];
1625 /* built-ins first */
1626 strcpy(buffer, "-bitstream-charter-");
1627 if(!RegOpenKeyA(HKEY_LOCAL_MACHINE, INIFontSection, &hkey))
1629 DWORD type, count = sizeof(buffer);
1630 RegQueryValueExA(hkey, INIDefaultSerif, 0, &type, buffer, &count);
1633 TRACE("Using '%s' as default serif font\n", buffer);
1634 lfd = LFD_Parse(buffer);
1635 /* NB XFONT_InitialCapitals should not change these standard aliases */
1638 XFONT_LoadAlias( lfd, "Tms Roman", FALSE);
1639 XFONT_LoadAlias( lfd, "MS Serif", FALSE);
1640 XFONT_LoadAlias( lfd, "Times New Roman", FALSE);
1642 XFONT_LoadDefaultLFD( lfd, "serif ");
1643 HeapFree(GetProcessHeap(), 0, lfd);
1646 strcpy(buffer, "-adobe-helvetica-");
1647 if(!RegOpenKeyA(HKEY_LOCAL_MACHINE, INIFontSection, &hkey))
1649 DWORD type, count = sizeof(buffer);
1650 RegQueryValueExA(hkey, INIDefaultSansSerif, 0, &type, buffer, &count);
1653 TRACE("Using '%s' as default sans serif font\n", buffer);
1654 lfd = LFD_Parse(buffer);
1657 XFONT_LoadAlias( lfd, "Helv", FALSE);
1658 XFONT_LoadAlias( lfd, "MS Sans Serif", FALSE);
1659 XFONT_LoadAlias( lfd, "MS Shell Dlg", FALSE);
1660 XFONT_LoadAlias( lfd, "System", FALSE);
1661 XFONT_LoadAlias( lfd, "Arial", FALSE);
1663 XFONT_LoadDefaultLFD( lfd, "sans serif ");
1664 HeapFree(GetProcessHeap(), 0, lfd);
1667 /* then user specified aliases */
1671 char subsection[32];
1672 snprintf( subsection, sizeof subsection, "%s%i", INIAliasSection, i++ );
1675 if(!RegOpenKeyA(HKEY_LOCAL_MACHINE, INIFontSection, &hkey))
1677 DWORD type, count = sizeof(buffer);
1678 RegQueryValueExA(hkey, subsection, 0, &type, buffer, &count);
1685 XFONT_InitialCapitals(buffer);
1686 lpResource = XFONT_GetStringItem( buffer );
1687 bSubst = (XFONT_GetStringItem( lpResource )) ? TRUE : FALSE;
1688 if( lpResource && *lpResource )
1690 lfd = LFD_Parse(lpResource);
1693 XFONT_LoadAlias(lfd, buffer, bSubst);
1694 HeapFree(GetProcessHeap(), 0, lfd);
1698 WARN("malformed font alias '%s'\n", buffer );
1703 /***********************************************************************
1706 * Convert an (potential) alias into a real windows name
1709 static LPCSTR XFONT_UnAlias(char* font)
1714 XFONT_InitialCapitals(font); /* to remove extra white space */
1716 for( fa = aliasTable; fa; fa = fa->next )
1717 /* use case insensitive matching to handle eg "MS Sans Serif" */
1718 if( !strcasecmp( fa->faAlias, font ) )
1720 TRACE("found alias '%s'->%s'\n", font, fa->faTypeFace );
1721 strcpy(font, fa->faTypeFace);
1729 /***********************************************************************
1730 * XFONT_RemoveFontResource
1732 * Caller should check if the font resource is in use. If it is it should
1733 * set FR_REMOVED flag to delay removal until the resource is not in use
1736 void XFONT_RemoveFontResource( fontResource** ppfr )
1738 fontResource* pfr = *ppfr;
1742 /* FIXME - if fonts were read from a cache, these HeapFrees will fail */
1745 pfi = pfr->fi->next;
1746 HeapFree( GetProcessHeap(), 0, pfr->fi );
1749 HeapFree( GetProcessHeap(), 0, pfr );
1754 /***********************************************************************
1759 * Removes specified fonts from the font table to prevent Wine from
1762 * Ignore# = [LFD font name]
1765 * Ignore0 = -misc-nil-
1766 * Ignore1 = -sun-open look glyph-
1770 static void XFONT_LoadIgnore(char* lfdname)
1772 fontResource** ppfr;
1774 LFD* lfd = LFD_Parse(lfdname);
1775 if (lfd && lfd->foundry && lfd->family)
1777 for( ppfr = &fontList; *ppfr ; ppfr = &((*ppfr)->next))
1779 if( XFONT_SameFoundryAndFamily( (*ppfr)->resource, lfd) )
1781 TRACE("Ignoring '-%s-%s-'\n",
1782 (*ppfr)->resource->foundry, (*ppfr)->resource->family );
1784 XFONT_RemoveFontResource( ppfr );
1790 WARN("Malformed font resource\n");
1792 HeapFree(GetProcessHeap(), 0, lfd);
1795 static void XFONT_LoadIgnores(void)
1798 char subsection[32];
1799 char buffer[MAX_LFD_LENGTH];
1801 /* Standard one that noone wants */
1802 strcpy(buffer, "-misc-nil-");
1803 XFONT_LoadIgnore(buffer);
1805 /* Others from INI file */
1809 sprintf( subsection, "%s%i", INIIgnoreSection, i++ );
1812 if(!RegOpenKeyA(HKEY_LOCAL_MACHINE, INIFontSection, &hkey))
1814 DWORD type, count = sizeof(buffer);
1815 RegQueryValueExA(hkey, subsection, 0, &type, buffer, &count);
1822 while( *pch && isspace(*pch) ) pch++;
1823 XFONT_LoadIgnore(pch);
1831 /***********************************************************************
1832 * XFONT_UserMetricsCache
1834 * Returns expanded name for the cachedmetrics file.
1835 * Now it also appends the current value of the $DISPLAY variable.
1837 static char* XFONT_UserMetricsCache( char* buffer, int* buf_size )
1839 const char *confdir = get_config_dir();
1840 const char *display_name = XDisplayName(NULL);
1841 int len = strlen(confdir) + strlen(INIFontMetrics) + strlen(display_name) + 8;
1847 ** Normalize the display name, since on Red Hat systems, DISPLAY
1848 ** is commonly set to one of either 'unix:0.0' or ':0' or ':0.0'.
1849 ** after this code, all of the above will resolve to ':0.0'.
1851 if (!strncmp( display_name, "unix:", 5 )) display_name += 4;
1852 p = strchr(display_name, ':');
1853 if (p) sscanf(p + 1, "%d.%d", &display, &screen);
1855 if ((len > *buf_size) &&
1856 !(buffer = HeapReAlloc( GetProcessHeap(), 0, buffer, *buf_size = len )))
1858 ERR("out of memory\n");
1861 sprintf( buffer, "%s/%s", confdir, INIFontMetrics );
1863 ext = buffer + strlen(buffer);
1864 strcpy( ext, display_name );
1866 if (!(p = strchr( ext, ':' ))) p = ext + strlen(ext);
1867 sprintf( p, ":%d.%d", display, screen );
1872 /***********************************************************************
1875 * Compare two fonts (only parameters set by the XFONT_InitFontInfo()).
1877 static INT XFONT_IsSubset(const fontInfo* match, const fontInfo* fi)
1881 /* 0 - keep both, 1 - keep match, -1 - keep fi */
1883 /* Compare dfItalic, Underline, Strikeout, Weight, Charset */
1884 m = (BYTE*)&fi->df.dfPixWidth - (BYTE*)&fi->df.dfItalic;
1885 if( memcmp(&match->df.dfItalic, &fi->df.dfItalic, m )) return 0;
1887 if( (!((fi->fi_flags & FI_SCALABLE) + (match->fi_flags & FI_SCALABLE))
1888 && fi->lfd_height != match->lfd_height) ||
1889 (!((fi->fi_flags & FI_POLYWEIGHT) + (match->fi_flags & FI_POLYWEIGHT))
1890 && fi->df.dfWeight != match->df.dfWeight) ) return 0;
1892 m = (int)(match->fi_flags & (FI_POLYWEIGHT | FI_SCALABLE)) -
1893 (int)(fi->fi_flags & (FI_SCALABLE | FI_POLYWEIGHT));
1895 if( m == (FI_POLYWEIGHT - FI_SCALABLE) ||
1896 m == (FI_SCALABLE - FI_POLYWEIGHT) ) return 0; /* keep both */
1897 else if( m >= 0 ) return 1; /* 'match' is better */
1899 return -1; /* 'fi' is better */
1902 /***********************************************************************
1905 * REMOVE_SUBSETS - attach new fi and purge subsets
1906 * UNMARK_SUBSETS - remove subset flags from all fi entries
1908 static void XFONT_CheckFIList( fontResource* fr, fontInfo* fi, int action)
1911 fontInfo* pfi, *prev;
1913 for( prev = NULL, pfi = fr->fi; pfi; )
1915 if( action == REMOVE_SUBSETS )
1917 if( pfi->fi_flags & FI_SUBSET )
1919 fontInfo* subset = pfi;
1923 if( prev ) prev->next = pfi = pfi->next;
1924 else fr->fi = pfi = pfi->next;
1925 HeapFree( GetProcessHeap(), 0, subset );
1929 else pfi->fi_flags &= ~FI_SUBSET;
1935 if( action == REMOVE_SUBSETS ) /* also add the superset */
1937 if( fi->fi_flags & FI_SCALABLE )
1942 else if( prev ) prev->next = fi; else fr->fi = fi;
1946 if( i ) TRACE("\t purged %i subsets [%i]\n", i , fr->fi_count);
1949 /***********************************************************************
1952 static fontResource* XFONT_FindFIList( fontResource* pfr, const char* pTypeFace )
1956 if( !strcasecmp( pfr->lfFaceName, pTypeFace ) ) break;
1959 /* Give the app back the font name it asked for. Encarta checks this. */
1960 if (pfr) strcpy(pfr->lfFaceName,pTypeFace);
1964 /***********************************************************************
1965 * XFONT_FixupPointSize
1967 static void XFONT_FixupPointSize(fontInfo* fi)
1970 df.dfHorizRes = df.dfVertRes = fi->lfd_resolution;
1971 df.dfPoints = (INT16)
1972 (((INT)(df.dfPixHeight - df.dfInternalLeading) * 72 + (df.dfVertRes >> 1)) /
1977 /***********************************************************************
1978 * XFONT_BuildMetrics
1980 * Build font metrics from X font
1982 static int XFONT_BuildMetrics(char** x_pattern, int res, unsigned x_checksum, int x_count)
1985 fontInfo* fi = NULL;
1986 fontResource* fr, *pfr;
1989 MESSAGE("Building font metrics. This may take some time...\n");
1990 for( i = 0; i < x_count; i++ )
1995 char buffer[MAX_LFD_LENGTH];
2000 if (!(typeface = HeapAlloc(GetProcessHeap(), 0, strlen(x_pattern[i])+1))) break;
2001 strcpy( typeface, x_pattern[i] );
2003 lfd = LFD_Parse(typeface);
2006 HeapFree(GetProcessHeap(), 0, typeface);
2010 /* find a family to insert into */
2012 for( pfr = NULL, fr = fontList; fr; fr = fr->next )
2014 if( XFONT_SameFoundryAndFamily(fr->resource, lfd))
2019 if( !fi ) fi = (fontInfo*) HeapAlloc(GetProcessHeap(), 0, sizeof(fontInfo));
2021 if( !LFD_InitFontInfo( fi, lfd, x_pattern[i]) )
2024 if( !fr ) /* add new family */
2027 fr = (fontResource*) HeapAlloc(GetProcessHeap(), 0, sizeof(fontResource));
2030 memset(fr, 0, sizeof(fontResource));
2032 fr->resource = (LFD*) HeapAlloc(GetProcessHeap(), 0, sizeof(LFD));
2033 memset(fr->resource, 0, sizeof(LFD));
2035 TRACE("family: -%s-%s-\n", lfd->foundry, lfd->family );
2036 fr->resource->foundry = HeapAlloc(GetProcessHeap(), 0, strlen(lfd->foundry)+1);
2037 strcpy( (char *)fr->resource->foundry, lfd->foundry );
2038 fr->resource->family = HeapAlloc(GetProcessHeap(), 0, strlen(lfd->family)+1);
2039 strcpy( (char *)fr->resource->family, lfd->family );
2040 fr->resource->weight = "";
2042 if( pfr ) pfr->next = fr;
2046 WARN("Not enough memory for a new font family\n");
2049 /* check if we already have something better than "fi" */
2051 for( pfi = fr->fi, j = 0; pfi && j <= 0; pfi = pfi->next )
2052 if( (j = XFONT_IsSubset( pfi, fi )) < 0 )
2053 pfi->fi_flags |= FI_SUBSET; /* superseded by "fi" */
2054 if( j > 0 ) goto nextfont;
2056 /* add new font instance "fi" to the "fr" font resource */
2058 if( fi->fi_flags & FI_SCALABLE )
2061 char pxl_string[4], res_string[4];
2062 /* set scalable font height to get an basis for extrapolation */
2064 fi->lfd_height = DEF_SCALABLE_HEIGHT;
2065 fi->lfd_resolution = res;
2067 sprintf(pxl_string, "%d", fi->lfd_height);
2068 sprintf(res_string, "%d", fi->lfd_resolution);
2071 lfd1.pixel_size = pxl_string;
2072 lfd1.point_size = "*";
2073 lfd1.resolution_x = res_string;
2074 lfd1.resolution_y = res_string;
2076 LFD_UnParse(buffer, sizeof buffer, &lfd1);
2080 else lpstr = x_pattern[i];
2082 if( (x_fs = TSXLoadQueryFont(gdi_display, lpstr)) )
2084 XFONT_SetFontMetric( fi, fr, x_fs );
2085 TSXFreeFont( gdi_display, x_fs );
2087 XFONT_FixupPointSize(fi);
2089 TRACE("\t[% 2ipt] '%s'\n", fi->df.dfPoints, x_pattern[i] );
2091 XFONT_CheckFIList( fr, fi, REMOVE_SUBSETS );
2092 fi = NULL; /* preventing reuse */
2096 ERR("failed to load %s\n", lpstr );
2098 XFONT_CheckFIList( fr, fi, UNMARK_SUBSETS );
2101 HeapFree(GetProcessHeap(), 0, lfd);
2102 HeapFree(GetProcessHeap(), 0, typeface);
2104 if( fi ) HeapFree(GetProcessHeap(), 0, fi);
2106 /* Scan through the font list and remove FontResource(s) (fr)
2107 * that have no associated Fontinfo(s) (fi).
2108 * This code is necessary because XFONT_ReadCachedMetrics
2109 * assumes that there is at least one fi associated with a fr.
2110 * This assumption is invalid for TT font
2111 * -altsys-ms outlook-medium-r-normal--0-0-0-0-p-0-microsoft-symbol.
2116 while (!fr->fi_count)
2118 fontList = fr->next;
2120 HeapFree(GetProcessHeap(), 0, fr->resource);
2121 HeapFree(GetProcessHeap(), 0, fr);
2131 if (!fr->next->fi_count)
2134 fr->next = fr->next->next;
2136 HeapFree(GetProcessHeap(), 0, pfr->resource);
2137 HeapFree(GetProcessHeap(), 0, pfr);
2148 /***********************************************************************
2149 * XFONT_ReadCachedMetrics
2153 static BOOL XFONT_ReadCachedMetrics( int fd, int res, unsigned x_checksum, int x_count )
2160 /* read checksums */
2161 read( fd, &u, sizeof(unsigned) );
2162 read( fd, &i, sizeof(int) );
2164 if( u == x_checksum && i == x_count )
2166 off_t length, offset = 3 * sizeof(int);
2168 /* read total size */
2169 read( fd, &i, sizeof(int) );
2170 length = lseek( fd, 0, SEEK_END );
2172 if( length == (i + offset) )
2174 lseek( fd, offset, SEEK_SET );
2175 fontList = (fontResource*)HeapAlloc( GetProcessHeap(), 0, i);
2178 fontResource* pfr = fontList;
2179 fontInfo* pfi = NULL;
2181 TRACE("Reading cached font metrics:\n");
2183 read( fd, fontList, i); /* read all metrics at once */
2184 while( offset < length )
2186 offset += sizeof(fontResource) + sizeof(fontInfo);
2187 pfr->fi = pfi = (fontInfo*)(pfr + 1);
2191 if( offset > length ||
2192 pfi->cptable >= (UINT16)X11DRV_CPTABLE_COUNT ||
2193 (int)(pfi->next) != j++ )
2195 TRACE("error: offset=%ld length=%ld cptable=%d pfi->next=%d j=%d\n",(long)offset,(long)length,pfi->cptable,(int)pfi->next,j-1);
2199 if( pfi->df.dfPixHeight == 0 )
2201 TRACE("error: dfPixHeight==0\n");
2205 pfi->df.dfFace = pfr->lfFaceName;
2206 if( pfi->fi_flags & FI_SCALABLE )
2208 /* we can pretend we got this font for any resolution */
2209 pfi->lfd_resolution = res;
2210 XFONT_FixupPointSize(pfi);
2212 pfi->next = pfi + 1;
2214 if( j > pfr->fi_count ) break;
2217 offset += sizeof(fontInfo);
2222 pfr->next = (fontResource*)(pfi + 1);
2227 if( pfr->next == NULL &&
2228 *(int*)(pfi + 1) == X_FMC_MAGIC )
2230 /* read LFD stubs */
2231 char* lpch = (char*)((int*)(pfi + 1) + 1);
2232 offset += sizeof(int);
2233 for( pfr = fontList; pfr; pfr = pfr->next )
2235 size_t len = strlen(lpch) + 1;
2236 TRACE("\t%s, %i instances\n", lpch, pfr->fi_count );
2237 pfr->resource = LFD_Parse(lpch);
2240 if (offset > length)
2242 TRACE("error: offset=%ld length=%ld\n",(long)offset,(long)length);
2251 TRACE("Wrong length: %ld!=%ld\n",(long)length,(long)(i+offset));
2254 TRACE("Checksum (%x vs. %x) or count (%d vs. %d) mismatch\n",
2255 u,x_checksum,i,x_count);
2258 if( fontList ) HeapFree( GetProcessHeap(), 0, fontList );
2265 /***********************************************************************
2266 * XFONT_WriteCachedMetrics
2270 static BOOL XFONT_WriteCachedMetrics( int fd, unsigned x_checksum, int x_count, int n_ff )
2278 char buffer[MAX_LFD_LENGTH];
2280 /* font metrics file:
2284 * +0008 total size to load
2285 * +000C prepackaged font metrics
2288 * +...x + 4 LFD stubs
2291 write( fd, &x_checksum, sizeof(unsigned) );
2292 write( fd, &x_count, sizeof(int) );
2294 for( j = i = 0, pfr = fontList; pfr; pfr = pfr->next )
2296 LFD_UnParse(buffer, sizeof buffer, pfr->resource);
2297 i += strlen( buffer) + 1;
2300 i += n_ff * sizeof(fontResource) + j * sizeof(fontInfo) + sizeof(int);
2301 write( fd, &i, sizeof(int) );
2303 TRACE("Writing font cache:\n");
2305 for( pfr = fontList; pfr; pfr = pfr->next )
2309 TRACE("\t-%s-%s-, %i instances\n", pfr->resource->foundry, pfr->resource->family, pfr->fi_count );
2311 i = write( fd, pfr, sizeof(fontResource) );
2312 if( i == sizeof(fontResource) )
2314 for( k = 1, pfi = pfr->fi; pfi; pfi = pfi->next )
2318 fi.df.dfFace = NULL;
2319 fi.next = (fontInfo*)k; /* loader checks this */
2321 j = write( fd, &fi, sizeof(fi) );
2324 if( j == sizeof(fontInfo) ) continue;
2328 if( i == sizeof(fontResource) && j == sizeof(fontInfo) )
2330 i = j = X_FMC_MAGIC;
2331 write( fd, &i, sizeof(int) );
2332 for( pfr = fontList; pfr && i == j; pfr = pfr->next )
2334 LFD_UnParse(buffer, sizeof buffer, pfr->resource);
2335 i = strlen( buffer ) + 1;
2336 j = write( fd, buffer, i );
2345 /***********************************************************************
2346 * XFONT_GetPointResolution()
2350 * Here we initialize DefResolution which is used in the
2351 * XFONT_Match() penalty function. We also load the point
2352 * resolution value (higher values result in larger fonts).
2354 static int XFONT_GetPointResolution( int *log_pixels_x, int *log_pixels_y )
2356 int i, j, point_resolution, num = 3;
2357 int allowed_xfont_resolutions[3] = { 72, 75, 100 };
2358 int best = 0, best_diff = 65536;
2361 point_resolution = 0;
2363 if(!RegOpenKeyA(HKEY_LOCAL_MACHINE, INIFontSection, &hkey))
2366 DWORD type, count = sizeof(buffer);
2367 if(!RegQueryValueExA(hkey, INIResolution, 0, &type, buffer, &count))
2368 point_resolution = atoi(buffer);
2372 if( !point_resolution )
2373 point_resolution = *log_pixels_y;
2375 *log_pixels_x = *log_pixels_y = point_resolution;
2378 /* FIXME We can only really guess at a best DefResolution
2379 * - this should be configurable
2381 for( i = best = 0; i < num; i++ )
2383 j = abs( point_resolution - allowed_xfont_resolutions[i] );
2390 DefResolution = allowed_xfont_resolutions[best];
2391 return point_resolution;
2395 /***********************************************************************
2398 * Compute the matching score between the logical font and the device font.
2400 * contributions from highest to lowest:
2404 * family flags (only when the facename is not present)
2406 * weight, italics, underlines, strikeouts
2408 * NOTE: you can experiment with different penalty weights to see what happens.
2409 * http://premium.microsoft.com/msdn/library/techart/f365/f36b/f37b/d38b/sa8bf.htm
2411 static UINT XFONT_Match( fontMatch* pfm )
2413 fontInfo* pfi = pfm->pfi; /* device font to match */
2414 LPLOGFONT16 plf = pfm->plf; /* wanted logical font */
2416 BOOL bR6 = pfm->flags & FO_MATCH_XYINDEP; /* from TextCaps */
2417 BOOL bScale = pfi->fi_flags & FI_SCALABLE;
2420 TRACE("\t[ %-2ipt h=%-3i w=%-3i %s%s]\n", pfi->df.dfPoints,
2421 pfi->df.dfPixHeight, pfi->df.dfAvgWidth,
2422 (pfi->df.dfWeight > FW_NORMAL) ? "Bold " : "Normal ",
2423 (pfi->df.dfItalic) ? "Italic" : "" );
2425 pfm->flags &= FO_MATCH_MASK;
2428 /* pfm->internal_charset: given(required) charset */
2429 /* pfi->internal_charset: charset of this font */
2430 if (pfi->internal_charset == DEFAULT_CHARSET)
2432 /* special case(unicode font) */
2433 /* priority: unmatched charset < unicode < matched charset */
2438 if( pfm->internal_charset == DEFAULT_CHARSET )
2441 if (pfi->internal_charset != ANSI_CHARSET)
2444 if ( pfi->codepage != GetACP() )
2447 else if (pfm->internal_charset != pfi->internal_charset)
2449 if ( pfi->internal_charset & 0xff00 )
2450 penalty += 0x1000; /* internal charset - should not be used */
2459 if( plf->lfHeight > 0 )
2461 int h = pfi->df.dfPixHeight;
2462 d = h - plf->lfHeight;
2463 height = plf->lfHeight;
2467 int h = pfi->df.dfPixHeight - pfi->df.dfInternalLeading;
2470 d = h + plf->lfHeight;
2471 height = (-plf->lfHeight * pfi->df.dfPixHeight) / h;
2475 ERR("PixHeight == InternalLeading\n");
2476 penalty += 0x1000; /* dont want this */
2482 pfm->height = 1; /* Very small */
2486 pfm->height = height;
2487 else if( (plf->lfQuality != PROOF_QUALITY) && bR6 )
2489 if( d > 0 ) /* do not shrink raster fonts */
2491 pfm->height = pfi->df.dfPixHeight;
2492 penalty += (pfi->df.dfPixHeight - height) * 0x4;
2494 else /* expand only in integer multiples */
2496 pfm->height = height - height%pfi->df.dfPixHeight;
2497 penalty += (height - pfm->height + 1) * height / pfi->df.dfPixHeight;
2500 else /* can't be scaled at all */
2502 if( plf->lfQuality != PROOF_QUALITY) pfm->flags |= FO_SYNTH_HEIGHT;
2503 pfm->height = pfi->df.dfPixHeight;
2504 penalty += (d > 0)? d * 0x8 : -d * 0x10;
2508 pfm->height = pfi->df.dfPixHeight;
2510 /* Pitch and Family */
2511 if( pfm->flags & FO_MATCH_PAF ) {
2512 int family = plf->lfPitchAndFamily & FF_FAMILY;
2514 /* TMPF_FIXED_PITCH means exactly the opposite */
2515 if( plf->lfPitchAndFamily & FIXED_PITCH ) {
2516 if( pfi->df.dfPitchAndFamily & TMPF_FIXED_PITCH ) penalty += 0x100;
2517 } else /* Variable is the default */
2518 if( !(pfi->df.dfPitchAndFamily & TMPF_FIXED_PITCH) ) penalty += 0x2;
2520 if (family != FF_DONTCARE && family != (pfi->df.dfPitchAndFamily & FF_FAMILY) )
2528 if( bR6 || bScale ) h = 0;
2531 /* FIXME: not complete */
2533 pfm->flags |= FO_SYNTH_WIDTH;
2534 h = abs(plf->lfWidth - (pfm->height * pfi->df.dfAvgWidth)/pfi->df.dfPixHeight);
2536 penalty += h * ( d ) ? 0x2 : 0x1 ;
2538 else if( !(pfi->fi_flags & FI_NORMAL) ) penalty++;
2541 if( plf->lfWeight != FW_DONTCARE )
2543 penalty += abs(plf->lfWeight - pfi->df.dfWeight) / 40;
2544 if( plf->lfWeight > pfi->df.dfWeight ) pfm->flags |= FO_SYNTH_BOLD;
2545 } else if( pfi->df.dfWeight >= FW_BOLD ) penalty++; /* choose normal by default */
2548 if( plf->lfItalic != pfi->df.dfItalic )
2551 pfm->flags |= FO_SYNTH_ITALIC;
2554 if( plf->lfUnderline ) pfm->flags |= FO_SYNTH_UNDERLINE;
2557 if( plf->lfStrikeOut ) pfm->flags |= FO_SYNTH_STRIKEOUT;
2560 if( penalty && !bScale && pfi->lfd_resolution != DefResolution )
2563 TRACE(" returning %i\n", penalty );
2568 /***********************************************************************
2571 * Scan a particular font resource for the best match.
2573 static UINT XFONT_MatchFIList( fontMatch* pfm )
2575 BOOL skipRaster = (pfm->flags & FO_MATCH_NORASTER);
2576 UINT current_score, score = (UINT)(-1);
2577 fontMatch fm = *pfm;
2579 for( fm.pfi = pfm->pfr->fi; fm.pfi && score; fm.pfi = fm.pfi->next)
2581 if( skipRaster && !(fm.pfi->fi_flags & FI_SCALABLE) )
2584 current_score = XFONT_Match( &fm );
2585 if( score > current_score )
2588 score = current_score;
2594 /***********************************************************************
2595 * XFONT_MatchDeviceFont
2597 * Scan font resource tree.
2600 static void XFONT_MatchDeviceFont( fontResource* start, fontMatch* pfm)
2602 fontMatch fm = *pfm;
2603 UINT current_score, score = (UINT)(-1);
2604 fontResource** ppfr;
2606 TRACE("(%u) '%s' h=%i weight=%i %s\n",
2607 pfm->plf->lfCharSet, pfm->plf->lfFaceName, pfm->plf->lfHeight,
2608 pfm->plf->lfWeight, (pfm->plf->lfItalic) ? "Italic" : "" );
2611 if( fm.plf->lfFaceName[0] )
2613 fm.pfr = XFONT_FindFIList( start, fm.plf->lfFaceName);
2614 if( fm.pfr ) /* match family */
2616 TRACE("found facename '%s'\n", fm.pfr->lfFaceName );
2618 if( fm.pfr->fr_flags & FR_REMOVED )
2622 XFONT_MatchFIList( &fm );
2629 /* get charset if lfFaceName is one of known facenames. */
2631 const struct CharsetBindingInfo* pcharsetbindings;
2633 pcharsetbindings = &charsetbindings[0];
2634 while ( pcharsetbindings->pszFaceName != NULL )
2636 if ( !strcmp( pcharsetbindings->pszFaceName,
2637 fm.plf->lfFaceName ) )
2639 fm.internal_charset = pcharsetbindings->charset;
2642 pcharsetbindings ++;
2644 TRACE( "%s charset %u\n", fm.plf->lfFaceName, fm.internal_charset );
2648 /* match all available fonts */
2650 fm.flags |= FO_MATCH_PAF;
2651 for( ppfr = &fontList; *ppfr && score; ppfr = &(*ppfr)->next )
2653 if( (*ppfr)->fr_flags & FR_REMOVED )
2655 if( (*ppfr)->fo_count == 0 )
2656 XFONT_RemoveFontResource( ppfr );
2662 TRACE("%s\n", fm.pfr->lfFaceName );
2664 current_score = XFONT_MatchFIList( &fm );
2665 if( current_score < score )
2667 score = current_score;
2674 /***********************************************************************
2677 static void XFONT_GrowFreeList(int start, int end)
2679 /* add all entries from 'start' up to and including 'end' */
2681 memset( fontCache + start, 0, (end - start + 1) * sizeof(fontObject) );
2683 fontCache[end].lru = fontLF;
2684 fontCache[end].count = -1;
2686 while( start < end )
2688 fontCache[start].count = -1;
2689 fontCache[start].lru = start + 1;
2694 static fontObject* XFONT_LookupCachedFont( const LPLOGFONT16 plf, UINT16* checksum )
2696 UINT16 cs = __lfCheckSum( plf );
2697 int i = fontMRU, prev = -1;
2702 if( fontCache[i].lfchecksum == cs &&
2703 !(fontCache[i].fo_flags & FO_REMOVED) )
2705 /* FIXME: something more intelligent here ? */
2707 if( !memcmp( plf, &fontCache[i].lf,
2708 sizeof(LOGFONT16) - LF_FACESIZE ) &&
2709 !strcmp( plf->lfFaceName, fontCache[i].lf.lfFaceName) )
2711 /* remove temporarily from the lru list */
2713 fontCache[prev].lru = fontCache[i].lru;
2715 fontMRU = (INT16)fontCache[i].lru;
2716 return (fontCache + i);
2720 i = (INT16)fontCache[i].lru;
2725 static fontObject* XFONT_GetCacheEntry(void)
2731 int prev_i, prev_j, j;
2733 TRACE("font cache is full\n");
2735 /* lookup the least recently used font */
2737 for( prev_i = prev_j = j = -1, i = fontMRU; i >= 0; i = (INT16)fontCache[i].lru )
2739 if( fontCache[i].count <= 0 &&
2740 !(fontCache[i].fo_flags & FO_SYSTEM) )
2748 if( j >= 0 ) /* unload font */
2750 /* detach from the lru list */
2752 TRACE("\tfreeing entry %i\n", j );
2754 fontCache[j].fr->fo_count--;
2757 fontCache[prev_j].lru = fontCache[j].lru;
2758 else fontMRU = (INT16)fontCache[j].lru;
2760 /* FIXME: lpXForm, lpPixmap */
2761 if(fontCache[j].lpX11Trans)
2762 HeapFree( GetProcessHeap(), 0, fontCache[j].lpX11Trans );
2764 TSXFreeFont( gdi_display, fontCache[j].fs );
2766 memset( fontCache + j, 0, sizeof(fontObject) );
2767 return (fontCache + j);
2769 else /* expand cache */
2771 fontObject* newCache;
2773 prev_i = fontCacheSize + FONTCACHE;
2775 TRACE("\tgrowing font cache from %i to %i\n", fontCacheSize, prev_i );
2777 if( (newCache = (fontObject*)HeapReAlloc(GetProcessHeap(), 0,
2778 fontCache, prev_i)) )
2781 fontCacheSize = prev_i;
2782 fontCache = newCache;
2783 XFONT_GrowFreeList( i, fontCacheSize - 1);
2789 /* detach from the free list */
2792 fontLF = (INT16)fontCache[i].lru;
2793 fontCache[i].count = 0;
2794 return (fontCache + i);
2797 static int XFONT_ReleaseCacheEntry(const fontObject* pfo)
2799 UINT u = (UINT)(pfo - fontCache);
2803 if( u < fontCacheSize )
2805 ret = --fontCache[u].count;
2808 for ( i = 0; i < X11FONT_REFOBJS_MAX; i++ )
2810 if( CHECK_PFONT(pfo->prefobjs[i]) )
2811 XFONT_ReleaseCacheEntry(__PFONT(pfo->prefobjs[i]));
2821 /***********************************************************************
2824 * Initialize font resource list and allocate font cache.
2826 int X11DRV_FONT_Init( int *log_pixels_x, int *log_pixels_y )
2829 unsigned x_checksum;
2830 int i,res, x_count, fd, buf_size;
2834 res = XFONT_GetPointResolution( log_pixels_x, log_pixels_y );
2836 x_pattern = TSXListFonts(gdi_display, "*", MAX_FONTS, &x_count );
2838 TRACE("Font Mapper: initializing %i fonts [logical dpi=%i, default dpi=%i]\n",
2839 x_count, res, DefResolution);
2840 if (x_count == MAX_FONTS)
2841 MESSAGE("There may be more fonts available - try increasing the value of MAX_FONTS\n");
2843 for( i = x_checksum = 0; i < x_count; i++ )
2847 printf("%i\t: %s\n", i, x_pattern[i] );
2850 j = strlen( x_pattern[i] );
2851 if( j ) x_checksum ^= __genericCheckSum( x_pattern[i], j );
2853 x_checksum |= X_PFONT_MAGIC;
2855 buffer = HeapAlloc( GetProcessHeap(), 0, buf_size );
2857 /* deal with systemwide font metrics cache */
2860 if(!RegOpenKeyA(HKEY_LOCAL_MACHINE, INIFontSection, &hkey))
2862 DWORD type, count = buf_size;
2863 RegQueryValueExA(hkey, INIGlobalMetrics, 0, &type, buffer, &count);
2869 fd = open( buffer, O_RDONLY );
2870 XFONT_ReadCachedMetrics(fd, DefResolution, x_checksum, x_count);
2872 if (fontList == NULL)
2875 buffer = XFONT_UserMetricsCache( buffer, &buf_size );
2878 fd = open( buffer, O_RDONLY );
2879 XFONT_ReadCachedMetrics(fd, DefResolution, x_checksum, x_count);
2883 if( fontList == NULL ) /* build metrics from scratch */
2885 int n_ff = XFONT_BuildMetrics(x_pattern, DefResolution, x_checksum, x_count);
2886 if( buffer[0] ) /* update cached metrics */
2888 fd = open( buffer, O_CREAT | O_TRUNC | O_RDWR, 0644 ); /* -rw-r--r-- */
2889 if( XFONT_WriteCachedMetrics( fd, x_checksum, x_count, n_ff ) == FALSE )
2891 WARN("Unable to write to fontcache '%s'\n", buffer);
2892 if( fd >= 0) remove( buffer ); /* couldn't write entire file */
2897 TSXFreeFontNames(x_pattern);
2899 /* check if we're dealing with X11 R6 server */
2902 strcpy(buffer, "-*-*-*-*-normal-*-[12 0 0 12]-*-72-*-*-*-iso8859-1");
2903 if( (x_fs = TSXLoadQueryFont(gdi_display, buffer)) )
2905 XTextCaps |= TC_SF_X_YINDEP;
2906 TSXFreeFont(gdi_display, x_fs);
2909 HeapFree(GetProcessHeap(), 0, buffer);
2911 XFONT_WindowsNames();
2912 XFONT_LoadAliases();
2913 XFONT_LoadDefaults();
2914 XFONT_LoadIgnores();
2916 /* fontList initialization is over, allocate X font cache */
2918 fontCache = (fontObject*) HeapAlloc(GetProcessHeap(), 0, fontCacheSize * sizeof(fontObject));
2919 XFONT_GrowFreeList(0, fontCacheSize - 1);
2923 /* update text caps parameter */
2925 RAW_ASCENT = TSXInternAtom(gdi_display, "RAW_ASCENT", TRUE);
2926 RAW_DESCENT = TSXInternAtom(gdi_display, "RAW_DESCENT", TRUE);
2928 if(X11DRV_XRender_Installed)
2929 XTextCaps |= TC_VA_ABLE;
2934 /**********************************************************************
2937 static BOOL XFONT_SetX11Trans( fontObject *pfo )
2943 TSXGetFontProperty( pfo->fs, XA_FONT, &nameAtom );
2944 fontName = TSXGetAtomName( gdi_display, nameAtom );
2945 lfd = LFD_Parse(fontName);
2952 if (lfd->pixel_size[0] != '[') {
2953 HeapFree(GetProcessHeap(), 0, lfd);
2958 #define PX pfo->lpX11Trans
2960 sscanf(lfd->pixel_size, "[%f%f%f%f]", &PX->a, &PX->b, &PX->c, &PX->d);
2962 HeapFree(GetProcessHeap(), 0, lfd);
2964 TSXGetFontProperty( pfo->fs, RAW_ASCENT, &PX->RAW_ASCENT );
2965 TSXGetFontProperty( pfo->fs, RAW_DESCENT, &PX->RAW_DESCENT );
2967 PX->pixelsize = hypot(PX->a, PX->b);
2968 PX->ascent = PX->pixelsize / 1000.0 * PX->RAW_ASCENT;
2969 PX->descent = PX->pixelsize / 1000.0 * PX->RAW_DESCENT;
2971 TRACE("[%f %f %f %f] RA = %ld RD = %ld\n",
2972 PX->a, PX->b, PX->c, PX->d,
2973 PX->RAW_ASCENT, PX->RAW_DESCENT);
2979 /***********************************************************************
2980 * X Device Font Objects
2982 static X_PHYSFONT XFONT_RealizeFont( const LPLOGFONT16 plf,
2983 LPCSTR* faceMatched, BOOL bSubFont,
2984 WORD internal_charset,
2985 WORD* pcharsetMatched )
2991 pfo = XFONT_LookupCachedFont( plf, &checksum );
3002 fm.internal_charset = internal_charset;
3004 if( XTextCaps & TC_SF_X_YINDEP ) fm.flags = FO_MATCH_XYINDEP;
3006 /* allocate new font cache entry */
3008 if( (pfo = XFONT_GetCacheEntry()) )
3010 /* initialize entry and load font */
3011 char lpLFD[MAX_LFD_LENGTH];
3012 UINT uRelaxLevel = 0;
3014 if(abs(plf->lfHeight) > MAX_FONT_SIZE) {
3016 "plf->lfHeight = %d, Creating a 100 pixel font and rescaling metrics \n",
3018 pfo->rescale = fabs(plf->lfHeight / 100.0);
3019 if(plf->lfHeight > 0) plf->lfHeight = 100;
3020 else plf->lfHeight = -100;
3024 XFONT_MatchDeviceFont( fontList, &fm );
3027 pfo->fr->fo_count++;
3028 pfo->fo_flags = fm.flags & ~FO_MATCH_MASK;
3031 pfo->lfchecksum = checksum;
3035 LFD_ComposeLFD( pfo, fm.height, lpLFD, uRelaxLevel++ );
3036 if( (pfo->fs = TSXLoadQueryFont( gdi_display, lpLFD )) ) break;
3037 } while( uRelaxLevel );
3040 if(pfo->lf.lfEscapement != 0) {
3041 pfo->lpX11Trans = HeapAlloc(GetProcessHeap(), 0, sizeof(XFONTTRANS));
3042 if(!XFONT_SetX11Trans( pfo )) {
3043 HeapFree(GetProcessHeap(), 0, pfo->lpX11Trans);
3044 pfo->lpX11Trans = NULL;
3047 XFONT_GetLeading( &pfo->fi->df, pfo->fs,
3048 &pfo->foInternalLeading, NULL, pfo->lpX11Trans );
3049 pfo->foAvgCharWidth = (INT16)XFONT_GetAvgCharWidth(&pfo->fi->df, pfo->fs, pfo->lpX11Trans );
3050 pfo->foMaxCharWidth = (INT16)XFONT_GetMaxCharWidth(pfo->fs, pfo->lpX11Trans);
3052 /* FIXME: If we've got a soft font or
3053 * there are FO_SYNTH_... flags for the
3054 * non PROOF_QUALITY request, the engine
3055 * should rasterize characters into mono
3056 * pixmaps and store them in the pfo->lpPixmap
3057 * array (pfo->fs should be updated as well).
3058 * array (pfo->fs should be updated as well).
3059 * X11DRV_ExtTextOut() must be heavily modified
3060 * to support pixmap blitting and FO_SYNTH_...
3064 pfo->lpPixmap = NULL;
3066 for ( i = 0; i < X11FONT_REFOBJS_MAX; i++ )
3067 pfo->prefobjs[i] = (X_PHYSFONT)0xffffffff; /* invalid value */
3069 /* special treatment for DBCS that needs multiple fonts */
3070 /* All member of pfo must be set correctly. */
3071 if ( bSubFont == FALSE )
3074 WORD charsetMatchedSub;
3076 LPCSTR faceMatchedSub;
3078 for ( i = 0; i < X11FONT_REFOBJS_MAX; i++ )
3080 charset_sub = X11DRV_cptable[pfo->fi->cptable].
3081 penum_subfont_charset( i );
3082 if ( charset_sub == DEFAULT_CHARSET ) break;
3086 lfSub.lfHeight=plf->lfHeight;
3087 lfSub.lfCharSet = (BYTE)(charset_sub & 0xff);
3088 lfSub.lfFaceName[0] = '\0'; /* FIXME? */
3089 /* this font has sub font */
3090 if ( i == 0 ) pfo->prefobjs[0] = (X_PHYSFONT)0;
3092 XFONT_RealizeFont( &lfSub, &faceMatchedSub,
3094 &charsetMatchedSub );
3095 /* FIXME: check charsetMatchedSub */
3100 if( !pfo ) /* couldn't get a new entry, get one of the cached fonts */
3102 UINT current_score, score = (UINT)(-1);
3104 i = index = fontMRU;
3105 fm.flags |= FO_MATCH_PAF;
3108 pfo = fontCache + i;
3109 fm.pfr = pfo->fr; fm.pfi = pfo->fi;
3111 current_score = XFONT_Match( &fm );
3112 if( current_score < score ) index = i;
3116 pfo = fontCache + index;
3121 /* attach at the head of the lru list */
3123 index = fontMRU = (pfo - fontCache);
3128 TRACE("physfont %i\n", index);
3129 *faceMatched = pfo->fi->df.dfFace;
3130 *pcharsetMatched = pfo->fi->internal_charset;
3132 return (X_PHYSFONT)(X_PFONT_MAGIC | index);
3135 /***********************************************************************
3136 * XFONT_GetFontObject
3138 fontObject* XFONT_GetFontObject( X_PHYSFONT pFont )
3140 if( CHECK_PFONT(pFont) ) return __PFONT(pFont);
3144 /***********************************************************************
3145 * XFONT_GetFontStruct
3147 XFontStruct* XFONT_GetFontStruct( X_PHYSFONT pFont )
3149 if( CHECK_PFONT(pFont) ) return __PFONT(pFont)->fs;
3153 /***********************************************************************
3156 LPIFONTINFO16 XFONT_GetFontInfo( X_PHYSFONT pFont )
3158 if( CHECK_PFONT(pFont) ) return &(__PFONT(pFont)->fi->df);
3164 /* X11DRV Interface ****************************************************
3166 * Exposed via the dc->funcs dispatch table. *
3168 ***********************************************************************/
3169 /***********************************************************************
3170 * X11DRV_FONT_SelectObject
3172 HFONT X11DRV_FONT_SelectObject( DC* dc, HFONT hfont )
3176 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
3178 TRACE("dc=%p, hfont=%04x\n", dc, hfont);
3180 if (!GetObjectW( hfont, sizeof(logfont), &logfont )) return GDI_ERROR;
3182 TRACE("dc->gdiFont = %p\n", dc->gdiFont);
3184 if(dc->gdiFont && X11DRV_XRender_Installed) {
3185 X11DRV_XRender_SelectFont(dc, hfont);
3189 EnterCriticalSection( &crtsc_fonts_X11 );
3191 if( CHECK_PFONT(physDev->font) )
3192 XFONT_ReleaseCacheEntry( __PFONT(physDev->font) );
3194 FONT_LogFontWTo16(&logfont, &lf);
3196 /* stock fonts ignore the mapping mode */
3197 if (!is_stock_font( hfont ))
3199 /* Make sure we don't change the sign when converting to device coords */
3200 /* FIXME - check that the other drivers do this correctly */
3203 lf.lfWidth = GDI_ROUND((FLOAT)lf.lfWidth * fabs(dc->xformWorld2Vport.eM11));
3204 if (lf.lfWidth == 0)
3205 lf.lfWidth = 1; /* Minimum width */
3209 lf.lfHeight = GDI_ROUND((FLOAT)lf.lfHeight * fabs(dc->xformWorld2Vport.eM22));
3211 if (lf.lfHeight == 0)
3212 lf.lfHeight = MIN_FONT_SIZE;
3217 lf.lfHeight = -(DEF_POINT_SIZE * GetDeviceCaps(dc->hSelf,LOGPIXELSY) + (72>>1)) / 72;
3220 /* Fixup aliases before passing to RealizeFont */
3221 /* alias = Windows name in the alias table */
3222 LPCSTR alias = XFONT_UnAlias( lf.lfFaceName );
3224 WORD charsetMatched;
3226 TRACE("hfont=%04x\n", hfont); /* to connect with the trace from RealizeFont */
3227 physDev->font = XFONT_RealizeFont( &lf, &faceMatched,
3228 FALSE, lf.lfCharSet,
3231 /* set face to the requested facename if it matched
3232 * so that GetTextFace can get the correct face name
3234 if (alias && !strcmp(faceMatched, lf.lfFaceName))
3235 MultiByteToWideChar(CP_ACP, 0, alias, -1,
3236 logfont.lfFaceName, LF_FACESIZE);
3238 MultiByteToWideChar(CP_ACP, 0, faceMatched, -1,
3239 logfont.lfFaceName, LF_FACESIZE);
3242 * In X, some encodings may have the same lfFaceName.
3244 * -misc-fixed-*-iso8859-1
3245 * -misc-fixed-*-jisx0208.1990-0
3246 * so charset should be saved...
3248 logfont.lfCharSet = charsetMatched;
3251 LeaveCriticalSection( &crtsc_fonts_X11 );
3253 return TRUE; /* Use a device font */
3257 /***********************************************************************
3259 * X11DRV_EnumDeviceFonts
3261 BOOL X11DRV_EnumDeviceFonts( HDC hdc, LPLOGFONTW plf,
3262 DEVICEFONTENUMPROC proc, LPARAM lp )
3265 NEWTEXTMETRICEXW tm;
3266 fontResource* pfr = fontList;
3271 FONT_LogFontWTo16(plf, &lf16);
3273 if( lf16.lfFaceName[0] )
3275 /* enum all entries in this resource */
3276 pfr = XFONT_FindFIList( pfr, lf16.lfFaceName );
3280 for( pfi = pfr->fi; pfi; pfi = pfi->next )
3282 /* Note: XFONT_GetFontMetric() will have to
3283 release the crit section, font list will
3284 have to be retraversed on return */
3286 if(lf16.lfCharSet == DEFAULT_CHARSET ||
3287 lf16.lfCharSet == pfi->df.dfCharSet) {
3288 if( (b = (*proc)( &lf, &tm,
3289 XFONT_GetFontMetric( pfi, &lf, &tm ), lp )) )
3296 else /* enum first entry in each resource */
3297 for( ; pfr ; pfr = pfr->next )
3301 if( (b = (*proc)( &lf, &tm,
3302 XFONT_GetFontMetric( pfr->fi, &lf, &tm ), lp )) )
3311 /***********************************************************************
3312 * X11DRV_GetTextMetrics
3314 BOOL X11DRV_GetTextMetrics(DC *dc, TEXTMETRICW *metrics)
3316 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
3319 if( CHECK_PFONT(physDev->font) )
3321 fontObject* pfo = __PFONT(physDev->font);
3322 X11DRV_cptable[pfo->fi->cptable].pGetTextMetricsA( pfo, &tmA );
3323 FONT_TextMetricAToW(&tmA, metrics);
3330 /***********************************************************************
3331 * X11DRV_GetCharWidth
3333 BOOL X11DRV_GetCharWidth( DC *dc, UINT firstChar, UINT lastChar,
3336 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
3337 fontObject* pfo = XFONT_GetFontObject( physDev->font );
3343 if (pfo->fs->per_char == NULL)
3344 for (i = firstChar; i <= lastChar; i++)
3346 *buffer++ = pfo->fs->min_bounds.attributes *
3347 pfo->lpX11Trans->pixelsize / 1000.0 * pfo->rescale;
3349 *buffer++ = pfo->fs->min_bounds.width * pfo->rescale;
3352 XCharStruct *cs, *def;
3353 static XCharStruct __null_char = { 0, 0, 0, 0, 0, 0 };
3355 CI_GET_CHAR_INFO(pfo->fs, pfo->fs->default_char, &__null_char,
3358 for (i = firstChar; i <= lastChar; i++)
3362 UINT ch_f; /* character code in the font encoding */
3363 WideCharToMultiByte( pfo->fi->codepage, 0, &wch, 1, &ch, 1, NULL, NULL );
3365 if (ch_f >= pfo->fs->min_char_or_byte2 &&
3366 ch_f <= pfo->fs->max_char_or_byte2)
3368 cs = &pfo->fs->per_char[(ch_f - pfo->fs->min_char_or_byte2)];
3369 if (CI_NONEXISTCHAR(cs)) cs = def;
3372 *buffer++ = max(cs->attributes, 0) *
3373 pfo->lpX11Trans->pixelsize / 1000.0 * pfo->rescale;
3375 *buffer++ = max(cs->width, 0 ) * pfo->rescale;