summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOneric <oneric@oneric.stub>2021-12-11 08:13:48 +0100
committerOneric <oneric@oneric.stub>2022-08-19 19:16:40 +0200
commit7cb7d0279f069dffe2a14a7088fae31d95caa4d5 (patch)
treed0588f5e6a5d9498933dd314555d63965fd03db4
parent41e1acf482e4500060576facd12582fd6f778b50 (diff)
downloadlibass-7cb7d0279f069dffe2a14a7088fae31d95caa4d5.tar.bz2
libass-7cb7d0279f069dffe2a14a7088fae31d95caa4d5.tar.xz
wrap_lines: consistently account for whitespace trimming
-rw-r--r--libass/ass_render.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/libass/ass_render.c b/libass/ass_render.c
index ecfffa7..eb1e526 100644
--- a/libass/ass_render.c
+++ b/libass/ass_render.c
@@ -1744,6 +1744,7 @@ wrap_lines_rebalance(ASS_Renderer *render_priv, double max_text_width, char *uni
// Find last word of line and trim surrounding whitespace before measuring
// (whitespace ' ' will also get trimmed in rendering)
GlyphInfo *w = rewind_trailing_spaces(s1, s2);
+ GlyphInfo *e1_old = w;
while ((w > s1) && (!ALLOWBREAK(w->symbol, w - text_info->glyphs))) {
--w;
}
@@ -1756,15 +1757,19 @@ wrap_lines_rebalance(ASS_Renderer *render_priv, double max_text_width, char *uni
if (w == s1)
continue; // Merging linebreaks is never beneficial
- l1 = d6_to_double(((s2 - 1)->bbox.x_max + (s2 - 1)->pos.x) -
+ GlyphInfo *e2 = rewind_trailing_spaces(s2, s3);
+
+ l1 = d6_to_double(
+ (e1_old->bbox.x_max + e1_old->pos.x) -
(s1->bbox.x_min + s1->pos.x));
- l2 = d6_to_double(((s3 - 1)->bbox.x_max + (s3 - 1)->pos.x) -
+ l2 = d6_to_double(
+ (e2->bbox.x_max + e2->pos.x) -
(s2->bbox.x_min + s2->pos.x));
l1_new = d6_to_double(
(e1->bbox.x_max + e1->pos.x) -
(s1->bbox.x_min + s1->pos.x));
l2_new = d6_to_double(
- ((s3 - 1)->bbox.x_max + (s3 - 1)->pos.x) -
+ (e2->bbox.x_max + e2->pos.x) -
(w->bbox.x_min + w->pos.x));
if (DIFF(l1_new, l2_new) < DIFF(l1, l2)) {