vlc | branch: master | Francois Cartegnie <[email protected]> | Mon Nov 13 17:03:26 2017 +0100| [43398aa5db0cdd40c88b7082e2a98d086b6367fa] | committer: Francois Cartegnie
freetype: text_layout: keep track of visible chars bbox otherwise we're stuck with glyphs coordinates which are insufficient for drawing a proper background > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=43398aa5db0cdd40c88b7082e2a98d086b6367fa --- modules/text_renderer/freetype/freetype.h | 17 +++++++++++++++ modules/text_renderer/freetype/text_layout.c | 31 +++++++++------------------- modules/text_renderer/freetype/text_layout.h | 1 + 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/modules/text_renderer/freetype/freetype.h b/modules/text_renderer/freetype/freetype.h index 7a4e496be7..b0ef9cf178 100644 --- a/modules/text_renderer/freetype/freetype.h +++ b/modules/text_renderer/freetype/freetype.h @@ -153,4 +153,21 @@ struct filter_sys_t FT_Face SelectAndLoadFace( filter_t *p_filter, const text_style_t *p_style, uni_char_t codepoint ); +static inline void BBoxInit( FT_BBox *p_box ) +{ + p_box->xMin = INT_MAX; + p_box->yMin = INT_MAX; + p_box->xMax = INT_MIN; + p_box->yMax = INT_MIN; +} + +static inline void BBoxEnlarge( FT_BBox *p_max, const FT_BBox *p ) +{ + p_max->xMin = __MIN(p_max->xMin, p->xMin); + p_max->yMin = __MIN(p_max->yMin, p->yMin); + p_max->xMax = __MAX(p_max->xMax, p->xMax); + p_max->yMax = __MAX(p_max->yMax, p->yMax); +} + + #endif diff --git a/modules/text_renderer/freetype/text_layout.c b/modules/text_renderer/freetype/text_layout.c index b2991a8c9a..d6844b23d0 100644 --- a/modules/text_renderer/freetype/text_layout.c +++ b/modules/text_renderer/freetype/text_layout.c @@ -199,10 +199,7 @@ line_desc_t *NewLine( int i_count ) 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; - p_line->bbox.xMax = INT_MIN; - p_line->bbox.yMax = INT_MIN; + BBoxInit( &p_line->bbox ); p_line->p_character = calloc( i_count, sizeof(*p_line->p_character) ); if( !p_line->p_character ) @@ -232,14 +229,6 @@ static void FixGlyph( FT_Glyph glyph, FT_BBox *p_bbox, } } -static void BBoxEnlarge( FT_BBox *p_max, const FT_BBox *p ) -{ - p_max->xMin = __MIN(p_max->xMin, p->xMin); - p_max->yMin = __MIN(p_max->yMin, p->yMin); - p_max->xMax = __MAX(p_max->xMax, p->xMax); - p_max->yMax = __MAX(p_max->yMax, p->yMax); -} - static paragraph_t *NewParagraph( filter_t *p_filter, int i_size, const uni_char_t *p_code_points, @@ -1123,6 +1112,7 @@ static int LayoutLine( filter_t *p_filter, if( !p_bitmaps->p_glyph ) { + BBoxInit( &p_ch->bbox ); --i_line_index; continue; } @@ -1251,11 +1241,14 @@ static int LayoutLine( filter_t *p_filter, p_ch->i_line_thickness = i_line_thickness; p_ch->i_line_offset = i_line_offset; - BBoxEnlarge( &p_line->bbox, &p_bitmaps->glyph_bbox ); + /* Compute bounding box for all glyphs */ + p_ch->bbox = p_bitmaps->glyph_bbox; if( p_bitmaps->p_outline ) - BBoxEnlarge( &p_line->bbox, &p_bitmaps->outline_bbox ); + BBoxEnlarge( &p_ch->bbox, &p_bitmaps->outline_bbox ); if( p_bitmaps->p_shadow ) - BBoxEnlarge( &p_line->bbox, &p_bitmaps->shadow_bbox ); + BBoxEnlarge( &p_ch->bbox, &p_bitmaps->shadow_bbox ); + + BBoxEnlarge( &p_line->bbox, &p_ch->bbox ); pen.x += p_bitmaps->i_x_advance; pen.y += p_bitmaps->i_y_advance; @@ -1585,12 +1578,8 @@ int LayoutText( filter_t *p_filter, } int i_base_line = 0; - FT_BBox bbox = { - .xMin = INT_MAX, - .yMin = INT_MAX, - .xMax = INT_MIN, - .yMax = INT_MIN - }; + FT_BBox bbox; + BBoxInit( &bbox ); for( line_desc_t *p_line = p_first_line; p_line; p_line = p_line->p_next ) { diff --git a/modules/text_renderer/freetype/text_layout.h b/modules/text_renderer/freetype/text_layout.h index b67674bf94..16ca48ef1e 100644 --- a/modules/text_renderer/freetype/text_layout.h +++ b/modules/text_renderer/freetype/text_layout.h @@ -38,6 +38,7 @@ typedef struct FT_BitmapGlyph p_glyph; FT_BitmapGlyph p_outline; FT_BitmapGlyph p_shadow; + FT_BBox bbox; const text_style_t *p_style; int i_line_offset; /* underline/strikethrough offset */ int i_line_thickness; /* underline/strikethrough thickness */ _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
