[vlc-commits] Freetype: split freetype init from Create

Jean-Baptiste Kempf git at videolan.org
Sun Dec 15 14:42:08 CET 2013


vlc | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Thu Sep 26 21:23:43 2013 +0200| [634111a2d1c2e5275e91bb4fbabd01212b1a062b] | committer: Jean-Baptiste Kempf

Freetype: split freetype init from Create

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=634111a2d1c2e5275e91bb4fbabd01212b1a062b
---

 modules/text_renderer/freetype.c |  103 ++++++++++++++++++++++----------------
 1 file changed, 61 insertions(+), 42 deletions(-)

diff --git a/modules/text_renderer/freetype.c b/modules/text_renderer/freetype.c
index baeeb96..28f09eb 100644
--- a/modules/text_renderer/freetype.c
+++ b/modules/text_renderer/freetype.c
@@ -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 );



More information about the vlc-commits mailing list