lavfi/vf_drawtext: log inferred shaping properties at verbose

Log the script and direction picked by HarfBuzz, plus codepoint and
glyph counts, so the shaper choice can be verified. Differing
codepoint and glyph counts indicate reordering / ligation /
decomposition.

Codepoints are sampled before hb_shape(), which flips the buffer
content type to GLYPHS.

Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
This commit is contained in:
Jun Zhao
2026-06-02 00:52:03 +00:00
committed by Jun Zhao
co-authored by Jun Zhao
parent 1f9888beb0
commit d092269996
+20 -3
View File
@@ -1368,8 +1368,11 @@ static int draw_glyphs(AVFilterContext *ctx, AVFrame *frame,
}
// Shapes a line of text using libharfbuzz
static int shape_text_hb(DrawTextContext *s, HarfbuzzData* hb, const char* text, int textLen)
static int shape_text_hb(AVFilterContext *ctx, DrawTextContext *s,
HarfbuzzData *hb, const char *text, int textLen)
{
unsigned codepoints;
hb->buf = hb_buffer_create();
if (!hb_buffer_allocation_successful(hb->buf))
goto fail;
@@ -1382,6 +1385,9 @@ static int shape_text_hb(DrawTextContext *s, HarfbuzzData* hb, const char* text,
hb_buffer_set_direction(hb->buf, HB_DIRECTION_LTR);
hb_buffer_set_language(hb->buf, hb_language_from_string("en", -1));
hb_buffer_guess_segment_properties(hb->buf);
/* Sample the buffer length here, before hb_shape() flips the buffer's
* content type from UNICODE to GLYPHS. */
codepoints = hb_buffer_get_length(hb->buf);
hb->font = hb_ft_font_create_referenced(s->face);
if (hb->font == NULL)
goto fail;
@@ -1389,6 +1395,17 @@ static int shape_text_hb(DrawTextContext *s, HarfbuzzData* hb, const char* text,
hb->glyph_info = hb_buffer_get_glyph_infos(hb->buf, &hb->glyph_count);
hb->glyph_pos = hb_buffer_get_glyph_positions(hb->buf, &hb->glyph_count);
if (av_log_get_level() >= AV_LOG_VERBOSE) {
char script_tag[5] = { 0 };
hb_script_t script = hb_buffer_get_script(hb->buf);
hb_direction_t dir = hb_buffer_get_direction(hb->buf);
hb_tag_to_string(hb_script_to_iso15924_tag(script), script_tag);
av_log(ctx, AV_LOG_VERBOSE,
"shape: script=%s direction=%s codepoints=%u glyphs=%u\n",
script_tag, hb_direction_to_string(dir),
codepoints, hb->glyph_count);
}
return 0;
fail:
hb_buffer_destroy(hb->buf);
@@ -1441,7 +1458,7 @@ continue_on_failed:
// Evaluate the width of the space character if needed to replace tabs
if (s->tab_count > 0 && !s->blank_advance64) {
HarfbuzzData hb_data;
ret = shape_text_hb(s, &hb_data, " ", 1);
ret = shape_text_hb(ctx, s, &hb_data, " ", 1);
if(ret != 0) {
goto done;
}
@@ -1479,7 +1496,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, len);
ret = shape_text_hb(ctx, s, hb, start, len);
if (ret != 0) {
goto done;
}