Alexandre Julliard : gdi32: Cache the codepage tables also for OpenType names mapping.

Alexandre Julliard julliard at winehq.org
Wed Feb 3 15:39:27 CST 2021


Module: wine
Branch: master
Commit: 9581b2df8c9c9ce1688b0d111d0206564b9fcd8b
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=9581b2df8c9c9ce1688b0d111d0206564b9fcd8b

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Wed Feb  3 20:55:06 2021 +0100

gdi32: Cache the codepage tables also for OpenType names mapping.

Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/gdi32/freetype.c | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/dlls/gdi32/freetype.c b/dlls/gdi32/freetype.c
index b3fc565afe8..fae4aa94a78 100644
--- a/dlls/gdi32/freetype.c
+++ b/dlls/gdi32/freetype.c
@@ -714,21 +714,27 @@ static const LANGID mac_langid_table[] =
     MAKELANGID(LANG_AZERI,SUBLANG_AZERI_LATIN),              /* TT_MAC_LANGID_AZERBAIJANI_ROMAN_SCRIPT */
 };
 
-static CPTABLEINFO *get_mac_code_page( const FT_SfntName *name )
+static CPTABLEINFO *get_cptable( WORD cp )
 {
     static CPTABLEINFO tables[100];
-    int id = name->encoding_id;
+    unsigned int i;
     USHORT *ptr;
     SIZE_T size;
 
+    for (i = 0; i < ARRAY_SIZE(tables) && tables[i].CodePage; i++)
+        if (tables[i].CodePage == cp) return &tables[i];
+    if (NtGetNlsSectionPtr( 11, cp, NULL, (void **)&ptr, &size )) return NULL;
+    if (i == ARRAY_SIZE(tables)) ERR( "too many code pages\n" );
+    RtlInitCodePageTable( ptr, &tables[i] );
+    return &tables[i];
+}
+
+static CPTABLEINFO *get_mac_code_page( const FT_SfntName *name )
+{
+    int id = name->encoding_id;
+
     if (name->encoding_id == TT_MAC_ID_SIMPLIFIED_CHINESE) id = 8;  /* special case */
-    if (id >= ARRAY_SIZE(tables)) return NULL;
-    if (!tables[id].CodePage)
-    {
-        if (NtGetNlsSectionPtr( 11, 10000 + id, NULL, (void **)&ptr, &size )) return NULL;
-        RtlInitCodePageTable( ptr, &tables[id] );
-    }
-    return &tables[id];
+    return get_cptable( 10000 + id );
 }
 
 static int match_name_table_language( const FT_SfntName *name, LANGID lang )
@@ -1144,9 +1150,6 @@ static BOOL search_face_name_callback( LANGID langid, struct opentype_name *name
 
 static WCHAR *decode_opentype_name( struct opentype_name *name )
 {
-    CPTABLEINFO codepage_info;
-    USHORT *codepage_ptr;
-    SIZE_T codepage_size;
     WCHAR buffer[512];
     DWORD len;
 
@@ -1158,11 +1161,10 @@ static WCHAR *decode_opentype_name( struct opentype_name *name )
     }
     else
     {
-        NtGetNlsSectionPtr( 11, name->codepage, NULL, (void **)&codepage_ptr, &codepage_size );
-        RtlInitCodePageTable( codepage_ptr, &codepage_info );
-        RtlCustomCPToUnicodeN( &codepage_info, buffer, sizeof(buffer), &len, name->bytes, name->length );
+        CPTABLEINFO *cptable = get_cptable( name->codepage );
+        if (!cptable) return NULL;
+        RtlCustomCPToUnicodeN( cptable, buffer, sizeof(buffer), &len, name->bytes, name->length );
         len /= sizeof(WCHAR);
-        NtUnmapViewOfSection( GetCurrentProcess(), codepage_ptr );
     }
 
     buffer[ARRAY_SIZE(buffer) - 1] = 0;




More information about the wine-cvs mailing list