@@ -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;
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(-)