[vlc-commits] Freetype: account for more complex font names on Windows

Jean-Baptiste Kempf git at videolan.org
Tue Nov 1 19:58:17 CET 2011


vlc | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Tue Nov  1 19:43:08 2011 +0100| [412774e9577174b4b975522dcbff8a6522cdecab] | committer: Jean-Baptiste Kempf

Freetype: account for more complex font names on Windows

We have to count for "Bold", "Normal" and "Italic" ending in registry

Close #4949

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

 modules/text_renderer/freetype.c |   18 +++++++++++++-----
 1 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/modules/text_renderer/freetype.c b/modules/text_renderer/freetype.c
index 8ab6196..7963f5c 100644
--- a/modules/text_renderer/freetype.c
+++ b/modules/text_renderer/freetype.c
@@ -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 )



More information about the vlc-commits mailing list