Commit a888fdf6 authored by Jean-Baptiste Kempf's avatar 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...
parent ce2d6368
......@@ -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 );
}
......@@ -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;
......
......@@ -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 );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment