[vlc-commits] Freetype: handle multibyte characters properly in registry entry.

Naohiro KORIYAMA git at videolan.org
Wed Dec 21 02:12:24 CET 2011


vlc | branch: master | Naohiro KORIYAMA <nkoriyama at gmail.com> | Wed Dec 21 09:58:25 2011 +0900| [d8fd1c1313a4734b324403c9aae5f76908f5e7f5] | committer: Jean-Baptiste Kempf

Freetype: handle multibyte characters properly in registry entry.

Close #5700

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

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

diff --git a/modules/text_renderer/freetype.c b/modules/text_renderer/freetype.c
index 3849e5a..5ec3b4d 100644
--- a/modules/text_renderer/freetype.c
+++ b/modules/text_renderer/freetype.c
@@ -573,12 +573,14 @@ static int GetFileFontByName( const char *font_name, char **psz_filename )
     wchar_t vbuffer[MAX_PATH];
     wchar_t dbuffer[256];
 
-    size_t fontname_len = strlen( font_name );
-
     if( RegOpenKeyEx(HKEY_LOCAL_MACHINE, FONT_DIR_NT, 0, KEY_READ, &hKey)
             != ERROR_SUCCESS )
         return 1;
 
+    MultiByteToWideChar( CP_ACP, 0, font_name, -1, dbuffer, 256 );
+    char *font_name_temp = FromWide( dbuffer );
+    size_t fontname_len = strlen( font_name_temp );
+
     for( int index = 0;; index++ )
     {
         DWORD vbuflen = MAX_PATH - 1;
@@ -596,16 +598,25 @@ static int GetFileFontByName( const char *font_name, char **psz_filename )
 
         /* Manage concatenated font names */
         if( strchr( psz_value, '&') ) {
-            if( strcasestr( psz_value, font_name ) != NULL )
+            if( strcasestr( psz_value, font_name_temp ) != NULL )
+            {
+                free( psz_value );
                 break;
+            }
         }
         else {
-            if( strncasecmp( psz_value, font_name, fontname_len ) == 0 )
+            if( strncasecmp( psz_value, font_name_temp, fontname_len ) == 0 )
+            {
+                free( psz_value );
                 break;
+            }
         }
+
+        free( psz_value );
     }
 
     *psz_filename = FromWide( dbuffer );
+    free( font_name_temp );
     return 0;
 }
 
@@ -635,7 +646,12 @@ static char* Win32_Select( filter_t *p_filter, const char* family,
         lf.lfItalic = true;
     if( b_bold )
         lf.lfWeight = FW_BOLD;
-    strncpy( (LPSTR)&lf.lfFaceName, family, 32);
+
+    char facename[32];
+    wchar_t* psz_fbuffer = ToWide( family );
+    WideCharToMultiByte( CP_ACP, 0, psz_fbuffer, -1, facename, 32, " ", 0 );
+    strncpy( (LPSTR)&lf.lfFaceName, facename, 32 );
+    free( psz_fbuffer );
 
     /* */
     char *psz_filename = NULL;



More information about the vlc-commits mailing list