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"
39 DEFAULT_DEBUG_CHANNEL(font
);
41 #define X_PFONT_MAGIC (0xFADE0000)
42 #define X_FMC_MAGIC (0x0000CAFE)
44 #define MAX_FONTS 1024*16
45 #define MAX_LFD_LENGTH 256
49 #define DEF_POINT_SIZE 8 /* CreateFont(0 .. ) gets this */
50 #define DEF_SCALABLE_HEIGHT 100 /* pixels */
51 #define MIN_FONT_SIZE 2 /* Min size in pixels */
52 #define MAX_FONT_SIZE 1000 /* Max size in pixels */
54 #define REMOVE_SUBSETS 1
55 #define UNMARK_SUBSETS 0
58 #define FF_FAMILY (FF_MODERN | FF_SWISS | FF_ROMAN | FF_DECORATIVE | FF_SCRIPT)
60 typedef struct __fontAlias
64 struct __fontAlias
* next
;
67 static fontAlias
*aliasTable
= NULL
;
69 UINT16 XTextCaps
= TC_OP_CHARACTER
| TC_OP_STROKE
|
70 TC_CP_STROKE
| TC_CR_ANY
|
71 TC_SA_DOUBLE
| TC_SA_INTEGER
| TC_SA_CONTIN
|
72 TC_UA_ABLE
| TC_SO_ABLE
| TC_RA_ABLE
;
74 /* X11R6 adds TC_SF_X_YINDEP, maybe more... */
76 static const char* INIFontMetrics
= "/cachedmetrics.";
77 static const char* INIFontSection
= "fonts";
78 static const char* INIAliasSection
= "Alias";
79 static const char* INIIgnoreSection
= "Ignore";
80 static const char* INIDefault
= "Default";
81 static const char* INIDefaultFixed
= "DefaultFixed";
82 static const char* INIResolution
= "Resolution";
83 static const char* INIGlobalMetrics
= "FontMetrics";
84 static const char* INIDefaultSerif
= "DefaultSerif";
85 static const char* INIDefaultSansSerif
= "DefaultSansSerif";
88 /* FIXME - are there any more Latin charsets ? */
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 ||\
101 /* suffix-charset mapping tables - must be less than 254 entries long */
103 typedef struct __sufch
111 static const SuffixCharset sufch_ansi
[] = {
112 { "0", ANSI_CHARSET
, 1252, X11DRV_CPTABLE_SBCS
},
113 { NULL
, ANSI_CHARSET
, 1252, X11DRV_CPTABLE_SBCS
}};
115 static const SuffixCharset sufch_iso646
[] = {
116 { "irv", ANSI_CHARSET
, 1252, X11DRV_CPTABLE_SBCS
},
117 { NULL
, ANSI_CHARSET
, 1252, X11DRV_CPTABLE_SBCS
}};
119 static const SuffixCharset sufch_iso8859
[] = {
120 { "1", ANSI_CHARSET
, 28591, X11DRV_CPTABLE_SBCS
},
121 { "2", EE_CHARSET
, 28592, X11DRV_CPTABLE_SBCS
},
122 { "3", ISO3_CHARSET
, 28593, X11DRV_CPTABLE_SBCS
},
123 { "4", ISO4_CHARSET
, 28594, X11DRV_CPTABLE_SBCS
},
124 { "5", RUSSIAN_CHARSET
, 28595, X11DRV_CPTABLE_SBCS
},
125 { "6", ARABIC_CHARSET
, 28596, X11DRV_CPTABLE_SBCS
},
126 { "7", GREEK_CHARSET
, 28597, X11DRV_CPTABLE_SBCS
},
127 { "8", HEBREW_CHARSET
, 28598, X11DRV_CPTABLE_SBCS
},
128 { "9", TURKISH_CHARSET
, 28599, X11DRV_CPTABLE_SBCS
},
129 { "10", BALTIC_CHARSET
, 1257, X11DRV_CPTABLE_SBCS
}, /* FIXME */
130 { "11", THAI_CHARSET
, 874, X11DRV_CPTABLE_SBCS
}, /* FIXME */
131 { "12", SYMBOL_CHARSET
, CP_SYMBOL
, X11DRV_CPTABLE_SBCS
},
132 { "13", SYMBOL_CHARSET
, CP_SYMBOL
, X11DRV_CPTABLE_SBCS
},
133 { "14", SYMBOL_CHARSET
, CP_SYMBOL
, X11DRV_CPTABLE_SBCS
},
134 { "15", ANSI_CHARSET
, 1252, X11DRV_CPTABLE_SBCS
},
135 { NULL
, ANSI_CHARSET
, 1252, X11DRV_CPTABLE_SBCS
}};
137 static const SuffixCharset sufch_microsoft
[] = {
138 { "cp1250", EE_CHARSET
, 1250, X11DRV_CPTABLE_SBCS
},
139 { "cp1251", RUSSIAN_CHARSET
, 1251, X11DRV_CPTABLE_SBCS
},
140 { "cp1252", ANSI_CHARSET
, 1252, X11DRV_CPTABLE_SBCS
},
141 { "cp1253", GREEK_CHARSET
, 1253, X11DRV_CPTABLE_SBCS
},
142 { "cp1254", TURKISH_CHARSET
, 1254, X11DRV_CPTABLE_SBCS
},
143 { "cp1255", HEBREW_CHARSET
, 1255, X11DRV_CPTABLE_SBCS
},
144 { "cp1256", ARABIC_CHARSET
, 1256, X11DRV_CPTABLE_SBCS
},
145 { "cp1257", BALTIC_CHARSET
, 1257, X11DRV_CPTABLE_SBCS
},
146 { "fontspecific", SYMBOL_CHARSET
, CP_SYMBOL
, X11DRV_CPTABLE_SBCS
},
147 { "symbol", SYMBOL_CHARSET
, CP_SYMBOL
, X11DRV_CPTABLE_SBCS
},
148 { NULL
, ANSI_CHARSET
, 1252, X11DRV_CPTABLE_SBCS
}};
150 static const SuffixCharset sufch_tcvn
[] = {
151 { "0", TCVN_CHARSET
, 1252, X11DRV_CPTABLE_SBCS
}, /* FIXME */
152 { NULL
, TCVN_CHARSET
, 1252, X11DRV_CPTABLE_SBCS
}};
154 static const SuffixCharset sufch_tis620
[] = {
155 { "0", THAI_CHARSET
, 874, X11DRV_CPTABLE_SBCS
}, /* FIXME */
156 { NULL
, THAI_CHARSET
, 874, X11DRV_CPTABLE_SBCS
}};
158 static const SuffixCharset sufch_viscii
[] = {
159 { "1", VISCII_CHARSET
, 1252, X11DRV_CPTABLE_SBCS
}, /* FIXME */
160 { NULL
, VISCII_CHARSET
, 1252, X11DRV_CPTABLE_SBCS
}};
162 static const SuffixCharset sufch_windows
[] = {
163 { "1250", EE_CHARSET
, 1250, X11DRV_CPTABLE_SBCS
},
164 { "1251", RUSSIAN_CHARSET
, 1251, X11DRV_CPTABLE_SBCS
},
165 { "1252", ANSI_CHARSET
, 1252, X11DRV_CPTABLE_SBCS
},
166 { "1253", GREEK_CHARSET
, 1253, X11DRV_CPTABLE_SBCS
},
167 { "1254", TURKISH_CHARSET
, 1254, X11DRV_CPTABLE_SBCS
},
168 { "1255", HEBREW_CHARSET
, 1255, X11DRV_CPTABLE_SBCS
},
169 { "1256", ARABIC_CHARSET
, 1256, X11DRV_CPTABLE_SBCS
},
170 { "1257", BALTIC_CHARSET
, 1257, X11DRV_CPTABLE_SBCS
},
171 { NULL
, ANSI_CHARSET
, 1252, X11DRV_CPTABLE_SBCS
}};
173 static const SuffixCharset sufch_koi8
[] = {
174 { "r", RUSSIAN_CHARSET
, 20866, X11DRV_CPTABLE_SBCS
},
175 { "u", RUSSIAN_CHARSET
, 20866, X11DRV_CPTABLE_SBCS
},
176 { NULL
, RUSSIAN_CHARSET
, 20866, X11DRV_CPTABLE_SBCS
}};
178 /* FIXME: DBCS charsets need 2 or more fonts */
179 static const SuffixCharset sufch_jisx0201
[] = {
180 { "0", ANSI_CHARSET
, 932, X11DRV_CPTABLE_SBCS
},
181 { NULL
, ANSI_CHARSET
, 932, X11DRV_CPTABLE_SBCS
}};
183 static const SuffixCharset sufch_jisx0208
[] = {
184 { "0", SHIFTJIS_CHARSET
, 932, X11DRV_CPTABLE_CP932
},
185 { NULL
, SHIFTJIS_CHARSET
, 932, X11DRV_CPTABLE_CP932
}};
187 static const SuffixCharset sufch_ksc5601
[] = {
188 { "0", HANGEUL_CHARSET
, 949, X11DRV_CPTABLE_CP949
},
189 { NULL
, HANGEUL_CHARSET
, 949, X11DRV_CPTABLE_CP949
}};
191 static const SuffixCharset sufch_gb2312
[] = {
192 { "0", GB2312_CHARSET
, 936, X11DRV_CPTABLE_CP936
},
193 { NULL
, GB2312_CHARSET
, 936, X11DRV_CPTABLE_CP936
}};
195 static const SuffixCharset sufch_big5
[] = {
196 { "0", CHINESEBIG5_CHARSET
, 950, X11DRV_CPTABLE_CP950
},
197 { NULL
, CHINESEBIG5_CHARSET
, 950, X11DRV_CPTABLE_CP950
}};
199 static const SuffixCharset sufch_unicode
[] = {
200 { "0", DEFAULT_CHARSET
, 0, X11DRV_CPTABLE_UNICODE
},
201 { NULL
, DEFAULT_CHARSET
, 0, X11DRV_CPTABLE_UNICODE
}};
203 static const SuffixCharset sufch_iso10646
[] = {
204 { "1", DEFAULT_CHARSET
, 0, X11DRV_CPTABLE_UNICODE
},
205 { NULL
, DEFAULT_CHARSET
, 0, X11DRV_CPTABLE_UNICODE
}};
207 /* Each of these must be matched explicitly */
208 static const SuffixCharset sufch_any
[] = {
209 { "fontspecific", SYMBOL_CHARSET
, CP_SYMBOL
, X11DRV_CPTABLE_SBCS
},
210 { NULL
, 0, 0, X11DRV_CPTABLE_SBCS
}};
216 const SuffixCharset
* sufch
;
218 } fontEncodingTemplate
;
220 /* Note: we can attach additional encoding mappings to the end
221 * of this table at runtime.
223 static fontEncodingTemplate __fETTable
[] = {
224 { "ansi", sufch_ansi
, &__fETTable
[1] },
225 { "ascii", sufch_ansi
, &__fETTable
[2] },
226 { "iso646.1991", sufch_iso646
, &__fETTable
[3] },
227 { "iso8859", sufch_iso8859
, &__fETTable
[4] },
228 { "microsoft", sufch_microsoft
, &__fETTable
[5] },
229 { "tcvn", sufch_tcvn
, &__fETTable
[6] },
230 { "tis620.2533", sufch_tis620
, &__fETTable
[7] },
231 { "viscii1.1", sufch_viscii
, &__fETTable
[8] },
232 { "windows", sufch_windows
, &__fETTable
[9] },
233 { "koi8", sufch_koi8
, &__fETTable
[10]},
234 { "jisx0201.1976",sufch_jisx0201
, &__fETTable
[11]},
235 { "jisc6226.1978",sufch_jisx0208
, &__fETTable
[12]},
236 { "jisx0208.1983",sufch_jisx0208
, &__fETTable
[13]},
237 { "jisx0208.1990",sufch_jisx0208
, &__fETTable
[14]},
238 { "ksc5601.1987", sufch_ksc5601
, &__fETTable
[15]},
239 { "gb2312.1980", sufch_gb2312
, &__fETTable
[16]},
240 { "big5.et", sufch_big5
, &__fETTable
[17]},
241 { "unicode", sufch_unicode
, &__fETTable
[18]},
242 { "iso10646", sufch_iso10646
, &__fETTable
[19]},
243 /* NULL prefix matches anything so put it last */
244 { NULL
, sufch_any
, NULL
},
246 static fontEncodingTemplate
* fETTable
= __fETTable
;
248 static int DefResolution
= 0;
250 static CRITICAL_SECTION crtsc_fonts_X11
= CRITICAL_SECTION_INIT
;
252 static fontResource
* fontList
= NULL
;
253 static fontObject
* fontCache
= NULL
; /* array */
254 static int fontCacheSize
= FONTCACHE
;
255 static int fontLF
= -1, fontMRU
= -1; /* last free, most recently used */
257 #define __PFONT(pFont) ( fontCache + ((UINT)(pFont) & 0x0000FFFF) )
258 #define CHECK_PFONT(pFont) ( (((UINT)(pFont) & 0xFFFF0000) == X_PFONT_MAGIC) &&\
259 (((UINT)(pFont) & 0x0000FFFF) < fontCacheSize) )
261 static Atom RAW_ASCENT
;
262 static Atom RAW_DESCENT
;
264 /***********************************************************************
265 * Helper macros from X distribution
268 #define CI_NONEXISTCHAR(cs) (((cs)->width == 0) && \
269 (((cs)->rbearing|(cs)->lbearing| \
270 (cs)->ascent|(cs)->descent) == 0))
272 #define CI_GET_CHAR_INFO(fs,col,def,cs) \
275 if (col >= fs->min_char_or_byte2 && col <= fs->max_char_or_byte2) { \
276 if (fs->per_char == NULL) { \
277 cs = &fs->min_bounds; \
279 cs = &fs->per_char[(col - fs->min_char_or_byte2)]; \
280 if (CI_NONEXISTCHAR(cs)) cs = def; \
285 #define CI_GET_DEFAULT_INFO(fs,cs) \
286 CI_GET_CHAR_INFO(fs, fs->default_char, NULL, cs)
288 /***********************************************************************
291 static UINT16
__lfCheckSum( LPLOGFONT16 plf
)
293 CHAR font
[LF_FACESIZE
];
297 #define ptr ((UINT16*)plf)
298 for( i
= 0; i
< 9; i
++ ) checksum
^= *ptr
++;
301 #define ptr ((CHAR*)plf)
302 do { font
[i
++] = tolower(*ptr
++); } while (( i
< LF_FACESIZE
) && (*ptr
) && (*ptr
!=' '));
303 for( ptr
= font
, i
>>= 1; i
> 0; i
-- )
305 #define ptr ((UINT16*)plf)
311 static UINT16
__genericCheckSum( const void *ptr
, int size
)
313 unsigned int checksum
= 0;
314 const char *p
= (const char *)ptr
;
316 checksum
^= (checksum
<< 3) + (checksum
>> 29) + *p
++;
318 return checksum
& 0xffff;
321 /*************************************************************************
322 * LFD parse/compose routines
324 * NB. LFD_Parse will use lpFont for its own ends, so if you want to keep it
327 * These functions also do TILDE to HYPHEN conversion
329 static LFD
* LFD_Parse(LPSTR lpFont
)
332 char *lpch
= lpFont
, *lfd_fld
[LFD_FIELDS
], *field_start
;
336 WARN("font '%s' doesn't begin with '%c'\n", lpFont
, HYPHEN
);
340 field_start
= ++lpch
;
341 for( i
= 0; i
< LFD_FIELDS
; )
346 lfd_fld
[i
] = field_start
;
348 field_start
= ++lpch
;
352 lfd_fld
[i
] = field_start
;
356 else if (*lpch
== TILDE
)
364 /* Fill in the empty fields with NULLS */
365 for (; i
< LFD_FIELDS
; i
++)
368 WARN("Extra ignored in font '%s'\n", lpFont
);
370 lfd
= HeapAlloc( GetProcessHeap(), 0, sizeof(LFD
) );
373 lfd
->foundry
= lfd_fld
[0];
374 lfd
->family
= lfd_fld
[1];
375 lfd
->weight
= lfd_fld
[2];
376 lfd
->slant
= lfd_fld
[3];
377 lfd
->set_width
= lfd_fld
[4];
378 lfd
->add_style
= lfd_fld
[5];
379 lfd
->pixel_size
= lfd_fld
[6];
380 lfd
->point_size
= lfd_fld
[7];
381 lfd
->resolution_x
= lfd_fld
[8];
382 lfd
->resolution_y
= lfd_fld
[9];
383 lfd
->spacing
= lfd_fld
[10];
384 lfd
->average_width
= lfd_fld
[11];
385 lfd
->charset_registry
= lfd_fld
[12];
386 lfd
->charset_encoding
= lfd_fld
[13];
392 static void LFD_UnParse(LPSTR dp
, UINT buf_size
, LFD
* lfd
)
394 const char* lfd_fld
[LFD_FIELDS
];
398 return; /* Dont be silly */
400 lfd_fld
[0] = lfd
->foundry
;
401 lfd_fld
[1] = lfd
->family
;
402 lfd_fld
[2] = lfd
->weight
;
403 lfd_fld
[3] = lfd
->slant
;
404 lfd_fld
[4] = lfd
->set_width
;
405 lfd_fld
[5] = lfd
->add_style
;
406 lfd_fld
[6] = lfd
->pixel_size
;
407 lfd_fld
[7] = lfd
->point_size
;
408 lfd_fld
[8] = lfd
->resolution_x
;
409 lfd_fld
[9] = lfd
->resolution_y
;
410 lfd_fld
[10] = lfd
->spacing
;
411 lfd_fld
[11] = lfd
->average_width
;
412 lfd_fld
[12] = lfd
->charset_registry
;
413 lfd_fld
[13] = lfd
->charset_encoding
;
415 buf_size
--; /* Room for the terminator */
417 for (i
= 0; i
< LFD_FIELDS
; i
++)
419 const char* sp
= lfd_fld
[i
];
420 if (!sp
|| !buf_size
)
425 while (buf_size
> 0 && *sp
)
427 *dp
= (*sp
== HYPHEN
) ? TILDE
: *sp
;
436 static void LFD_GetWeight( fontInfo
* fi
, LPCSTR lpStr
)
438 int j
= strlen(lpStr
);
439 if( j
== 1 && *lpStr
== '0')
440 fi
->fi_flags
|= FI_POLYWEIGHT
;
443 if( !strcasecmp( "bold", lpStr
) )
444 fi
->df
.dfWeight
= FW_BOLD
;
445 else if( !strcasecmp( "demi", lpStr
) )
447 fi
->fi_flags
|= FI_FW_DEMI
;
448 fi
->df
.dfWeight
= FW_DEMIBOLD
;
450 else if( !strcasecmp( "book", lpStr
) )
452 fi
->fi_flags
|= FI_FW_BOOK
;
453 fi
->df
.dfWeight
= FW_REGULAR
;
458 if( !strcasecmp( "light", lpStr
) )
459 fi
->df
.dfWeight
= FW_LIGHT
;
460 else if( !strcasecmp( "black", lpStr
) )
461 fi
->df
.dfWeight
= FW_BLACK
;
463 else if( j
== 6 && !strcasecmp( "medium", lpStr
) )
464 fi
->df
.dfWeight
= FW_REGULAR
;
465 else if( j
== 8 && !strcasecmp( "demibold", lpStr
) )
466 fi
->df
.dfWeight
= FW_DEMIBOLD
;
468 fi
->df
.dfWeight
= FW_DONTCARE
; /* FIXME: try to get something
469 * from the weight property */
472 static BOOL
LFD_GetSlant( fontInfo
* fi
, LPCSTR lpStr
)
474 int l
= strlen(lpStr
);
477 switch( tolower( *lpStr
) )
479 case '0': fi
->fi_flags
|= FI_POLYSLANT
; /* haven't seen this one yet */
481 case 'r': fi
->df
.dfItalic
= 0;
484 fi
->fi_flags
|= FI_OBLIQUE
;
485 case 'i': fi
->df
.dfItalic
= 1;
493 static void LFD_GetStyle( fontInfo
* fi
, LPCSTR lpstr
, int dec_style_check
)
495 int j
= strlen(lpstr
);
496 if( j
> 3 ) /* find out is there "sans" or "script" */
500 if( strstr(lpstr
, "sans") )
502 fi
->df
.dfPitchAndFamily
|= FF_SWISS
;
505 if( strstr(lpstr
, "script") )
507 fi
->df
.dfPitchAndFamily
|= FF_SCRIPT
;
510 if( !j
&& dec_style_check
)
511 fi
->df
.dfPitchAndFamily
|= FF_DECORATIVE
;
515 /*************************************************************************
520 * Fill in some fields in the fontInfo struct.
522 static int LFD_InitFontInfo( fontInfo
* fi
, const LFD
* lfd
, LPCSTR fullname
)
524 int i
, j
, dec_style_check
, scalability
;
525 fontEncodingTemplate
* boba
;
526 const char* ridiculous
= "font '%s' has ridiculous %s\n";
529 if (!lfd
->charset_registry
)
531 WARN("font '%s' does not have enough fields\n", fullname
);
535 memset(fi
, 0, sizeof(fontInfo
) );
538 LFD_GetWeight( fi
, lfd
->weight
);
541 dec_style_check
= LFD_GetSlant( fi
, lfd
->slant
);
544 lpstr
= lfd
->set_width
;
545 if( strcasecmp( "normal", lpstr
) ) /* XXX 'narrow', 'condensed', etc... */
546 dec_style_check
= TRUE
;
548 fi
->fi_flags
|= FI_NORMAL
;
551 LFD_GetStyle(fi
, lfd
->add_style
, dec_style_check
);
553 /* pixel & decipoint height, and res_x & y */
557 j
= strlen(lfd
->pixel_size
);
558 if( j
== 0 || j
> 3 )
560 WARN(ridiculous
, fullname
, "pixel_size");
563 if( !(fi
->lfd_height
= atoi(lfd
->pixel_size
)) )
566 j
= strlen(lfd
->point_size
);
567 if( j
== 0 || j
> 3 )
569 WARN(ridiculous
, fullname
, "point_size");
572 if( !(atoi(lfd
->point_size
)) )
575 j
= strlen(lfd
->resolution_x
);
576 if( j
== 0 || j
> 3 )
578 WARN(ridiculous
, fullname
, "resolution_x");
581 if( !(fi
->lfd_resolution
= atoi(lfd
->resolution_x
)) )
584 j
= strlen(lfd
->resolution_y
);
585 if( j
== 0 || j
> 3 )
587 WARN(ridiculous
, fullname
, "resolution_y");
590 if( !(atoi(lfd
->resolution_y
)) )
593 /* Check scalability */
598 case 4: /* Scalable */
599 fi
->fi_flags
|= FI_SCALABLE
;
602 /* #$%^!!! X11R6 mutant garbage (scalable bitmap) */
603 TRACE("Skipping scalable bitmap '%s'\n", fullname
);
606 WARN("Font '%s' has weird scalability\n", fullname
);
611 lpstr
= lfd
->spacing
;
615 WARN("font '%s' has no spacing\n", fullname
);
618 case 'p': fi
->fi_flags
|= FI_VARIABLEPITCH
;
620 case 'c': fi
->df
.dfPitchAndFamily
|= FF_MODERN
;
621 fi
->fi_flags
|= FI_FIXEDEX
;
623 case 'm': fi
->fi_flags
|= FI_FIXEDPITCH
;
626 /* Of course this line does nothing */
627 fi
->df
.dfPitchAndFamily
|= DEFAULT_PITCH
| FF_DONTCARE
;
630 /* average width - */
631 lpstr
= lfd
->average_width
;
633 if( j
== 0 || j
> 3 )
635 WARN(ridiculous
, fullname
, "average_width");
639 if( !(atoi(lpstr
)) && !scalability
)
641 WARN("font '%s' has average_width 0 but is not scalable!!\n", fullname
);
645 /* charset registry, charset encoding - */
646 lpstr
= lfd
->charset_registry
;
647 if( strstr(lpstr
, "jisx") ||
648 strstr(lpstr
, "jisc") ||
649 strstr(lpstr
, "ksc") ||
650 strstr(lpstr
, "gb2312") ||
651 strstr(lpstr
, "big5") )
653 FIXME("DBCS fonts like '%s' are not working correctly now.\n", fullname
);
656 fi
->df
.dfCharSet
= ANSI_CHARSET
;
658 for( i
= 0, boba
= fETTable
; boba
; boba
= boba
->next
, i
++ )
660 if (!boba
->prefix
|| !strcasecmp(lpstr
, boba
->prefix
))
662 if (lfd
->charset_encoding
)
664 for( j
= 0; boba
->sufch
[j
].psuffix
; j
++ )
666 if( !strcasecmp(lfd
->charset_encoding
, boba
->sufch
[j
].psuffix
))
668 fi
->df
.dfCharSet
= boba
->sufch
[j
].charset
;
669 fi
->codepage
= boba
->sufch
[j
].codepage
;
670 fi
->cptable
= boba
->sufch
[j
].cptable
;
676 WARN("font '%s' has unknown character encoding '%s'\n",
677 fullname
, lfd
->charset_encoding
);
678 fi
->df
.dfCharSet
= boba
->sufch
[j
].charset
;
679 fi
->codepage
= boba
->sufch
[j
].codepage
;
680 fi
->cptable
= boba
->sufch
[j
].cptable
;
685 else if (boba
->prefix
)
687 for( j
= 0; boba
->sufch
[j
].psuffix
; j
++ )
689 fi
->df
.dfCharSet
= boba
->sufch
[j
].charset
;
690 fi
->codepage
= boba
->sufch
[j
].codepage
;
691 fi
->cptable
= boba
->sufch
[j
].cptable
;
697 WARN("font '%s' has unknown character set '%s'\n", fullname
, lpstr
);
701 /* i - index into fETTable
702 * j - index into suffix array for fETTable[i]
704 * 254 - unknown suffix
705 * 255 - no suffix at all.
707 fi
->fi_encoding
= 256 * (UINT16
)i
+ (UINT16
)j
;
713 /*************************************************************************
716 * make a matrix suitable for LFD based on theta radians
718 static void LFD_AngleMatrix( char* buffer
, int h
, double theta
)
721 matrix
[0] = h
*cos(theta
);
722 matrix
[1] = h
*sin(theta
);
723 matrix
[2] = -h
*sin(theta
);
724 matrix
[3] = h
*cos(theta
);
725 sprintf(buffer
, "[%+f%+f%+f%+f]", matrix
[0], matrix
[1], matrix
[2], matrix
[3]);
728 /*************************************************************************
731 * Note: uRelax is a treatment not a cure. Font mapping algorithm
732 * should be bulletproof enough to allow us to avoid hacks like
733 * this despite LFD being so braindead.
735 static BOOL
LFD_ComposeLFD( const fontObject
* fo
,
736 INT height
, LPSTR lpLFD
, UINT uRelax
)
740 char h_string
[64], resx_string
[64], resy_string
[64];
743 /* Get the worst case over with first */
745 /* RealizeFont() will call us repeatedly with increasing uRelax
746 * until XLoadFont() succeeds.
747 * to avoid an infinite loop; these will always match
752 sprintf( lpLFD
, "-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-1" );
754 sprintf( lpLFD
, "-*-*-*-*-*-*-*-*-*-*-*-*-*-*" );
758 /* read foundry + family from fo */
759 aLFD
.foundry
= fo
->fr
->resource
->foundry
;
760 aLFD
.family
= fo
->fr
->resource
->family
;
763 switch( fo
->fi
->df
.dfWeight
)
766 aLFD
.weight
= "bold"; break;
768 if( fo
->fi
->fi_flags
& FI_FW_BOOK
)
769 aLFD
.weight
= "book";
771 aLFD
.weight
= "medium";
774 aLFD
.weight
= "demi";
775 if( !( fo
->fi
->fi_flags
& FI_FW_DEMI
) )
776 aLFD
.weight
= "bold";
779 aLFD
.weight
= "black"; break;
781 aLFD
.weight
= "light"; break;
787 if( fo
->fi
->df
.dfItalic
)
788 if( fo
->fi
->fi_flags
& FI_OBLIQUE
)
793 aLFD
.slant
= (uRelax
< 1) ? "r" : any
;
796 if( fo
->fi
->fi_flags
& FI_NORMAL
)
797 aLFD
.set_width
= "normal";
799 aLFD
.set_width
= any
;
802 aLFD
.add_style
= any
;
806 * FIXME: fill in lpXForm and lpPixmap for rotated fonts
808 if( fo
->fo_flags
& FO_SYNTH_HEIGHT
)
809 h
= fo
->fi
->lfd_height
;
812 h
= (fo
->fi
->lfd_height
* height
+ (fo
->fi
->df
.dfPixHeight
>>1));
813 h
/= fo
->fi
->df
.dfPixHeight
;
815 if (h
< MIN_FONT_SIZE
) /* Resist rounding down to 0 */
817 else if (h
> MAX_FONT_SIZE
) /* Sanity check as huge fonts can lock up the font server */
819 WARN("Huge font size %d pixels has been reduced to %d\n", h
, MAX_FONT_SIZE
);
824 /* handle rotated fonts */
825 if (fo
->lf
.lfEscapement
) {
826 /* escapement is in tenths of degrees, theta is in radians */
827 double theta
= M_PI
*fo
->lf
.lfEscapement
/1800.;
828 LFD_AngleMatrix(h_string
, h
, theta
);
832 sprintf(h_string
, "%d", h
);
835 sprintf(h_string
, "%d", fo
->fi
->lfd_height
);
837 aLFD
.pixel_size
= h_string
;
838 aLFD
.point_size
= any
;
840 /* resolution_x,y, average width */
841 /* FOX ME - Why do some font servers ignore average width ?
842 * so that you have to mess around with res_y
844 aLFD
.average_width
= any
;
847 sprintf(resx_string
, "%d", fo
->fi
->lfd_resolution
);
848 aLFD
.resolution_x
= resx_string
;
850 strcpy(resy_string
, resx_string
);
851 if( uRelax
== 0 && XTextCaps
& TC_SF_X_YINDEP
)
853 if( fo
->lf
.lfWidth
&& !(fo
->fo_flags
& FO_SYNTH_WIDTH
))
855 int resy
= 0.5 + fo
->fi
->lfd_resolution
*
856 (fo
->fi
->df
.dfAvgWidth
* height
) /
857 (fo
->lf
.lfWidth
* fo
->fi
->df
.dfPixHeight
) ;
858 sprintf(resy_string
, "%d", resy
);
861 ; /* FIXME - synth width */
863 aLFD
.resolution_y
= resy_string
;
867 aLFD
.resolution_x
= aLFD
.resolution_y
= any
;
874 if( fo
->fi
->fi_flags
& FI_FIXEDPITCH
)
875 w
= ( fo
->fi
->fi_flags
& FI_FIXEDEX
) ? "c" : "m";
877 w
= ( fo
->fi
->fi_flags
& FI_VARIABLEPITCH
) ? "p" : any
;
879 aLFD
.spacing
= (uRelax
<= 1) ? w
: any
;
886 fontEncodingTemplate
* boba
;
888 i
= fo
->fi
->fi_encoding
>> 8;
889 for( boba
= fETTable
; i
; i
--, boba
= boba
->next
);
891 aLFD
.charset_registry
= boba
->prefix
? boba
->prefix
: any
;
893 i
= fo
->fi
->fi_encoding
& 255;
897 aLFD
.charset_encoding
= boba
->sufch
[i
].psuffix
;
901 aLFD
.charset_encoding
= any
;
904 case 255: /* no suffix - it ends eg "-ascii" */
905 aLFD
.charset_encoding
= NULL
;
911 aLFD
.charset_registry
= any
;
912 aLFD
.charset_encoding
= any
;
915 LFD_UnParse(lpLFD
, MAX_LFD_LENGTH
, &aLFD
);
917 TRACE("\tLFD(uRelax=%d): %s\n", uRelax
, lpLFD
);
922 /***********************************************************************
925 * font info - http://www.microsoft.com/kb/articles/q65/1/23.htm
926 * Windows font metrics - http://www.microsoft.com/kb/articles/q32/6/67.htm
928 static void XFONT_GetLeading( const LPIFONTINFO16 pFI
, const XFontStruct
* x_fs
,
929 INT16
* pIL
, INT16
* pEL
, const XFONTTRANS
*XFT
)
931 unsigned long height
;
932 unsigned min
= (unsigned char)pFI
->dfFirstChar
;
933 BOOL bIsLatin
= IS_LATIN_CHARSET(pFI
->dfCharSet
);
938 Atom RAW_CAP_HEIGHT
= TSXInternAtom(display
, "RAW_CAP_HEIGHT", TRUE
);
939 if(TSXGetFontProperty((XFontStruct
*)x_fs
, RAW_CAP_HEIGHT
, &height
))
941 (INT
)(XFT
->pixelsize
/ 1000.0 * height
);
947 if( TSXGetFontProperty((XFontStruct
*)x_fs
, XA_CAP_HEIGHT
, &height
) == FALSE
)
951 height
= x_fs
->per_char
['X' - min
].ascent
;
953 if (x_fs
->ascent
>= x_fs
->max_bounds
.ascent
)
954 height
= x_fs
->max_bounds
.ascent
;
957 height
= x_fs
->ascent
;
959 *pEL
= x_fs
->max_bounds
.ascent
- height
;
962 height
= x_fs
->min_bounds
.ascent
;
965 *pIL
= x_fs
->ascent
- height
;
968 /***********************************************************************
971 static int XFONT_CharWidth(const XFontStruct
* x_fs
,
972 const XFONTTRANS
*XFT
, int ch
)
975 return x_fs
->per_char
[ch
].width
;
977 return x_fs
->per_char
[ch
].attributes
* XFT
->pixelsize
/ 1000.0;
980 /***********************************************************************
981 * XFONT_GetAvgCharWidth
983 static INT
XFONT_GetAvgCharWidth( LPIFONTINFO16 pFI
, const XFontStruct
* x_fs
,
984 const XFONTTRANS
*XFT
)
986 unsigned min
= (unsigned char)pFI
->dfFirstChar
;
987 unsigned max
= (unsigned char)pFI
->dfLastChar
;
993 int width
= 0, chars
= 0, j
;
994 if( IS_LATIN_CHARSET(pFI
->dfCharSet
))
996 /* FIXME - should use a weighted average */
997 for( j
= 0; j
< 26; j
++ )
998 width
+= XFONT_CharWidth(x_fs
, XFT
, 'a' + j
- min
) +
999 XFONT_CharWidth(x_fs
, XFT
, 'A' + j
- min
);
1002 else /* unweighted average of everything */
1004 for( j
= 0, max
-= min
; j
<= max
; j
++ )
1005 if( !CI_NONEXISTCHAR(x_fs
->per_char
+ j
) )
1007 width
+= XFONT_CharWidth(x_fs
, XFT
, j
);
1011 if (chars
) avg
= (width
+ (chars
>>1))/ chars
;
1012 else avg
= 0; /* No characters exist at all */
1014 else /* uniform width */
1015 avg
= x_fs
->min_bounds
.width
;
1020 /***********************************************************************
1021 * XFONT_GetMaxCharWidth
1023 static INT
XFONT_GetMaxCharWidth(const XFontStruct
* xfs
, const XFONTTRANS
*XFT
)
1025 unsigned min
= (unsigned char)xfs
->min_char_or_byte2
;
1026 unsigned max
= (unsigned char)xfs
->max_char_or_byte2
;
1029 if(!XFT
|| !xfs
->per_char
)
1030 return abs(xfs
->max_bounds
.width
);
1032 for( j
= 0, maxwidth
= 0, max
-= min
; j
<= max
; j
++ )
1033 if( !CI_NONEXISTCHAR(xfs
->per_char
+ j
) )
1034 if(maxwidth
< xfs
->per_char
[j
].attributes
)
1035 maxwidth
= xfs
->per_char
[j
].attributes
;
1037 maxwidth
*= XFT
->pixelsize
/ 1000.0;
1041 /***********************************************************************
1042 * XFONT_SetFontMetric
1046 * Initializes IFONTINFO16.
1048 static void XFONT_SetFontMetric(fontInfo
* fi
, const fontResource
* fr
, XFontStruct
* xfs
)
1051 fi
->df
.dfFirstChar
= (BYTE
)(min
= xfs
->min_char_or_byte2
);
1052 fi
->df
.dfLastChar
= (BYTE
)(max
= xfs
->max_char_or_byte2
);
1054 fi
->df
.dfDefaultChar
= (BYTE
)xfs
->default_char
;
1055 fi
->df
.dfBreakChar
= (BYTE
)(( ' ' < min
|| ' ' > max
) ? xfs
->default_char
: ' ');
1057 fi
->df
.dfPixHeight
= (INT16
)((fi
->df
.dfAscent
= (INT16
)xfs
->ascent
) + xfs
->descent
);
1058 fi
->df
.dfPixWidth
= (xfs
->per_char
) ? 0 : xfs
->min_bounds
.width
;
1060 XFONT_GetLeading( &fi
->df
, xfs
, &fi
->df
.dfInternalLeading
, &fi
->df
.dfExternalLeading
, NULL
);
1061 fi
->df
.dfAvgWidth
= (INT16
)XFONT_GetAvgCharWidth(&fi
->df
, xfs
, NULL
);
1062 fi
->df
.dfMaxWidth
= (INT16
)XFONT_GetMaxCharWidth(xfs
, NULL
);
1064 if( xfs
->min_bounds
.width
!= xfs
->max_bounds
.width
)
1065 fi
->df
.dfPitchAndFamily
|= TMPF_FIXED_PITCH
; /* au contraire! */
1066 if( fi
->fi_flags
& FI_SCALABLE
)
1068 fi
->df
.dfType
= DEVICE_FONTTYPE
;
1069 fi
->df
.dfPitchAndFamily
|= TMPF_DEVICE
;
1071 else if( fi
->fi_flags
& FI_TRUETYPE
)
1072 fi
->df
.dfType
= TRUETYPE_FONTTYPE
;
1074 fi
->df
.dfType
= RASTER_FONTTYPE
;
1076 fi
->df
.dfFace
= fr
->lfFaceName
;
1079 /***********************************************************************
1080 * XFONT_GetTextMetrics
1082 * GetTextMetrics() back end.
1084 static void XFONT_GetTextMetrics( const fontObject
* pfo
, const LPTEXTMETRICA pTM
)
1086 LPIFONTINFO16 pdf
= &pfo
->fi
->df
;
1088 if( ! pfo
->lpX11Trans
) {
1089 pTM
->tmAscent
= pfo
->fs
->ascent
;
1090 pTM
->tmDescent
= pfo
->fs
->descent
;
1092 pTM
->tmAscent
= pfo
->lpX11Trans
->ascent
;
1093 pTM
->tmDescent
= pfo
->lpX11Trans
->descent
;
1096 pTM
->tmAscent
*= pfo
->rescale
;
1097 pTM
->tmDescent
*= pfo
->rescale
;
1099 pTM
->tmHeight
= pTM
->tmAscent
+ pTM
->tmDescent
;
1101 pTM
->tmAveCharWidth
= pfo
->foAvgCharWidth
* pfo
->rescale
;
1102 pTM
->tmMaxCharWidth
= pfo
->foMaxCharWidth
* pfo
->rescale
;
1104 pTM
->tmInternalLeading
= pfo
->foInternalLeading
* pfo
->rescale
;
1105 pTM
->tmExternalLeading
= pdf
->dfExternalLeading
* pfo
->rescale
;
1107 pTM
->tmStruckOut
= (pfo
->fo_flags
& FO_SYNTH_STRIKEOUT
)
1108 ? 1 : pdf
->dfStrikeOut
;
1109 pTM
->tmUnderlined
= (pfo
->fo_flags
& FO_SYNTH_UNDERLINE
)
1110 ? 1 : pdf
->dfUnderline
;
1112 pTM
->tmOverhang
= 0;
1113 if( pfo
->fo_flags
& FO_SYNTH_ITALIC
)
1115 pTM
->tmOverhang
+= pTM
->tmHeight
/3;
1118 pTM
->tmItalic
= pdf
->dfItalic
;
1120 pTM
->tmWeight
= pdf
->dfWeight
;
1121 if( pfo
->fo_flags
& FO_SYNTH_BOLD
)
1124 pTM
->tmWeight
+= 100;
1127 pTM
->tmFirstChar
= pdf
->dfFirstChar
;
1128 pTM
->tmLastChar
= pdf
->dfLastChar
;
1129 pTM
->tmDefaultChar
= pdf
->dfDefaultChar
;
1130 pTM
->tmBreakChar
= pdf
->dfBreakChar
;
1132 pTM
->tmCharSet
= pdf
->dfCharSet
;
1133 pTM
->tmPitchAndFamily
= pdf
->dfPitchAndFamily
;
1135 pTM
->tmDigitizedAspectX
= pdf
->dfHorizRes
;
1136 pTM
->tmDigitizedAspectY
= pdf
->dfVertRes
;
1139 /***********************************************************************
1140 * XFONT_GetFontMetric
1142 * Retrieve font metric info (enumeration).
1144 static UINT
XFONT_GetFontMetric( const fontInfo
* pfi
, const LPENUMLOGFONTEX16 pLF
,
1145 const LPNEWTEXTMETRIC16 pTM
)
1147 memset( pLF
, 0, sizeof(*pLF
) );
1148 memset( pTM
, 0, sizeof(*pTM
) );
1150 #define plf ((LPLOGFONT16)pLF)
1151 plf
->lfHeight
= pTM
->tmHeight
= pfi
->df
.dfPixHeight
;
1152 plf
->lfWidth
= pTM
->tmAveCharWidth
= pfi
->df
.dfAvgWidth
;
1153 plf
->lfWeight
= pTM
->tmWeight
= pfi
->df
.dfWeight
;
1154 plf
->lfItalic
= pTM
->tmItalic
= pfi
->df
.dfItalic
;
1155 plf
->lfUnderline
= pTM
->tmUnderlined
= pfi
->df
.dfUnderline
;
1156 plf
->lfStrikeOut
= pTM
->tmStruckOut
= pfi
->df
.dfStrikeOut
;
1157 plf
->lfCharSet
= pTM
->tmCharSet
= pfi
->df
.dfCharSet
;
1159 /* convert pitch values */
1161 pTM
->tmPitchAndFamily
= pfi
->df
.dfPitchAndFamily
;
1162 plf
->lfPitchAndFamily
= (pfi
->df
.dfPitchAndFamily
& 0xF1) + 1;
1164 lstrcpynA( plf
->lfFaceName
, pfi
->df
.dfFace
, LF_FACESIZE
);
1167 /* FIXME: fill in rest of plF values
1168 lstrcpynA(plF->elfFullName, , LF_FULLFACESIZE);
1169 lstrcpynA(plF->elfStyle, , LF_FACESIZE);
1170 lstrcpynA(plF->elfScript, , LF_FACESIZE);
1173 pTM
->tmAscent
= pfi
->df
.dfAscent
;
1174 pTM
->tmDescent
= pTM
->tmHeight
- pTM
->tmAscent
;
1175 pTM
->tmInternalLeading
= pfi
->df
.dfInternalLeading
;
1176 pTM
->tmMaxCharWidth
= pfi
->df
.dfMaxWidth
;
1177 pTM
->tmDigitizedAspectX
= pfi
->df
.dfHorizRes
;
1178 pTM
->tmDigitizedAspectY
= pfi
->df
.dfVertRes
;
1180 pTM
->tmFirstChar
= pfi
->df
.dfFirstChar
;
1181 pTM
->tmLastChar
= pfi
->df
.dfLastChar
;
1182 pTM
->tmDefaultChar
= pfi
->df
.dfDefaultChar
;
1183 pTM
->tmBreakChar
= pfi
->df
.dfBreakChar
;
1185 /* return font type */
1187 return pfi
->df
.dfType
;
1191 /***********************************************************************
1196 * dfPitchAndFamily flags for some common typefaces.
1198 static BYTE
XFONT_FixupFlags( LPCSTR lfFaceName
)
1200 switch( lfFaceName
[0] )
1203 case 'A': if(!strncasecmp(lfFaceName
, "Arial", 5) )
1207 case 'H': if(!strcasecmp(lfFaceName
, "Helvetica") )
1211 case 'C': if(!strncasecmp(lfFaceName
, "Courier", 7))
1214 if (!strcasecmp(lfFaceName
, "Charter") )
1218 case 'P': if( !strcasecmp(lfFaceName
,"Palatino") )
1222 case 'T': if(!strncasecmp(lfFaceName
, "Times", 5) )
1226 case 'U': if(!strcasecmp(lfFaceName
, "Utopia") )
1230 case 'Z': if(!strcasecmp(lfFaceName
, "Zapf Dingbats") )
1231 return FF_DECORATIVE
;
1236 /***********************************************************************
1237 * XFONT_SameFoundryAndFamily
1241 static BOOL
XFONT_SameFoundryAndFamily( const LFD
* lfd1
, const LFD
* lfd2
)
1243 return ( !strcasecmp( lfd1
->foundry
, lfd2
->foundry
) &&
1244 !strcasecmp( lfd1
->family
, lfd2
->family
) );
1247 /***********************************************************************
1248 * XFONT_InitialCapitals
1252 * Upper case first letters of words & remove multiple spaces
1254 static void XFONT_InitialCapitals(LPSTR lpch
)
1260 for( i
= 0, up
= TRUE
; *lpch
; lpch
++, i
++ )
1262 if( isspace(*lpch
) )
1264 if (!up
) /* Not already got one */
1270 else if( isalpha(*lpch
) && up
)
1272 *lpstr
++ = toupper(*lpch
);
1282 /* Remove possible trailing space */
1289 /***********************************************************************
1290 * XFONT_WindowsNames
1294 * Build generic Windows aliases for X font names.
1296 * -misc-fixed- -> "Fixed"
1297 * -sony-fixed- -> "Sony Fixed", etc...
1299 static void XFONT_WindowsNames(void)
1303 for( fr
= fontList
; fr
; fr
= fr
->next
)
1308 if( fr
->fr_flags
& FR_NAMESET
) continue; /* skip already assigned */
1310 for( pfr
= fontList
; pfr
!= fr
; pfr
= pfr
->next
)
1311 if( pfr
->fr_flags
& FR_NAMESET
)
1313 if (!strcasecmp( pfr
->resource
->family
, fr
->resource
->family
))
1317 lpch
= fr
->lfFaceName
;
1318 snprintf( fr
->lfFaceName
, sizeof(fr
->lfFaceName
), "%s %s",
1319 /* prepend vendor name */
1320 (pfr
==fr
) ? "" : fr
->resource
->foundry
,
1321 fr
->resource
->family
);
1322 XFONT_InitialCapitals(fr
->lfFaceName
);
1324 BYTE bFamilyStyle
= XFONT_FixupFlags( fr
->lfFaceName
);
1328 for( fi
= fr
->fi
; fi
; fi
= fi
->next
)
1329 fi
->df
.dfPitchAndFamily
|= bFamilyStyle
;
1333 TRACE("typeface '%s'\n", fr
->lfFaceName
);
1335 fr
->fr_flags
|= FR_NAMESET
;
1339 /***********************************************************************
1340 * XFONT_LoadDefaultLFD
1342 * Move lfd to the head of fontList to make it more likely to be matched
1344 static void XFONT_LoadDefaultLFD(LFD
* lfd
, LPCSTR fonttype
)
1347 fontResource
*fr
, *pfr
;
1348 for( fr
= NULL
, pfr
= fontList
; pfr
; pfr
= pfr
->next
)
1350 if( XFONT_SameFoundryAndFamily(pfr
->resource
, lfd
) )
1354 fr
->next
= pfr
->next
;
1355 pfr
->next
= fontList
;
1363 WARN("Default %sfont '-%s-%s-' not available\n", fonttype
,
1364 lfd
->foundry
, lfd
->family
);
1368 /***********************************************************************
1371 static void XFONT_LoadDefault(LPCSTR ini
, LPCSTR fonttype
)
1373 char buffer
[MAX_LFD_LENGTH
];
1375 if( PROFILE_GetWineIniString( INIFontSection
, ini
, "", buffer
, sizeof buffer
) )
1381 while( *pch
&& isspace(*pch
) ) pch
++;
1383 TRACE("Using '%s' as default %sfont\n", pch
, fonttype
);
1384 lfd
= LFD_Parse(pch
);
1385 if (lfd
&& lfd
->foundry
&& lfd
->family
)
1386 XFONT_LoadDefaultLFD(lfd
, fonttype
);
1388 WARN("Ini section [%s]%s is malformed\n", INIFontSection
, ini
);
1389 HeapFree(GetProcessHeap(), 0, lfd
);
1394 /***********************************************************************
1395 * XFONT_LoadDefaults
1397 static void XFONT_LoadDefaults(void)
1399 XFONT_LoadDefault(INIDefaultFixed
, "fixed ");
1400 XFONT_LoadDefault(INIDefault
, "");
1403 /***********************************************************************
1406 static fontAlias
* XFONT_CreateAlias( LPCSTR lpTypeFace
, LPCSTR lpAlias
)
1409 fontAlias
*pfa
, *prev
= NULL
;
1411 for(pfa
= aliasTable
; pfa
; pfa
= pfa
->next
)
1413 /* check if we already got one */
1414 if( !strcasecmp( pfa
->faTypeFace
, lpAlias
) )
1416 TRACE("redundant alias '%s' -> '%s'\n",
1417 lpAlias
, lpTypeFace
);
1423 j
= strlen(lpTypeFace
) + 1;
1424 pfa
= HeapAlloc( GetProcessHeap(), 0, sizeof(fontAlias
) +
1425 j
+ strlen(lpAlias
) + 1 );
1434 pfa
->faTypeFace
= (LPSTR
)(pfa
+ 1);
1435 strcpy( pfa
->faTypeFace
, lpTypeFace
);
1436 pfa
->faAlias
= pfa
->faTypeFace
+ j
;
1437 strcpy( pfa
->faAlias
, lpAlias
);
1439 TRACE("added alias '%s' for '%s'\n", lpAlias
, lpTypeFace
);
1447 /***********************************************************************
1450 static void XFONT_LoadAlias(const LFD
* lfd
, LPCSTR lpAlias
, BOOL bSubst
)
1452 fontResource
*fr
, *frMatch
= NULL
;
1453 if (!lfd
->foundry
|| ! lfd
->family
)
1455 WARN("Malformed font resource for alias '%s'\n", lpAlias
);
1458 for (fr
= fontList
; fr
; fr
= fr
->next
)
1460 if(!strcasecmp(fr
->resource
->family
, lpAlias
))
1462 /* alias is not needed since the real font is present */
1463 TRACE("Ignoring font alias '%s' as it is already available as a real font\n", lpAlias
);
1466 if( XFONT_SameFoundryAndFamily( fr
->resource
, lfd
) )
1477 fontAlias
*pfa
, *prev
= NULL
;
1479 for(pfa
= aliasTable
; pfa
; pfa
= pfa
->next
)
1481 /* Remove lpAlias from aliasTable - we should free the old entry */
1482 if(!strcmp(lpAlias
, pfa
->faAlias
))
1485 prev
->next
= pfa
->next
;
1487 aliasTable
= pfa
->next
;
1490 /* Update any references to the substituted font in aliasTable */
1491 if(!strcmp(frMatch
->lfFaceName
, pfa
->faTypeFace
))
1492 pfa
->faTypeFace
= HEAP_strdupA( GetProcessHeap(), 0, lpAlias
);
1496 TRACE("\tsubstituted '%s' with '%s'\n", frMatch
->lfFaceName
, lpAlias
);
1498 lstrcpynA( frMatch
->lfFaceName
, lpAlias
, LF_FACESIZE
);
1499 frMatch
->fr_flags
|= FR_NAMESET
;
1503 /* create new entry in the alias table */
1504 XFONT_CreateAlias( frMatch
->lfFaceName
, lpAlias
);
1509 WARN("Font alias '-%s-%s-' is not available\n", lfd
->foundry
, lfd
->family
);
1513 /***********************************************************************
1518 * Create font aliases for some standard windows fonts using user's
1519 * default choice of (sans-)serif fonts
1521 * Read user-defined aliases from wine.conf. Format is as follows
1523 * Alias# = [Windows font name],[LFD font name], <substitute original name>
1526 * Alias0 = Arial, -adobe-helvetica-
1527 * Alias1 = Times New Roman, -bitstream-courier-, 1
1530 * Note that from 970817 and on we have built-in alias templates that take
1531 * care of the necessary Windows typefaces.
1539 static void XFONT_LoadAliases(void)
1542 char buffer
[MAX_LFD_LENGTH
];
1546 /* built-ins first */
1547 PROFILE_GetWineIniString( INIFontSection
, INIDefaultSerif
,
1548 "-bitstream-charter-", buffer
, sizeof buffer
);
1549 TRACE("Using '%s' as default serif font\n", buffer
);
1550 lfd
= LFD_Parse(buffer
);
1551 /* NB XFONT_InitialCapitals should not change these standard aliases */
1554 XFONT_LoadAlias( lfd
, "Tms Roman", FALSE
);
1555 XFONT_LoadAlias( lfd
, "MS Serif", FALSE
);
1556 XFONT_LoadAlias( lfd
, "Times New Roman", FALSE
);
1558 XFONT_LoadDefaultLFD( lfd
, "serif ");
1559 HeapFree(GetProcessHeap(), 0, lfd
);
1562 PROFILE_GetWineIniString( INIFontSection
, INIDefaultSansSerif
,
1563 "-adobe-helvetica-", buffer
, sizeof buffer
);
1564 TRACE("Using '%s' as default sans serif font\n", buffer
);
1565 lfd
= LFD_Parse(buffer
);
1568 XFONT_LoadAlias( lfd
, "Helv", FALSE
);
1569 XFONT_LoadAlias( lfd
, "MS Sans Serif", FALSE
);
1570 XFONT_LoadAlias( lfd
, "Arial", FALSE
);
1572 XFONT_LoadDefaultLFD( lfd
, "sans serif ");
1573 HeapFree(GetProcessHeap(), 0, lfd
);
1576 /* then user specified aliases */
1579 BOOL bHaveAlias
, bSubst
;
1580 char subsection
[32];
1581 snprintf( subsection
, sizeof subsection
, "%s%i", INIAliasSection
, i
++ );
1583 bHaveAlias
= PROFILE_GetWineIniString( INIFontSection
,
1584 subsection
, "", buffer
, sizeof buffer
);
1588 XFONT_InitialCapitals(buffer
);
1589 lpResource
= PROFILE_GetStringItem( buffer
);
1590 bSubst
= (PROFILE_GetStringItem( lpResource
)) ? TRUE
: FALSE
;
1591 if( lpResource
&& *lpResource
)
1593 lfd
= LFD_Parse(lpResource
);
1596 XFONT_LoadAlias(lfd
, buffer
, bSubst
);
1597 HeapFree(GetProcessHeap(), 0, lfd
);
1601 WARN("malformed font alias '%s'\n", buffer
);
1606 /***********************************************************************
1609 * Convert an (potential) alias into a real windows name
1612 static LPCSTR
XFONT_UnAlias(char* font
)
1617 XFONT_InitialCapitals(font
); /* to remove extra white space */
1619 for( fa
= aliasTable
; fa
; fa
= fa
->next
)
1620 /* use case insensitive matching to handle eg "MS Sans Serif" */
1621 if( !strcasecmp( fa
->faAlias
, font
) )
1623 TRACE("found alias '%s'->%s'\n", font
, fa
->faTypeFace
);
1624 strcpy(font
, fa
->faTypeFace
);
1632 /***********************************************************************
1633 * XFONT_RemoveFontResource
1635 * Caller should check if the font resource is in use. If it is it should
1636 * set FR_REMOVED flag to delay removal until the resource is not in use
1639 void XFONT_RemoveFontResource( fontResource
** ppfr
)
1641 fontResource
* pfr
= *ppfr
;
1645 /* FIXME - if fonts were read from a cache, these HeapFrees will fail */
1648 pfi
= pfr
->fi
->next
;
1649 HeapFree( GetProcessHeap(), 0, pfr
->fi
);
1652 HeapFree( GetProcessHeap(), 0, pfr
);
1657 /***********************************************************************
1662 * Removes specified fonts from the font table to prevent Wine from
1665 * Ignore# = [LFD font name]
1668 * Ignore0 = -misc-nil-
1669 * Ignore1 = -sun-open look glyph-
1673 static void XFONT_LoadIgnore(char* lfdname
)
1675 fontResource
** ppfr
;
1677 LFD
* lfd
= LFD_Parse(lfdname
);
1678 if (lfd
&& lfd
->foundry
&& lfd
->family
)
1680 for( ppfr
= &fontList
; *ppfr
; ppfr
= &((*ppfr
)->next
))
1682 if( XFONT_SameFoundryAndFamily( (*ppfr
)->resource
, lfd
) )
1684 TRACE("Ignoring '-%s-%s-'\n",
1685 (*ppfr
)->resource
->foundry
, (*ppfr
)->resource
->family
);
1687 XFONT_RemoveFontResource( ppfr
);
1693 WARN("Malformed font resource\n");
1695 HeapFree(GetProcessHeap(), 0, lfd
);
1698 static void XFONT_LoadIgnores(void)
1701 char subsection
[32];
1702 char buffer
[MAX_LFD_LENGTH
];
1704 /* Standard one that noone wants */
1705 strcpy(buffer
, "-misc-nil-");
1706 XFONT_LoadIgnore(buffer
);
1708 /* Others from INI file */
1711 sprintf( subsection
, "%s%i", INIIgnoreSection
, i
++ );
1713 if( PROFILE_GetWineIniString( INIFontSection
,
1714 subsection
, "", buffer
, sizeof buffer
) )
1717 while( *pch
&& isspace(*pch
) ) pch
++;
1718 XFONT_LoadIgnore(pch
);
1726 /***********************************************************************
1727 * XFONT_UserMetricsCache
1729 * Returns expanded name for the cachedmetrics file.
1730 * Now it also appends the current value of the $DISPLAY variable.
1732 static char* XFONT_UserMetricsCache( char* buffer
, int* buf_size
)
1734 const char *confdir
= get_config_dir();
1735 const char *display_name
= Options
.display
;
1736 int len
= strlen(confdir
) + strlen(INIFontMetrics
) + strlen(display_name
) + 2;
1738 if ((len
> *buf_size
) &&
1739 !(buffer
= HeapReAlloc( GetProcessHeap(), 0, buffer
, *buf_size
= len
)))
1741 ERR("out of memory\n");
1745 sprintf( buffer
, "%s/%s%s", confdir
, INIFontMetrics
, display_name
);
1750 /***********************************************************************
1753 * Compare two fonts (only parameters set by the XFONT_InitFontInfo()).
1755 static INT
XFONT_IsSubset(const fontInfo
* match
, const fontInfo
* fi
)
1759 /* 0 - keep both, 1 - keep match, -1 - keep fi */
1761 /* Compare dfItalic, Underline, Strikeout, Weight, Charset */
1762 m
= (BYTE
*)&fi
->df
.dfPixWidth
- (BYTE
*)&fi
->df
.dfItalic
;
1763 if( memcmp(&match
->df
.dfItalic
, &fi
->df
.dfItalic
, m
)) return 0;
1765 if( (!((fi
->fi_flags
& FI_SCALABLE
) + (match
->fi_flags
& FI_SCALABLE
))
1766 && fi
->lfd_height
!= match
->lfd_height
) ||
1767 (!((fi
->fi_flags
& FI_POLYWEIGHT
) + (match
->fi_flags
& FI_POLYWEIGHT
))
1768 && fi
->df
.dfWeight
!= match
->df
.dfWeight
) ) return 0;
1770 m
= (int)(match
->fi_flags
& (FI_POLYWEIGHT
| FI_SCALABLE
)) -
1771 (int)(fi
->fi_flags
& (FI_SCALABLE
| FI_POLYWEIGHT
));
1773 if( m
== (FI_POLYWEIGHT
- FI_SCALABLE
) ||
1774 m
== (FI_SCALABLE
- FI_POLYWEIGHT
) ) return 0; /* keep both */
1775 else if( m
>= 0 ) return 1; /* 'match' is better */
1777 return -1; /* 'fi' is better */
1780 /***********************************************************************
1783 * REMOVE_SUBSETS - attach new fi and purge subsets
1784 * UNMARK_SUBSETS - remove subset flags from all fi entries
1786 static void XFONT_CheckFIList( fontResource
* fr
, fontInfo
* fi
, int action
)
1789 fontInfo
* pfi
, *prev
;
1791 for( prev
= NULL
, pfi
= fr
->fi
; pfi
; )
1793 if( action
== REMOVE_SUBSETS
)
1795 if( pfi
->fi_flags
& FI_SUBSET
)
1797 fontInfo
* subset
= pfi
;
1801 if( prev
) prev
->next
= pfi
= pfi
->next
;
1802 else fr
->fi
= pfi
= pfi
->next
;
1803 HeapFree( GetProcessHeap(), 0, subset
);
1807 else pfi
->fi_flags
&= ~FI_SUBSET
;
1813 if( action
== REMOVE_SUBSETS
) /* also add the superset */
1815 if( fi
->fi_flags
& FI_SCALABLE
)
1820 else if( prev
) prev
->next
= fi
; else fr
->fi
= fi
;
1824 if( i
) TRACE("\t purged %i subsets [%i]\n", i
, fr
->fi_count
);
1827 /***********************************************************************
1830 static fontResource
* XFONT_FindFIList( fontResource
* pfr
, const char* pTypeFace
)
1834 if( !strcasecmp( pfr
->lfFaceName
, pTypeFace
) ) break;
1837 /* Give the app back the font name it asked for. Encarta checks this. */
1838 if (pfr
) strcpy(pfr
->lfFaceName
,pTypeFace
);
1842 /***********************************************************************
1843 * XFONT_FixupPointSize
1845 static void XFONT_FixupPointSize(fontInfo
* fi
)
1848 df
.dfHorizRes
= df
.dfVertRes
= fi
->lfd_resolution
;
1849 df
.dfPoints
= (INT16
)
1850 (((INT
)(df
.dfPixHeight
- df
.dfInternalLeading
) * 72 + (df
.dfVertRes
>> 1)) /
1855 /***********************************************************************
1856 * XFONT_BuildMetrics
1858 * Build font metrics from X font
1860 static int XFONT_BuildMetrics(char** x_pattern
, int res
, unsigned x_checksum
, int x_count
)
1863 fontInfo
* fi
= NULL
;
1864 fontResource
* fr
, *pfr
;
1867 MESSAGE("Building font metrics. This may take some time...\n");
1868 for( i
= 0; i
< x_count
; i
++ )
1873 char buffer
[MAX_LFD_LENGTH
];
1878 typeface
= HEAP_strdupA(GetProcessHeap(), 0, x_pattern
[i
]);
1882 lfd
= LFD_Parse(typeface
);
1885 HeapFree(GetProcessHeap(), 0, typeface
);
1889 /* find a family to insert into */
1891 for( pfr
= NULL
, fr
= fontList
; fr
; fr
= fr
->next
)
1893 if( XFONT_SameFoundryAndFamily(fr
->resource
, lfd
))
1898 if( !fi
) fi
= (fontInfo
*) HeapAlloc(GetProcessHeap(), 0, sizeof(fontInfo
));
1900 if( !LFD_InitFontInfo( fi
, lfd
, x_pattern
[i
]) )
1903 if( !fr
) /* add new family */
1906 fr
= (fontResource
*) HeapAlloc(GetProcessHeap(), 0, sizeof(fontResource
));
1909 memset(fr
, 0, sizeof(fontResource
));
1911 fr
->resource
= (LFD
*) HeapAlloc(GetProcessHeap(), 0, sizeof(LFD
));
1912 memset(fr
->resource
, 0, sizeof(LFD
));
1914 TRACE("family: -%s-%s-\n", lfd
->foundry
, lfd
->family
);
1915 fr
->resource
->foundry
= HEAP_strdupA(GetProcessHeap(), 0, lfd
->foundry
);
1916 fr
->resource
->family
= HEAP_strdupA(GetProcessHeap(), 0, lfd
->family
);
1917 fr
->resource
->weight
= "";
1919 if( pfr
) pfr
->next
= fr
;
1923 WARN("Not enough memory for a new font family\n");
1926 /* check if we already have something better than "fi" */
1928 for( pfi
= fr
->fi
, j
= 0; pfi
&& j
<= 0; pfi
= pfi
->next
)
1929 if( (j
= XFONT_IsSubset( pfi
, fi
)) < 0 )
1930 pfi
->fi_flags
|= FI_SUBSET
; /* superseded by "fi" */
1931 if( j
> 0 ) goto nextfont
;
1933 /* add new font instance "fi" to the "fr" font resource */
1935 if( fi
->fi_flags
& FI_SCALABLE
)
1938 char pxl_string
[4], res_string
[4];
1939 /* set scalable font height to get an basis for extrapolation */
1941 fi
->lfd_height
= DEF_SCALABLE_HEIGHT
;
1942 fi
->lfd_resolution
= res
;
1944 sprintf(pxl_string
, "%d", fi
->lfd_height
);
1945 sprintf(res_string
, "%d", fi
->lfd_resolution
);
1948 lfd1
.pixel_size
= pxl_string
;
1949 lfd1
.point_size
= "*";
1950 lfd1
.resolution_x
= res_string
;
1951 lfd1
.resolution_y
= res_string
;
1953 LFD_UnParse(buffer
, sizeof buffer
, &lfd1
);
1957 else lpstr
= x_pattern
[i
];
1959 if( (x_fs
= TSXLoadQueryFont(display
, lpstr
)) )
1961 XFONT_SetFontMetric( fi
, fr
, x_fs
);
1962 TSXFreeFont( display
, x_fs
);
1964 XFONT_FixupPointSize(fi
);
1966 TRACE("\t[% 2ipt] '%s'\n", fi
->df
.dfPoints
, x_pattern
[i
] );
1968 XFONT_CheckFIList( fr
, fi
, REMOVE_SUBSETS
);
1969 fi
= NULL
; /* preventing reuse */
1973 ERR("failed to load %s\n", lpstr
);
1975 XFONT_CheckFIList( fr
, fi
, UNMARK_SUBSETS
);
1978 HeapFree(GetProcessHeap(), 0, lfd
);
1979 HeapFree(GetProcessHeap(), 0, typeface
);
1981 if( fi
) HeapFree(GetProcessHeap(), 0, fi
);
1983 /* Scan through the font list and remove FontResorce(s) (fr)
1984 * that have no associated Fontinfo(s) (fi).
1985 * This code is necessary because XFONT_ReadCachedMetrics
1986 * assumes that there is at least one fi associated with a fr.
1987 * This assumption is invalid for TT font
1988 * -altsys-ms outlook-medium-r-normal--0-0-0-0-p-0-microsoft-symbol.
1993 while (!fr
->fi_count
)
1995 fontList
= fr
->next
;
1997 HeapFree(GetProcessHeap(), 0, fr
->resource
);
1998 HeapFree(GetProcessHeap(), 0, fr
);
2008 if (!fr
->next
->fi_count
)
2011 fr
->next
= fr
->next
->next
;
2013 HeapFree(GetProcessHeap(), 0, pfr
->resource
);
2014 HeapFree(GetProcessHeap(), 0, pfr
);
2025 /***********************************************************************
2026 * XFONT_ReadCachedMetrics
2030 static BOOL
XFONT_ReadCachedMetrics( int fd
, int res
, unsigned x_checksum
, int x_count
)
2037 /* read checksums */
2038 read( fd
, &u
, sizeof(unsigned) );
2039 read( fd
, &i
, sizeof(int) );
2041 if( u
== x_checksum
&& i
== x_count
)
2043 off_t length
, offset
= 3 * sizeof(int);
2045 /* read total size */
2046 read( fd
, &i
, sizeof(int) );
2047 length
= lseek( fd
, 0, SEEK_END
);
2049 if( length
== (i
+ offset
) )
2051 lseek( fd
, offset
, SEEK_SET
);
2052 fontList
= (fontResource
*)HeapAlloc( GetProcessHeap(), 0, i
);
2055 fontResource
* pfr
= fontList
;
2056 fontInfo
* pfi
= NULL
;
2058 TRACE("Reading cached font metrics:\n");
2060 read( fd
, fontList
, i
); /* read all metrics at once */
2061 while( offset
< length
)
2063 offset
+= sizeof(fontResource
) + sizeof(fontInfo
);
2064 pfr
->fi
= pfi
= (fontInfo
*)(pfr
+ 1);
2068 if( offset
> length
||
2069 pfi
->cptable
>= (UINT16
)X11DRV_CPTABLE_COUNT
||
2070 (int)(pfi
->next
) != j
++ ) goto fail
;
2072 if( pfi
->df
.dfPixHeight
== 0 ) goto fail
;
2074 pfi
->df
.dfFace
= pfr
->lfFaceName
;
2075 if( pfi
->fi_flags
& FI_SCALABLE
)
2077 /* we can pretend we got this font for any resolution */
2078 pfi
->lfd_resolution
= res
;
2079 XFONT_FixupPointSize(pfi
);
2081 pfi
->next
= pfi
+ 1;
2083 if( j
> pfr
->fi_count
) break;
2086 offset
+= sizeof(fontInfo
);
2091 pfr
->next
= (fontResource
*)(pfi
+ 1);
2096 if( pfr
->next
== NULL
&&
2097 *(int*)(pfi
+ 1) == X_FMC_MAGIC
)
2099 /* read LFD stubs */
2100 char* lpch
= (char*)((int*)(pfi
+ 1) + 1);
2101 offset
+= sizeof(int);
2102 for( pfr
= fontList
; pfr
; pfr
= pfr
->next
)
2104 size_t len
= strlen(lpch
) + 1;
2105 TRACE("\t%s, %i instances\n", lpch
, pfr
->fi_count
);
2106 pfr
->resource
= LFD_Parse(lpch
);
2109 if (offset
> length
)
2119 if( fontList
) HeapFree( GetProcessHeap(), 0, fontList
);
2126 /***********************************************************************
2127 * XFONT_WriteCachedMetrics
2131 static BOOL
XFONT_WriteCachedMetrics( int fd
, unsigned x_checksum
, int x_count
, int n_ff
)
2139 char buffer
[MAX_LFD_LENGTH
];
2141 /* font metrics file:
2145 * +0008 total size to load
2146 * +000C prepackaged font metrics
2149 * +...x + 4 LFD stubs
2152 write( fd
, &x_checksum
, sizeof(unsigned) );
2153 write( fd
, &x_count
, sizeof(int) );
2155 for( j
= i
= 0, pfr
= fontList
; pfr
; pfr
= pfr
->next
)
2157 LFD_UnParse(buffer
, sizeof buffer
, pfr
->resource
);
2158 i
+= strlen( buffer
) + 1;
2161 i
+= n_ff
* sizeof(fontResource
) + j
* sizeof(fontInfo
) + sizeof(int);
2162 write( fd
, &i
, sizeof(int) );
2164 TRACE("Writing font cache:\n");
2166 for( pfr
= fontList
; pfr
; pfr
= pfr
->next
)
2170 TRACE("\t-%s-%s-, %i instances\n", pfr
->resource
->foundry
, pfr
->resource
->family
, pfr
->fi_count
);
2172 i
= write( fd
, pfr
, sizeof(fontResource
) );
2173 if( i
== sizeof(fontResource
) )
2175 for( k
= 1, pfi
= pfr
->fi
; pfi
; pfi
= pfi
->next
)
2179 fi
.df
.dfFace
= NULL
;
2180 fi
.next
= (fontInfo
*)k
; /* loader checks this */
2182 j
= write( fd
, &fi
, sizeof(fi
) );
2185 if( j
== sizeof(fontInfo
) ) continue;
2189 if( i
== sizeof(fontResource
) && j
== sizeof(fontInfo
) )
2191 i
= j
= X_FMC_MAGIC
;
2192 write( fd
, &i
, sizeof(int) );
2193 for( pfr
= fontList
; pfr
&& i
== j
; pfr
= pfr
->next
)
2195 LFD_UnParse(buffer
, sizeof buffer
, pfr
->resource
);
2196 i
= strlen( buffer
) + 1;
2197 j
= write( fd
, buffer
, i
);
2206 /***********************************************************************
2207 * XFONT_GetPointResolution()
2211 * Here we initialize DefResolution which is used in the
2212 * XFONT_Match() penalty function. We also load the point
2213 * resolution value (higher values result in larger fonts).
2215 static int XFONT_GetPointResolution( DeviceCaps
* pDevCaps
)
2217 int i
, j
, point_resolution
, num
= 3;
2218 int allowed_xfont_resolutions
[3] = { 72, 75, 100 };
2219 int best
= 0, best_diff
= 65536;
2221 point_resolution
= PROFILE_GetWineIniInt( INIFontSection
, INIResolution
, 0 );
2222 if( !point_resolution
)
2223 point_resolution
= pDevCaps
->logPixelsY
;
2225 pDevCaps
->logPixelsX
= pDevCaps
->logPixelsY
= point_resolution
;
2228 /* FIXME We can only really guess at a best DefResolution
2229 * - this should be configurable
2231 for( i
= best
= 0; i
< num
; i
++ )
2233 j
= abs( point_resolution
- allowed_xfont_resolutions
[i
] );
2240 DefResolution
= allowed_xfont_resolutions
[best
];
2242 /* FIXME - do win95,nt40,... do this as well ? */
2243 if (TWEAK_WineLook
== WIN98_LOOK
)
2245 /* Lie about the screen size, so that eg MM_LOMETRIC becomes MM_logical_LOMETRIC */
2247 denom
= pDevCaps
->logPixelsX
* 10;
2248 pDevCaps
->horzSize
= (pDevCaps
->horzRes
* 254 + (denom
>>1)) / denom
;
2249 denom
= pDevCaps
->logPixelsY
* 10;
2250 pDevCaps
->vertSize
= (pDevCaps
->vertRes
* 254 + (denom
>>1)) / denom
;
2253 return point_resolution
;
2257 /***********************************************************************
2260 * Compute the matching score between the logical font and the device font.
2262 * contributions from highest to lowest:
2266 * family flags (only when the facename is not present)
2268 * weight, italics, underlines, strikeouts
2270 * NOTE: you can experiment with different penalty weights to see what happens.
2271 * http://premium.microsoft.com/msdn/library/techart/f365/f36b/f37b/d38b/sa8bf.htm
2273 static UINT
XFONT_Match( fontMatch
* pfm
)
2275 fontInfo
* pfi
= pfm
->pfi
; /* device font to match */
2276 LPLOGFONT16 plf
= pfm
->plf
; /* wanted logical font */
2278 BOOL bR6
= pfm
->flags
& FO_MATCH_XYINDEP
; /* from TextCaps */
2279 BOOL bScale
= pfi
->fi_flags
& FI_SCALABLE
;
2282 TRACE("\t[ %-2ipt h=%-3i w=%-3i %s%s]\n", pfi
->df
.dfPoints
,
2283 pfi
->df
.dfPixHeight
, pfi
->df
.dfAvgWidth
,
2284 (pfi
->df
.dfWeight
> FW_NORMAL
) ? "Bold " : "Normal ",
2285 (pfi
->df
.dfItalic
) ? "Italic" : "" );
2287 pfm
->flags
&= FO_MATCH_MASK
;
2290 if (pfi
->df
.dfCharSet
== DEFAULT_CHARSET
)
2292 /* special case(unicode font) */
2293 /* priority: unmatched charset < unicode < matched charset */
2298 if( plf
->lfCharSet
== DEFAULT_CHARSET
)
2300 if (pfi
->df
.dfCharSet
!= ANSI_CHARSET
)
2303 else if (plf
->lfCharSet
!= pfi
->df
.dfCharSet
) penalty
+= 0x200;
2309 if( plf
->lfHeight
> 0 )
2311 int h
= pfi
->df
.dfPixHeight
;
2312 d
= h
- plf
->lfHeight
;
2313 height
= plf
->lfHeight
;
2317 int h
= pfi
->df
.dfPixHeight
- pfi
->df
.dfInternalLeading
;
2320 d
= h
+ plf
->lfHeight
;
2321 height
= (-plf
->lfHeight
* pfi
->df
.dfPixHeight
) / h
;
2325 ERR("PixHeight == InternalLeading\n");
2326 penalty
+= 0x1000; /* dont want this */
2332 pfm
->height
= 1; /* Very small */
2336 pfm
->height
= height
;
2337 else if( (plf
->lfQuality
!= PROOF_QUALITY
) && bR6
)
2339 if( d
> 0 ) /* do not shrink raster fonts */
2341 pfm
->height
= pfi
->df
.dfPixHeight
;
2342 penalty
+= (pfi
->df
.dfPixHeight
- height
) * 0x4;
2344 else /* expand only in integer multiples */
2346 pfm
->height
= height
- height
%pfi
->df
.dfPixHeight
;
2347 penalty
+= (height
- pfm
->height
+ 1) * height
/ pfi
->df
.dfPixHeight
;
2350 else /* can't be scaled at all */
2352 if( plf
->lfQuality
!= PROOF_QUALITY
) pfm
->flags
|= FO_SYNTH_HEIGHT
;
2353 pfm
->height
= pfi
->df
.dfPixHeight
;
2354 penalty
+= (d
> 0)? d
* 0x8 : -d
* 0x10;
2358 pfm
->height
= pfi
->df
.dfPixHeight
;
2360 /* Pitch and Family */
2361 if( pfm
->flags
& FO_MATCH_PAF
) {
2362 int family
= plf
->lfPitchAndFamily
& FF_FAMILY
;
2364 /* TMPF_FIXED_PITCH means exactly the opposite */
2365 if( plf
->lfPitchAndFamily
& FIXED_PITCH
) {
2366 if( pfi
->df
.dfPitchAndFamily
& TMPF_FIXED_PITCH
) penalty
+= 0x100;
2367 } else /* Variable is the default */
2368 if( !(pfi
->df
.dfPitchAndFamily
& TMPF_FIXED_PITCH
) ) penalty
+= 0x2;
2370 if (family
!= FF_DONTCARE
&& family
!= (pfi
->df
.dfPitchAndFamily
& FF_FAMILY
) )
2378 if( bR6
|| bScale
) h
= 0;
2381 /* FIXME: not complete */
2383 pfm
->flags
|= FO_SYNTH_WIDTH
;
2384 h
= abs(plf
->lfWidth
- (pfm
->height
* pfi
->df
.dfAvgWidth
)/pfi
->df
.dfPixHeight
);
2386 penalty
+= h
* ( d
) ? 0x2 : 0x1 ;
2388 else if( !(pfi
->fi_flags
& FI_NORMAL
) ) penalty
++;
2391 if( plf
->lfWeight
!= FW_DONTCARE
)
2393 penalty
+= abs(plf
->lfWeight
- pfi
->df
.dfWeight
) / 40;
2394 if( plf
->lfWeight
> pfi
->df
.dfWeight
) pfm
->flags
|= FO_SYNTH_BOLD
;
2395 } else if( pfi
->df
.dfWeight
>= FW_BOLD
) penalty
++; /* choose normal by default */
2398 if( plf
->lfItalic
!= pfi
->df
.dfItalic
)
2401 pfm
->flags
|= FO_SYNTH_ITALIC
;
2404 if( plf
->lfUnderline
) pfm
->flags
|= FO_SYNTH_UNDERLINE
;
2407 if( plf
->lfStrikeOut
) pfm
->flags
|= FO_SYNTH_STRIKEOUT
;
2410 if( penalty
&& !bScale
&& pfi
->lfd_resolution
!= DefResolution
)
2413 TRACE(" returning %i\n", penalty
);
2418 /***********************************************************************
2421 * Scan a particular font resource for the best match.
2423 static UINT
XFONT_MatchFIList( fontMatch
* pfm
)
2425 BOOL skipRaster
= (pfm
->flags
& FO_MATCH_NORASTER
);
2426 UINT current_score
, score
= (UINT
)(-1);
2427 fontMatch fm
= *pfm
;
2429 for( fm
.pfi
= pfm
->pfr
->fi
; fm
.pfi
&& score
; fm
.pfi
= fm
.pfi
->next
)
2431 if( skipRaster
&& !(fm
.pfi
->fi_flags
& FI_SCALABLE
) )
2434 current_score
= XFONT_Match( &fm
);
2435 if( score
> current_score
)
2438 score
= current_score
;
2444 /***********************************************************************
2445 * XFONT_MatchDeviceFont
2447 * Scan font resource tree.
2450 static void XFONT_MatchDeviceFont( fontResource
* start
, fontMatch
* pfm
)
2452 fontMatch fm
= *pfm
;
2453 UINT current_score
, score
= (UINT
)(-1);
2454 fontResource
** ppfr
;
2456 TRACE("(%u) '%s' h=%i weight=%i %s\n",
2457 pfm
->plf
->lfCharSet
, pfm
->plf
->lfFaceName
, pfm
->plf
->lfHeight
,
2458 pfm
->plf
->lfWeight
, (pfm
->plf
->lfItalic
) ? "Italic" : "" );
2461 if( fm
.plf
->lfFaceName
[0] )
2463 fm
.pfr
= XFONT_FindFIList( start
, fm
.plf
->lfFaceName
);
2464 if( fm
.pfr
) /* match family */
2466 TRACE("found facename '%s'\n", fm
.pfr
->lfFaceName
);
2468 if( fm
.pfr
->fr_flags
& FR_REMOVED
)
2472 XFONT_MatchFIList( &fm
);
2480 /* match all available fonts */
2482 fm
.flags
|= FO_MATCH_PAF
;
2483 for( ppfr
= &fontList
; *ppfr
&& score
; ppfr
= &(*ppfr
)->next
)
2485 if( (*ppfr
)->fr_flags
& FR_REMOVED
)
2487 if( (*ppfr
)->fo_count
== 0 )
2488 XFONT_RemoveFontResource( ppfr
);
2494 TRACE("%s\n", fm
.pfr
->lfFaceName
);
2496 current_score
= XFONT_MatchFIList( &fm
);
2497 if( current_score
< score
)
2499 score
= current_score
;
2506 /***********************************************************************
2509 static void XFONT_GrowFreeList(int start
, int end
)
2511 /* add all entries from 'start' up to and including 'end' */
2513 memset( fontCache
+ start
, 0, (end
- start
+ 1) * sizeof(fontObject
) );
2515 fontCache
[end
].lru
= fontLF
;
2516 fontCache
[end
].count
= -1;
2518 while( start
< end
)
2520 fontCache
[start
].count
= -1;
2521 fontCache
[start
].lru
= start
+ 1;
2526 static fontObject
* XFONT_LookupCachedFont( const LPLOGFONT16 plf
, UINT16
* checksum
)
2528 UINT16 cs
= __lfCheckSum( plf
);
2529 int i
= fontMRU
, prev
= -1;
2534 if( fontCache
[i
].lfchecksum
== cs
&&
2535 !(fontCache
[i
].fo_flags
& FO_REMOVED
) )
2537 /* FIXME: something more intelligent here ? */
2539 if( !memcmp( plf
, &fontCache
[i
].lf
,
2540 sizeof(LOGFONT16
) - LF_FACESIZE
) &&
2541 !strcmp( plf
->lfFaceName
, fontCache
[i
].lf
.lfFaceName
) )
2543 /* remove temporarily from the lru list */
2545 fontCache
[prev
].lru
= fontCache
[i
].lru
;
2547 fontMRU
= (INT16
)fontCache
[i
].lru
;
2548 return (fontCache
+ i
);
2552 i
= (INT16
)fontCache
[i
].lru
;
2557 static fontObject
* XFONT_GetCacheEntry(void)
2563 int prev_i
, prev_j
, j
;
2565 TRACE("font cache is full\n");
2567 /* lookup the least recently used font */
2569 for( prev_i
= prev_j
= j
= -1, i
= fontMRU
; i
>= 0; i
= (INT16
)fontCache
[i
].lru
)
2571 if( fontCache
[i
].count
<= 0 &&
2572 !(fontCache
[i
].fo_flags
& FO_SYSTEM
) )
2580 if( j
>= 0 ) /* unload font */
2582 /* detach from the lru list */
2584 TRACE("\tfreeing entry %i\n", j
);
2586 fontCache
[j
].fr
->fo_count
--;
2589 fontCache
[prev_j
].lru
= fontCache
[j
].lru
;
2590 else fontMRU
= (INT16
)fontCache
[j
].lru
;
2592 /* FIXME: lpXForm, lpPixmap */
2593 if(fontCache
[j
].lpX11Trans
)
2594 HeapFree( GetProcessHeap(), 0, fontCache
[j
].lpX11Trans
);
2596 TSXFreeFont( display
, fontCache
[j
].fs
);
2598 memset( fontCache
+ j
, 0, sizeof(fontObject
) );
2599 return (fontCache
+ j
);
2601 else /* expand cache */
2603 fontObject
* newCache
;
2605 prev_i
= fontCacheSize
+ FONTCACHE
;
2607 TRACE("\tgrowing font cache from %i to %i\n", fontCacheSize
, prev_i
);
2609 if( (newCache
= (fontObject
*)HeapReAlloc(GetProcessHeap(), 0,
2610 fontCache
, prev_i
)) )
2613 fontCacheSize
= prev_i
;
2614 fontCache
= newCache
;
2615 XFONT_GrowFreeList( i
, fontCacheSize
- 1);
2621 /* detach from the free list */
2624 fontLF
= (INT16
)fontCache
[i
].lru
;
2625 fontCache
[i
].count
= 0;
2626 return (fontCache
+ i
);
2629 static int XFONT_ReleaseCacheEntry(const fontObject
* pfo
)
2631 UINT u
= (UINT
)(pfo
- fontCache
);
2633 if( u
< fontCacheSize
) return (--fontCache
[u
].count
);
2637 /***********************************************************************
2640 * Initialize font resource list and allocate font cache.
2642 BOOL
X11DRV_FONT_Init( DeviceCaps
* pDevCaps
)
2645 unsigned x_checksum
;
2646 int i
,res
, x_count
, fd
, buf_size
;
2649 res
= XFONT_GetPointResolution( pDevCaps
);
2651 x_pattern
= TSXListFonts(display
, "*", MAX_FONTS
, &x_count
);
2653 TRACE("Font Mapper: initializing %i fonts [logical dpi=%i, default dpi=%i]\n",
2654 x_count
, res
, DefResolution
);
2655 if (x_count
== MAX_FONTS
)
2656 MESSAGE("There may be more fonts available - try increasing the value of MAX_FONTS\n");
2658 for( i
= x_checksum
= 0; i
< x_count
; i
++ )
2662 printf("%i\t: %s\n", i
, x_pattern
[i
] );
2665 j
= strlen( x_pattern
[i
] );
2666 if( j
) x_checksum
^= __genericCheckSum( x_pattern
[i
], j
);
2668 x_checksum
|= X_PFONT_MAGIC
;
2670 buffer
= HeapAlloc( GetProcessHeap(), 0, buf_size
);
2672 /* deal with systemwide font metrics cache */
2674 if( PROFILE_GetWineIniString( INIFontSection
, INIGlobalMetrics
, "", buffer
, buf_size
) )
2676 fd
= open( buffer
, O_RDONLY
);
2677 XFONT_ReadCachedMetrics(fd
, DefResolution
, x_checksum
, x_count
);
2679 if (fontList
== NULL
)
2682 buffer
= XFONT_UserMetricsCache( buffer
, &buf_size
);
2685 fd
= open( buffer
, O_RDONLY
);
2686 XFONT_ReadCachedMetrics(fd
, DefResolution
, x_checksum
, x_count
);
2690 if( fontList
== NULL
) /* build metrics from scratch */
2692 int n_ff
= XFONT_BuildMetrics(x_pattern
, DefResolution
, x_checksum
, x_count
);
2693 if( buffer
[0] ) /* update cached metrics */
2695 fd
= open( buffer
, O_CREAT
| O_TRUNC
| O_RDWR
, 0644 ); /* -rw-r--r-- */
2696 if( XFONT_WriteCachedMetrics( fd
, x_checksum
, x_count
, n_ff
) == FALSE
)
2698 WARN("Unable to write to fontcache '%s'\n", buffer
);
2699 if( fd
>= 0) remove( buffer
); /* couldn't write entire file */
2704 TSXFreeFontNames(x_pattern
);
2706 /* check if we're dealing with X11 R6 server */
2709 strcpy(buffer
, "-*-*-*-*-normal-*-[12 0 0 12]-*-72-*-*-*-iso8859-1");
2710 if( (x_fs
= TSXLoadQueryFont(display
, buffer
)) )
2712 XTextCaps
|= TC_SF_X_YINDEP
;
2713 TSXFreeFont(display
, x_fs
);
2716 HeapFree(GetProcessHeap(), 0, buffer
);
2718 XFONT_WindowsNames();
2719 XFONT_LoadAliases();
2720 XFONT_LoadDefaults();
2721 XFONT_LoadIgnores();
2723 /* fontList initialization is over, allocate X font cache */
2725 fontCache
= (fontObject
*) HeapAlloc(GetProcessHeap(), 0, fontCacheSize
* sizeof(fontObject
));
2726 XFONT_GrowFreeList(0, fontCacheSize
- 1);
2730 /* update text caps parameter */
2732 pDevCaps
->textCaps
= XTextCaps
;
2734 RAW_ASCENT
= TSXInternAtom(display
, "RAW_ASCENT", TRUE
);
2735 RAW_DESCENT
= TSXInternAtom(display
, "RAW_DESCENT", TRUE
);
2740 /**********************************************************************
2743 static BOOL
XFONT_SetX11Trans( fontObject
*pfo
)
2749 TSXGetFontProperty( pfo
->fs
, XA_FONT
, &nameAtom
);
2750 fontName
= TSXGetAtomName( display
, nameAtom
);
2751 lfd
= LFD_Parse(fontName
);
2758 if (lfd
->pixel_size
[0] != '[') {
2759 HeapFree(GetProcessHeap(), 0, lfd
);
2764 #define PX pfo->lpX11Trans
2766 sscanf(lfd
->pixel_size
, "[%f%f%f%f]", &PX
->a
, &PX
->b
, &PX
->c
, &PX
->d
);
2768 HeapFree(GetProcessHeap(), 0, lfd
);
2770 TSXGetFontProperty( pfo
->fs
, RAW_ASCENT
, &PX
->RAW_ASCENT
);
2771 TSXGetFontProperty( pfo
->fs
, RAW_DESCENT
, &PX
->RAW_DESCENT
);
2773 PX
->pixelsize
= hypot(PX
->a
, PX
->b
);
2774 PX
->ascent
= PX
->pixelsize
/ 1000.0 * PX
->RAW_ASCENT
;
2775 PX
->descent
= PX
->pixelsize
/ 1000.0 * PX
->RAW_DESCENT
;
2777 TRACE("[%f %f %f %f] RA = %ld RD = %ld\n",
2778 PX
->a
, PX
->b
, PX
->c
, PX
->d
,
2779 PX
->RAW_ASCENT
, PX
->RAW_DESCENT
);
2785 /***********************************************************************
2786 * X Device Font Objects
2788 static X_PHYSFONT
XFONT_RealizeFont( const LPLOGFONT16 plf
, LPCSTR
* faceMatched
)
2794 pfo
= XFONT_LookupCachedFont( plf
, &checksum
);
2806 if( XTextCaps
& TC_SF_X_YINDEP
) fm
.flags
= FO_MATCH_XYINDEP
;
2808 /* allocate new font cache entry */
2810 if( (pfo
= XFONT_GetCacheEntry()) )
2812 /* initialize entry and load font */
2813 char lpLFD
[MAX_LFD_LENGTH
];
2814 UINT uRelaxLevel
= 0;
2816 if(abs(plf
->lfHeight
) > MAX_FONT_SIZE
) {
2818 "plf->lfHeight = %d, Creating a 100 pixel font and rescaling metrics \n",
2820 pfo
->rescale
= fabs(plf
->lfHeight
/ 100.0);
2821 if(plf
->lfHeight
> 0) plf
->lfHeight
= 100;
2822 else plf
->lfHeight
= -100;
2826 XFONT_MatchDeviceFont( fontList
, &fm
);
2829 pfo
->fr
->fo_count
++;
2830 pfo
->fo_flags
= fm
.flags
& ~FO_MATCH_MASK
;
2833 pfo
->lfchecksum
= checksum
;
2837 LFD_ComposeLFD( pfo
, fm
.height
, lpLFD
, uRelaxLevel
++ );
2838 if( (pfo
->fs
= TSXLoadQueryFont( display
, lpLFD
)) ) break;
2839 } while( uRelaxLevel
);
2842 if(pfo
->lf
.lfEscapement
!= 0) {
2843 pfo
->lpX11Trans
= HeapAlloc(GetProcessHeap(), 0, sizeof(XFONTTRANS
));
2844 if(!XFONT_SetX11Trans( pfo
)) {
2845 HeapFree(GetProcessHeap(), 0, pfo
->lpX11Trans
);
2846 pfo
->lpX11Trans
= NULL
;
2849 XFONT_GetLeading( &pfo
->fi
->df
, pfo
->fs
,
2850 &pfo
->foInternalLeading
, NULL
, pfo
->lpX11Trans
);
2851 pfo
->foAvgCharWidth
= (INT16
)XFONT_GetAvgCharWidth(&pfo
->fi
->df
, pfo
->fs
, pfo
->lpX11Trans
);
2852 pfo
->foMaxCharWidth
= (INT16
)XFONT_GetMaxCharWidth(pfo
->fs
, pfo
->lpX11Trans
);
2854 /* FIXME: If we've got a soft font or
2855 * there are FO_SYNTH_... flags for the
2856 * non PROOF_QUALITY request, the engine
2857 * should rasterize characters into mono
2858 * pixmaps and store them in the pfo->lpPixmap
2859 * array (pfo->fs should be updated as well).
2860 * array (pfo->fs should be updated as well).
2861 * X11DRV_ExtTextOut() must be heavily modified
2862 * to support pixmap blitting and FO_SYNTH_...
2866 pfo
->lpPixmap
= NULL
;
2869 if( !pfo
) /* couldn't get a new entry, get one of the cached fonts */
2871 UINT current_score
, score
= (UINT
)(-1);
2873 i
= index
= fontMRU
;
2874 fm
.flags
|= FO_MATCH_PAF
;
2877 pfo
= fontCache
+ i
;
2878 fm
.pfr
= pfo
->fr
; fm
.pfi
= pfo
->fi
;
2880 current_score
= XFONT_Match( &fm
);
2881 if( current_score
< score
) index
= i
;
2885 pfo
= fontCache
+ index
;
2890 /* attach at the head of the lru list */
2892 index
= fontMRU
= (pfo
- fontCache
);
2897 TRACE("physfont %i\n", index
);
2898 *faceMatched
= pfo
->fi
->df
.dfFace
;
2900 return (X_PHYSFONT
)(X_PFONT_MAGIC
| index
);
2903 /***********************************************************************
2904 * XFONT_GetFontObject
2906 fontObject
* XFONT_GetFontObject( X_PHYSFONT pFont
)
2908 if( CHECK_PFONT(pFont
) ) return __PFONT(pFont
);
2912 /***********************************************************************
2913 * XFONT_GetFontStruct
2915 XFontStruct
* XFONT_GetFontStruct( X_PHYSFONT pFont
)
2917 if( CHECK_PFONT(pFont
) ) return __PFONT(pFont
)->fs
;
2921 /***********************************************************************
2924 LPIFONTINFO16
XFONT_GetFontInfo( X_PHYSFONT pFont
)
2926 if( CHECK_PFONT(pFont
) ) return &(__PFONT(pFont
)->fi
->df
);
2932 /* X11DRV Interface ****************************************************
2934 * Exposed via the dc->funcs dispatch table. *
2936 ***********************************************************************/
2937 /***********************************************************************
2938 * X11DRV_FONT_SelectObject
2940 HFONT
X11DRV_FONT_SelectObject( DC
* dc
, HFONT hfont
, FONTOBJ
* font
)
2942 HFONT hPrevFont
= 0;
2944 X11DRV_PDEVICE
*physDev
= (X11DRV_PDEVICE
*)dc
->physDev
;
2946 EnterCriticalSection( &crtsc_fonts_X11
);
2948 if( CHECK_PFONT(physDev
->font
) )
2949 XFONT_ReleaseCacheEntry( __PFONT(physDev
->font
) );
2953 /* Make sure we don't change the sign when converting to device coords */
2954 /* FIXME - check that the other drivers do this correctly */
2957 int vpt
= abs(dc
->vportExtX
);
2958 int wnd
= abs(dc
->wndExtX
);
2959 lf
.lfWidth
= (abs(lf
.lfWidth
) * vpt
+ (wnd
>>1))/wnd
;
2960 if (lf
.lfWidth
== 0)
2961 lf
.lfWidth
= 1; /* Minimum width */
2965 int vpt
= abs(dc
->vportExtY
);
2966 int wnd
= abs(dc
->wndExtY
);
2967 if (lf
.lfHeight
> 0)
2968 lf
.lfHeight
= (lf
.lfHeight
* vpt
+ (wnd
>>1))/wnd
;
2970 lf
.lfHeight
= (lf
.lfHeight
* vpt
- (wnd
>>1))/wnd
;
2972 if (lf
.lfHeight
== 0)
2973 lf
.lfHeight
= MIN_FONT_SIZE
;
2976 lf
.lfHeight
= -(DEF_POINT_SIZE
* dc
->w
.devCaps
->logPixelsY
+ (72>>1)) / 72;
2979 /* Fixup aliases before passing to RealizeFont */
2980 /* alias = Windows name in the alias table */
2981 LPCSTR alias
= XFONT_UnAlias( lf
.lfFaceName
);
2984 TRACE("hfont=%04x\n", hfont
); /* to connect with the trace from RealizeFont */
2985 physDev
->font
= XFONT_RealizeFont( &lf
, &faceMatched
);
2987 /* set face to the requested facename if it matched
2988 * so that GetTextFace can get the correct face name
2990 if (alias
&& !strcmp(faceMatched
, lf
.lfFaceName
))
2991 strcpy( font
->logfont
.lfFaceName
, alias
);
2993 strcpy( font
->logfont
.lfFaceName
, faceMatched
);
2996 hPrevFont
= dc
->w
.hFont
;
2997 dc
->w
.hFont
= hfont
;
2999 LeaveCriticalSection( &crtsc_fonts_X11
);
3005 /***********************************************************************
3007 * X11DRV_EnumDeviceFonts
3009 BOOL
X11DRV_EnumDeviceFonts( DC
* dc
, LPLOGFONT16 plf
,
3010 DEVICEFONTENUMPROC proc
, LPARAM lp
)
3014 fontResource
* pfr
= fontList
;
3017 if( plf
->lfFaceName
[0] )
3019 /* enum all entries in this resource */
3020 pfr
= XFONT_FindFIList( pfr
, plf
->lfFaceName
);
3024 for( pfi
= pfr
->fi
; pfi
; pfi
= pfi
->next
)
3026 /* Note: XFONT_GetFontMetric() will have to
3027 release the crit section, font list will
3028 have to be retraversed on return */
3030 if( (b
= (*proc
)( &lf
, &tm
,
3031 XFONT_GetFontMetric( pfi
, &lf
, &tm
), lp
)) )
3037 else /* enum first entry in each resource */
3038 for( ; pfr
; pfr
= pfr
->next
)
3042 if( (b
= (*proc
)( &lf
, &tm
,
3043 XFONT_GetFontMetric( pfr
->fi
, &lf
, &tm
), lp
)) )
3052 /***********************************************************************
3053 * X11DRV_GetTextMetrics
3055 BOOL
X11DRV_GetTextMetrics(DC
*dc
, TEXTMETRICA
*metrics
)
3057 X11DRV_PDEVICE
*physDev
= (X11DRV_PDEVICE
*)dc
->physDev
;
3059 if( CHECK_PFONT(physDev
->font
) )
3061 fontObject
* pfo
= __PFONT(physDev
->font
);
3062 XFONT_GetTextMetrics( pfo
, metrics
);
3070 /***********************************************************************
3071 * X11DRV_GetCharWidth
3073 BOOL
X11DRV_GetCharWidth( DC
*dc
, UINT firstChar
, UINT lastChar
,
3076 X11DRV_PDEVICE
*physDev
= (X11DRV_PDEVICE
*)dc
->physDev
;
3077 fontObject
* pfo
= XFONT_GetFontObject( physDev
->font
);
3083 if (pfo
->fs
->per_char
== NULL
)
3084 for (i
= firstChar
; i
<= lastChar
; i
++)
3086 *buffer
++ = pfo
->fs
->min_bounds
.attributes
*
3087 pfo
->lpX11Trans
->pixelsize
/ 1000.0 * pfo
->rescale
;
3089 *buffer
++ = pfo
->fs
->min_bounds
.width
* pfo
->rescale
;
3092 XCharStruct
*cs
, *def
;
3093 static XCharStruct __null_char
= { 0, 0, 0, 0, 0, 0 };
3095 CI_GET_CHAR_INFO(pfo
->fs
, pfo
->fs
->default_char
, &__null_char
,
3098 for (i
= firstChar
; i
<= lastChar
; i
++)
3100 if (i
>= pfo
->fs
->min_char_or_byte2
&&
3101 i
<= pfo
->fs
->max_char_or_byte2
)
3103 cs
= &pfo
->fs
->per_char
[(i
- pfo
->fs
->min_char_or_byte2
)];
3104 if (CI_NONEXISTCHAR(cs
)) cs
= def
;
3107 *buffer
++ = max(cs
->attributes
, 0) *
3108 pfo
->lpX11Trans
->pixelsize
/ 1000.0 * pfo
->rescale
;
3110 *buffer
++ = max(cs
->width
, 0 ) * pfo
->rescale
;