From 025c1705634887b29817ce648cc6f496acdb5135 Mon Sep 17 00:00:00 2001 From: yethie Date: Fri, 3 Feb 2023 14:34:07 +0100 Subject: [PATCH 4/7] new variables added --- doc/filters.texi | 12 ++++++++++++ libavfilter/vf_drawtext.c | 14 ++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/doc/filters.texi b/doc/filters.texi index 2a84fa9cc8..cb1a3ff983 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -12286,6 +12286,18 @@ contained in the rendered text, it is equivalent to @var{ascent} - maximum glyph width, that is the maximum width for all the glyphs contained in the rendered text +@item font_a +the ascent size defined in the font metrics + +@item font_d +the descent size defined in the font metrics + +@item top_a +the maximum ascender of the glyphs of the first text line + +@item bottom_d +the maximum descender of the glyphs of the last text line + @item n the number of input frame, starting from 0 diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c index c67824c006..25348ba7de 100644 --- a/libavfilter/vf_drawtext.c +++ b/libavfilter/vf_drawtext.c @@ -31,6 +31,8 @@ * - The default line height is now the one defined in the font * - The boxborderw parameter can now contain a different value for each border * (e.g. boxborderw=top|right|bottom|left) + * - The following new variables can be used in the x and y expressions: + * font_a, font_d, top_a, bottom_d */ /** @@ -101,6 +103,10 @@ static const char *const var_names[] = { "max_glyph_d", "descent", ///< min glyph descender "max_glyph_h", ///< max glyph height "max_glyph_w", ///< max glyph width + "font_a", ///< font-defined ascent + "font_d", ///< font-defined descent + "top_a", ///< max glyph ascender of the top line + "bottom_d", ///< max glyph descender of the bottom line "n", ///< number of frame "sar", "t", ///< timestamp expressed in seconds @@ -144,6 +150,10 @@ enum var_name { VAR_MAX_GLYPH_D, VAR_DESCENT, VAR_MAX_GLYPH_H, VAR_MAX_GLYPH_W, + VAR_FONT_A, + VAR_FONT_D, + VAR_TOP_A, + VAR_BOTTOM_D, VAR_N, VAR_SAR, VAR_T, @@ -1800,8 +1810,12 @@ static int draw_text(AVFilterContext *ctx, AVFrame *frame) s->var_values[VAR_MAX_GLYPH_W] = s->max_glyph_w; s->var_values[VAR_MAX_GLYPH_H] = s->max_glyph_h; s->var_values[VAR_MAX_GLYPH_A] = s->var_values[VAR_ASCENT] = POS_CEIL(metrics.max_y64, 64); + s->var_values[VAR_FONT_A] = s->face->size->metrics.ascender / 64; s->var_values[VAR_MAX_GLYPH_D] = s->var_values[VAR_DESCENT] = POS_CEIL(metrics.min_y64, 64); + s->var_values[VAR_FONT_D] = -s->face->size->metrics.descender / 64; + s->var_values[VAR_TOP_A] = POS_CEIL(metrics.offset_top64, 64); + s->var_values[VAR_BOTTOM_D] = POS_CEIL(metrics.offset_bottom64, 64); s->var_values[VAR_LINE_H] = s->var_values[VAR_LH] = metrics.line_height64 / 64.; if (s->text_source == AV_FRAME_DATA_DETECTION_BBOXES) { -- 2.30.2