Nikolay Sivov : dwrite: Look for English name strings in mac platform records.

Alexandre Julliard julliard at winehq.org
Wed Mar 10 14:58:45 CST 2021


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

Author: Nikolay Sivov <nsivov at codeweavers.com>
Date:   Wed Mar 10 12:30:25 2021 +0300

dwrite: Look for English name strings in mac platform records.

Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/dwrite/dwrite_private.h |  1 +
 dlls/dwrite/main.c           | 10 ++++++---
 dlls/dwrite/opentype.c       | 51 +++++++++++++++++++++++++++-----------------
 3 files changed, 40 insertions(+), 22 deletions(-)

diff --git a/dlls/dwrite/dwrite_private.h b/dlls/dwrite/dwrite_private.h
index a91b8f99d70..7f7c933e7e2 100644
--- a/dlls/dwrite/dwrite_private.h
+++ b/dlls/dwrite/dwrite_private.h
@@ -298,6 +298,7 @@ extern HRESULT add_localizedstring(IDWriteLocalizedStrings*,const WCHAR*,const W
 extern HRESULT clone_localizedstrings(IDWriteLocalizedStrings *iface, IDWriteLocalizedStrings **strings) DECLSPEC_HIDDEN;
 extern void    set_en_localizedstring(IDWriteLocalizedStrings*,const WCHAR*) DECLSPEC_HIDDEN;
 extern void    sort_localizedstrings(IDWriteLocalizedStrings*) DECLSPEC_HIDDEN;
+extern unsigned int get_localizedstrings_count(IDWriteLocalizedStrings *strings) DECLSPEC_HIDDEN;
 extern HRESULT get_system_fontcollection(IDWriteFactory7 *factory, IDWriteFontCollection1 **collection) DECLSPEC_HIDDEN;
 extern HRESULT get_eudc_fontcollection(IDWriteFactory7 *factory, IDWriteFontCollection3 **collection) DECLSPEC_HIDDEN;
 extern IDWriteTextAnalyzer2 *get_text_analyzer(void) DECLSPEC_HIDDEN;
diff --git a/dlls/dwrite/main.c b/dlls/dwrite/main.c
index d66a27d7f68..4e308485a01 100644
--- a/dlls/dwrite/main.c
+++ b/dlls/dwrite/main.c
@@ -323,11 +323,9 @@ static ULONG WINAPI localizedstrings_Release(IDWriteLocalizedStrings *iface)
 
 static UINT32 WINAPI localizedstrings_GetCount(IDWriteLocalizedStrings *iface)
 {
-    struct localizedstrings *strings = impl_from_IDWriteLocalizedStrings(iface);
-
     TRACE("%p.\n", iface);
 
-    return strings->count;
+    return get_localizedstrings_count(iface);
 }
 
 static HRESULT WINAPI localizedstrings_FindLocaleName(IDWriteLocalizedStrings *iface,
@@ -559,6 +557,12 @@ void sort_localizedstrings(IDWriteLocalizedStrings *iface)
     qsort(strings->data, strings->count, sizeof(*strings->data), localizedstrings_sorting_compare);
 }
 
+unsigned int get_localizedstrings_count(IDWriteLocalizedStrings *iface)
+{
+    struct localizedstrings *strings = impl_from_IDWriteLocalizedStrings(iface);
+    return strings->count;
+}
+
 struct collectionloader
 {
     struct list entry;
diff --git a/dlls/dwrite/opentype.c b/dlls/dwrite/opentype.c
index 717b1ea0351..a74c9712b6a 100644
--- a/dlls/dwrite/opentype.c
+++ b/dlls/dwrite/opentype.c
@@ -2288,9 +2288,21 @@ static void get_name_record_locale(enum OPENTYPE_PLATFORM_ID platform, USHORT la
     }
 }
 
+static BOOL opentype_is_english_namerecord(const struct dwrite_fonttable *table, unsigned int idx)
+{
+    const struct name_header *header = (const struct name_header *)table->data;
+    const struct name_record *record;
+
+    record = &header->records[idx];
+
+    return GET_BE_WORD(record->platformID) == OPENTYPE_PLATFORM_MAC &&
+            GET_BE_WORD(record->languageID) == TT_NAME_MAC_LANGID_ENGLISH;
+}
+
 static BOOL opentype_decode_namerecord(const struct dwrite_fonttable *table, unsigned int idx,
         IDWriteLocalizedStrings *strings)
 {
+    static const WCHAR enusW[] = {'e','n','-','U','S',0};
     USHORT lang_id, length, offset, encoding, platform;
     const struct name_header *header = (const struct name_header *)table->data;
     const struct name_record *record;
@@ -2338,7 +2350,8 @@ static BOOL opentype_decode_namerecord(const struct dwrite_fonttable *table, uns
         TRACE("string %s for locale %s found\n", debugstr_w(name_string), debugstr_w(locale));
         add_localizedstring(strings, locale, name_string);
         heap_free(name_string);
-        ret = TRUE;
+
+        ret = !lstrcmpW(locale, enusW);
     }
     else
         FIXME("handle NAME format 1\n");
@@ -2349,10 +2362,10 @@ static BOOL opentype_decode_namerecord(const struct dwrite_fonttable *table, uns
 static HRESULT opentype_get_font_strings_from_id(const struct dwrite_fonttable *table, enum OPENTYPE_STRING_ID id,
         IDWriteLocalizedStrings **strings)
 {
-    int i, count, candidate_mac, candidate_unicode;
+    int i, count, candidate_mac, candidate_mac_en, candidate_unicode;
     const struct name_record *records;
+    BOOL has_english;
     WORD format;
-    BOOL exists;
     HRESULT hr;
 
     if (!table->data)
@@ -2374,8 +2387,8 @@ static HRESULT opentype_get_font_strings_from_id(const struct dwrite_fonttable *
         count = 0;
     }
 
-    exists = FALSE;
-    candidate_unicode = candidate_mac = -1;
+    has_english = FALSE;
+    candidate_unicode = candidate_mac = candidate_mac_en = -1;
 
     for (i = 0; i < count; i++)
     {
@@ -2398,10 +2411,11 @@ static HRESULT opentype_get_font_strings_from_id(const struct dwrite_fonttable *
             case OPENTYPE_PLATFORM_MAC:
                 if (candidate_mac == -1)
                     candidate_mac = i;
+                if (candidate_mac_en == -1 && opentype_is_english_namerecord(table, i))
+                    candidate_mac_en = i;
                 break;
             case OPENTYPE_PLATFORM_WIN:
-                if (opentype_decode_namerecord(table, i, *strings))
-                    exists = TRUE;
+                has_english |= opentype_decode_namerecord(table, i, *strings);
                 break;
             default:
                 FIXME("platform %i not supported\n", platform);
@@ -2409,24 +2423,23 @@ static HRESULT opentype_get_font_strings_from_id(const struct dwrite_fonttable *
         }
     }
 
-    if (!exists)
-    {
-        if (candidate_mac != -1)
-            exists = opentype_decode_namerecord(table, candidate_mac, *strings);
-        if (!exists && candidate_unicode != -1)
-            exists = opentype_decode_namerecord(table, candidate_unicode, *strings);
+    if (!get_localizedstrings_count(*strings) && candidate_mac != -1)
+        has_english |= opentype_decode_namerecord(table, candidate_mac, *strings);
+    if (!get_localizedstrings_count(*strings) && candidate_unicode != -1)
+        has_english |= opentype_decode_namerecord(table, candidate_unicode, *strings);
+    if (!has_english && candidate_mac_en != -1)
+        opentype_decode_namerecord(table, candidate_mac_en, *strings);
 
-        if (!exists)
-        {
-            IDWriteLocalizedStrings_Release(*strings);
-            *strings = NULL;
-        }
+    if (!get_localizedstrings_count(*strings))
+    {
+        IDWriteLocalizedStrings_Release(*strings);
+        *strings = NULL;
     }
 
     if (*strings)
         sort_localizedstrings(*strings);
 
-    return exists ? S_OK : E_FAIL;
+    return *strings ? S_OK : E_FAIL;
 }
 
 static WCHAR *meta_get_lng_name(WCHAR *str, WCHAR **ctx)




More information about the wine-cvs mailing list