vlc | branch: master | Jean-Baptiste Kempf <[email protected]> | Sun Dec 15 16:15:53 2013 +0100| [a888fdf60d0a72478ca82fc472d43043298c2410] | committer: Jean-Baptiste Kempf
Freetype: simplify win32 fonts lookup folder It's less elegant, because it is not cached, but it's cleaner in freetype.c with less #ifdef all around... > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a888fdf60d0a72478ca82fc472d43043298c2410 --- modules/text_renderer/freetype.c | 25 ++++--------------------- modules/text_renderer/platform_fonts.c | 22 ++++++++++++++++++++-- modules/text_renderer/platform_fonts.h | 1 + 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/modules/text_renderer/freetype.c b/modules/text_renderer/freetype.c index 20e438b..5e0233b 100644 --- a/modules/text_renderer/freetype.c +++ b/modules/text_renderer/freetype.c @@ -342,11 +342,6 @@ struct filter_sys_t bool bold, bool italic, int size, int *index); - /* Cache the Win32 font folder */ -#ifdef _WIN32 - char* psz_win_fonts_path; -#endif - }; /* */ @@ -1972,17 +1967,6 @@ static int Create( vlc_object_t *p_this ) p_sys->f_shadow_vector_x = f_shadow_distance * cos(2 * M_PI * f_shadow_angle / 360); p_sys->f_shadow_vector_y = f_shadow_distance * sin(2 * M_PI * f_shadow_angle / 360); -#ifdef _WIN32 - /* Get Windows Font folder */ - wchar_t wdir[MAX_PATH]; - if( S_OK != SHGetFolderPathW( NULL, CSIDL_FONTS, NULL, SHGFP_TYPE_CURRENT, wdir ) ) - { - GetWindowsDirectoryW( wdir, MAX_PATH ); - wcscat( wdir, L"\\fonts" ); - } - p_sys->psz_win_fonts_path = FromWide( wdir ); -#endif - /* Set default psz_fontname */ if( !psz_fontname || !*psz_fontname ) { @@ -1991,11 +1975,14 @@ static int Create( vlc_object_t *p_this ) psz_fontname = strdup( DEFAULT_FAMILY ); #else # ifdef _WIN32 - if( asprintf( &psz_fontname, "%s"DEFAULT_FONT_FILE, p_sys->psz_win_fonts_path ) == -1 ) + /* Get Windows Font folder */ + char *psz_win_fonts_path = GetWindowsFontPath(); + if( asprintf( &psz_fontname, "%s"DEFAULT_FONT_FILE, psz_win_fonts_path ) == -1 ) { psz_fontname = NULL; goto error; } + free(psz_win_fonts_path); # else psz_fontname = strdup( DEFAULT_FONT_FILE ); # endif @@ -2109,10 +2096,6 @@ static void Destroy( vlc_object_t *p_this ) free( p_sys->style.psz_fontname ); free( p_sys->style.psz_monofontname ); -#ifdef _WIN32 - free( p_sys->psz_win_fonts_path ); -#endif - Destroy_FT( p_this ); free( p_sys ); } diff --git a/modules/text_renderer/platform_fonts.c b/modules/text_renderer/platform_fonts.c index a666a5c..8466ccc 100644 --- a/modules/text_renderer/platform_fonts.c +++ b/modules/text_renderer/platform_fonts.c @@ -253,6 +253,18 @@ static int CALLBACK EnumFontCallback(const ENUMLOGFONTEX *lpelfe, const NEWTEXTM return GetFileFontByName( (LPCTSTR)lpelfe->elfFullName, (char **)lParam ); } +char *GetWindowsFontPath() +{ + wchar_t wdir[MAX_PATH]; + if( S_OK != SHGetFolderPathW( NULL, CSIDL_FONTS, NULL, SHGFP_TYPE_CURRENT, wdir ) ) + { + GetWindowsDirectoryW( wdir, MAX_PATH ); + wcscat( wdir, L"\\fonts" ); + } + return FromWide( wdir ); +} + + char* Win32_Select( filter_t *p_filter, const char* family, bool b_bold, bool b_italic, int i_size, int *i_idx ) { @@ -290,21 +302,27 @@ char* Win32_Select( filter_t *p_filter, const char* family, return psz_filename; else { + /* Get Windows Font folder */ + char psz_win_fonts_path = GetWindowsFontPath(); char *psz_tmp; - if( asprintf( &psz_tmp, "%s\\%s", p_filter->p_sys->psz_win_fonts_path, psz_filename ) == -1 ) + if( asprintf( &psz_tmp, "%s\\%s", psz_win_fonts_path, psz_filename ) == -1 ) { free( psz_filename ); + free( psz_win_fonts_path ); return NULL; } free( psz_filename ); + free( psz_win_fonts_path ); + return psz_tmp; } } else /* Let's take any font we can */ fail: { + char psz_win_fonts_path = GetWindowsFontPath(); char *psz_tmp; - if( asprintf( &psz_tmp, "%s\\%s", p_filter->p_sys->psz_win_fonts_path, "arial.ttf" ) == -1 ) + if( asprintf( &psz_tmp, "%s\\%s", psz_win_fonts_path, "arial.ttf" ) == -1 ) return NULL; else return psz_tmp; diff --git a/modules/text_renderer/platform_fonts.h b/modules/text_renderer/platform_fonts.h index ac70bbe..87cea63 100644 --- a/modules/text_renderer/platform_fonts.h +++ b/modules/text_renderer/platform_fonts.h @@ -41,6 +41,7 @@ void FontConfig_BuildCache( filter_t *p_filter ); #ifdef _WIN32 +char *GetWindowsFontPath(); char* Win32_Select( filter_t *p_filter, const char* family, bool b_bold, bool b_italic, int i_size, int *i_idx ); _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
