Font selection - please review

Huw D M Davies h.davies1 at physics.ox.ac.uk
Fri Nov 15 09:37:24 CST 2002


On Fri, Nov 15, 2002 at 03:25:48PM +0200, Shachar Shemesh wrote:
> Hi all,
> 
> I am thinking of submitting the attached patch. The problem is that I am 
> not comfertable with the location I added it.
> 
> As far as I could tell, there is nowhere in the whole of Wine where the 
> selected language is matched with the charset to be used by default. 
> This is what this patch comes to amend.
> 
> There is a slight awkwardness that is inherent to the Win32 API, in 
> which, in order to create the default font, you zero out a LOGFONT 
> struct, fill in the struct length, and call "CreateFontIndirect". 
> Looking at the resulting struct, however, reveals that what you have 
> just asked for is a ANSI_CHARSET font. It appears that windows correctly 
> understands that this is an uninitialized LOGFONT, apparently based on 
> the fields tested.

Hi,

CHARSET_DEFAULT is translated to the charset assosicated with the
current ansi codepage in
dlls/gdi/freetype.c:WineEngCreateFontInstance(). This of course only
works if you're using client side rendered fonts (this becomes easier
as of last night as you don't even need a RENDER capable XServer
anymore).  CreateFontIndirect is definitely the wrong place for these
kind of fixups since GetOject on the hfont always returns the original
logfont values.  If you need to get this working for X11 fonts then
you'll have to poke around in graphics/x11drv/xfont.c somewhere...

I hadn't spotted the brokenness of the Win32 API with regard to
certain elements of logfont being set to zero giving a DEFAULT_CHARSET
font.  In fact it turns out that even if lfFaceName[0] != 0 then you
still get this behaviour if the name doesn't match an installed
fontname.  The attached patch should fix this.

Huw.
-------------- next part --------------
Index: dlls/gdi/freetype.c
===================================================================
RCS file: /home/wine/wine/dlls/gdi/freetype.c,v
retrieving revision 1.27
diff -u -r1.27 freetype.c
--- dlls/gdi/freetype.c	13 Nov 2002 23:54:50 -0000	1.27
+++ dlls/gdi/freetype.c	15 Nov 2002 15:21:40 -0000
@@ -1030,8 +1030,12 @@
 not_found:
     if(!family) {
       /* If requested charset was DEFAULT_CHARSET then try using charset
-	 corresponding to the current ansi codepage */
-        if(!csi.fs.fsCsb[0]) {
+         corresponding to the current ansi codepage. Also it appears if
+         various other elements of lf are set to zero then we should use 
+         the current ACP's charset. */
+        if(!csi.fs.fsCsb[0] || (lf.lfCharSet == 0 && lf.lfHeight == 0 &&
+                                lf.lfEscapement == 0 && lf.lfPitchAndFamily == 0 &&
+                                lf.lfWidth == 0)) {
 	    INT acp = GetACP();
 	    if(!TranslateCharsetInfo((DWORD*)acp, &csi, TCI_SRCCODEPAGE)) {
 	        FIXME("TCI failed on codepage %d\n", acp);


More information about the wine-devel mailing list