Commit f64051ad authored by Francois Cartegnie's avatar Francois Cartegnie

freetype: precompute line edges

parent e124678e
...@@ -700,16 +700,12 @@ static inline void RenderBackground( subpicture_region_t *p_region, ...@@ -700,16 +700,12 @@ static inline void RenderBackground( subpicture_region_t *p_region,
max_height = p_glyph->top; 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) */ /* Compute the background for the line (identify leading/trailing space) */
for( int i = 0; i < p_line->i_character_count; i++ ) { line_start = p_line->p_character[p_line->i_first_visible_char_index].p_glyph->left +
const line_character_t *ch = &p_line->p_character[i]; i_align_left - p_bbox->xMin;
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;
}
}
/* Fudge factor to make sure caption background edges are left aligned /* Fudge factor to make sure caption background edges are left aligned
despite variable font width */ despite variable font width */
...@@ -717,15 +713,9 @@ static inline void RenderBackground( subpicture_region_t *p_region, ...@@ -717,15 +713,9 @@ static inline void RenderBackground( subpicture_region_t *p_region,
line_start = 0; line_start = 0;
/* Find right boundary for bounding box for background */ /* Find right boundary for bounding box for background */
for( int i = p_line->i_character_count; i > 0; i-- ) { line_end = p_line->p_character[p_line->i_last_visible_char_index].p_glyph->left +
const line_character_t *ch = &p_line->p_character[i - 1]; p_line->p_character[p_line->i_last_visible_char_index].p_glyph->bitmap.width +
FT_BitmapGlyph p_glyph = ch->p_shadow ? ch->p_shadow : ch->p_glyph; i_align_left - p_bbox->xMin;
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;
}
}
/* Setup color for the background */ /* Setup color for the background */
uint8_t i_x, i_y, i_z; uint8_t i_x, i_y, i_z;
......
...@@ -163,6 +163,8 @@ line_desc_t *NewLine( int i_count ) ...@@ -163,6 +163,8 @@ line_desc_t *NewLine( int i_count )
p_line->i_width = 0; p_line->i_width = 0;
p_line->i_base_line = 0; p_line->i_base_line = 0;
p_line->i_character_count = 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.xMin = INT_MAX;
p_line->bbox.yMin = INT_MAX; p_line->bbox.yMin = INT_MAX;
...@@ -1071,6 +1073,14 @@ static int LayoutLine( filter_t *p_filter, ...@@ -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, i_font_max_advance_y = abs( FT_FLOOR( FT_MulFix( p_face->max_advance_height,
p_face->size->metrics.y_scale ) ) ); 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 ); p_line->i_width = __MAX( 0, p_line->bbox.xMax - p_line->bbox.xMin );
......
...@@ -46,6 +46,8 @@ struct line_desc_t ...@@ -46,6 +46,8 @@ struct line_desc_t
int i_height; int i_height;
int i_base_line; int i_base_line;
int i_character_count; int i_character_count;
int i_first_visible_char_index;
int i_last_visible_char_index;
line_character_t *p_character; line_character_t *p_character;
FT_BBox bbox; FT_BBox bbox;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment