Commit 634111a2 authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf
Browse files

Freetype: split freetype init from Create


Signed-off-by: Jean-Baptiste Kempf's avatarJean-Baptiste Kempf <jb@videolan.org>
parent fb9d7879
......@@ -2195,6 +2195,65 @@ static int RenderHtml( filter_t *p_filter, subpicture_region_t *p_region_out,
*****************************************************************************
* This function allocates and initializes a Clone vout method.
*****************************************************************************/
static int Init_FT( vlc_object_t *p_this,
const char *psz_fontfile,
const int fontindex,
const float f_outline_thickness)
{
filter_t *p_filter = (filter_t *)p_this;
filter_sys_t *p_sys = p_filter->p_sys;
/* */
int i_error = FT_Init_FreeType( &p_sys->p_library );
if( i_error )
{
msg_Err( p_filter, "couldn't initialize freetype" );
goto error;
}
i_error = FT_New_Face( p_sys->p_library, psz_fontfile ? psz_fontfile : "",
fontindex, &p_sys->p_face );
if( i_error == FT_Err_Unknown_File_Format )
{
msg_Err( p_filter, "file %s have unknown format",
psz_fontfile ? psz_fontfile : "(null)" );
goto error;
}
else if( i_error )
{
msg_Err( p_filter, "failed to load font file %s",
psz_fontfile ? psz_fontfile : "(null)" );
goto error;
}
i_error = FT_Select_Charmap( p_sys->p_face, ft_encoding_unicode );
if( i_error )
{
msg_Err( p_filter, "font has no unicode translation table" );
goto error;
}
if( SetFontSize( p_filter, 0 ) != VLC_SUCCESS ) goto error;
p_sys->p_stroker = NULL;
if( f_outline_thickness > 0.001 )
{
i_error = FT_Stroker_New( p_sys->p_library, &p_sys->p_stroker );
if( i_error )
msg_Err( p_filter, "Failed to create stroker for outlining" );
}
return VLC_SUCCESS;
error:
if( p_sys->p_face ) FT_Done_Face( p_sys->p_face );
if( p_sys->p_library ) FT_Done_FreeType( p_sys->p_library );
return VLC_EGENERIC;
}
static int Create( vlc_object_t *p_this )
{
filter_t *p_filter = (filter_t *)p_this;
......@@ -2203,7 +2262,7 @@ static int Create( vlc_object_t *p_this )
char *psz_fontname = NULL;
char *psz_monofontfile = NULL;
char *psz_monofontfamily = NULL;
int i_error = 0, fontindex = 0, monofontindex = 0;
int fontindex = 0, monofontindex = 0;
/* Allocate structure */
p_filter->p_sys = p_sys = malloc( sizeof(*p_sys) );
......@@ -2314,46 +2373,8 @@ static int Create( vlc_object_t *p_this )
#endif
p_sys->style.psz_monofontname = psz_monofontfamily;
/* */
i_error = FT_Init_FreeType( &p_sys->p_library );
if( i_error )
{
msg_Err( p_filter, "couldn't initialize freetype" );
goto error;
}
i_error = FT_New_Face( p_sys->p_library, psz_fontfile ? psz_fontfile : "",
fontindex, &p_sys->p_face );
if( i_error == FT_Err_Unknown_File_Format )
{
msg_Err( p_filter, "file %s have unknown format",
psz_fontfile ? psz_fontfile : "(null)" );
goto error;
}
else if( i_error )
{
msg_Err( p_filter, "failed to load font file %s",
psz_fontfile ? psz_fontfile : "(null)" );
goto error;
}
i_error = FT_Select_Charmap( p_sys->p_face, ft_encoding_unicode );
if( i_error )
{
msg_Err( p_filter, "font has no unicode translation table" );
if( Init_FT( p_this, psz_fontname, fontindex, f_outline_thickness ) != VLC_SUCCESS )
goto error;
}
if( SetFontSize( p_filter, 0 ) != VLC_SUCCESS ) goto error;
p_sys->p_stroker = NULL;
if( f_outline_thickness > 0.001 )
{
i_error = FT_Stroker_New( p_sys->p_library, &p_sys->p_stroker );
if( i_error )
msg_Err( p_filter, "Failed to create stroker for outlining" );
}
p_sys->pp_font_attachments = NULL;
p_sys->i_font_attachments = 0;
......@@ -2371,8 +2392,6 @@ static int Create( vlc_object_t *p_this )
return VLC_SUCCESS;
error:
if( p_sys->p_face ) FT_Done_Face( p_sys->p_face );
if( p_sys->p_library ) FT_Done_FreeType( p_sys->p_library );
#ifdef HAVE_STYLES
free( psz_fontfile );
free( psz_monofontfile );
......
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