Skip to content

Commit

Permalink
Freetype: split freetype init from Create
Browse files Browse the repository at this point in the history
Signed-off-by: Jean-Baptiste Kempf <[email protected]>
  • Loading branch information
jbkempf committed Dec 15, 2013
1 parent fb9d787 commit 634111a
Showing 1 changed file with 61 additions and 42 deletions.
103 changes: 61 additions & 42 deletions modules/text_renderer/freetype.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) );
Expand Down Expand Up @@ -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;
Expand All @@ -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 );
Expand Down

0 comments on commit 634111a

Please sign in to comment.