[vlc-commits] freetype: use lowercase everywhere

Francois Cartegnie git at videolan.org
Mon Aug 24 17:38:56 CEST 2020


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Mon Aug  3 17:51:29 2020 +0200| [2f5ba8a16b799f31c4b31ee183be45fcd93ae41a] | committer: Francois Cartegnie

freetype: use lowercase everywhere

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=2f5ba8a16b799f31c4b31ee183be45fcd93ae41a
---

 modules/text_renderer/freetype/fonts/android.c    |  43 +++---
 modules/text_renderer/freetype/fonts/darwin.c     |  45 +++----
 modules/text_renderer/freetype/fonts/dwrite.cpp   |  40 ++----
 modules/text_renderer/freetype/fonts/fontconfig.c |  46 ++-----
 modules/text_renderer/freetype/fonts/win32.c      |  39 ++----
 modules/text_renderer/freetype/platform_fonts.c   | 154 ++++++++++++++--------
 modules/text_renderer/freetype/platform_fonts.h   |   8 +-
 7 files changed, 178 insertions(+), 197 deletions(-)

diff --git a/modules/text_renderer/freetype/fonts/android.c b/modules/text_renderer/freetype/fonts/android.c
index 6e73643a76..a68949519f 100644
--- a/modules/text_renderer/freetype/fonts/android.c
+++ b/modules/text_renderer/freetype/fonts/android.c
@@ -97,6 +97,7 @@ static int Android_Nougat_ParseFamily( vlc_font_select_t *fs, xml_reader_t *p_xm
     const char       *psz_val     = NULL;
     const char       *psz_attr    = NULL;
     const char       *psz_name    = NULL;
+    char             *psz_lc      = NULL;
     int               i_type      = 0;
 
     while( ( psz_attr = xml_ReaderNextAttr( p_xml, &psz_val ) ) )
@@ -114,13 +115,11 @@ static int Android_Nougat_ParseFamily( vlc_font_select_t *fs, xml_reader_t *p_xm
          * Family has a name. See if we have that name already.
          * If the name already exists, it's one of the font attachments.
          */
-        char *psz_lc = ToLower( psz_name );
+        psz_lc = LowercaseDup( psz_name );
         if( unlikely( !psz_lc ) )
             return VLC_ENOMEM;
 
         p_family = vlc_dictionary_value_for_key( p_dict, psz_lc );
-
-        free( psz_lc );
     }
 
     if( p_family == NULL )
@@ -132,13 +131,15 @@ static int Android_Nougat_ParseFamily( vlc_font_select_t *fs, xml_reader_t *p_xm
          * Create a new family with the given name or, if psz_name is NULL,
          * with the name fallback-xxxx
          */
-        p_family = NewFamily( fs, psz_name, &fs->p_families,
+        p_family = NewFamilyFromMixedCase( fs, psz_lc, &fs->p_families,
                               &fs->family_map, NULL );
-
-        if( unlikely( !p_family ) )
-            return VLC_ENOMEM;
     }
 
+    free( psz_lc );
+
+    if( unlikely( !p_family ) )
+        return VLC_ENOMEM;
+
     while( ( i_type = xml_ReaderNextNode( p_xml, &psz_val ) ) > 0 )
     {
         switch( i_type )
@@ -194,9 +195,9 @@ static int Android_ParseAlias( vlc_font_select_t *fs, xml_reader_t *p_xml )
         if( !strcasecmp( "weight", psz_attr ) && psz_val && *psz_val )
             i_weight = atoi( psz_val );
         else if( !strcasecmp( "to", psz_attr ) && psz_val && *psz_val )
-            psz_dest = ToLower( psz_val );
+            psz_dest = LowercaseDup( psz_val );
         else if( !strcasecmp( "name", psz_attr ) && psz_val && *psz_val )
-            psz_name = ToLower( psz_val );
+            psz_name = LowercaseDup( psz_val );
     }
 
     if( !psz_dest || !psz_name )
@@ -252,7 +253,7 @@ static int Android_Legacy_ParseFamily( vlc_font_select_t *fs, xml_reader_t *p_xm
                     continue;
                 }
 
-                psz_lc = ToLower( p_node );
+                psz_lc = LowercaseDup( p_node );
                 if( unlikely( !psz_lc ) )
                     return VLC_ENOMEM;
 
@@ -425,16 +426,10 @@ int Android_Prepare( vlc_font_select_t *fs )
     return VLC_SUCCESS;
 }
 
-const vlc_family_t *Android_GetFamily( vlc_font_select_t *fs, const char *psz_family )
+const vlc_family_t *Android_GetFamily( vlc_font_select_t *fs, const char *psz_lcname )
 {
-    char *psz_lc = ToLower( psz_family );
-    if( unlikely( !psz_lc ) )
-        return NULL;
-
     vlc_family_t *p_family =
-            vlc_dictionary_value_for_key( &fs->family_map, psz_lc );
-
-    free( psz_lc );
+            vlc_dictionary_value_for_key( &fs->family_map, psz_lcname );
 
     if( p_family == kVLCDictionaryNotFound )
         return NULL;
@@ -442,19 +437,13 @@ const vlc_family_t *Android_GetFamily( vlc_font_select_t *fs, const char *psz_fa
     return p_family;
 }
 
-vlc_family_t *Android_GetFallbacks( vlc_font_select_t *fs, const char *psz_family,
+vlc_family_t *Android_GetFallbacks( vlc_font_select_t *fs, const char *psz_lcname,
                                     uni_char_t codepoint )
 {
     VLC_UNUSED( codepoint );
 
-    vlc_family_t *p_fallbacks = NULL;
-    char *psz_lc = ToLower( psz_family );
-    if( unlikely( !psz_lc ) )
-        return NULL;
-
-    p_fallbacks = vlc_dictionary_value_for_key( &fs->fallback_map, psz_lc );
-
-    free( psz_lc );
+    vlc_family_t *p_fallbacks =
+                vlc_dictionary_value_for_key( &fs->fallback_map, psz_lcname );
 
     if( p_fallbacks == kVLCDictionaryNotFound )
         return NULL;
diff --git a/modules/text_renderer/freetype/fonts/darwin.c b/modules/text_renderer/freetype/fonts/darwin.c
index 646853c9d6..6816192be5 100644
--- a/modules/text_renderer/freetype/fonts/darwin.c
+++ b/modules/text_renderer/freetype/fonts/darwin.c
@@ -92,15 +92,15 @@ static const struct
 }
 CoreTextGenericMapping[] =
 {
-    { "cursive",   "Apple Chancery" },
+    { "cursive",   "apple chancery" },
 //    { "emoji",     "" },
 //    { "fangsong",     "" },
-    { "fantasy",   "Papyrus" },
-    { "monospace", "Courier" },
-    { "sans",      "Helvetica" },
-    { "sans-serif","Helvetica" },
-    { "serif",     "Times" },
-    { "system-ui", ".AppleSystemUIFont" },
+    { "fantasy",   "papyrus" },
+    { "monospace", "courier" },
+    { "sans",      "helvetica" },
+    { "sans-serif","helvetica" },
+    { "serif",     "times" },
+    { "system-ui", ".applesystemuifont" },
 //    { "math",     "" },
 //    { "ui-monospace",     "" },
 //    { "ui-rounded",     "" },
@@ -159,23 +159,17 @@ static CFComparisonResult SortCTFontMatchResults(CTFontDescriptorRef desc1,
         return kCFCompareGreaterThan;
 }
 
-const vlc_family_t *CoreText_GetFamily(vlc_font_select_t *fs, const char *psz_family)
+const vlc_family_t *CoreText_GetFamily(vlc_font_select_t *fs, const char *psz_lcname)
 {
-    if (unlikely(psz_family == NULL)) {
+    if (unlikely(psz_lcname == NULL)) {
         return NULL;
     }
 
-    psz_family = CoreText_TranslateGenericFamily(psz_family);
-
-    char *psz_lc = ToLower(psz_family);
-    if (unlikely(!psz_lc)) {
-        return NULL;
-    }
+    psz_lcname = CoreText_TranslateGenericFamily(psz_lcname);
 
     /* let's double check if we have parsed this family already */
-    vlc_family_t *p_family = vlc_dictionary_value_for_key(&fs->family_map, psz_lc);
+    vlc_family_t *p_family = vlc_dictionary_value_for_key(&fs->family_map, psz_lcname);
     if (p_family) {
-        free(psz_lc);
         return p_family;
     }
 
@@ -193,11 +187,11 @@ const vlc_family_t *CoreText_GetFamily(vlc_font_select_t *fs, const char *psz_fa
     };
 
 #ifndef NDEBUG
-    msg_Dbg(fs->p_obj, "Creating new family for '%s'", psz_family);
+    msg_Dbg(fs->p_obj, "Creating new family for '%s'", psz_lcname);
 #endif
 
     CFStringRef familyName = CFStringCreateWithCString(kCFAllocatorDefault,
-                                                       psz_family,
+                                                       psz_lcname,
                                                        kCFStringEncodingUTF8);
     for (size_t x = 0; x < numberOfAttributes; x++) {
         coreTextAttributes[x] = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, NULL, NULL);
@@ -227,7 +221,7 @@ const vlc_family_t *CoreText_GetFamily(vlc_font_select_t *fs, const char *psz_fa
     char *path = NULL;
 
     /* create a new family object */
-    p_family = NewFamily(fs, psz_lc, &fs->p_families, &fs->family_map, psz_lc);
+    p_family = NewFamily(fs, psz_lcname, &fs->p_families, &fs->family_map, psz_lcname);
     if (unlikely(!p_family)) {
         goto end;
     }
@@ -260,18 +254,17 @@ end:
 
     CFRelease(coreTextFontDescriptorsArray);
     CFRelease(familyName);
-    free(psz_lc);
 
     return p_family;
 }
 
-vlc_family_t *CoreText_GetFallbacks(vlc_font_select_t *fs, const char *psz_family, uni_char_t codepoint)
+vlc_family_t *CoreText_GetFallbacks(vlc_font_select_t *fs, const char *psz_lcname, uni_char_t codepoint)
 {
-    if (unlikely(psz_family == NULL)) {
+    if (unlikely(psz_lcname == NULL)) {
         return NULL;
     }
 
-    psz_family = CoreText_TranslateGenericFamily(psz_family);
+    psz_lcname = CoreText_TranslateGenericFamily(psz_lcname);
 
     vlc_family_t *p_family = NULL;
     CFStringRef postScriptFallbackFontname = NULL;
@@ -280,7 +273,7 @@ vlc_family_t *CoreText_GetFallbacks(vlc_font_select_t *fs, const char *psz_famil
     char *psz_fontPath = NULL;
 
     CFStringRef familyName = CFStringCreateWithCString(kCFAllocatorDefault,
-                                                       psz_family,
+                                                       psz_lcname,
                                                        kCFStringEncodingUTF8);
     CTFontRef font = CTFontCreateWithName(familyName, 0, NULL);
     uint32_t littleEndianCodePoint = OSSwapHostToLittleInt32(codepoint);
@@ -302,7 +295,7 @@ vlc_family_t *CoreText_GetFallbacks(vlc_font_select_t *fs, const char *psz_famil
     msg_Dbg(fs->p_obj, "Will deploy fallback font '%s'", psz_fallbackFamilyName);
 #endif
 
-    psz_lc_fallback = ToLower(psz_fallbackFamilyName);
+    psz_lc_fallback = LowercaseDup(psz_fallbackFamilyName);
 
     p_family = vlc_dictionary_value_for_key(&fs->family_map, psz_lc_fallback);
     if (p_family) {
diff --git a/modules/text_renderer/freetype/fonts/dwrite.cpp b/modules/text_renderer/freetype/fonts/dwrite.cpp
index 13e44ac76e..12216f7d92 100644
--- a/modules/text_renderer/freetype/fonts/dwrite.cpp
+++ b/modules/text_renderer/freetype/fonts/dwrite.cpp
@@ -571,7 +571,7 @@ static void DWrite_ParseFamily( vlc_font_select_t *fs, IDWriteFontFamily *p_dw_f
     }
 }
 
-extern "C" const vlc_family_t *DWrite_GetFamily( vlc_font_select_t *fs, const char *psz_family )
+extern "C" const vlc_family_t *DWrite_GetFamily( vlc_font_select_t *fs, const char *psz_lcname )
 {
     dw_sys_t                     *p_dw_sys     = ( dw_sys_t * ) fs->p_dw_sys;
     ComPtr< IDWriteFontFamily >   p_dw_family;
@@ -579,27 +579,21 @@ extern "C" const vlc_family_t *DWrite_GetFamily( vlc_font_select_t *fs, const ch
     UINT32 i_index;
     BOOL b_exists = false;
 
-    char *psz_lc = ToLower( psz_family );
-    if( unlikely( !psz_lc ) )
-        return NULL;
-
     vlc_family_t *p_family =
-        ( vlc_family_t * ) vlc_dictionary_value_for_key( &fs->family_map, psz_lc );
-
-    free( psz_lc );
+        ( vlc_family_t * ) vlc_dictionary_value_for_key( &fs->family_map, psz_lcname );
 
     if( p_family )
         return p_family;
 
-    p_family = NewFamily( fs, psz_family, &fs->p_families,
-                          &fs->family_map, psz_family );
+    p_family = NewFamily( fs, psz_lcname, &fs->p_families,
+                          &fs->family_map, psz_lcname );
 
     if( unlikely( !p_family ) )
         return NULL;
 
-    msg_Dbg( fs->p_obj, "DWrite_GetFamily(): family name: %s", psz_family );
+    msg_Dbg( fs->p_obj, "DWrite_GetFamily(): family name: %s", psz_lcname );
 
-    wchar_t *pwsz_family = ToWide( psz_family );
+    wchar_t *pwsz_family = ToWide( psz_lcname );
     if( unlikely( !pwsz_family ) )
         goto done;
 
@@ -683,7 +677,7 @@ done:
     return p_family;
 }
 
-static char *DWrite_Fallback( vlc_font_select_t *fs, const char *psz_family,
+static char *DWrite_Fallback( vlc_font_select_t *fs, const char *psz_lcname,
                               uni_char_t codepoint )
 {
     dw_sys_t                         *p_dw_sys          = ( dw_sys_t * ) fs->p_dw_sys;
@@ -696,13 +690,13 @@ static char *DWrite_Fallback( vlc_font_select_t *fs, const char *psz_family,
     ComPtr< IDWriteFontFamily >       p_dw_family;
     ComPtr< IDWriteLocalizedStrings > p_names;
 
-    msg_Dbg( fs->p_obj, "DWrite_Fallback(): family: %s, codepoint: 0x%x", psz_family, codepoint );
+    msg_Dbg( fs->p_obj, "DWrite_Fallback(): family: %s, codepoint: 0x%x", psz_lcname, codepoint );
 
     wchar_t p_text[2];
     UINT32  i_text_length;
     ToUTF16( codepoint, p_text, &i_text_length );
 
-    wchar_t *pwsz_family = ToWide( psz_family );
+    wchar_t *pwsz_family = ToWide( psz_lcname );
     if( unlikely( !pwsz_family ) ) return NULL;
 
     ComPtr< TextSource > p_ts;
@@ -747,6 +741,7 @@ static char *DWrite_Fallback( vlc_font_select_t *fs, const char *psz_family,
     }
 
     psz_result = FromWide( pwsz_buffer );
+    LowercaseTransform( psz_result );
     msg_Dbg( fs->p_obj, "DWrite_Fallback(): returning %s", psz_result );
 
 done:
@@ -755,20 +750,14 @@ done:
     return psz_result;
 }
 
-extern "C" vlc_family_t *DWrite_GetFallbacks( vlc_font_select_t *fs, const char *psz_family,
+extern "C" vlc_family_t *DWrite_GetFallbacks( vlc_font_select_t *fs, const char *psz_lcname,
                                               uni_char_t codepoint )
 {
     vlc_family_t  *p_family      = NULL;
     vlc_family_t  *p_fallbacks   = NULL;
     char          *psz_fallback  = NULL;
 
-
-    char *psz_lc = ToLower( psz_family );
-
-    if( unlikely( !psz_lc ) )
-        return NULL;
-
-    p_fallbacks = ( vlc_family_t * ) vlc_dictionary_value_for_key( &fs->fallback_map, psz_lc );
+    p_fallbacks = ( vlc_family_t * ) vlc_dictionary_value_for_key( &fs->fallback_map, psz_lcname );
 
     if( p_fallbacks )
         p_family = SearchFallbacks( fs, p_fallbacks, codepoint );
@@ -781,7 +770,7 @@ extern "C" vlc_family_t *DWrite_GetFallbacks( vlc_font_select_t *fs, const char
      */
     if( !p_family )
     {
-        psz_fallback = DWrite_Fallback( fs, psz_lc, codepoint );
+        psz_fallback = DWrite_Fallback( fs, psz_lcname, codepoint );
 
         if( !psz_fallback )
             goto done;
@@ -804,11 +793,10 @@ extern "C" vlc_family_t *DWrite_GetFallbacks( vlc_font_select_t *fs, const char
             AppendFamily( &p_fallbacks, p_family );
         else
             vlc_dictionary_insert( &fs->fallback_map,
-                                   psz_lc, p_family );
+                                   psz_lcname, p_family );
     }
 
 done:
-    free( psz_lc );
     free( psz_fallback );
     return p_family;
 }
diff --git a/modules/text_renderer/freetype/fonts/fontconfig.c b/modules/text_renderer/freetype/fonts/fontconfig.c
index d37b02fa4a..265f3ef9a9 100644
--- a/modules/text_renderer/freetype/fonts/fontconfig.c
+++ b/modules/text_renderer/freetype/fonts/fontconfig.c
@@ -106,26 +106,14 @@ void FontConfig_Unprepare( vlc_font_select_t *fs )
     vlc_mutex_unlock( &lock );
 }
 
-const vlc_family_t *FontConfig_GetFamily( vlc_font_select_t *fs, const char *psz_family )
+const vlc_family_t *FontConfig_GetFamily( vlc_font_select_t *fs, const char *psz_lcname )
 {
-    char *psz_lc = ToLower( psz_family );
-
-    if( unlikely( !psz_lc ) )
-        return NULL;
-
-    vlc_family_t *p_family =
-            vlc_dictionary_value_for_key( &fs->family_map, psz_lc );
-
+    vlc_family_t *p_family = vlc_dictionary_value_for_key( &fs->family_map, psz_lcname );
     if( p_family != kVLCDictionaryNotFound )
-    {
-        free( psz_lc );
         return p_family;
-    }
-
-    p_family = NewFamily( fs, psz_lc, &fs->p_families,
-                          &fs->family_map, psz_lc );
 
-    free( psz_lc );
+    p_family = NewFamily( fs, psz_lcname, &fs->p_families,
+                          &fs->family_map, psz_lcname );
     if( !p_family )
         return NULL;
 
@@ -146,7 +134,7 @@ const vlc_family_t *FontConfig_GetFamily( vlc_font_select_t *fs, const char *psz
         if (!pat) continue;
 
         /* */
-        FcPatternAddString( pat, FC_FAMILY, (const FcChar8*) psz_family );
+        FcPatternAddString( pat, FC_FAMILY, (const FcChar8*) psz_lcname );
         FcPatternAddBool( pat, FC_OUTLINE, FcTrue );
         FcPatternAddInteger( pat, FC_SLANT, b_italic ? FC_SLANT_ITALIC : FC_SLANT_ROMAN );
         FcPatternAddInteger( pat, FC_WEIGHT, b_bold ? FC_WEIGHT_EXTRABOLD : FC_WEIGHT_NORMAL );
@@ -197,26 +185,16 @@ const vlc_family_t *FontConfig_GetFamily( vlc_font_select_t *fs, const char *psz
     return p_family;
 }
 
-vlc_family_t *FontConfig_GetFallbacks( vlc_font_select_t *fs, const char *psz_family,
+vlc_family_t *FontConfig_GetFallbacks( vlc_font_select_t *fs, const char *psz_lcname,
                                        uni_char_t codepoint )
 {
 
     VLC_UNUSED( codepoint );
 
-    vlc_family_t *p_family = NULL;
-
-    char *psz_lc = ToLower( psz_family );
-
-    if( unlikely( !psz_lc ) )
-        return NULL;
-
-    p_family = vlc_dictionary_value_for_key( &fs->fallback_map, psz_lc );
-
+    vlc_family_t *p_family =
+            vlc_dictionary_value_for_key( &fs->fallback_map, psz_lcname );
     if( p_family != kVLCDictionaryNotFound )
-    {
-        free( psz_lc );
         return p_family;
-    }
     else
         p_family = NULL;
 
@@ -224,7 +202,7 @@ vlc_family_t *FontConfig_GetFallbacks( vlc_font_select_t *fs, const char *psz_fa
     FcPattern  *p_pattern = FcPatternCreate();
     FcValue     family;
     family.type = FcTypeString;
-    family.u.s = ( const FcChar8* ) psz_family;
+    family.u.s = ( const FcChar8* ) psz_lcname;
     FcPatternAdd( p_pattern, FC_FAMILY, family, FcFalse );
     if( FcConfigSubstitute( config, p_pattern, FcMatchPattern ) == FcTrue )
     {
@@ -242,7 +220,7 @@ vlc_family_t *FontConfig_GetFallbacks( vlc_font_select_t *fs, const char *psz_fa
                 /* Avoid duplicate family names */
                 if( strcasecmp( psz_last_name, psz_name ) )
                 {
-                    vlc_family_t *p_temp = NewFamily( fs, psz_name,
+                    vlc_family_t *p_temp = NewFamilyFromMixedCase( fs, psz_name,
                                                       &p_family, NULL, NULL );
 
                     if( unlikely( !p_temp ) )
@@ -251,7 +229,6 @@ vlc_family_t *FontConfig_GetFallbacks( vlc_font_select_t *fs, const char *psz_fa
                         FcPatternDestroy( p_pattern );
                         if( p_family )
                             FreeFamilies( p_family, NULL );
-                        free( psz_lc );
                         return NULL;
                     }
 
@@ -264,8 +241,7 @@ vlc_family_t *FontConfig_GetFallbacks( vlc_font_select_t *fs, const char *psz_fa
     FcPatternDestroy( p_pattern );
 
     if( p_family )
-        vlc_dictionary_insert( &fs->fallback_map, psz_lc, p_family );
+        vlc_dictionary_insert( &fs->fallback_map, psz_lcname, p_family );
 
-    free( psz_lc );
     return p_family;
 }
diff --git a/modules/text_renderer/freetype/fonts/win32.c b/modules/text_renderer/freetype/fonts/win32.c
index a827da2dfb..00866595c7 100644
--- a/modules/text_renderer/freetype/fonts/win32.c
+++ b/modules/text_renderer/freetype/fonts/win32.c
@@ -392,23 +392,16 @@ static int CALLBACK EnumFontCallback(const ENUMLOGFONTEX *lpelfe, const NEWTEXTM
     return 1;
 }
 
-const vlc_family_t *Win32_GetFamily( vlc_font_select_t *fs, const char *psz_family )
+const vlc_family_t *Win32_GetFamily( vlc_font_select_t *fs, const char *psz_lcname )
 {
-    char *psz_lc = ToLower( psz_family );
-
-    if( unlikely( !psz_lc ) )
-        return NULL;
-
     vlc_family_t *p_family =
-        vlc_dictionary_value_for_key( &fs->family_map, psz_lc );
-
-    free( psz_lc );
+        vlc_dictionary_value_for_key( &fs->family_map, psz_lcname );
 
     if( p_family )
         return p_family;
 
-    p_family = NewFamily( fs, psz_family, &fs->p_families,
-                          &fs->family_map, psz_family );
+    p_family = NewFamily( fs, psz_lcname, &fs->p_families,
+                          &fs->family_map, psz_lcname );
 
     if( unlikely( !p_family ) )
         return NULL;
@@ -416,7 +409,7 @@ const vlc_family_t *Win32_GetFamily( vlc_font_select_t *fs, const char *psz_fami
     LOGFONT lf;
     lf.lfCharSet = DEFAULT_CHARSET;
 
-    LPTSTR psz_fbuffer = ToWide( psz_family );
+    LPTSTR psz_fbuffer = ToWide( psz_lcname );
     wcsncpy( (LPTSTR)&lf.lfFaceName, psz_fbuffer, LF_FACESIZE );
     free( psz_fbuffer );
 
@@ -453,7 +446,7 @@ static int CALLBACK MetaFileEnumProc( HDC hdc, HANDLETABLE* table,
  * This is a hack used by Chrome and WebKit to expose the fallback font used
  * by Uniscribe for some given text for use with custom shapers / font engines.
  */
-static char *UniscribeFallback( const char *psz_family, uni_char_t codepoint )
+static char *UniscribeFallback( const char *psz_lcname, uni_char_t codepoint )
 {
     HDC          hdc          = NULL;
     HDC          meta_file_dc = NULL;
@@ -471,7 +464,7 @@ static char *UniscribeFallback( const char *psz_family, uni_char_t codepoint )
     LOGFONT lf;
     memset( &lf, 0, sizeof( lf ) );
 
-    wchar_t *psz_fbuffer = ToWide( psz_family );
+    wchar_t *psz_fbuffer = ToWide( psz_lcname );
     if( !psz_fbuffer )
         goto error;
     wcsncpy( ( LPTSTR ) &lf.lfFaceName, psz_fbuffer, LF_FACESIZE );
@@ -507,7 +500,10 @@ static char *UniscribeFallback( const char *psz_family, uni_char_t codepoint )
         log_font.lfFaceName[ 0 ] = 0;
         EnumEnhMetaFile( 0, meta_file, MetaFileEnumProc, &log_font, NULL );
         if( log_font.lfFaceName[ 0 ] )
+        {
             psz_result = FromWide( log_font.lfFaceName );
+            LowercaseTransform( psz_result );
+        }
     }
 
     DeleteEnhMetaFile(meta_file);
@@ -520,20 +516,14 @@ error:
     return NULL;
 }
 
-vlc_family_t *Win32_GetFallbacks( vlc_font_select_t *fs, const char *psz_family,
+vlc_family_t *Win32_GetFallbacks( vlc_font_select_t *fs, const char *psz_lcname,
                                   uni_char_t codepoint )
 {
     vlc_family_t  *p_family      = NULL;
     vlc_family_t  *p_fallbacks   = NULL;
     char          *psz_uniscribe = NULL;
 
-
-    char *psz_lc = ToLower( psz_family );
-
-    if( unlikely( !psz_lc ) )
-        return NULL;
-
-    p_fallbacks = vlc_dictionary_value_for_key( &fs->fallback_map, psz_lc );
+    p_fallbacks = vlc_dictionary_value_for_key( &fs->fallback_map, psz_lcname );
 
     if( p_fallbacks )
         p_family = SearchFallbacks( fs, p_fallbacks, codepoint );
@@ -546,7 +536,7 @@ vlc_family_t *Win32_GetFallbacks( vlc_font_select_t *fs, const char *psz_family,
      */
     if( !p_family )
     {
-        psz_uniscribe = UniscribeFallback( psz_lc, codepoint );
+        psz_uniscribe = UniscribeFallback( psz_lcname, codepoint );
 
         if( !psz_uniscribe )
             goto done;
@@ -569,11 +559,10 @@ vlc_family_t *Win32_GetFallbacks( vlc_font_select_t *fs, const char *psz_family,
             AppendFamily( &p_fallbacks, p_family );
         else
             vlc_dictionary_insert( &fs->fallback_map,
-                                   psz_lc, p_family );
+                                   psz_lcname, p_family );
     }
 
 done:
-    free( psz_lc );
     free( psz_uniscribe );
     return p_family;
 }
diff --git a/modules/text_renderer/freetype/platform_fonts.c b/modules/text_renderer/freetype/platform_fonts.c
index dfe50df108..a74aa4a882 100644
--- a/modules/text_renderer/freetype/platform_fonts.c
+++ b/modules/text_renderer/freetype/platform_fonts.c
@@ -205,7 +205,27 @@ static inline void AppendFamily( vlc_family_t **pp_list, vlc_family_t *p_family
     *pp_list = p_family;
 }
 
-vlc_family_t *NewFamily( vlc_font_select_t *fs, const char *psz_family,
+vlc_family_t *NewFamilyFromMixedCase( vlc_font_select_t *fs, const char *psz_family,
+                                      vlc_family_t **pp_list, vlc_dictionary_t *p_dict,
+                                      const char *psz_key )
+{
+    char *psz_alloc = NULL;
+    char *psz_alloc_key = NULL;
+    if( psz_family && *psz_family )
+        psz_family = psz_alloc = LowercaseDup( psz_family );
+
+    if( psz_key && p_dict )
+        psz_key = psz_alloc_key = LowercaseDup( psz_key );
+
+    vlc_family_t *ret = NewFamily( fs, psz_family, pp_list, p_dict, psz_key );
+
+    free( psz_alloc );
+    free( psz_alloc_key );
+
+    return ret;
+}
+
+vlc_family_t *NewFamily( vlc_font_select_t *fs, const char *psz_lcname,
                          vlc_family_t **pp_list, vlc_dictionary_t *p_dict,
                          const char *psz_key )
 {
@@ -213,44 +233,40 @@ vlc_family_t *NewFamily( vlc_font_select_t *fs, const char *psz_family,
     if( unlikely(!p_family) )
         return NULL;
 
-    char *psz_name;
-    if( psz_family && *psz_family )
-        psz_name = ToLower( psz_family );
-    else
-        psz_name = CreateUniqueFamilyKey( fs );
+    assert(!psz_lcname || IsLowercase(psz_lcname));
 
-    char *psz_lc = NULL;
-    if( likely( psz_name ) )
+    char *psz_alloc = NULL;
+    if( !psz_lcname || !*psz_lcname )
+        psz_lcname = psz_alloc = CreateUniqueFamilyKey( fs );
+    if( unlikely( !psz_lcname ) )
     {
-        if( !psz_key )
-            psz_lc = strdup( psz_name );
-        else
-            psz_lc = ToLower( psz_key );
+        free( p_family );
+        return NULL;
     }
 
-    if( unlikely( !p_family || !psz_name || !psz_lc ) )
+    p_family->psz_name = strdup( psz_lcname );
+    if( unlikely(!p_family->psz_name) )
     {
+        free( psz_alloc );
         free( p_family );
-        free( psz_name );
-        free( psz_lc );
         return NULL;
     }
 
-    p_family->psz_name = psz_name;
-
     if( pp_list )
         AppendFamily( pp_list, p_family );
 
     if( p_dict )
     {
-        vlc_family_t *p_root = vlc_dictionary_value_for_key( p_dict, psz_lc );
+        if( !psz_key )
+            psz_key = psz_lcname;
+        vlc_family_t *p_root = vlc_dictionary_value_for_key( p_dict, psz_key );
         if( p_root )
             AppendFamily( &p_root, p_family );
         else
-            vlc_dictionary_insert( p_dict, psz_lc, p_family );
+            vlc_dictionary_insert( p_dict, psz_key, p_family );
     }
 
-    free( psz_lc );
+    free( psz_alloc );
     return p_family;
 }
 
@@ -268,7 +284,7 @@ vlc_family_t * DeclareNewFamily( vlc_font_select_t *fs, const char *psz_family )
     char *psz_lc;
 
     if( psz_family )
-        psz_lc = ToLower( psz_family );
+        psz_lc = LowercaseDup( psz_family );
     else
         psz_lc = CreateUniqueFamilyKey( fs );
 
@@ -376,18 +392,26 @@ vlc_family_t *InitDefaultList( vlc_font_select_t *fs, const char *const *ppsz_de
 
     for( int i = 0; i < i_size; ++i )
     {
-        const vlc_family_t *p_family = FontSelectGetFamily( fs, ppsz_default[ i ] );
+        char *psz_lc = LowercaseDup( ppsz_default[ i ] );
+        if( !psz_lc )
+            continue;
 
+        const vlc_family_t *p_family = FontSelectGetFamily( fs, psz_lc );
         if( p_family )
         {
             vlc_family_t *p_temp =
-                NewFamily( fs, ppsz_default[ i ], &p_default, NULL, NULL );
+                NewFamily( fs, psz_lc, &p_default, NULL, NULL );
 
             if( unlikely( !p_temp ) )
+            {
+                free( psz_lc );
                 goto error;
+            }
 
             p_temp->p_fonts = p_family->p_fonts;
         }
+
+        free( psz_lc );
     }
 
     if( p_default )
@@ -471,7 +495,27 @@ void DumpFamilies( vlc_font_select_t *fs )
 }
 #endif
 
-char* ToLower( const char *psz_src )
+bool IsLowercase( const char *psz_src )
+{
+    size_t i_size=strlen(psz_src);
+    for(size_t i = 0; i < i_size; ++i )
+    {
+        if( psz_src[ i ] != (char)tolower( psz_src[ i ] ) )
+            return false;
+    }
+    return true;
+}
+
+void LowercaseTransform( char *psz )
+{
+    if( !psz )
+        return;
+    size_t i_size = strlen( psz );
+    for( size_t i = 0; i < i_size; ++i )
+        psz[ i ] = tolower( psz[ i ] );
+}
+
+char* LowercaseDup( const char *psz_src )
 {
     int i_size = strlen( psz_src ) + 1;
     char *psz_buffer = malloc( i_size );
@@ -563,32 +607,33 @@ static char* SelectFontWithFamilyFallback( vlc_font_select_t *fs,
     if( codepoint && !p_family )
     {
         vlc_family_t *p_fallbacks;
-        const char *psz_name;
+        const char *psz_lcname;
         /*
          * Try regular face of the same family first.
          * It usually has the best coverage.
          */
-        vlc_vector_foreach( psz_name, families )
+        vlc_vector_foreach( psz_lcname, families )
         {
-            Debug( fs->p_obj, "Looking for family \"%s\"", psz_name );
+            assert(IsLowercase(psz_lcname));
+            Debug( fs->p_obj, "Looking for family \"%s\"", psz_lcname );
 
             p_fallbacks = vlc_dictionary_value_for_key( &fs->fallback_map,
                                                         FB_LIST_ATTACHMENTS );
             if( p_fallbacks )
             {
                 p_family = SearchFontByFamilyName( fs, p_fallbacks,
-                                                   psz_name, codepoint );
+                                                   psz_lcname, codepoint );
                 if( p_family )
                     break;
             }
 
-            p_family = FontSelectGetFamily( fs, psz_name );
+            p_family = FontSelectGetFamily( fs, psz_lcname );
             if( p_family && p_family->p_fonts )
             {
                 if( CheckFace( fs, p_family->p_fonts, codepoint ) )
                 {
                     Debug( fs->p_obj, "Found family \"%s\" for codepoint %x",
-                           psz_name, codepoint );
+                           psz_lcname, codepoint );
                     break;
                 }
             }
@@ -599,7 +644,7 @@ static char* SelectFontWithFamilyFallback( vlc_font_select_t *fs,
         /* Try font attachments if not available locally */
         if( !p_family )
         {
-            Debug( fs->p_obj, "Looking for family \"%s\" in attachments cp %x", psz_name, codepoint );
+            Debug( fs->p_obj, "Looking for family \"%s\" in attachments cp %x", psz_lcname, codepoint );
             p_fallbacks = vlc_dictionary_value_for_key( &fs->fallback_map,
                                                         FB_LIST_ATTACHMENTS );
             if( p_fallbacks )
@@ -616,10 +661,10 @@ static char* SelectFontWithFamilyFallback( vlc_font_select_t *fs,
         /* Try system fallbacks */
         if( !p_family )
         {
-            vlc_vector_foreach( psz_name, families )
+            vlc_vector_foreach( psz_lcname, families )
             {
-                Debug( fs->p_obj, "Looking for family \"%s\" in system fallbacks cp %x", psz_name, codepoint );
-                p_fallbacks = FontSelectGetFallbacks( fs, psz_name, codepoint );
+                Debug( fs->p_obj, "Looking for family \"%s\" in system fallbacks cp %x", psz_lcname, codepoint );
+                p_fallbacks = FontSelectGetFallbacks( fs, psz_lcname, codepoint );
                 if( p_fallbacks )
                 {
                     p_family = SearchFallbacks( fs, p_fallbacks, codepoint );
@@ -655,7 +700,9 @@ static char* SelectFontWithFamilyFallback( vlc_font_select_t *fs,
     if( !p_family || !p_family->p_fonts )
     {
         Debug( fs->p_obj, "Looking for DEFAULT_FAMILY \"%s\" as a last resort", DEFAULT_FAMILY );
-        p_family = FontSelectGetFamily( fs, DEFAULT_FAMILY );
+        char *lc = LowercaseDup(DEFAULT_FAMILY);
+        p_family = FontSelectGetFamily( fs, lc );
+        free(lc);
     }
 
     vlc_font_t *p_font;
@@ -679,12 +726,17 @@ SelectAndLoadFace( filter_t *p_filter, const text_style_t *p_style, uni_char_t c
     const char *psz_fontname = (p_style->i_style_flags & STYLE_MONOSPACED)
                                ? p_style->psz_monofontname : p_style->psz_fontname;
 
+    char *psz_alloc = !IsLowercase(psz_fontname) ? LowercaseDup(psz_fontname) : NULL;
+    if( psz_alloc )
+        psz_fontname = psz_alloc;
+
     fontfamilies_t families;
     vlc_vector_init( &families );
     SplitIntoSingleFamily( psz_fontname, &families );
     if( families.size == 0 )
     {
         vlc_vector_clear( &families );
+        free(psz_alloc);
         return NULL;
     }
 
@@ -720,53 +772,41 @@ SelectAndLoadFace( filter_t *p_filter, const text_style_t *p_style, uni_char_t c
         free( psz_temp );
     vlc_vector_clear( &families );
     free( psz_fontfile );
+    free(psz_alloc);
 
     return p_faceid;
 }
 
 #ifndef HAVE_GET_FONT_BY_FAMILY_NAME
 static const vlc_family_t * StaticMap_GetFamily( vlc_font_select_t *fs,
-                                                 const char *psz_family )
+                                                 const char *psz_lcname )
 {
     filter_t *p_filter = fs->p_filter;
     filter_sys_t *p_sys = p_filter->p_sys;
-    char *psz_lc = ToLower( psz_family );
-
-    if( unlikely( !psz_lc ) )
-        return NULL;
 
     vlc_family_t *p_family =
-        vlc_dictionary_value_for_key( &fs->family_map, psz_lc );
-
+            vlc_dictionary_value_for_key( &fs->family_map, psz_lcname );
     if( p_family )
-    {
-        free( psz_lc );
         return p_family;
-    }
 
     const char *psz_file = NULL;
-    if( !strcasecmp( psz_family, DEFAULT_FAMILY ) )
+    if( !strcasecmp( psz_lcname, DEFAULT_FAMILY ) )
     {
         psz_file = p_sys->psz_fontfile ? p_sys->psz_fontfile
                                        : DEFAULT_FONT_FILE;
     }
-    else if( !strcasecmp( psz_family, DEFAULT_MONOSPACE_FAMILY ) )
+    else if( !strcasecmp( psz_lcname, DEFAULT_MONOSPACE_FAMILY ) )
     {
         psz_file = p_sys->psz_monofontfile ? p_sys->psz_monofontfile
                                            : DEFAULT_MONOSPACE_FONT_FILE;
     }
 
     if( !psz_file )
-    {
-        free( psz_lc );
         return NULL;
-    }
 
     /* Create new entry */
-    p_family = NewFamily( fs, psz_lc, &fs->p_families,
-                          &fs->family_map, psz_lc );
-
-    free( psz_lc );
+    p_family = NewFamily( fs, psz_lcname, &fs->p_families,
+                          &fs->family_map, psz_lcname );
 
     if( unlikely( !p_family ) )
         return NULL;
@@ -840,7 +880,7 @@ vlc_font_select_t * FontSelectNew( filter_t *p_filter )
 #else
         msg_Warn( p_filter, "DirectWrite initialization failed. Falling back to GDI/Uniscribe" );
         const char *const ppsz_default[] =
-            { "Tahoma", "FangSong", "SimHei", "KaiTi" };
+            { "tahoma", "fangsong", "simhei", "kaiti" };
         fs->pf_get_family = Win32_GetFamily;
         fs->pf_get_fallbacks = Win32_GetFallbacks;
         if( InitDefaultList( fs, ppsz_default, ARRAY_SIZE(ppsz_default) ) == NULL )
@@ -890,9 +930,9 @@ void FontSelectDelete( vlc_font_select_t *fs )
     free( fs );
 }
 
-const vlc_family_t * FontSelectGetFamily( vlc_font_select_t *fs, const char *psz_family )
+const vlc_family_t * FontSelectGetFamily( vlc_font_select_t *fs, const char *psz_lcname )
 {
-    return fs->pf_get_family ? fs->pf_get_family( fs, psz_family ) : NULL;
+    return fs->pf_get_family ? fs->pf_get_family( fs, psz_lcname ) : NULL;
 }
 
 vlc_family_t * FontSelectGetFallbacks( vlc_font_select_t *fs, const char *psz_family,
diff --git a/modules/text_renderer/freetype/platform_fonts.h b/modules/text_renderer/freetype/platform_fonts.h
index a977a1b459..3ab71f9268 100644
--- a/modules/text_renderer/freetype/platform_fonts.h
+++ b/modules/text_renderer/freetype/platform_fonts.h
@@ -203,6 +203,9 @@ vlc_family_t * FontSelectGetFallbacks( vlc_font_select_t *, const char *psz_fami
 vlc_family_t *NewFamily( vlc_font_select_t *, const char *psz_family,
                          vlc_family_t **pp_list, vlc_dictionary_t *p_dict,
                          const char *psz_key );
+vlc_family_t *NewFamilyFromMixedCase( vlc_font_select_t *, const char *psz_family,
+                                      vlc_family_t **pp_list, vlc_dictionary_t *p_dict,
+                                      const char *psz_key );
 
 vlc_family_t * DeclareNewFamily( vlc_font_select_t *, const char *psz_family );
 int DeclareFamilyAsAttachMenFallback( vlc_font_select_t *, vlc_family_t * );
@@ -272,7 +275,10 @@ void DumpFamilies( vlc_font_select_t * );
 #endif
 
 /* String helpers */
-char* ToLower( const char *psz_src );
+char* LowercaseDup( const char *psz_src );
+
+bool IsLowercase( const char *psz_src );
+void LowercaseTransform( char *psz );
 
 /* Size helper, depending on the scaling factor */
 int ConvertToLiveSize( filter_t *p_filter, const text_style_t *p_style );



More information about the vlc-commits mailing list