From cd29011665608d11788000e7269ce886892cf4cd Mon Sep 17 00:00:00 2001 From: Grigori Goronzy Date: Sat, 9 Jul 2011 22:04:01 +0200 Subject: Redesign horizontal alignment calculations for bidi The line alignment code determined the first and last glyph in a line and calculated the distance from that. This is rather arcane and doesn't easily work with bidi. Redesign the algorithm to simply add together all individual character widths instead. --- libass/ass_render.c | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/libass/ass_render.c b/libass/ass_render.c index ec1f839..8c80210 100644 --- a/libass/ass_render.c +++ b/libass/ass_render.c @@ -1914,25 +1914,10 @@ ass_render_event(ASS_Renderer *render_priv, ASS_Event *event, // align text last_break = -1; - for (i = 1; i < text_info->length + 1; ++i) { // (text_info->length + 1) is the end of the last line + double width = 0; + for (i = 0; i <= text_info->length; ++i) { // (text_info->length + 1) is the end of the last line if ((i == text_info->length) || glyphs[i].linebreak) { - double width, shift = 0; - GlyphInfo *first_glyph = - glyphs + last_break + 1; - GlyphInfo *last_glyph = glyphs + i - 1; - - while (first_glyph < last_glyph && first_glyph->skip) - first_glyph++; - - while ((last_glyph > first_glyph) - && ((last_glyph->symbol == '\n') - || (last_glyph->symbol == 0) - || (last_glyph->skip))) - last_glyph--; - - width = d6_to_double( - last_glyph->pos.x + last_glyph->advance.x - - first_glyph->pos.x); + double shift = 0; if (halign == HALIGN_LEFT) { // left aligned, no action shift = 0; } else if (halign == HALIGN_RIGHT) { // right aligned @@ -1944,7 +1929,11 @@ ass_render_event(ASS_Renderer *render_priv, ASS_Event *event, glyphs[j].pos.x += double_to_d6(shift); } last_break = i - 1; + width = 0; } + if (i < text_info->length && !glyphs[i].skip && + glyphs[i].symbol != '\n' && glyphs[i].symbol != 0) + width += d6_to_double(glyphs[i].advance.x); } } else { // render_priv->state.evt_type == EVENT_HSCROLL measure_text(render_priv); -- cgit v1.2.3