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 9bc3c572ea)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
Zhao Zhili 2025-11-14 16:23:10 +08:00 committed by Michael Niedermayer
parent baee5f5e27
commit bdc11c44b1
No known key found for this signature in database
GPG Key ID: B18E8928B3948D64
1 changed files with 1 additions and 4 deletions

View File

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