4 * Copyright 1993 Alexandre Julliard
6 * Enhacements by Juergen Marquardt 1996
8 * Implementation of a second font cache which
9 * will be updated dynamically
15 #include <X11/Xatom.h>
25 #define FONTCACHE 32 /* dynamic font cache size */
27 static LPLOGFONT lpLogFontList
[MAX_FONTS
] = { NULL
};
29 static int ParseFontParms(LPSTR lpFont
, WORD wParmsNo
, LPSTR lpRetStr
, WORD wMaxSiz
);
31 #define CI_NONEXISTCHAR(cs) (((cs)->width == 0) && \
32 (((cs)->rbearing|(cs)->lbearing| \
33 (cs)->ascent|(cs)->descent) == 0))
36 * CI_GET_CHAR_INFO - return the charinfo struct for the indicated 8bit
37 * character. If the character is in the column and exists, then return the
38 * appropriate metrics (note that fonts with common per-character metrics will
39 * return min_bounds). If none of these hold true, try again with the default
42 #define CI_GET_CHAR_INFO(fs,col,def,cs) \
45 if (col >= fs->min_char_or_byte2 && col <= fs->max_char_or_byte2) { \
46 if (fs->per_char == NULL) { \
47 cs = &fs->min_bounds; \
49 cs = &fs->per_char[(col - fs->min_char_or_byte2)]; \
50 if (CI_NONEXISTCHAR(cs)) cs = def; \
55 #define CI_GET_DEFAULT_INFO(fs,cs) \
56 CI_GET_CHAR_INFO(fs, fs->default_char, NULL, cs)
58 struct FontStructure
{
65 /***********************************************************************
68 BOOL
FONT_Init( void )
74 if (PROFILE_GetWineIniString( "fonts", NULL
, "*", temp
, sizeof(temp
) ) > 2 )
76 for( ptr
= temp
, i
= 1; strlen(ptr
) != 0; ptr
+= strlen(ptr
) + 1 )
77 if( strcmp( ptr
, "default" ) )
78 FontNames
[i
++].window
= xstrdup( ptr
);
81 for( i
= 1; i
< FontSize
; i
++ )
83 PROFILE_GetWineIniString( "fonts", FontNames
[i
].window
, "*",
85 FontNames
[i
].x11
= xstrdup( temp
);
87 PROFILE_GetWineIniString( "fonts", "default", "*", temp
, sizeof(temp
) );
88 FontNames
[0].x11
= xstrdup( temp
);
91 FontNames
[0].window
= NULL
; FontNames
[0].x11
= "*-helvetica";
92 FontNames
[1].window
= "ms sans serif"; FontNames
[1].x11
= "*-helvetica";
93 FontNames
[2].window
= "ms serif"; FontNames
[2].x11
= "*-times";
94 FontNames
[3].window
= "fixedsys"; FontNames
[3].x11
= "*-fixed";
95 FontNames
[4].window
= "arial"; FontNames
[4].x11
= "*-helvetica";
96 FontNames
[5].window
= "helv"; FontNames
[5].x11
= "*-helvetica";
97 FontNames
[6].window
= "roman"; FontNames
[6].x11
= "*-times";
103 /***********************************************************************
106 * returns a valid X11 equivalent if a Windows face name
107 * is like a X11 family - or NULL if translation is needed
109 static char *FONT_ChkX11Family(char *winFaceName
)
111 static char x11fam
[32+2]; /* will be returned */
114 for(i
= 0; lpLogFontList
[i
] != NULL
; i
++)
115 if( !strcasecmp(winFaceName
, lpLogFontList
[i
]->lfFaceName
) )
118 return strcat(x11fam
,winFaceName
);
120 return NULL
; /* a FONT_TranslateName() call is needed */
125 /***********************************************************************
128 * Translate a Windows face name to its X11 equivalent.
129 * This will probably have to be customizable.
131 static const char *FONT_TranslateName( char *winFaceName
)
135 for (i
= 1; i
< FontSize
; i
++)
136 if( !strcmp( winFaceName
, FontNames
[i
].window
) ) {
137 dprintf_font(stddeb
, "---- Mapped %s to %s\n", winFaceName
, FontNames
[i
].x11
);
138 return FontNames
[i
].x11
;
140 return FontNames
[0].x11
;
144 /***********************************************************************
147 * Find a X font matching the logical font.
149 static XFontStruct
* FONT_MatchFont( LOGFONT
* font
, DC
* dc
)
152 const char *family
, *weight
, *charset
;
154 char slant
, oldspacing
, spacing
;
155 int width
, height
, oldheight
, count
;
156 XFontStruct
* fontStruct
;
159 "FONT_MatchFont(H,W = %d,%d; Weight = %d; Italic = %d; FaceName = '%s'\n",
160 font
->lfHeight
, font
->lfWidth
, font
->lfWeight
, font
->lfItalic
, font
->lfFaceName
);
161 weight
= (font
->lfWeight
> 550) ? "bold" : "medium";
162 slant
= font
->lfItalic
? 'i' : 'r';
163 if (font
->lfHeight
== -1)
166 height
= font
->lfHeight
* dc
->w
.VportExtX
/ dc
->w
.WndExtX
;
167 if (height
== 0) height
= 120; /* Default height = 12 */
170 /* If height is negative, it means the height of the characters */
171 /* *without* the internal leading. So we adjust it a bit to */
172 /* compensate. 5/4 seems to give good results for small fonts. */
174 * J.M.: This causes wrong font size for bigger fonts e.g. in Winword & Write
175 height = 10 * (-height * 9 / 8);
176 * may be we have to use an non linear function
178 /* assume internal leading is 2 pixels. Else small fonts will become
180 height
= (height
-2) * -10;
183 width
= 10 * (font
->lfWidth
* dc
->w
.VportExtY
/ dc
->w
.WndExtY
);
185 dprintf_font( stddeb
, "FONT_MatchFont: negative width %d(%d)\n",
186 width
, font
->lfWidth
);
190 spacing
= (font
->lfPitchAndFamily
& FIXED_PITCH
) ? 'm' :
191 (font
->lfPitchAndFamily
& VARIABLE_PITCH
) ? 'p' : '*';
194 charset
= (font
->lfCharSet
== ANSI_CHARSET
) ? "iso8859-1" : "*-*";
195 if (*font
->lfFaceName
) {
196 family
= FONT_ChkX11Family(font
->lfFaceName
);
197 /*--do _not_ translate if lfFaceName is family from X11 A.K.*/
199 family
= FONT_TranslateName( font
->lfFaceName
);
200 /* FIX ME: I don't if that's correct but it works J.M. */
203 else switch(font
->lfPitchAndFamily
& 0xf0)
206 family
= FONT_TranslateName( "roman" );
209 family
= FONT_TranslateName( "swiss" );
212 family
= FONT_TranslateName( "modern" );
215 family
= FONT_TranslateName( "script" );
218 family
= FONT_TranslateName( "decorative" );
225 oldspacing
= spacing
;
227 /* Width==0 seems not to be a valid wildcard on SGI's, using * instead */
229 sprintf( pattern
, "-%s-%s-%c-normal-*-*-%d-*-*-%c-*-%s",
230 family
, weight
, slant
, height
, spacing
, charset
);
232 sprintf( pattern
, "-%s-%s-%c-normal-*-*-%d-*-*-%c-%d-%s",
233 family
, weight
, slant
, height
, spacing
, width
, charset
);
234 dprintf_font(stddeb
, "FONT_MatchFont: '%s'\n", pattern
);
235 names
= XListFonts( display
, pattern
, 1, &count
);
236 if (count
> 0) break;
237 if (spacing
== 'm') /* try 'c' if no 'm' found */ {
241 } else if (spacing
== 'p') /* try '*' if no 'p' found */ {
245 spacing
= oldspacing
;
249 /* try oblique if no italic font */
254 if (spacing
== 'm' && strcmp(family
, "*-*") != 0) {
255 /* If a fixed spacing font could not be found, ignore
261 fprintf(stderr
, "FONT_MatchFont(%s) : returning NULL\n", pattern
);
265 dprintf_font(stddeb
," Found '%s'\n", *names
);
266 if (!*font
->lfFaceName
)
267 ParseFontParms(*names
, 2, font
->lfFaceName
, LF_FACESIZE
-1);
268 /* we need a font name for function GetTextFace() even if there isn't one ;-) */
270 fontStruct
= XLoadQueryFont( display
, *names
);
271 XFreeFontNames( names
);
276 /***********************************************************************
279 void FONT_GetMetrics( LOGFONT
* logfont
, XFontStruct
* xfont
,
280 TEXTMETRIC
* metrics
)
282 int average
, i
, count
;
285 metrics
->tmAscent
= xfont
->ascent
;
286 metrics
->tmDescent
= xfont
->descent
;
287 metrics
->tmHeight
= xfont
->ascent
+ xfont
->descent
;
289 metrics
->tmInternalLeading
= 0;
290 if (XGetFontProperty( xfont
, XA_X_HEIGHT
, &prop
))
291 metrics
->tmInternalLeading
= xfont
->ascent
- (short)prop
;
292 metrics
->tmExternalLeading
= 0;
293 metrics
->tmMaxCharWidth
= xfont
->max_bounds
.width
;
294 metrics
->tmWeight
= logfont
->lfWeight
;
295 metrics
->tmItalic
= logfont
->lfItalic
;
296 metrics
->tmUnderlined
= logfont
->lfUnderline
;
297 metrics
->tmStruckOut
= logfont
->lfStrikeOut
;
298 metrics
->tmFirstChar
= xfont
->min_char_or_byte2
;
299 metrics
->tmLastChar
= xfont
->max_char_or_byte2
;
300 metrics
->tmDefaultChar
= xfont
->default_char
;
301 metrics
->tmBreakChar
= ' ';
302 metrics
->tmCharSet
= logfont
->lfCharSet
;
303 metrics
->tmOverhang
= 0;
304 metrics
->tmDigitizedAspectX
= 1;
305 metrics
->tmDigitizedAspectY
= 1;
306 metrics
->tmPitchAndFamily
= (logfont
->lfPitchAndFamily
&0xf0)|TMPF_DEVICE
;
307 if (logfont
->lfPitchAndFamily
& FIXED_PITCH
)
308 metrics
->tmPitchAndFamily
|= TMPF_FIXED_PITCH
;
310 if (!xfont
->per_char
) average
= metrics
->tmMaxCharWidth
;
313 XCharStruct
* charPtr
= xfont
->per_char
;
315 for (i
= metrics
->tmFirstChar
; i
<= metrics
->tmLastChar
; i
++)
317 if (!CI_NONEXISTCHAR( charPtr
))
319 average
+= charPtr
->width
;
324 if (count
) average
= (average
+ count
/2) / count
;
326 metrics
->tmAveCharWidth
= average
;
329 /***********************************************************************
330 * GetGlyphOutLine (GDI.309)
332 DWORD
GetGlyphOutLine(HDC hdc
, UINT uChar
, UINT fuFormat
, LPGLYPHMETRICS lpgm
,
333 DWORD cbBuffer
, LPSTR lpBuffer
, LPMAT2 lpmat2
)
335 fprintf( stdnimp
,"GetGlyphOutLine(%04x, '%c', %04x, %p, %ld, %p, %p) // - empty stub!\n",
336 hdc
, uChar
, fuFormat
, lpgm
, cbBuffer
, lpBuffer
, lpmat2
);
337 return (DWORD
)-1; /* failure */
341 /***********************************************************************
342 * CreateScalableFontResource (GDI.310)
344 BOOL
CreateScalableFontResource( UINT fHidden
,LPSTR lpszResourceFile
,
345 LPSTR lpszFontFile
, LPSTR lpszCurrentPath
)
347 /* fHidden=1 - only visible for the calling app, read-only, not
348 * enumbered with EnumFonts/EnumFontFamilies
349 * lpszCurrentPath can be NULL
351 fprintf(stdnimp
,"CreateScalableFontResource(%d,%s,%s,%s) // empty stub!\n",
352 fHidden
, lpszResourceFile
, lpszFontFile
, lpszCurrentPath
);
353 return FALSE
; /* create failed */
357 /***********************************************************************
358 * CreateFontIndirect (GDI.57)
360 HFONT
CreateFontIndirect( const LOGFONT
* font
)
367 fprintf(stderr
, "CreateFontIndirect : font is NULL : returning NULL\n");
370 hfont
= GDI_AllocObject( sizeof(FONTOBJ
), FONT_MAGIC
);
371 if (!hfont
) return 0;
372 fontPtr
= (FONTOBJ
*) GDI_HEAP_LIN_ADDR( hfont
);
373 memcpy( &fontPtr
->logfont
, font
, sizeof(LOGFONT
) );
374 AnsiLower( fontPtr
->logfont
.lfFaceName
);
375 dprintf_font(stddeb
,"CreateFontIndirect(%p (%d,%d)); return %04x\n",
376 font
, font
->lfHeight
, font
->lfWidth
, hfont
);
381 /***********************************************************************
382 * CreateFont (GDI.56)
384 HFONT
CreateFont( INT height
, INT width
, INT esc
, INT orient
, INT weight
,
385 BYTE italic
, BYTE underline
, BYTE strikeout
, BYTE charset
,
386 BYTE outpres
, BYTE clippres
, BYTE quality
, BYTE pitch
,
389 LOGFONT logfont
= { height
, width
, esc
, orient
, weight
, italic
, underline
,
390 strikeout
, charset
, outpres
, clippres
, quality
, pitch
, };
391 dprintf_font(stddeb
,"CreateFont(%d,%d)\n", height
, width
);
394 strncpy( logfont
.lfFaceName
, name
, LF_FACESIZE
- 1 );
395 logfont
.lfFaceName
[LF_FACESIZE
- 1] = '\0';
397 else logfont
.lfFaceName
[0] = '\0';
398 return CreateFontIndirect( &logfont
);
402 /***********************************************************************
405 int FONT_GetObject( FONTOBJ
* font
, int count
, LPSTR buffer
)
407 if (count
> sizeof(LOGFONT
)) count
= sizeof(LOGFONT
);
408 memcpy( buffer
, &font
->logfont
, count
);
413 /***********************************************************************
416 HFONT
FONT_SelectObject( DC
* dc
, HFONT hfont
, FONTOBJ
* font
)
418 static X_PHYSFONT stockFonts
[LAST_STOCK_FONT
-FIRST_STOCK_FONT
+1];
425 X_PHYSFONT cacheFont
; } cacheFonts
[FONTCACHE
], *cacheFontsMin
;
428 X_PHYSFONT
* stockPtr
;
429 HFONT prevHandle
= dc
->w
.hFont
;
430 XFontStruct
* fontStruct
;
431 dprintf_font(stddeb
,"FONT_SelectObject(%p, %04x, %p)\n", dc
, hfont
, font
);
433 #if 0 /* From the code in SelectObject, this can not happen */
434 /* Load font if necessary */
439 hnewfont
= CreateFont(10, 7, 0, 0, FW_DONTCARE
,
440 FALSE
, FALSE
, FALSE
, DEFAULT_CHARSET
, 0, 0,
441 DEFAULT_QUALITY
, FF_DONTCARE
, "*" );
442 font
= (FONTOBJ
*) GDI_HEAP_LIN_ADDR( hnewfont
);
446 if (dc
->header
.wMagic
== METAFILE_DC_MAGIC
)
447 if (MF_CreateFontIndirect(dc
, hfont
, &(font
->logfont
)))
452 if ((hfont
>= FIRST_STOCK_FONT
) && (hfont
<= LAST_STOCK_FONT
))
453 stockPtr
= &stockFonts
[hfont
- FIRST_STOCK_FONT
];
457 * Ok, It's not a stock font but
458 * may be it's cached in dynamic cache
460 for(i
=0; i
<FONTCACHE
; i
++) /* search for same handle */
461 if (cacheFonts
[i
].id
==hfont
) { /* Got the handle */
463 * Check if Handle matches the font
465 if(memcmp(&cacheFonts
[i
].logfont
,&(font
->logfont
), sizeof(LOGFONT
))) {
466 /* No: remove handle id from dynamic font cache */
467 cacheFonts
[i
].access
=0;
468 cacheFonts
[i
].used
=0;
470 /* may be there is an unused handle which contains the font */
471 for(i
=0; i
<FONTCACHE
; i
++) {
472 if((cacheFonts
[i
].used
== 0) &&
473 (memcmp(&cacheFonts
[i
].logfont
,&(font
->logfont
), sizeof(LOGFONT
)))== 0) {
474 /* got it load from cache and set new handle id */
475 stockPtr
= &cacheFonts
[i
].cacheFont
;
476 cacheFonts
[i
].access
=1;
477 cacheFonts
[i
].used
=1;
478 cacheFonts
[i
].id
=hfont
;
479 dprintf_font(stddeb
,"FONT_SelectObject: got font from unused handle\n");
486 /* Yes: load from dynamic font cache */
487 stockPtr
= &cacheFonts
[i
].cacheFont
;
488 cacheFonts
[i
].access
++;
489 cacheFonts
[i
].used
++;
494 if (!stockPtr
|| !stockPtr
->fstruct
)
496 if (!(fontStruct
= FONT_MatchFont( &font
->logfont
, dc
)))
498 /* If it is not a stock font, we can simply return 0 */
499 if (!stockPtr
) return 0;
500 /* Otherwise we must try to find a substitute */
501 dprintf_font(stddeb
,"Loading font 'fixed' for %04x\n", hfont
);
502 font
->logfont
.lfPitchAndFamily
&= ~VARIABLE_PITCH
;
503 font
->logfont
.lfPitchAndFamily
|= FIXED_PITCH
;
504 fontStruct
= XLoadQueryFont( display
, "fixed" );
507 fprintf( stderr
, "No system font could be found. Please check your font path.\n" );
514 fontStruct
= stockPtr
->fstruct
;
516 "FONT_SelectObject: Loaded font from cache %04x %p\n",
520 /* Unuse previous font */
521 for (i
=0; i
< FONTCACHE
; i
++) {
522 if (cacheFonts
[i
].id
== prevHandle
) {
523 if(cacheFonts
[i
].used
== 0)
524 fprintf(stderr
, "Trying to decrement a use count of 0.\n");
526 cacheFonts
[i
].used
--;
534 if (!stockPtr
->fstruct
)
536 stockPtr
->fstruct
= fontStruct
;
537 FONT_GetMetrics( &font
->logfont
, fontStruct
, &stockPtr
->metrics
);
539 memcpy( &dc
->u
.x
.font
, stockPtr
, sizeof(*stockPtr
) );
547 for (i
=0; i
< FONTCACHE
; i
++) {
548 if (cacheFonts
[i
].used
==0)
549 if ((!cacheFontsMin
) || ((cacheFontsMin
) && (cacheFontsMin
->access
> cacheFonts
[i
].access
)))
550 cacheFontsMin
=&cacheFonts
[i
];
552 if (!cacheFontsMin
) {
553 fprintf(stderr
,"No unused font cache entry !!!!\n" );
556 if (cacheFontsMin
->id
!=0) {
558 "FONT_SelectObject: Freeing %04x \n",cacheFontsMin
->id
);
559 XFreeFont( display
, cacheFontsMin
->cacheFont
.fstruct
);
561 cacheFontsMin
->cacheFont
.fstruct
= fontStruct
;
562 FONT_GetMetrics( &font
->logfont
, fontStruct
, &cacheFontsMin
->cacheFont
.metrics
);
563 cacheFontsMin
->access
=1;
564 cacheFontsMin
->used
=1;
565 cacheFontsMin
->id
=hfont
;
566 memcpy( &dc
->u
.x
.font
, &(cacheFontsMin
->cacheFont
), sizeof(cacheFontsMin
->cacheFont
) );
567 memcpy(&cacheFontsMin
->logfont
,&(font
->logfont
), sizeof(LOGFONT
));
574 /***********************************************************************
575 * GetTextCharacterExtra (GDI.89)
577 short GetTextCharacterExtra( HDC hdc
)
579 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
581 return abs( (dc
->w
.charExtra
* dc
->w
.WndExtX
+ dc
->w
.VportExtX
/ 2)
586 /***********************************************************************
587 * SetTextCharacterExtra (GDI.8)
589 short SetTextCharacterExtra( HDC hdc
, short extra
)
592 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
594 extra
= (extra
* dc
->w
.VportExtX
+ dc
->w
.WndExtX
/ 2) / dc
->w
.WndExtX
;
595 prev
= dc
->w
.charExtra
;
596 dc
->w
.charExtra
= abs(extra
);
597 return (prev
* dc
->w
.WndExtX
+ dc
->w
.VportExtX
/ 2) / dc
->w
.VportExtX
;
601 /***********************************************************************
602 * SetTextJustification (GDI.10)
604 short SetTextJustification( HDC hdc
, short extra
, short breaks
)
606 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
609 extra
= abs((extra
* dc
->w
.VportExtX
+ dc
->w
.WndExtX
/ 2) / dc
->w
.WndExtX
);
610 if (!extra
) breaks
= 0;
611 dc
->w
.breakTotalExtra
= extra
;
612 dc
->w
.breakCount
= breaks
;
615 dc
->w
.breakExtra
= extra
/ breaks
;
616 dc
->w
.breakRem
= extra
- (dc
->w
.breakCount
* dc
->w
.breakExtra
);
620 dc
->w
.breakExtra
= 0;
627 /***********************************************************************
628 * GetTextFace (GDI.92)
630 INT
GetTextFace( HDC hdc
, INT count
, LPSTR name
)
634 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
636 if (!(font
= (FONTOBJ
*) GDI_GetObjPtr( dc
->w
.hFont
, FONT_MAGIC
)))
638 lstrcpyn( name
, font
->logfont
.lfFaceName
, count
);
643 /***********************************************************************
644 * GetTextExtent (GDI.91)
646 DWORD
GetTextExtent( HDC hdc
, LPCSTR str
, short count
)
649 if (!GetTextExtentPoint16( hdc
, str
, count
, &size
)) return 0;
650 return MAKELONG( size
.cx
, size
.cy
);
654 /***********************************************************************
655 * GetTextExtentPoint16 (GDI.471)
657 BOOL16
GetTextExtentPoint16( HDC16 hdc
, LPCSTR str
, INT16 count
, LPSIZE16 size
)
660 BOOL32 ret
= GetTextExtentPoint32A( hdc
, str
, count
, &size32
);
661 CONV_SIZE32TO16( &size32
, size
);
666 /***********************************************************************
667 * GetTextExtentPoint32A (GDI32.232)
669 BOOL32
GetTextExtentPoint32A( HDC32 hdc
, LPCSTR str
, INT32 count
,
672 int dir
, ascent
, descent
;
675 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
676 if (!dc
) return FALSE
;
677 XTextExtents( dc
->u
.x
.font
.fstruct
, str
, count
, &dir
,
678 &ascent
, &descent
, &info
);
679 size
->cx
= abs((info
.width
+ dc
->w
.breakRem
+ count
* dc
->w
.charExtra
)
680 * dc
->w
.WndExtX
/ dc
->w
.VportExtX
);
681 size
->cy
= abs((dc
->u
.x
.font
.fstruct
->ascent
+dc
->u
.x
.font
.fstruct
->descent
)
682 * dc
->w
.WndExtY
/ dc
->w
.VportExtY
);
684 dprintf_font(stddeb
,"GetTextExtentPoint(%08x '%*.*s' %d %p): returning %d,%d\n",
685 hdc
, count
, count
, str
, count
, size
, size
->cx
, size
->cy
);
690 /***********************************************************************
691 * GetTextExtentPoint32W (GDI32.233)
693 BOOL32
GetTextExtentPoint32W( HDC32 hdc
, LPCWSTR str
, INT32 count
,
696 char *p
= STRING32_DupUniToAnsi( str
);
697 BOOL32 ret
= GetTextExtentPoint32A( hdc
, p
, count
, size
);
703 /***********************************************************************
704 * GetTextMetrics (GDI.93)
706 BOOL
GetTextMetrics( HDC hdc
, LPTEXTMETRIC metrics
)
708 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
709 if (!dc
) return FALSE
;
710 memcpy( metrics
, &dc
->u
.x
.font
.metrics
, sizeof(*metrics
) );
712 metrics
->tmAscent
= abs( metrics
->tmAscent
713 * dc
->w
.WndExtY
/ dc
->w
.VportExtY
);
714 metrics
->tmDescent
= abs( metrics
->tmDescent
715 * dc
->w
.WndExtY
/ dc
->w
.VportExtY
);
716 metrics
->tmHeight
= metrics
->tmAscent
+ metrics
->tmDescent
;
717 metrics
->tmInternalLeading
= abs( metrics
->tmInternalLeading
718 * dc
->w
.WndExtY
/ dc
->w
.VportExtY
);
719 metrics
->tmExternalLeading
= abs( metrics
->tmExternalLeading
720 * dc
->w
.WndExtY
/ dc
->w
.VportExtY
);
721 metrics
->tmMaxCharWidth
= abs( metrics
->tmMaxCharWidth
722 * dc
->w
.WndExtX
/ dc
->w
.VportExtX
);
723 metrics
->tmAveCharWidth
= abs( metrics
->tmAveCharWidth
724 * dc
->w
.WndExtX
/ dc
->w
.VportExtX
);
726 dprintf_font(stdnimp
,"text metrics:\n
740 DigitizedAspectX = %i
741 DigitizedAspectY = %i
747 metrics
->tmInternalLeading
,
748 metrics
->tmExternalLeading
,
749 metrics
->tmMaxCharWidth
,
752 metrics
->tmUnderlined
,
753 metrics
->tmStruckOut
,
754 metrics
->tmFirstChar
,
756 metrics
->tmDefaultChar
,
757 metrics
->tmBreakChar
,
760 metrics
->tmDigitizedAspectX
,
761 metrics
->tmDigitizedAspectY
,
762 metrics
->tmAveCharWidth
,
763 metrics
->tmMaxCharWidth
,
772 /***********************************************************************
773 * SetMapperFlags (GDI.349)
775 DWORD
SetMapperFlags(HDC hDC
, DWORD dwFlag
)
777 dprintf_font(stdnimp
,"SetmapperFlags(%04x, %08lX) // Empty Stub !\n",
783 /***********************************************************************
784 * GetCharABCWidths (GDI.307)
786 BOOL
GetCharABCWidths(HDC hdc
, UINT wFirstChar
, UINT wLastChar
, LPABC lpABC
)
788 /* No TrueType fonts in Wine */
793 /***********************************************************************
794 * GetCharWidth (GDI.350)
796 BOOL
GetCharWidth(HDC hdc
, WORD wFirstChar
, WORD wLastChar
, LPINT16 lpBuffer
)
800 XCharStruct
*cs
, *def
;
802 DC
*dc
= (DC
*)GDI_GetObjPtr(hdc
, DC_MAGIC
);
803 if (!dc
) return FALSE
;
804 xfont
= dc
->u
.x
.font
.fstruct
;
807 if (xfont
->per_char
== NULL
)
809 for (i
= wFirstChar
, j
= 0; i
<= wLastChar
; i
++, j
++)
810 *(lpBuffer
+ j
) = xfont
->max_bounds
.width
;
814 CI_GET_DEFAULT_INFO(xfont
, def
);
816 for (i
= wFirstChar
, j
= 0; i
<= wLastChar
; i
++, j
++)
818 CI_GET_CHAR_INFO(xfont
, i
, def
, cs
);
819 *(lpBuffer
+ j
) = cs
? cs
->width
: xfont
->max_bounds
.width
;
820 if (*(lpBuffer
+ j
) < 0)
827 /***********************************************************************
828 * AddFontResource (GDI.119)
830 INT
AddFontResource( LPCSTR str
)
832 fprintf( stdnimp
, "STUB: AddFontResource('%s')\n", str
);
837 /***********************************************************************
838 * RemoveFontResource (GDI.136)
840 BOOL
RemoveFontResource( LPSTR str
)
842 fprintf( stdnimp
, "STUB: RemoveFontResource('%s')\n", str
);
847 /*************************************************************************
848 * ParseFontParms [internal]
850 int ParseFontParms(LPSTR lpFont
, WORD wParmsNo
, LPSTR lpRetStr
, WORD wMaxSiz
)
853 if (lpFont
== NULL
) return 0;
854 if (lpRetStr
== NULL
) return 0;
855 for (i
= 0; (*lpFont
!= '\0' && i
!= wParmsNo
); ) {
856 if (*lpFont
== '-') i
++;
860 if (*lpFont
== '-') lpFont
++;
862 for (i
= 0; (*lpFont
!= '\0' && *lpFont
!= '-' && i
< wMaxSiz
); i
++)
863 *(lpRetStr
+ i
) = *lpFont
++;
864 *(lpRetStr
+ i
) = '\0';
873 /*************************************************************************
874 * InitFontsList [internal]
877 static int logfcmp(const void *a
,const void *b
)
879 return strcmp( (*(LPLOGFONT
*)a
)->lfFaceName
, (*(LPLOGFONT
*)b
)->lfFaceName
);
882 void InitFontsList(void)
886 char *family
, *weight
, *charset
;
896 dprintf_font(stddeb
,"InitFontsList !\n");
897 sprintf( pattern
, "-%s-%s-%c-normal-*-*-*-*-*-%c-*-%s",
898 family
, weight
, slant
, spacing
, charset
);
899 names
= XListFonts( display
, pattern
, MAX_FONTS
, &count
);
900 dprintf_font(stddeb
,"InitFontsList // count=%d \n", count
);
901 for (i
= 0; i
< count
; i
++) {
902 lpNewFont
= malloc(sizeof(LOGFONT
) + LF_FACESIZE
);
903 if (lpNewFont
== NULL
) {
904 dprintf_font(stddeb
, "InitFontsList // Error alloc new font structure !\n");
907 dprintf_font(stddeb
,"InitFontsList // names[%d]='%s' \n", i
, names
[i
]);
908 ParseFontParms(names
[i
], 2, str
, sizeof(str
));
910 /* not necessary because new function FONT_ChkX11Family() */
911 if (strcmp(str
, "fixed") == 0) strcat(str
, "sys");
914 strcpy(lpNewFont
->lfFaceName
, str
);
915 ParseFontParms(names
[i
], 8, str
, sizeof(str
));
916 lpNewFont
->lfHeight
= atoi(str
) / 10;
917 ParseFontParms(names
[i
], 12, str
, sizeof(str
));
918 lpNewFont
->lfWidth
= atoi(str
) / 10;
919 lpNewFont
->lfEscapement
= 0;
920 lpNewFont
->lfOrientation
= 0;
921 lpNewFont
->lfWeight
= FW_REGULAR
;
922 lpNewFont
->lfItalic
= 0;
923 lpNewFont
->lfUnderline
= 0;
924 lpNewFont
->lfStrikeOut
= 0;
925 ParseFontParms(names
[i
], 13, str
, sizeof(str
));
926 if (strcmp(str
, "iso8859") == 0) {
927 lpNewFont
->lfCharSet
= ANSI_CHARSET
;
929 lpNewFont
->lfCharSet
= OEM_CHARSET
;
931 lpNewFont
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
932 lpNewFont
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
933 lpNewFont
->lfQuality
= DEFAULT_QUALITY
;
934 ParseFontParms(names
[i
], 11, str
, sizeof(str
));
937 lpNewFont
->lfPitchAndFamily
= VARIABLE_PITCH
| FF_SWISS
;
941 lpNewFont
->lfPitchAndFamily
= FIXED_PITCH
| FF_MODERN
;
944 lpNewFont
->lfPitchAndFamily
= DEFAULT_PITCH
| FF_DONTCARE
;
947 dprintf_font(stddeb
,"InitFontsList // lpNewFont->lfHeight=%d \n", lpNewFont
->lfHeight
);
948 dprintf_font(stddeb
,"InitFontsList // lpNewFont->lfWidth=%d \n", lpNewFont
->lfWidth
);
949 dprintf_font(stddeb
,"InitFontsList // lfFaceName='%s' \n", lpNewFont
->lfFaceName
);
950 lpLogFontList
[i
] = lpNewFont
;
951 lpLogFontList
[i
+1] = NULL
;
953 qsort(lpLogFontList
,count
,sizeof(*lpLogFontList
),logfcmp
);
954 XFreeFontNames(names
);
958 /*************************************************************************
961 INT
EnumFonts(HDC hDC
, LPCSTR lpFaceName
, FONTENUMPROC lpEnumFunc
, LPARAM lpData
)
970 char FaceName
[LF_FACESIZE
];
974 dprintf_font(stddeb
,"EnumFonts(%04x, %p='%s', %08lx, %08lx)\n",
975 hDC
, lpFaceName
, lpFaceName
, (LONG
)lpEnumFunc
, lpData
);
976 if (lpEnumFunc
== 0) return 0;
977 hLog
= GDI_HEAP_ALLOC( sizeof(LOGFONT
) + LF_FACESIZE
);
978 lpLogFont
= (LPLOGFONT
) GDI_HEAP_LIN_ADDR(hLog
);
979 if (lpLogFont
== NULL
) {
980 fprintf(stderr
,"EnumFonts // can't alloc LOGFONT struct !\n");
983 hMet
= GDI_HEAP_ALLOC( sizeof(TEXTMETRIC
) );
984 lptm
= (LPTEXTMETRIC
) GDI_HEAP_LIN_ADDR(hMet
);
987 fprintf(stderr
, "EnumFonts // can't alloc TEXTMETRIC struct !\n");
990 if (lpFaceName
!= NULL
) {
991 strcpy(FaceName
, lpFaceName
);
996 if (lpLogFontList
[0] == NULL
) InitFontsList();
997 for(i
= 0; lpLogFontList
[i
] != NULL
; i
++) {
998 if (lpFaceName
== NULL
) {
999 if (lpOldName
!= NULL
) {
1000 if (strcmp(lpOldName
,lpLogFontList
[i
]->lfFaceName
) == 0) continue;
1002 lpOldName
= lpLogFontList
[i
]->lfFaceName
;
1004 if (strcmp(FaceName
, lpLogFontList
[i
]->lfFaceName
) != 0) continue;
1006 dprintf_font(stddeb
,"EnumFonts // enum '%s' !\n", lpLogFontList
[i
]->lfFaceName
);
1007 dprintf_font(stddeb
,"EnumFonts // %p !\n", lpLogFontList
[i
]);
1008 memcpy(lpLogFont
, lpLogFontList
[i
], sizeof(LOGFONT
) + LF_FACESIZE
);
1009 hFont
= CreateFontIndirect(lpLogFont
);
1010 hOldFont
= SelectObject(hDC
, hFont
);
1011 GetTextMetrics(hDC
, lptm
);
1012 SelectObject(hDC
, hOldFont
);
1013 DeleteObject(hFont
);
1014 dprintf_font(stddeb
,"EnumFonts // i=%d lpLogFont=%p lptm=%p\n", i
, lpLogFont
, lptm
);
1015 nRet
= CallEnumFontsProc(lpEnumFunc
, GDI_HEAP_SEG_ADDR(hLog
),
1016 GDI_HEAP_SEG_ADDR(hMet
), 0, (LONG
)lpData
);
1018 dprintf_font(stddeb
,"EnumFonts // EnumEnd requested by application !\n");
1022 GDI_HEAP_FREE(hMet
);
1023 GDI_HEAP_FREE(hLog
);
1028 /*************************************************************************
1029 * EnumFontFamilies [GDI.330]
1031 INT
EnumFontFamilies(HDC hDC
, LPCSTR lpszFamily
, FONTENUMPROC lpEnumFunc
, LPARAM lpData
)
1037 LPENUMLOGFONT lpEnumLogFont
;
1040 char FaceName
[LF_FACESIZE
];
1044 dprintf_font(stddeb
,"EnumFontFamilies(%04x, %p, %08lx, %08lx)\n",
1045 hDC
, lpszFamily
, (DWORD
)lpEnumFunc
, lpData
);
1046 if (lpEnumFunc
== 0) return 0;
1047 hLog
= GDI_HEAP_ALLOC( sizeof(ENUMLOGFONT
) );
1048 lpEnumLogFont
= (LPENUMLOGFONT
) GDI_HEAP_LIN_ADDR(hLog
);
1049 if (lpEnumLogFont
== NULL
) {
1050 fprintf(stderr
,"EnumFontFamilies // can't alloc LOGFONT struct !\n");
1053 hMet
= GDI_HEAP_ALLOC( sizeof(TEXTMETRIC
) );
1054 lptm
= (LPTEXTMETRIC
) GDI_HEAP_LIN_ADDR(hMet
);
1056 GDI_HEAP_FREE(hLog
);
1057 fprintf(stderr
,"EnumFontFamilies // can't alloc TEXTMETRIC struct !\n");
1061 if (lpszFamily
!= NULL
) {
1062 strcpy(FaceName
, lpszFamily
);
1063 AnsiUpper(FaceName
);
1065 if (lpLogFontList
[0] == NULL
) InitFontsList();
1066 for(i
= 0; lpLogFontList
[i
] != NULL
; i
++) {
1067 if (lpszFamily
== NULL
) {
1068 if (lpOldName
!= NULL
) {
1069 if (strcmp(lpOldName
,lpLogFontList
[i
]->lfFaceName
) == 0) continue;
1071 lpOldName
= lpLogFontList
[i
]->lfFaceName
;
1073 if (strcmp(FaceName
, lpLogFontList
[i
]->lfFaceName
) != 0) continue;
1075 memcpy(lpEnumLogFont
, lpLogFontList
[i
], sizeof(LOGFONT
));
1076 strcpy(lpEnumLogFont
->elfFullName
,"");
1077 strcpy(lpEnumLogFont
->elfStyle
,"");
1078 hFont
= CreateFontIndirect((LPLOGFONT
)lpEnumLogFont
);
1079 hOldFont
= SelectObject(hDC
, hFont
);
1080 GetTextMetrics(hDC
, lptm
);
1081 SelectObject(hDC
, hOldFont
);
1082 DeleteObject(hFont
);
1083 dprintf_font(stddeb
, "EnumFontFamilies // i=%d lpLogFont=%p lptm=%p\n", i
, lpEnumLogFont
, lptm
);
1085 nRet
= CallEnumFontFamProc( lpEnumFunc
,
1086 GDI_HEAP_SEG_ADDR(hLog
),
1087 GDI_HEAP_SEG_ADDR(hMet
),
1090 dprintf_font(stddeb
,"EnumFontFamilies // EnumEnd requested by application !\n");
1094 GDI_HEAP_FREE(hMet
);
1095 GDI_HEAP_FREE(hLog
);
1099 /*************************************************************************
1100 * GetRasterizerCaps [GDI.313]
1103 BOOL
GetRasterizerCaps(LPRASTERIZER_STATUS lprs
, UINT cbNumBytes
)
1105 /* This is not much more than a dummy */
1106 RASTERIZER_STATUS rs
;
1108 rs
.nSize
= sizeof(rs
);
1114 /*************************************************************************
1115 * GetKerningPairs [GDI.332]
1117 int GetKerningPairs(HDC hDC
,int cBufLen
,LPKERNINGPAIR lpKerningPairs
)
1119 /* Wine fonts are ugly and don't support kerning :) */