[vlc-commits] freetype: precompute line edges

Francois Cartegnie git at videolan.org
Fri Aug 21 00:42:26 CEST 2015


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Fri Aug 21 00:31:14 2015 +0200| [f64051ad2908469c6dd116f270654145e3535939] | committer: Francois Cartegnie

freetype: precompute line edges

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

 modules/text_renderer/freetype.c    |   26 ++++++++------------------
 modules/text_renderer/text_layout.c |   10 ++++++++++
 modules/text_renderer/text_layout.h |    2 ++
 3 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/modules/text_renderer/freetype.c b/modules/text_renderer/freetype.c
index 361ddfc..562edac 100644
--- a/modules/text_renderer/freetype.c
+++ b/modules/text_renderer/freetype.c
@@ -700,16 +700,12 @@ static inline void RenderBackground( subpicture_region_t *p_region,
                 max_height = p_glyph->top;
         }
 
+        if( p_line->i_first_visible_char_index < 0 )
+            continue; /* only spaces */
+
         /* Compute the background for the line (identify leading/trailing space) */
-        for( int i = 0; i < p_line->i_character_count; i++ ) {
-            const line_character_t *ch = &p_line->p_character[i];
-            FT_BitmapGlyph p_glyph = ch->p_outline ? ch->p_outline : ch->p_glyph;
-            if (p_glyph && p_glyph->bitmap.rows > 0) {
-                // Found a non-whitespace character
-                line_start = i_align_left + p_glyph->left - p_bbox->xMin;
-                break;
-            }
-        }
+        line_start = p_line->p_character[p_line->i_first_visible_char_index].p_glyph->left +
+                     i_align_left - p_bbox->xMin;
 
         /* Fudge factor to make sure caption background edges are left aligned
            despite variable font width */
@@ -717,15 +713,9 @@ static inline void RenderBackground( subpicture_region_t *p_region,
             line_start = 0;
 
         /* Find right boundary for bounding box for background */
-        for( int i = p_line->i_character_count; i > 0; i-- ) {
-            const line_character_t *ch = &p_line->p_character[i - 1];
-            FT_BitmapGlyph p_glyph = ch->p_shadow ? ch->p_shadow : ch->p_glyph;
-            if (p_glyph && p_glyph->bitmap.rows > 0) {
-                // Found a non-whitespace character
-                line_end = i_align_left + p_glyph->left - p_bbox->xMin + p_glyph->bitmap.width;
-                break;
-            }
-        }
+        line_end = p_line->p_character[p_line->i_last_visible_char_index].p_glyph->left +
+                   p_line->p_character[p_line->i_last_visible_char_index].p_glyph->bitmap.width +
+                   i_align_left - p_bbox->xMin;
 
         /* Setup color for the background */
         uint8_t i_x, i_y, i_z;
diff --git a/modules/text_renderer/text_layout.c b/modules/text_renderer/text_layout.c
index 3493663..9dcec5d 100644
--- a/modules/text_renderer/text_layout.c
+++ b/modules/text_renderer/text_layout.c
@@ -163,6 +163,8 @@ line_desc_t *NewLine( int i_count )
     p_line->i_width = 0;
     p_line->i_base_line = 0;
     p_line->i_character_count = 0;
+    p_line->i_first_visible_char_index = -1;
+    p_line->i_last_visible_char_index = -2;
 
     p_line->bbox.xMin = INT_MAX;
     p_line->bbox.yMin = INT_MAX;
@@ -1071,6 +1073,14 @@ static int LayoutLine( filter_t *p_filter,
             i_font_max_advance_y = abs( FT_FLOOR( FT_MulFix( p_face->max_advance_height,
                                       p_face->size->metrics.y_scale ) ) );
         }
+
+        /* Keep track of blank/spaces in front/end of line */
+        if( p_ch->p_glyph->bitmap.rows )
+        {
+            if( p_line->i_first_visible_char_index < 0 )
+                p_line->i_first_visible_char_index = i_line_index;
+            p_line->i_last_visible_char_index = i_line_index;
+        }
     }
 
     p_line->i_width = __MAX( 0, p_line->bbox.xMax - p_line->bbox.xMin );
diff --git a/modules/text_renderer/text_layout.h b/modules/text_renderer/text_layout.h
index fca4159..f6542ce 100644
--- a/modules/text_renderer/text_layout.h
+++ b/modules/text_renderer/text_layout.h
@@ -46,6 +46,8 @@ struct line_desc_t
     int              i_height;
     int              i_base_line;
     int              i_character_count;
+    int              i_first_visible_char_index;
+    int              i_last_visible_char_index;
     line_character_t *p_character;
     FT_BBox          bbox;
 };



More information about the vlc-commits mailing list