]> git.sesse.net Git - vlc/commitdiff
Freetype: account for more complex font names on Windows
authorJean-Baptiste Kempf <jb@videolan.org>
Tue, 1 Nov 2011 18:43:08 +0000 (19:43 +0100)
committerJean-Baptiste Kempf <jb@videolan.org>
Tue, 1 Nov 2011 18:50:21 +0000 (19:50 +0100)
We have to count for "Bold", "Normal" and "Italic" ending in registry

Close #4949

modules/text_renderer/freetype.c

index 8ab61969055dcb836429439be5814c6215579e1f..7963f5cd4515d91b67d38e23d624e24b18f9ee3f 100644 (file)
@@ -545,7 +545,10 @@ static int GetFileFontByName( const char *font_name, char **psz_filename )
     wchar_t vbuffer[MAX_PATH];
     wchar_t dbuffer[256];
 
-    if( RegOpenKeyEx(HKEY_LOCAL_MACHINE, FONT_DIR_NT, 0, KEY_READ, &hKey) != ERROR_SUCCESS )
+    size_t fontname_len = strlen( font_name );
+
+    if( RegOpenKeyEx(HKEY_LOCAL_MACHINE, FONT_DIR_NT, 0, KEY_READ, &hKey)
+            != ERROR_SUCCESS )
         return 1;
 
     for( int index = 0;; index++ )
@@ -553,9 +556,10 @@ static int GetFileFontByName( const char *font_name, char **psz_filename )
         DWORD vbuflen = MAX_PATH - 1;
         DWORD dbuflen = 255;
 
-        if( RegEnumValueW( hKey, index, vbuffer, &vbuflen,
-                           NULL, NULL, (LPBYTE)dbuffer, &dbuflen) != ERROR_SUCCESS )
-            return 2;
+        LONG i_result = RegEnumValueW( hKey, index, vbuffer, &vbuflen,
+                                       NULL, NULL, (LPBYTE)dbuffer, &dbuflen);
+        if( i_result != ERROR_SUCCESS )
+            return i_result;
 
         char *psz_value = FromWide( vbuffer );
 
@@ -568,7 +572,7 @@ static int GetFileFontByName( const char *font_name, char **psz_filename )
                 break;
         }
         else {
-            if( strcasecmp( psz_value, font_name ) == 0 )
+            if( strncasecmp( psz_value, font_name, fontname_len ) == 0 )
                 break;
         }
     }
@@ -593,6 +597,9 @@ static char* Win32_Select( filter_t *p_filter, const char* family,
 {
     VLC_UNUSED( i_size );
 
+    if( strlen( family ) < 1 )
+        goto fail;
+
     /* */
     LOGFONT lf;
     lf.lfCharSet = DEFAULT_CHARSET;
@@ -630,6 +637,7 @@ static char* Win32_Select( filter_t *p_filter, const char* family,
         }
     }
     else /* Let's take any font we can */
+fail:
     {
         char *psz_tmp;
         if( asprintf( &psz_tmp, "%s\\%s", p_filter->p_sys->psz_win_fonts_path, "arial.ttf" ) == -1 )