[vlc-devel] [PATCH 4/4] freetype: apply sub-text-scale factor where possible

Francois Cartegnie fcvlcdev at free.fr
Fri Aug 28 20:01:31 CEST 2015


---
 modules/text_renderer/freetype.c | 33 +++++++++++++++++++++++++++++++--
 modules/text_renderer/freetype.h |  3 +++
 2 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/modules/text_renderer/freetype.c b/modules/text_renderer/freetype.c
index 4ccafc3..0974981 100644
--- a/modules/text_renderer/freetype.c
+++ b/modules/text_renderer/freetype.c
@@ -876,10 +876,12 @@ static void FillDefaultStyles( filter_t *p_filter )
     text_style_Merge( p_sys->p_default_style, p_sys->p_forced_style, true );
 }
 
-static uni_char_t* SegmentsToTextAndStyles( filter_t *p_filter, const text_segment_t *p_segment, size_t *pi_string_length, const text_style_t ***ppp_styles)
+static uni_char_t* SegmentsToTextAndStyles( filter_t *p_filter, const text_segment_t *p_segment,
+                                            size_t *pi_string_length, const text_style_t ***ppp_styles, bool b_grid )
 {
     const text_style_t **pp_styles = NULL;
     uni_char_t *psz_uni = NULL;
+    const int i_scale = ( b_grid ) ? 100 : atomic_load( &p_filter->p_sys->i_scale_factor );
     size_t i_size = 0;
     size_t i_nb_char = 0;
     for( const text_segment_t *s = p_segment; s != NULL; s = s->p_next )
@@ -933,6 +935,12 @@ static uni_char_t* SegmentsToTextAndStyles( filter_t *p_filter, const text_segme
         /* Overwrite any default or value with forced ones */
         text_style_Merge( p_style, p_filter->p_sys->p_forced_style, true );
 
+        if( i_scale != 100 )
+        {
+            p_style->i_font_size = p_style->i_font_size * i_scale / 100;
+            p_style->f_font_relsize = p_style->f_font_relsize * i_scale / 100;
+        }
+
         // i_string_bytes is a number of bytes, while here we're going to assign pointer by pointer
         for ( size_t i = 0; i < i_string_bytes / sizeof( *psz_uni ); ++i )
             pp_styles[i_nb_char + i] = p_style;
@@ -959,7 +967,8 @@ static int Render( filter_t *p_filter, subpicture_region_t *p_region_out,
 
     const text_style_t **pp_styles = NULL;
     size_t i_text_length = 0;
-    uni_char_t *psz_text = SegmentsToTextAndStyles( p_filter, p_region_in->p_text, &i_text_length, &pp_styles );
+    uni_char_t *psz_text = SegmentsToTextAndStyles( p_filter, p_region_in->p_text, &i_text_length,
+                                                    &pp_styles, p_region_in->b_gridmode );
     if( !psz_text || !pp_styles )
     {
         return VLC_EGENERIC;
@@ -1102,6 +1111,13 @@ error:
     return VLC_EGENERIC;
 }
 
+static int VarCallback( vlc_object_t *p_obj, char const *psz_name,
+                        vlc_value_t oldvar, vlc_value_t newvar, void *p_data )
+{
+    VLC_UNUSED(p_obj); VLC_UNUSED(psz_name); VLC_UNUSED(oldvar);
+    atomic_store( (atomic_int *) p_data, newvar.i_int );
+    return VLC_SUCCESS;
+}
 
 static int Create( vlc_object_t *p_this )
 {
@@ -1225,6 +1241,13 @@ static int Create( vlc_object_t *p_this )
     free( psz_fontfile );
     free( psz_monofontfile );
 
+    atomic_init( &p_sys->i_scale_factor, var_InheritInteger( p_filter, "sub-text-scale") );
+    if( p_filter->p_parent && p_filter->p_parent->p_parent )
+    {
+        p_sys->b_callback = ( var_AddCallback( p_filter->p_parent->p_parent,
+            "sub-text-scale", VarCallback, &p_sys->i_scale_factor ) == VLC_SUCCESS );
+    }
+
     return VLC_SUCCESS;
 
 error:
@@ -1259,6 +1282,12 @@ static void Destroy( vlc_object_t *p_this )
     filter_t *p_filter = (filter_t *)p_this;
     filter_sys_t *p_sys = p_filter->p_sys;
 
+    if( p_sys->b_callback )
+    {
+        var_DelCallback( p_filter->p_parent->p_parent, "sub-text-scale",
+                         VarCallback, &p_sys->i_scale_factor );
+    }
+
     faces_cache_t *p_cache = &p_sys->faces_cache;
     for( int i = 0; i < p_cache->i_faces_count; ++i )
     {
diff --git a/modules/text_renderer/freetype.h b/modules/text_renderer/freetype.h
index ae7c36f..901a62f 100644
--- a/modules/text_renderer/freetype.h
+++ b/modules/text_renderer/freetype.h
@@ -29,6 +29,7 @@
 #define VLC_FREETYPE_H
 
 #include <vlc_text_style.h>                                   /* text_style_t*/
+#include <vlc_atomic.h>
 
 typedef struct faces_cache_t
 {
@@ -52,6 +53,8 @@ struct filter_sys_t
 
     text_style_t  *p_default_style;
     text_style_t  *p_forced_style;/* Renderer overridings */
+    atomic_int     i_scale_factor;
+    bool           b_callback;
 
     /* More styles... */
     float          f_shadow_vector_x;
-- 
2.4.3



More information about the vlc-devel mailing list