[PATCH 3/7] gdi32: Rewrite prepend_at helper as get_vertical_name.

Rémi Bernon rbernon at codeweavers.com
Fri Sep 4 13:07:16 CDT 2020


And only prepend @ if it's not already prepended.

Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---
 dlls/gdi32/freetype.c | 32 +++++++++++++++-----------------
 1 file changed, 15 insertions(+), 17 deletions(-)

diff --git a/dlls/gdi32/freetype.c b/dlls/gdi32/freetype.c
index 2f04b76ef44..ed4dc9f034e 100644
--- a/dlls/gdi32/freetype.c
+++ b/dlls/gdi32/freetype.c
@@ -1911,18 +1911,17 @@ static void remove_face_from_cache( Face *face )
     RegCloseKey(hkey_family);
 }
 
-static WCHAR *prepend_at(WCHAR *family)
+static WCHAR *get_vertical_name( WCHAR *name )
 {
-    WCHAR *str;
+    SIZE_T length;
+    if (!name) return NULL;
+    if (name[0] == '@') return name;
 
-    if (!family)
-        return NULL;
-
-    str = HeapAlloc(GetProcessHeap(), 0, sizeof (WCHAR) * (strlenW(family) + 2));
-    str[0] = '@';
-    strcpyW(str + 1, family);
-    HeapFree(GetProcessHeap(), 0, family);
-    return str;
+    length = strlenW( name ) + 1;
+    name = HeapReAlloc( GetProcessHeap(), 0, name, (length + 1) * sizeof(WCHAR) );
+    memmove( name + 1, name, length * sizeof(WCHAR) );
+    name[0] = '@';
+    return name;
 }
 
 static void get_family_names( FT_Face ft_face, WCHAR **name, WCHAR **english, BOOL vertical )
@@ -1938,8 +1937,8 @@ static void get_family_names( FT_Face ft_face, WCHAR **name, WCHAR **english, BO
 
     if (vertical)
     {
-        *name = prepend_at( *name );
-        *english = prepend_at( *english );
+        *name = get_vertical_name( *name );
+        *english = get_vertical_name( *english );
     }
 }
 
@@ -2104,8 +2103,7 @@ static Face *create_face( FT_Face ft_face, FT_Long face_index, const char *file,
     face->refcount = 1;
     face->StyleName = ft_face_get_style_name( ft_face, GetSystemDefaultLangID() );
     face->FullName = get_face_name( ft_face, TT_NAME_ID_FULL_NAME, GetSystemDefaultLangID() );
-    if (flags & ADDFONT_VERTICAL_FONT)
-        face->FullName = prepend_at( face->FullName );
+    if (flags & ADDFONT_VERTICAL_FONT) face->FullName = get_vertical_name( face->FullName );
 
     face->dev = 0;
     face->ino = 0;
@@ -2383,10 +2381,10 @@ static BOOL map_vertical_font_family(const WCHAR *orig, const WCHAR *repl, const
     if (!face || !(face->fs.fsCsb[0] & FS_DBCS_MASK))
         return FALSE;
 
-    at_orig = prepend_at(strdupW(orig));
+    at_orig = get_vertical_name( strdupW( orig ) );
     if (at_orig && !find_family_from_any_name(at_orig))
     {
-        at_repl = prepend_at(strdupW(repl));
+        at_repl = get_vertical_name( strdupW( repl ) );
         if (at_repl)
             ret = map_font_family(at_orig, at_repl);
     }
@@ -7976,7 +7974,7 @@ static BOOL get_outline_text_metrics(GdiFont *font)
         FIXME("failed to read face_nameW for font %s!\n", wine_dbgstr_w(font->name));
         face_nameW = strdupW(font->name);
     }
-    if (font->name[0] == '@') face_nameW = prepend_at( face_nameW );
+    if (font->name[0] == '@') face_nameW = get_vertical_name( face_nameW );
     lenface = (strlenW(face_nameW) + 1) * sizeof(WCHAR);
 
     full_nameW = get_face_name( ft_face, TT_NAME_ID_UNIQUE_ID, GetSystemDefaultLangID() );
-- 
2.28.0




More information about the wine-devel mailing list