Message ID | c0493773-f13b-4041-a92c-35aa92ed5c0e@YW-A2526-D.local |
---|---|
State | New |
Headers | show |
On Fri, Jul 21, 2017 at 11:35:14AM +0800, efren yang wrote: > It is applied to every glyph. There is no space between all words in some languages, for example Chinese, Japanese and so on. So a sentence will look very compactly. I think if we could set glyph spacing, it will adapt to more different scenarios. Maybe it is simple but useful. > > ffmpeg -i input -vf drawtext="glyph_spacing=10:text="PROGRAMMING":fontfile=demo.ttf" -f flv 1.flv could set glyph spacing 10 pixel. > > Signed-off-by: efren yang <efren_yang@163.com> > --- > doc/filters.texi | 4 ++++ > libavfilter/vf_drawtext.c | 3 +++ > 2 files changed, 7 insertions(+) > > diff --git a/doc/filters.texi b/doc/filters.texi > index 119d1be69d..0f336f8826 100644 > --- a/doc/filters.texi > +++ b/doc/filters.texi > @@ -7077,6 +7077,10 @@ The default value of @var{boxcolor} is "white". > Set the line spacing in pixels of the border to be drawn around the box using @var{box}. > The default value of @var{line_spacing} is 0. > > +@item glyph_spacing > +Set the glyph spacing in pixels for drawing text. > +The default value of @var{glyph_spacing} is 0. > + > @item borderw > Set the width of the border to be drawn around the text using @var{bordercolor}. > The default value of @var{borderw} is 0. > diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c > index f6151443bb..152d8f35d5 100644 > --- a/libavfilter/vf_drawtext.c > +++ b/libavfilter/vf_drawtext.c > @@ -162,6 +162,7 @@ typedef struct DrawTextContext { > unsigned int default_fontsize; ///< default font size to use > > int line_spacing; ///< lines spacing in pixels > + int glyph_spacing; ///< glyph spacing in pixels > short int draw_box; ///< draw box around text - true or false > int boxborderw; ///< box border width > int use_kerning; ///< font kerning is used - true/false > @@ -214,6 +215,7 @@ static const AVOption drawtext_options[]= { > {"box", "set box", OFFSET(draw_box), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 , FLAGS}, > {"boxborderw", "set box border width", OFFSET(boxborderw), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX , FLAGS}, > {"line_spacing", "set line spacing in pixels", OFFSET(line_spacing), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX,FLAGS}, > + {"glyph_spacing", "set glyph spacing in pixels", OFFSET(glyph_spacing), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX,FLAGS }, > {"fontsize", "set font size", OFFSET(fontsize_expr), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX , FLAGS}, > {"x", "set x expression", OFFSET(x_expr), AV_OPT_TYPE_STRING, {.str="0"}, CHAR_MIN, CHAR_MAX, FLAGS}, > {"y", "set y expression", OFFSET(y_expr), AV_OPT_TYPE_STRING, {.str="0"}, CHAR_MIN, CHAR_MAX, FLAGS}, > @@ -1374,6 +1376,7 @@ static int draw_text(AVFilterContext *ctx, AVFrame *frame, > s->positions[i].y = y - glyph->bitmap_top + y_max; > if (code == '\t') x = (x / s->tabsize + 1)*s->tabsize; > else x += glyph->advance; > + x += s->glyph_spacing; This still needs a check glyph_spacing is just checked against INT_MAX and x is a int so if x is > 0 this would be undefined and even if defined it would be wrong [...]
diff --git a/doc/filters.texi b/doc/filters.texi index 119d1be69d..0f336f8826 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -7077,6 +7077,10 @@ The default value of @var{boxcolor} is "white". Set the line spacing in pixels of the border to be drawn around the box using @var{box}. The default value of @var{line_spacing} is 0. +@item glyph_spacing +Set the glyph spacing in pixels for drawing text. +The default value of @var{glyph_spacing} is 0. + @item borderw Set the width of the border to be drawn around the text using @var{bordercolor}. The default value of @var{borderw} is 0. diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c index f6151443bb..152d8f35d5 100644 --- a/libavfilter/vf_drawtext.c +++ b/libavfilter/vf_drawtext.c @@ -162,6 +162,7 @@ typedef struct DrawTextContext { unsigned int default_fontsize; ///< default font size to use int line_spacing; ///< lines spacing in pixels + int glyph_spacing; ///< glyph spacing in pixels short int draw_box; ///< draw box around text - true or false int boxborderw; ///< box border width int use_kerning; ///< font kerning is used - true/false @@ -214,6 +215,7 @@ static const AVOption drawtext_options[]= { {"box", "set box", OFFSET(draw_box), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 , FLAGS}, {"boxborderw", "set box border width", OFFSET(boxborderw), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX , FLAGS}, {"line_spacing", "set line spacing in pixels", OFFSET(line_spacing), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX,FLAGS}, + {"glyph_spacing", "set glyph spacing in pixels", OFFSET(glyph_spacing), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX,FLAGS }, {"fontsize", "set font size", OFFSET(fontsize_expr), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX , FLAGS}, {"x", "set x expression", OFFSET(x_expr), AV_OPT_TYPE_STRING, {.str="0"}, CHAR_MIN, CHAR_MAX, FLAGS}, {"y", "set y expression", OFFSET(y_expr), AV_OPT_TYPE_STRING, {.str="0"}, CHAR_MIN, CHAR_MAX, FLAGS}, @@ -1374,6 +1376,7 @@ static int draw_text(AVFilterContext *ctx, AVFrame *frame, s->positions[i].y = y - glyph->bitmap_top + y_max; if (code == '\t') x = (x / s->tabsize + 1)*s->tabsize; else x += glyph->advance; + x += s->glyph_spacing; } max_text_line_w = FFMAX(x, max_text_line_w);
It is applied to every glyph. There is no space between all words in some languages, for example Chinese, Japanese and so on. So a sentence will look very compactly. I think if we could set glyph spacing, it will adapt to more different scenarios. Maybe it is simple but useful. ffmpeg -i input -vf drawtext="glyph_spacing=10:text="PROGRAMMING":fontfile=demo.ttf" -f flv 1.flv could set glyph spacing 10 pixel. Signed-off-by: efren yang <efren_yang@163.com> --- doc/filters.texi | 4 ++++ libavfilter/vf_drawtext.c | 3 +++ 2 files changed, 7 insertions(+)