From 0ba8cc29723257840b9afb43c0364c68a190c77d Mon Sep 17 00:00:00 2001 From: eugeni Date: Fri, 22 Sep 2006 18:56:09 +0000 Subject: Move calculation of text parameters (number of lines, height, etc.) from wrap_lines_smart() into a separate function. Call it for every event, even those that do not require line wrapping. This fixes randomly wrong positioning of 'Banner' events. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@19938 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libass/ass_render.c | 57 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/libass/ass_render.c b/libass/ass_render.c index 7a0ebf79da..3a98267a16 100644 --- a/libass/ass_render.c +++ b/libass/ass_render.c @@ -1257,6 +1257,38 @@ static int get_glyph(int index, int symbol, glyph_info_t* info, FT_Vector* advan return 0; } +/** + * This function goes through text_info and calculates text parameters. + * The following text_info fields are filled: + * n_lines + * height + * lines[].height + * lines[].asc + * lines[].desc + */ +static void measure_text() +{ + int cur_line = 0, max_asc = 0, max_desc = 0; + int i; + text_info.height = 0; + for (i = 0; i < text_info.length + 1; ++i) { + if ((i == text_info.length) || text_info.glyphs[i].linebreak) { + text_info.lines[cur_line].asc = max_asc; + text_info.lines[cur_line].desc = max_desc; + text_info.height += max_asc + max_desc; + cur_line ++; + max_asc = max_desc = 0; + } + if (i < text_info.length) { + glyph_info_t* cur = text_info.glyphs + i; + if (cur->asc > max_asc) + max_asc = cur->asc * render_context.scale_y; + if (cur->desc > max_desc) + max_desc = cur->desc * render_context.scale_y; + } + } +} + /** * \brief rearrange text between lines * \param max_text_width maximal text line width in pixels @@ -1275,7 +1307,6 @@ static void wrap_lines_smart(int max_text_width) int exit; int pen_shift_x; int pen_shift_y; - int max_asc, max_desc; int cur_line; last_space = -1; @@ -1370,26 +1401,8 @@ static void wrap_lines_smart(int max_text_width) assert(text_info.n_lines >= 1); #undef DIFF - text_info.height = 0; - max_asc = max_desc = 0; - cur_line = 0; - for (i = 0; i < text_info.length + 1; ++i) { - if ((i == text_info.length) || text_info.glyphs[i].linebreak) { - text_info.lines[cur_line].asc = max_asc; - text_info.lines[cur_line].desc = max_desc; - text_info.height += max_asc + max_desc; - cur_line ++; - max_asc = max_desc = 0; - } - if (i < text_info.length) { - cur = text_info.glyphs + i; - if (cur->asc > max_asc) - max_asc = cur->asc * render_context.scale_y; - if (cur->desc > max_desc) - max_desc = cur->desc * render_context.scale_y; - } - } - + measure_text(); + pen_shift_x = 0; pen_shift_y = 0; cur_line = 1; @@ -1674,6 +1687,8 @@ static int ass_render_event(ass_event_t* event, event_images_t* event_images) last_break = i - 1; } } + } else { // render_context.evt_type == EVENT_HSCROLL + measure_text(); } // determing text bounding box -- cgit v1.2.3