diff mbox

[FFmpeg-devel] doc/filters: drawtext: add example of printing texts on same baseline

Message ID 20161128162929.19220-1-andrey.utkin@pb.com
State Superseded
Headers show

Commit Message

Andrey Utkin Nov. 28, 2016, 4:29 p.m. UTC
Dimensions of canvas drawtext produces vary depending on symbols in
text, so add example for printing multiple texts aligned horizontally.

Signed-off-by: Andrey Utkin <andrey.utkin@pb.com>
---
 doc/filters.texi | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

--
2.11.0.rc2

Comments

Lou Logan Nov. 29, 2016, 6:31 p.m. UTC | #1
On Mon, Nov 28, 2016, at 07:29 AM, Andrey Utkin wrote:
> Dimensions of canvas drawtext produces vary depending on symbols in
> text, so add example for printing multiple texts aligned horizontally.

I don't really understand the use case. Can you explain?
Andriy Utkin Nov. 29, 2016, 6:55 p.m. UTC | #2
On Tue, Nov 29, 2016 at 09:31:08AM -0900, lou@lrcd.com wrote:
> On Mon, Nov 28, 2016, at 07:29 AM, Andrey Utkin wrote:
> > Dimensions of canvas drawtext produces vary depending on symbols in
> > text, so add example for printing multiple texts aligned horizontally.
> 
> I don't really understand the use case. Can you explain?

The point is that with more naive approach to printing parts of text,
using just same vertical offset (code given below), it will look fine in
some cases (e.g. all capital letters), but case of printing part with
capital letter(s) and part without capitals, the parts won't be aligned.

With the following script, you'll see the dot floating at the top of "A"
letter:

#!/bin/sh
FONTFILE=font.ttf
FONTSIZE=32
Y=10 # vertical offset of texts
X1=10 # horizontal offset of first text
X2=30 # horizontal offset of second text
TEXT1="A"
TEXT2="."
ffplay -f lavfi -i "color=color=white,
drawtext=fontfile=$FONTFILE:text=$TEXT1:fontsize=$FONTSIZE:x=$X1:y=$Y,
drawtext=fontfile=$FONTFILE:text=$TEXT2:fontsize=$FONTSIZE:x=$X2:y=$Y"
Lou Logan Nov. 29, 2016, 7:19 p.m. UTC | #3
On Tue, Nov 29, 2016, at 09:55 AM, Andrey Utkin wrote:
>
> The point is that with more naive approach to printing parts of text,
> using just same vertical offset (code given below), it will look fine in
> some cases (e.g. all capital letters), but case of printing part with
> capital letter(s) and part without capitals, the parts won't be aligned.
> 
> With the following script, you'll see the dot floating at the top of "A"
> letter:

I already realized that, but this example may be confusing to users. I
assume the close proximity of TEXT1 and TEXT2 were to demonstrate the
"normalized" placement of various glyph heights for multiple drawtexts,
but users may see this and wonder why you need to print "A.", with the
characters close together as in your example, using two drawtexts when
you could just use one (with text='A.'). Increasing X2 may make the
example less confusing in that regard.
Andrey Utkin Nov. 30, 2016, 9:24 a.m. UTC | #4
On Tue, Nov 29, 2016 at 10:19:04AM -0900, lou@lrcd.com wrote:
> On Tue, Nov 29, 2016, at 09:55 AM, Andrey Utkin wrote:
> >
> > The point is that with more naive approach to printing parts of text,
> > using just same vertical offset (code given below), it will look fine in
> > some cases (e.g. all capital letters), but case of printing part with
> > capital letter(s) and part without capitals, the parts won't be aligned.
> >
> > With the following script, you'll see the dot floating at the top of "A"
> > letter:
>
> I already realized that, but this example may be confusing to users. I
> assume the close proximity of TEXT1 and TEXT2 were to demonstrate the
> "normalized" placement of various glyph heights for multiple drawtexts,
> but users may see this and wonder why you need to print "A.", with the
> characters close together as in your example, using two drawtexts when
> you could just use one (with text='A.'). Increasing X2 may make the
> example less confusing in that regard.

Thanks for your comments.

It's hard for me to stress the point of the approach further.

I wonder if it becomes clearer if we use

TEXT1="one"
TEXT2="two"
X2=100

in discussed scripts.

Maybe a paragraph describing the flaw of naive approach should be added
to example annotation itself? I just followed the present pattern, that
example description is very concise.
Lou Logan Dec. 8, 2016, 11:47 p.m. UTC | #5
On Wed, 30 Nov 2016 09:24:52 +0000, Andrey Utkin wrote:

> Thanks for your comments.
> 
> It's hard for me to stress the point of the approach further.
> 
> I wonder if it becomes clearer if we use
> 
> TEXT1="one"
> TEXT2="two"
> X2=100
> 
> in discussed scripts.
> 
> Maybe a paragraph describing the flaw of naive approach should be added
> to example annotation itself? I just followed the present pattern, that
> example description is very concise.

I don't think a script is needed for this example. It can be simplified
to something like:

Horizontally align multiple separate texts. Note that the
@option{fontsize} value is included in the @option{y} offset.

drawtext=fontfile=FreeSans.ttf:text=DOG:fontsize=24:x=10:y=20+24-max_glyph_a,
drawtext=fontfile=FreeSans.ttf:text=cow:fontsize=24:x=80:y=20+24-max_glyph_a
diff mbox

Patch

diff --git a/doc/filters.texi b/doc/filters.texi
index b3899b2693..c740b2671e 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -7134,6 +7134,22 @@  FOD=5 # fade out duration
 ffplay -f lavfi "color,drawtext=text=TEST:fontsize=50:fontfile=FreeSerif.ttf:fontcolor_expr=ff0000%@{eif\\\\: clip(255*(1*between(t\\, $DS + $FID\\, $DE - $FOD) + ((t - $DS)/$FID)*between(t\\, $DS\\, $DS + $FID) + (-(t - $DE)/$FOD)*between(t\\, $DE - $FOD\\, $DE) )\\, 0\\, 255) \\\\: x\\\\: 2 @}"
 @end example

+@item
+Print multiple different texts on same baseline:
+@example
+#!/bin/sh
+FONTFILE=font.ttf
+FONTSIZE=32
+Y=10 # vertical offset of texts
+X1=10 # horizontal offset of first text
+X2=30 # horizontal offset of second text
+TEXT1="A"
+TEXT2="."
+ffplay -f lavfi -i "color=color=white,
+drawtext=fontfile=$FONTFILE:text=$TEXT1:fontsize=$FONTSIZE:x=$X1:y=$Y+$FONTSIZE-max_glyph_a,
+drawtext=fontfile=$FONTFILE:text=$TEXT2:fontsize=$FONTSIZE:x=$X2:y=$Y+$FONTSIZE-max_glyph_a"
+@end example
+
 @end itemize

 For more information about libfreetype, check: