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
12597maximum glyph width, that is the maximum width for all the glyphs12597maximum glyph width, that is the maximum width for all the glyphs
12598contained in the rendered text12598contained in the rendered text
12599 12599
12600@item font_a
12601the ascent size defined in the font metrics
12602
12603@item font_d
12604the descent size defined in the font metrics
12605
12606@item top_a
12607the maximum ascender of the glyphs of the first text line
12608
12609@item bottom_d
12610the maximum descender of the glyphs of the last text line
12611
12600@item n12612@item n
12601the number of input frame, starting from 012613the number of input frame, starting from 0
12602 12614
libavfilter/vf_drawtext.c+12−0
@@ -89,6 +89,10 @@ static const char *const var_names[] = { · 88 unmodified lines
89 "max_glyph_d", "descent", ///< min glyph descender89 "max_glyph_d", "descent", ///< min glyph descender
90 "max_glyph_h", ///< max glyph height90 "max_glyph_h", ///< max glyph height
91 "max_glyph_w", ///< max glyph width91 "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
92 "n", ///< number of frame96 "n", ///< number of frame
93 "sar",97 "sar",
94 "t", ///< timestamp expressed in seconds98 "t", ///< timestamp expressed in seconds
@@ -136,6 +140,10 @@ enum var_name { · 41 unmodified lines
136 VAR_MAX_GLYPH_D, VAR_DESCENT,140 VAR_MAX_GLYPH_D, VAR_DESCENT,
137 VAR_MAX_GLYPH_H,141 VAR_MAX_GLYPH_H,
138 VAR_MAX_GLYPH_W,142 VAR_MAX_GLYPH_W,
143 VAR_FONT_A,
144 VAR_FONT_D,
145 VAR_TOP_A,
146 VAR_BOTTOM_D,
139 VAR_N,147 VAR_N,
140 VAR_SAR,148 VAR_SAR,
141 VAR_T,149 VAR_T,
@@ -1800,8 +1808,12 @@ static int draw_text(AVFilterContext *ctx, AVFrame *frame) · 1658 unmodified lines
1800 s->var_values[VAR_MAX_GLYPH_W] = s->max_glyph_w;1808 s->var_values[VAR_MAX_GLYPH_W] = s->max_glyph_w;
1801 s->var_values[VAR_MAX_GLYPH_H] = s->max_glyph_h;1809 s->var_values[VAR_MAX_GLYPH_H] = s->max_glyph_h;
1802 s->var_values[VAR_MAX_GLYPH_A] = s->var_values[VAR_ASCENT] = POS_CEIL(metrics.max_y64, 64);1810 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;
1803 s->var_values[VAR_MAX_GLYPH_D] = s->var_values[VAR_DESCENT] = POS_CEIL(metrics.min_y64, 64);1812 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;
1804 1814
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);
1805 s->var_values[VAR_LINE_H] = s->var_values[VAR_LH] = metrics.line_height64 / 64.;1817 s->var_values[VAR_LINE_H] = s->var_values[VAR_LH] = metrics.line_height64 / 64.;
1806 1818
1807 if (s->text_source == AV_FRAME_DATA_DETECTION_BBOXES) {1819 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