From bdc11c44b15be12f8eebef1cb3bfcda240a31d00 Mon Sep 17 00:00:00 2001 From: Zhao Zhili Date: Fri, 14 Nov 2025 16:23:10 +0800 Subject: [PATCH] avfilter/vf_drawtext: fix incorrect text length From the doc of HarfBuzz, what hb_buffer_add_utf8 needs is the number of bytes, not Unicode character: hb_buffer_add_utf8(buf, text, strlen(text), 0, strlen(text)); Fix issue #20906. (cherry picked from commit 9bc3c572eaaab559a7258c392528e7a1cad2a9b7) Signed-off-by: Michael Niedermayer --- libavfilter/vf_drawtext.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c index 232e4015fb..d8737a2145 100644 --- a/libavfilter/vf_drawtext.c +++ b/libavfilter/vf_drawtext.c @@ -1395,7 +1395,6 @@ static int measure_text(AVFilterContext *ctx, TextMetrics *metrics) DrawTextContext *s = ctx->priv; char *text = s->expanded_text.str; char *textdup = NULL, *start = NULL; - int num_chars = 0; int width64 = 0, w64 = 0; int cur_min_y64 = 0, first_max_y64 = -32000; int first_min_x64 = 32000, last_max_x64 = -32000; @@ -1458,7 +1457,7 @@ continue_on_failed2: TextLine *cur_line = &s->lines[line_count]; HarfbuzzData *hb = &cur_line->hb_data; cur_line->cluster_offset = line_offset; - ret = shape_text_hb(s, hb, start, num_chars); + ret = shape_text_hb(s, hb, start, p - start); if (ret != 0) { goto done; } @@ -1516,14 +1515,12 @@ continue_on_failed2: if (w64 > width64) { width64 = w64; } - num_chars = -1; start = p; ++line_count; line_offset = i + 1; } if (code == 0) break; - ++num_chars; } metrics->line_height64 = s->face->size->metrics.height;