]> git.sesse.net Git - vlc/blobdiff - modules/misc/freetype.c
Compile fix
[vlc] / modules / misc / freetype.c
index 94523571c4853b1d1fc9ac40b3de1f02969066ec..1f5850c4d67599b85e74b7b015d5913196fc47ce 100644 (file)
@@ -31,7 +31,8 @@
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 #include <vlc_vout.h>
 #include <vlc_osd.h>
 #include <vlc_block.h>
@@ -72,6 +73,8 @@
 #include <fontconfig/fontconfig.h>
 #endif
 
+#include <assert.h>
+
 typedef struct line_desc_t line_desc_t;
 
 /*****************************************************************************
@@ -90,7 +93,8 @@ static int RenderHtml( filter_t *, subpicture_region_t *,
                        subpicture_region_t * );
 static char *FontConfig_Select( FcConfig *, const char *,
                                 bool, bool, int * );
-static int CheckIfFontBuildComplete( filter_t *p_filter );
+static int BuildDone( vlc_object_t*, const char *, vlc_value_t, vlc_value_t,
+                        void* );
 #endif
 static line_desc_t *NewLine( int );
 
@@ -123,9 +127,9 @@ static void YUVFromRGB( uint32_t i_argb,
     "fonts that will be rendered on the video. If absolute font size is set, "\
     "relative size will be overriden." )
 
-static int   pi_sizes[] = { 20, 18, 16, 12, 6 };
-static const char *ppsz_sizes_text[] = { N_("Smaller"), N_("Small"), N_("Normal"),
-                                         N_("Large"), N_("Larger") };
+static const int pi_sizes[] = { 20, 18, 16, 12, 6 };
+static const char *const ppsz_sizes_text[] = {
+    N_("Smaller"), N_("Small"), N_("Normal"), N_("Large"), N_("Larger") };
 #define YUVP_TEXT N_("Use YUVP renderer")
 #define YUVP_LONGTEXT N_("This renders the font using \"paletized YUV\". " \
   "This option is only needed if you want to encode into DVB subtitles" )
@@ -137,22 +141,22 @@ static const char *ppsz_sizes_text[] = { N_("Smaller"), N_("Small"), N_("Normal"
 #define EFFECT_OUTLINE     2
 #define EFFECT_OUTLINE_FAT 3
 
-static int   pi_effects[] = { 1, 2, 3 };
-static const char *ppsz_effects_text[] = { N_("Background"),N_("Outline"),
-                                           N_("Fat Outline") };
-static int pi_color_values[] = {
+static int const pi_effects[] = { 1, 2, 3 };
+static const char *const ppsz_effects_text[] = {
+    N_("Background"),N_("Outline"), N_("Fat Outline") };
+static const int pi_color_values[] = {
   0x00000000, 0x00808080, 0x00C0C0C0, 0x00FFFFFF, 0x00800000,
   0x00FF0000, 0x00FF00FF, 0x00FFFF00, 0x00808000, 0x00008000, 0x00008080,
   0x0000FF00, 0x00800080, 0x00000080, 0x000000FF, 0x0000FFFF };
 
-static const char *ppsz_color_descriptions[] = {
+static const char *const ppsz_color_descriptions[] = {
   N_("Black"), N_("Gray"), N_("Silver"), N_("White"), N_("Maroon"),
   N_("Red"), N_("Fuchsia"), N_("Yellow"), N_("Olive"), N_("Green"), N_("Teal"),
   N_("Lime"), N_("Purple"), N_("Navy"), N_("Blue"), N_("Aqua") };
 
 vlc_module_begin();
-    set_shortname( _("Text renderer"));
-    set_description( _("Freetype2 font renderer") );
+    set_shortname( N_("Text renderer"));
+    set_description( N_("Freetype2 font renderer") );
     set_category( CAT_VIDEO );
     set_subcategory( SUBCAT_VIDEO_SUBPIC );
 
@@ -280,7 +284,6 @@ static int Create( vlc_object_t *p_this )
     char          *psz_fontfile = NULL;
     int            i_error;
     vlc_value_t    val;
-    vlc_mutex_t   *lock;
     vlc_object_t  *p_fontbuilder;
 
     /* Allocate structure */
@@ -363,12 +366,12 @@ static int Create( vlc_object_t *p_this )
     }
 
 #ifdef HAVE_FONTCONFIG
-    vlc_mutex_init( p_filter, &p_sys->fontconfig_lock );
+    vlc_mutex_init( &p_sys->fontconfig_lock );
     p_sys->b_fontconfig_ok = false;
     p_sys->p_fontconfig    = NULL;
 
     /* Check for an existing Fontbuilder thread */
-    lock = var_AcquireMutex( "fontbuilder" );
+    vlc_mutex_t *lock = var_AcquireMutex( "fontbuilder" );
     p_fontbuilder = vlc_object_find_name( p_filter->p_libvlc,
                                           "fontlist builder",
                                           FIND_CHILD );
@@ -391,6 +394,7 @@ static int Create( vlc_object_t *p_this )
 
             var_Create( p_fontbuilder, "build-done", VLC_VAR_BOOL );
             var_SetBool( p_fontbuilder, "build-done", false );
+            var_AddCallback( p_fontbuilder, "build-done", BuildDone, p_sys );
 
             if( vlc_thread_create( p_fontbuilder,
                                    "fontlist builder",
@@ -472,6 +476,16 @@ static void Destroy( vlc_object_t *p_this )
     }
 
 #ifdef HAVE_FONTCONFIG
+    vlc_mutex_t *lock = var_AcquireMutex( "fontbuilder" );
+    vlc_object_t *p_fontbuilder = vlc_object_find_name( p_filter->p_libvlc,
+                                    "fontlist builder", FIND_CHILD );
+    if( p_fontbuilder )
+    {
+        var_DelCallback( p_fontbuilder, "build-done", BuildDone, p_sys );
+        vlc_object_release( p_fontbuilder );
+    }
+    vlc_mutex_unlock( lock );
+
     vlc_mutex_destroy( &p_sys->fontconfig_lock );
 
     if( p_sys->p_fontconfig )
@@ -518,6 +532,7 @@ static void FontBuilder( vlc_object_t *p_this )
         msg_Dbg( p_this, "Took %ld seconds", (long)((t2 - t1)/1000000) );
 
         lock = var_AcquireMutex( "fontbuilder" );
+
         var_SetBool( p_this, "build-done", true );
 
         FcConfigDestroy( p_fontconfig );
@@ -1293,6 +1308,7 @@ static int RenderText( filter_t *p_filter, subpicture_region_t *p_region_out,
             glyph_size.xMin + ((FT_BitmapGlyph)tmp_glyph)->left;
         if( line.xMax > (int)p_filter->fmt_out.video.i_visible_width - 20 )
         {
+            FT_Done_Glyph( (FT_Glyph)p_line->pp_glyphs[ i ] );
             p_line->pp_glyphs[ i ] = NULL;
             FreeLine( p_line );
             p_line = NewLine( strlen( psz_string ));
@@ -2187,35 +2203,15 @@ static int CheckForEmbeddedFont( filter_sys_t *p_sys, FT_Face *pp_face, ft_style
     return VLC_EGENERIC;
 }
 
-static int CheckIfFontBuildComplete( filter_t *p_filter )
+static int BuildDone( vlc_object_t *p_this, const char *psz_var,
+                       vlc_value_t oldval, vlc_value_t newval, void *param )
 {
-    filter_sys_t   *p_sys = p_filter->p_sys;
-    vlc_object_t   *p_fb = vlc_object_find_name( p_filter->p_libvlc,
-                                                 "fontlist builder",
-                                                 FIND_CHILD );
-    if( p_fb )
-    {
-        vlc_mutex_t *lock = var_AcquireMutex( "fontbuilder" );
-        vlc_value_t  val;
-
-        if( VLC_SUCCESS == var_Get( p_fb, "build-done", &val ))
-        {
-            p_sys->b_fontconfig_ok = val.b_bool;
-
-            if( p_sys->b_fontconfig_ok )
-            {
-                FcInit();
-                p_sys->p_fontconfig = FcConfigGetCurrent();
-            }
-            else
-                msg_Dbg( p_filter, "Font Build still not complete" );
-        }
-        vlc_mutex_unlock( lock );
-        vlc_object_release( p_fb );
-
-        return VLC_SUCCESS;
-    }
-    return VLC_EGENERIC;
+    (void)p_this;
+    (void)psz_var;
+    (void)oldval;
+    ((filter_sys_t*)param)->b_fontconfig_ok = newval.b_bool;
+    assert( newval.b_bool );
+    return VLC_SUCCESS;
 }
 
 static int ProcessLines( filter_t *p_filter,
@@ -2434,12 +2430,6 @@ static int ProcessLines( filter_t *p_filter,
             /* Look for a match amongst our attachments first */
             CheckForEmbeddedFont( p_sys, &p_face, p_style );
 
-            if( !p_sys->b_fontconfig_ok )
-            {
-                if( VLC_EGENERIC == CheckIfFontBuildComplete( p_filter ))
-                    msg_Err( p_filter, "Can't find FontBuilder thread!" );
-            }
-
             if( ! p_face && p_sys->b_fontconfig_ok )
             {
                 char *psz_fontfile;