swfc has font support. That means you can also insert texts into
your animations.
The easiest way to load a font is to do something like
.font Arial filename="Arial.ttf"
.
You now have a font named Arial to play with.
For example, for the obligatory hello world program:
Note:
The text argument expects UTF-8 strings. So if you want to
pass any special characters (umlauts, digraphs etc.), they have to
be UTF-8 encoded.
Besides TrueType fonts, swfc also supports native SWF fonts.
If you have a SWF with a font you would like to use, do a
swfextract file.swf
Then write down the font ID of the font, and do a
swfextract -f <fontid> file.swf -o myfont.swf
.
This will give you a file named myfont.swf which you can
also use in the filename parameter of .font.
Furthermore, you can convert TTF and Type1
fonts into SWF using font2swf:
font2swf Arial.ttf -o Arial.swf
The nice advantage of this is that you can play
Arial.swf in the flash player and see what the
font looks like.
(Also, loading a font in SWF format is slighly
faster than from a TTF file, as with TTFs spline
conversion has to take place).
So much for the basics. Now let's go to the more advanced
functionality around fonts.
Apart from being able to define text in your swfc files,
you can also define text outlines.
Those are not real characters but rather abstract vector
objects which you can use in other commands.
Here, .textshape helloworld defines an outline named "helloworld",
which is then used to construct a filled outline named filled_helloworld.
To make this a little more interesting, let's fill with a gradient instead
of a plain color:
But let's get back to normal .text characters.
The following demonstrates that you can treat objects defined
with .text like normal shapes, i.e., scale them, move them, and use
them for clipping:
The last two examples look similar, but their underlying structure
is different: The first is a shape object filled with
image data (that is, a texture), while the second uses a normal
text object to clip an rectangular image. (More about clipping in
the next section)
Also, .text takes a color attribute (that's actually
the poor man's version of the more advanced filling options
that .textshape in conjunction with .filled offers),
which is used here together with the alpha parameter of .change:
A special type of text in SWF is the edittext, which
can be modified by the viewer. It's content can also be queried
and set from ActionScript (see below).
You can generate this type of text with the .edittext command:
Code listing 2.8
.flash filename="edittext.swf" bbox=410x210
.font Arial "Arial.swf"
.edittext myedittext font=Arial size=50%
width=400 height=200
color=blue border multiline wordwrap
text="Edit me!\nClick with your mouse on this text to edit it."
.put myedittext x=3 y=3
.end