[vlc-devel] [PATCH 3/7] freetype: avoid redundant calls to FT_Set_Pixel_Sizes()

Salah-Eddin Shaban salshaaban at gmail.com
Tue May 12 08:16:00 CEST 2015


---
 modules/text_renderer/freetype.c    | 11 +++++++++++
 modules/text_renderer/text_layout.c | 24 +++++++++---------------
 2 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/modules/text_renderer/freetype.c b/modules/text_renderer/freetype.c
index ab04f0c..af5572f 100644
--- a/modules/text_renderer/freetype.c
+++ b/modules/text_renderer/freetype.c
@@ -1442,6 +1442,17 @@ FT_Face LoadFace( filter_t *p_filter,
         return NULL;
     }
 
+    int i_font_width = p_style->i_style_flags & STYLE_HALFWIDTH
+                     ? p_style->i_font_size / 2 : p_style->i_font_size;
+
+    if( FT_Set_Pixel_Sizes( p_face, i_font_width, p_style->i_font_size ) )
+    {
+        msg_Err( p_filter,
+                 "Failed to set font size to %d", p_style->i_font_size );
+        FT_Done_Face( p_face );
+        return NULL;
+    }
+
     if( p_cache->i_faces_count == p_cache->i_cache_size )
     {
         FT_Face *p_new_faces =
diff --git a/modules/text_renderer/text_layout.c b/modules/text_renderer/text_layout.c
index c55ae80..71b3a81 100644
--- a/modules/text_renderer/text_layout.c
+++ b/modules/text_renderer/text_layout.c
@@ -517,19 +517,16 @@ static int ShapeParagraphHarfBuzz( filter_t *p_filter,
         {
             p_face = LoadFace( p_filter, p_style );
             if( !p_face )
+            {
                 p_face = p_sys->p_face;
+                p_style = &p_sys->style;
+                p_run->p_style = p_style;
+            }
             p_run->p_face = p_face;
         }
         else
             p_face = p_run->p_face;
 
-        int i_font_width = p_style->i_style_flags & STYLE_HALFWIDTH
-                         ? p_style->i_font_size / 2 : p_style->i_font_size;
-
-        if( FT_Set_Pixel_Sizes( p_face, i_font_width, p_style->i_font_size ) )
-            msg_Err( p_filter,
-                     "Failed to set font size to %d", p_style->i_font_size );
-
         p_run->p_hb_font = hb_ft_font_create( p_face, 0 );
         if( !p_run->p_hb_font )
         {
@@ -773,24 +770,21 @@ static int LoadGlyphs( filter_t *p_filter, paragraph_t *p_paragraph,
         run_desc_t *p_run = p_paragraph->p_runs + i;
         text_style_t *p_style = p_run->p_style;
 
-        FT_Face p_face;
+        FT_Face p_face = 0;
         if( !p_run->p_face )
         {
             p_face = LoadFace( p_filter, p_style );
             if( !p_face )
+            {
                 p_face = p_sys->p_face;
+                p_style = &p_sys->style;
+                p_run->p_style = p_style;
+            }
             p_run->p_face = p_face;
         }
         else
             p_face = p_run->p_face;
 
-        int i_font_width = p_style->i_style_flags & STYLE_HALFWIDTH ?
-                p_style->i_font_size / 2 : p_style->i_font_size;
-
-        if( FT_Set_Pixel_Sizes( p_face, i_font_width, p_style->i_font_size ) )
-            msg_Err( p_filter,
-                     "Failed to set font size to %d", p_style->i_font_size );
-
         if( p_sys->p_stroker )
         {
             double f_outline_thickness =
-- 
1.9.1




More information about the vlc-devel mailing list