diff mbox series

[FFmpeg-devel] fix for defect #10531

Message ID 7fc3d15e-ab08-8e7b-cd68-2308e548906d@tiscali.it
State New
Headers show
Series [FFmpeg-devel] fix for defect #10531 | expand


Context Check Description
andriy/commit_msg_x86 warning The first line of the commit message must start with a context terminated by a colon and a space, for example "lavu/opt: " or "doc: ".
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Francesco Carusi Sept. 11, 2023, 2:48 p.m. UTC
I attached a patch for defect [ #10531: vf_drawtext causing font 
rendering jitter after libharfbuz commit. ]

Before the patch the width of a text line was measured up to the 
rightmost visible pixel of the last character.
Pros: the right padding specified with the boxborderw parameter is exact 
with respect to the visible text
Cons: the width of a text line depends on the last character, even with 
monospaced fonts

After the patch the width of the last character is set equal to the 
width specified in the font file, which may include some empty space.
Pros: when using monospaced fonts the width of a line depends only on 
the number of characters, this is also the standard behavior adopted by 
other rendering strategies, e.g. in browsers
Cons: the user specified right padding may not be equal to the distance 
between the background box right border and the rightmost visible pixel 
of the text.
From 62ccf3fc27f2a7df7b79a6241aae2e8d7fd8058d Mon Sep 17 00:00:00 2001
From: yethie <klimklim@tiscali.it>
Date: Thu, 7 Sep 2023 18:39:25 +0200
Subject: [PATCH 1/1] text width measurement fixed

 libavfilter/vf_drawtext.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
diff mbox series


diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c
index ec8d215795..9e5f013c09 100644
--- a/libavfilter/vf_drawtext.c
+++ b/libavfilter/vf_drawtext.c
@@ -1757,9 +1757,17 @@  continue_on_failed2:
                     first_min_x64 = FFMIN(glyph->bbox.xMin, first_min_x64);
                 if (t == hb->glyph_count - 1) {
-                    w64 += glyph->bbox.xMax;
-                    last_max_x64 = FFMAX(glyph->bbox.xMax, last_max_x64);
-                    cur_line->offset_right64 = glyph->bbox.xMax;
+                    // The following code measures the width of the line up to the last
+                    // character's horizontal advance
+                    int last_char_width = hb->glyph_pos[t].x_advance;
+                    // The following code measures the width of the line up to the rightmost
+                    // visible pixel of the last character
+                    // int last_char_width = glyph->bbox.xMax;
+                    w64 += last_char_width;
+                    last_max_x64 = FFMAX(last_char_width, last_max_x64);
+                    cur_line->offset_right64 = last_char_width;
                 } else {
                     if (is_tab) {
                         int size = s->blank_advance64 * s->tabsize;