From b9116997ce1fa3e0b4726fa8a5533c6c11f39bfc Mon Sep 17 00:00:00 2001 From: eugeni Date: Mon, 6 Nov 2006 02:47:57 +0000 Subject: [PATCH] Calculate text bounding box in a way that does not depend on actual glyph bitmaps. Each glyph is considered to be bounded by (origin, origin + advance) horizontally, and (max font ascender, max font descender) vertically. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@20734 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libass/ass_render.c | 51 +++++++++++++-------------------------------- 1 file changed, 15 insertions(+), 36 deletions(-) diff --git a/libass/ass_render.c b/libass/ass_render.c index aa3918b..0b44719 100644 --- a/libass/ass_render.c +++ b/libass/ass_render.c @@ -492,43 +492,24 @@ static int y2scr_sub(int y) { return y * frame_context.orig_height / frame_context.track->PlayResY + global_settings->top_margin; } -static void vmirror_bbox(FT_BBox* orig, FT_BBox* pbbox) { - pbbox->xMin = orig->xMin; - pbbox->xMax = orig->xMax; - pbbox->yMin = - orig->yMax; - pbbox->yMax = - orig->yMin; -} - static void compute_string_bbox( text_info_t* info, FT_BBox *abbox ) { FT_BBox bbox; - int n; - - /* initialize string bbox to "empty" values */ - bbox.xMin = bbox.yMin = 32000; - bbox.xMax = bbox.yMax = -32000; - - /* for each glyph image, compute its bounding box, */ - /* translate it, and grow the string bbox */ - for ( n = 0; n < info->length; n++ ) { - FT_BBox glyph_bbox; - vmirror_bbox( &(info->glyphs[n].bbox), &glyph_bbox ); - glyph_bbox.xMin += info->glyphs[n].pos.x; - glyph_bbox.xMax += info->glyphs[n].pos.x; - glyph_bbox.yMin += info->glyphs[n].pos.y; - glyph_bbox.yMax += info->glyphs[n].pos.y; - if ( glyph_bbox.xMin < bbox.xMin ) bbox.xMin = glyph_bbox.xMin; - if ( glyph_bbox.yMin < bbox.yMin ) bbox.yMin = glyph_bbox.yMin; - if ( glyph_bbox.xMax > bbox.xMax ) bbox.xMax = glyph_bbox.xMax; - if ( glyph_bbox.yMax > bbox.yMax ) bbox.yMax = glyph_bbox.yMax; - } + int i; - /* check that we really grew the string bbox */ - if ( bbox.xMin > bbox.xMax ) { - bbox.xMin = 0; - bbox.yMin = 0; - bbox.xMax = 0; - bbox.yMax = 0; - } + if (text_info.length > 0) { + bbox.xMin = 32000; + bbox.xMax = -32000; + bbox.yMin = - (text_info.lines[0].asc >> 6) + text_info.glyphs[0].pos.y; + bbox.yMax = ((text_info.height - text_info.lines[0].asc) >> 6) + text_info.glyphs[0].pos.y; + + for (i = 0; i < text_info.length; ++i) { + int s = text_info.glyphs[i].pos.x; + int e = s + (text_info.glyphs[i].advance.x >> 6); + bbox.xMin = FFMIN(bbox.xMin, s); + bbox.xMax = FFMAX(bbox.xMax, e); + } + } else + bbox.xMin = bbox.xMax = bbox.yMin = bbox.yMax = 0; /* return string bbox */ *abbox = bbox; @@ -1774,8 +1755,6 @@ static int ass_render_event(ass_event_t* event, event_images_t* event_images) // determing text bounding box compute_string_bbox(&text_info, &bbox); - bbox.yMin = - (text_info.lines[0].asc >> 6); - bbox.yMax = (text_info.height - text_info.lines[0].asc) >> 6; // determine device coordinates for text -- 2.40.0