Commit 3dc91d61 authored by Ilkka Ollakka's avatar Ilkka Ollakka

freetype: use fontconfig to get default font if available

With fontconfig freetype-font is font-family to use, not fontfile.
This should solve issue on linux-side where there aren't any one
place and one file thats usually there.

I'm not that familiar with freetype/fontconfig stuff, so this one could
be way wrong. So feel free to mention/fix/revert this if you spot
something odd.
parent d94eb977
...@@ -70,6 +70,8 @@ ...@@ -70,6 +70,8 @@
#ifdef HAVE_FONTCONFIG #ifdef HAVE_FONTCONFIG
#include <fontconfig/fontconfig.h> #include <fontconfig/fontconfig.h>
#undef DEFAULT_FONT
#define DEFAULT_FONT FC_DEFAULT_FONT
#endif #endif
#include <assert.h> #include <assert.h>
...@@ -81,7 +83,13 @@ static int Create ( vlc_object_t * ); ...@@ -81,7 +83,13 @@ static int Create ( vlc_object_t * );
static void Destroy( vlc_object_t * ); static void Destroy( vlc_object_t * );
#define FONT_TEXT N_("Font") #define FONT_TEXT N_("Font")
#define FONT_LONGTEXT N_("Filename for the font you want to use")
#ifdef HAVE_FONTCONFIG
#define FONT_LONGTEXT N_("Font family for the font you want to use")
#else
#define FONT_LONGTEXT N_("Fontfile for the font you want to use")
#endif
#define FONTSIZE_TEXT N_("Font size in pixels") #define FONTSIZE_TEXT N_("Font size in pixels")
#define FONTSIZE_LONGTEXT N_("This is the default size of the fonts " \ #define FONTSIZE_LONGTEXT N_("This is the default size of the fonts " \
"that will be rendered on the video. " \ "that will be rendered on the video. " \
...@@ -284,8 +292,15 @@ static int Create( vlc_object_t *p_this ) ...@@ -284,8 +292,15 @@ static int Create( vlc_object_t *p_this )
{ {
filter_t *p_filter = (filter_t *)p_this; filter_t *p_filter = (filter_t *)p_this;
filter_sys_t *p_sys; filter_sys_t *p_sys;
char *psz_fontfile = NULL; char *psz_fontfile=NULL;
int i_error; char *psz_fontfamily=NULL;
int i_error,fontindex;
#ifdef HAVE_FONTCONFIG
FcPattern *fontpattern, *fontmatch;
FcResult fontresult;
#endif
vlc_value_t val; vlc_value_t val;
/* Allocate structure */ /* Allocate structure */
...@@ -314,35 +329,73 @@ static int Create( vlc_object_t *p_this ) ...@@ -314,35 +329,73 @@ static int Create( vlc_object_t *p_this )
var_Get( p_filter, "freetype-color", &val ); var_Get( p_filter, "freetype-color", &val );
p_sys->i_font_color = __MAX( __MIN( val.i_int, 0xFFFFFF ), 0 ); p_sys->i_font_color = __MAX( __MIN( val.i_int, 0xFFFFFF ), 0 );
p_sys->i_effect = var_GetInteger( p_filter, "freetype-effect" ); p_sys->i_effect = var_GetInteger( p_filter, "freetype-effect" );
var_Get( p_filter, "freetype-fontsize", &val );
p_sys->i_default_font_size = val.i_int;
/* Look what method was requested */ fontindex=0;
var_Get( p_filter, "freetype-font", &val ); var_Get( p_filter, "freetype-font", &val );
psz_fontfile = val.psz_string; psz_fontfamily = val.psz_string;
if( !psz_fontfile || !*psz_fontfile ) if( !psz_fontfamily || !*psz_fontfamily )
{ {
free( psz_fontfile ); #ifdef HAVE_FONTCONFIG
psz_fontfile = (char *)malloc( PATH_MAX + 1 ); free( psz_fontfamily);
if( !psz_fontfile ) psz_fontfamily=strdup( DEFAULT_FONT );
goto error;
#ifdef WIN32
GetWindowsDirectory( psz_fontfile, PATH_MAX + 1 );
strcat( psz_fontfile, "\\fonts\\arial.ttf" );
#elif defined(__APPLE__)
strcpy( psz_fontfile, DEFAULT_FONT );
#else #else
msg_Err( p_filter, "user didn't specify a font" ); free( psz_fontfamily );
goto error; psz_fontfamily = (char *)malloc( PATH_MAX + 1 );
if( !psz_fontfamily )
goto error;
# ifdef WIN32
GetWindowsDirectory( psz_fontfamily , PATH_MAX + 1 );
strcat( psz_fontfamily, "\\fonts\\arial.ttf" );
# else
strcpy( psz_fontfamily, DEFAULT_FONT );
# endif
msg_Err( p_filter,"User didn't specify fontfile, using %s", psz_fontfamily);
#endif #endif
} }
#ifdef HAVE_FONTCONFIG
/* Lets find some fontfile from freetype-font variable family */
char *psz_fontsize = malloc( 4 );
if( !psz_fontsize )
goto error;
snprintf( psz_fontsize, 4, "%d", p_sys->i_default_font_size );
fontpattern = FcPatternCreate();
FcPatternAddString( fontpattern, FC_FAMILY, psz_fontfamily);
FcPatternAddString( fontpattern, FC_SIZE, psz_fontsize );
if( FcConfigSubstitute( NULL, fontpattern, FcMatchPattern ) == FcFalse )
{
FcPatternDestroy( fontpattern );
free( psz_fontsize );
goto error;
}
FcDefaultSubstitute( fontpattern );
fontmatch = FcFontMatch( NULL, fontpattern, &fontresult );
FcPatternGetString( fontmatch, FC_FILE, 0, (FcChar8 **)&psz_fontfile);
FcPatternGetInteger( fontmatch, FC_INDEX, 0, &fontindex );
if( !psz_fontfile )
goto error;
msg_Dbg( p_filter, "Using %s as font from file %s", psz_fontfamily, psz_fontfile);
free( psz_fontsize );
#else
psz_fontfile = psz_fontfamily;
#endif
i_error = FT_Init_FreeType( &p_sys->p_library ); i_error = FT_Init_FreeType( &p_sys->p_library );
if( i_error ) if( i_error )
{ {
msg_Err( p_filter, "couldn't initialize freetype" ); msg_Err( p_filter, "couldn't initialize freetype" );
goto error; goto error;
} }
i_error = FT_New_Face( p_sys->p_library, psz_fontfile ? psz_fontfile : "", i_error = FT_New_Face( p_sys->p_library, psz_fontfile ? psz_fontfile : "",
0, &p_sys->p_face ); fontindex, &p_sys->p_face );
if( i_error == FT_Err_Unknown_File_Format ) if( i_error == FT_Err_Unknown_File_Format )
{ {
msg_Err( p_filter, "file %s have unknown format", psz_fontfile ); msg_Err( p_filter, "file %s have unknown format", psz_fontfile );
...@@ -369,11 +422,8 @@ static int Create( vlc_object_t *p_this ) ...@@ -369,11 +422,8 @@ static int Create( vlc_object_t *p_this )
p_sys->i_use_kerning = FT_HAS_KERNING( p_sys->p_face ); p_sys->i_use_kerning = FT_HAS_KERNING( p_sys->p_face );
var_Get( p_filter, "freetype-fontsize", &val );
p_sys->i_default_font_size = val.i_int;
if( SetFontSize( p_filter, 0 ) != VLC_SUCCESS ) goto error; if( SetFontSize( p_filter, 0 ) != VLC_SUCCESS ) goto error;
free( psz_fontfile );
p_sys->pp_font_attachments = NULL; p_sys->pp_font_attachments = NULL;
p_sys->i_font_attachments = 0; p_sys->i_font_attachments = 0;
...@@ -381,10 +431,13 @@ static int Create( vlc_object_t *p_this ) ...@@ -381,10 +431,13 @@ static int Create( vlc_object_t *p_this )
p_filter->pf_render_text = RenderText; p_filter->pf_render_text = RenderText;
#ifdef HAVE_FONTCONFIG #ifdef HAVE_FONTCONFIG
p_filter->pf_render_html = RenderHtml; p_filter->pf_render_html = RenderHtml;
FcPatternDestroy( fontmatch );
FcPatternDestroy( fontpattern );
#else #else
p_filter->pf_render_html = NULL; p_filter->pf_render_html = NULL;
#endif #endif
free( psz_fontfamily );
LoadFontsFromAttachments( p_filter ); LoadFontsFromAttachments( p_filter );
return VLC_SUCCESS; return VLC_SUCCESS;
......
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