History

avfilter/vf_drawtext: add expression variables to control font ascent/descent

The following new variables can be used in the x and y expressions: font_a, font_d, top_a, bottom_d.

yethie committed 3 years ago

Commit 01d843f1 parent fac7bb02 files · +24 −0Browse files

Unified · Split

2 files
  1. doc/filters.texi +12 −0
  2. libavfilter/vf_drawtext.c +12 −0
doc/filters.texi+12−0
@@ -12597,6 +12597,18 @@ contained in the rendered text, it is equivalent to @var{ascent} - · 12596 unmodified lines
1259712597 maximum glyph width, that is the maximum width for all the glyphs
1259812598 contained in the rendered text
1259912599
12600+@item font_a
12601+the ascent size defined in the font metrics
12602+
12603+@item font_d
12604+the descent size defined in the font metrics
12605+
12606+@item top_a
12607+the maximum ascender of the glyphs of the first text line
12608+
12609+@item bottom_d
12610+the maximum descender of the glyphs of the last text line
12611+
1260012612 @item n
1260112613 the number of input frame, starting from 0
1260212614
libavfilter/vf_drawtext.c+12−0
@@ -89,6 +89,10 @@ static const char *const var_names[] = { · 88 unmodified lines
8989 "max_glyph_d", "descent", ///< min glyph descender
9090 "max_glyph_h", ///< max glyph height
9191 "max_glyph_w", ///< max glyph width
92+ "font_a", ///< font-defined ascent
93+ "font_d", ///< font-defined descent
94+ "top_a", ///< max glyph ascender of the top line
95+ "bottom_d", ///< max glyph descender of the bottom line
9296 "n", ///< number of frame
9397 "sar",
9498 "t", ///< timestamp expressed in seconds
@@ -136,6 +140,10 @@ enum var_name { · 41 unmodified lines
136140 VAR_MAX_GLYPH_D, VAR_DESCENT,
137141 VAR_MAX_GLYPH_H,
138142 VAR_MAX_GLYPH_W,
143+ VAR_FONT_A,
144+ VAR_FONT_D,
145+ VAR_TOP_A,
146+ VAR_BOTTOM_D,
139147 VAR_N,
140148 VAR_SAR,
141149 VAR_T,
@@ -1800,8 +1808,12 @@ static int draw_text(AVFilterContext *ctx, AVFrame *frame) · 1658 unmodified lines
18001808 s->var_values[VAR_MAX_GLYPH_W] = s->max_glyph_w;
18011809 s->var_values[VAR_MAX_GLYPH_H] = s->max_glyph_h;
18021810 s->var_values[VAR_MAX_GLYPH_A] = s->var_values[VAR_ASCENT] = POS_CEIL(metrics.max_y64, 64);
1811+ s->var_values[VAR_FONT_A] = s->face->size->metrics.ascender / 64;
18031812 s->var_values[VAR_MAX_GLYPH_D] = s->var_values[VAR_DESCENT] = POS_CEIL(metrics.min_y64, 64);
1813+ s->var_values[VAR_FONT_D] = -s->face->size->metrics.descender / 64;
18041814
1815+ s->var_values[VAR_TOP_A] = POS_CEIL(metrics.offset_top64, 64);
1816+ s->var_values[VAR_BOTTOM_D] = -POS_CEIL(metrics.offset_bottom64, 64);
18051817 s->var_values[VAR_LINE_H] = s->var_values[VAR_LH] = metrics.line_height64 / 64.;
18061818
18071819 if (s->text_source == AV_FRAME_DATA_DETECTION_BBOXES) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t