[2/3] gdi32: Cache current font code page in the DC structure.

Dmitry Timoshkov dmitry at codeweavers.com
Mon Apr 6 03:16:40 CDT 2009


---
 dlls/gdi32/dc.c          |    1 +
 dlls/gdi32/font.c        |   89 +++++++++++++++++++++++++++-------------------
 dlls/gdi32/gdi_private.h |    1 +
 3 files changed, 54 insertions(+), 37 deletions(-)

diff --git a/dlls/gdi32/dc.c b/dlls/gdi32/dc.c
index aa8fbc5..fd28663 100644
--- a/dlls/gdi32/dc.c
+++ b/dlls/gdi32/dc.c
@@ -110,6 +110,7 @@ DC *alloc_dc_ptr( const DC_FUNCTIONS *funcs, WORD magic )
     dc->hDevice             = 0;
     dc->hPalette            = GetStockObject( DEFAULT_PALETTE );
     dc->gdiFont             = 0;
+    dc->font_code_page      = CP_ACP;
     dc->ROPmode             = R2_COPYPEN;
     dc->polyFillMode        = ALTERNATE;
     dc->stretchBltMode      = BLACKONWHITE;
diff --git a/dlls/gdi32/font.c b/dlls/gdi32/font.c
index 107536e..14de327 100644
--- a/dlls/gdi32/font.c
+++ b/dlls/gdi32/font.c
@@ -247,45 +247,13 @@ static void FONT_NewTextMetricExWToA(const NEWTEXTMETRICEXW *ptmW, NEWTEXTMETRIC
 DWORD WINAPI GdiGetCodePage( HDC hdc )
 {
     UINT cp = CP_ACP;
-    CHARSETINFO csi;
-    int charset = GetTextCharset(hdc);
-
-    /* Hmm, nicely designed api this one! */
-    if(TranslateCharsetInfo(ULongToPtr(charset), &csi, TCI_SRCCHARSET))
-        cp = csi.ciACP;
-    else {
-        switch(charset) {
-        case OEM_CHARSET:
-            cp = GetOEMCP();
-            break;
-        case DEFAULT_CHARSET:
-            cp = GetACP();
-            break;
-
-        case VISCII_CHARSET:
-        case TCVN_CHARSET:
-        case KOI8_CHARSET:
-        case ISO3_CHARSET:
-        case ISO4_CHARSET:
-        case ISO10_CHARSET:
-        case CELTIC_CHARSET:
-            /* FIXME: These have no place here, but because x11drv
-               enumerates fonts with these (made up) charsets some apps
-               might use them and then the FIXME below would become
-               annoying.  Now we could pick the intended codepage for
-               each of these, but since it's broken anyway we'll just
-               use CP_ACP and hope it'll go away...
-            */
-            cp = CP_ACP;
-            break;
+    DC *dc = get_dc_ptr( hdc );
 
-        default:
-            FIXME("Can't find codepage for charset %d\n", charset);
-            break;
-        }
+    if (dc)
+    {
+        cp = dc->font_code_page;
+        release_dc_ptr( dc );
     }
-
-    TRACE("charset %d => cp %d\n", charset, cp);
     return cp;
 }
 
@@ -465,6 +433,52 @@ HFONT WINAPI CreateFontW( INT height, INT width, INT esc,
     return CreateFontIndirectW( &logfont );
 }
 
+static void update_font_code_page( DC *dc )
+{
+    CHARSETINFO csi;
+    int charset = DEFAULT_CHARSET;
+
+    if (dc->gdiFont)
+        charset = WineEngGetTextCharsetInfo( dc->gdiFont, NULL, 0 );
+
+    /* Hmm, nicely designed api this one! */
+    if (TranslateCharsetInfo( ULongToPtr(charset), &csi, TCI_SRCCHARSET) )
+        dc->font_code_page = csi.ciACP;
+    else {
+        switch(charset) {
+        case OEM_CHARSET:
+            dc->font_code_page = GetOEMCP();
+            break;
+        case DEFAULT_CHARSET:
+            dc->font_code_page = GetACP();
+            break;
+
+        case VISCII_CHARSET:
+        case TCVN_CHARSET:
+        case KOI8_CHARSET:
+        case ISO3_CHARSET:
+        case ISO4_CHARSET:
+        case ISO10_CHARSET:
+        case CELTIC_CHARSET:
+            /* FIXME: These have no place here, but because x11drv
+               enumerates fonts with these (made up) charsets some apps
+               might use them and then the FIXME below would become
+               annoying.  Now we could pick the intended codepage for
+               each of these, but since it's broken anyway we'll just
+               use CP_ACP and hope it'll go away...
+            */
+            dc->font_code_page = CP_ACP;
+            break;
+
+        default:
+            FIXME("Can't find codepage for charset %d\n", charset);
+            dc->font_code_page = CP_ACP;
+            break;
+        }
+    }
+
+    TRACE("charset %d => cp %d\n", charset, dc->font_code_page);
+}
 
 /***********************************************************************
  *           FONT_SelectObject
@@ -506,6 +520,7 @@ static HGDIOBJ FONT_SelectObject( HGDIOBJ handle, HDC hdc )
     {
         ret = dc->hFont;
         dc->hFont = handle;
+        update_font_code_page( dc );
         GDI_dec_ref_count( ret );
     }
     release_dc_ptr( dc );
diff --git a/dlls/gdi32/gdi_private.h b/dlls/gdi32/gdi_private.h
index bc22741..a21fc76 100644
--- a/dlls/gdi32/gdi_private.h
+++ b/dlls/gdi32/gdi_private.h
@@ -281,6 +281,7 @@ typedef struct tagDC
     GdiFont      *gdiFont;
     GdiPath       path;
 
+    UINT          font_code_page;
     WORD          ROPmode;
     WORD          polyFillMode;
     WORD          stretchBltMode;
-- 
1.6.2




More information about the wine-patches mailing list