[id] = CreateFont(id, brushid, charmap, width, height, cols[, t])
id
argument and the identifier of the brush source in the
brushid
argument. If you pass Nil in id
, CreateFont()
will
automatically choose an identifier and return it. After the font has been
created successfully, you can set it as the current font using UseFont().
The charmap
parameter must be set to a string describing the individual
characters in the brush. The character dimensions must be passed in the width
and height
parameters. All characters must share the same dimensions. The
number of characters per row must be passed in the cols
argument.
For example, a font which supports the upper-case characters A-Z and whose characters
are 32x32 pixels each could be laid out in a brush that has 4 rows containing 8 characters
per row, except for the last row which contains only 2 because the English alphabet has
just 26 characters so 3 rows with 8 characters plus one last row with 2 characters
are sufficient. Thus, you could create such a font from a 256x128 sized brush
and pass 32 for width
and height
, 8 for cols
and "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
in charmap
.
The optional table argument can be used to set some additional options. The following tags are currently recognized:
Name:
RowSpacing:
CreateFont()
about it using this tag. Just set this tag to the
number of spacing pixels between each row and CreateFont()
will skip the spacing
when it creates font. Defaults to 0 which means no vertical spacing.
ColSpacing:
CreateFont()
about it using this tag. Just set this tag to the
number of spacing pixels between each character and CreateFont()
will skip the
spacing when it creates font. Defaults to 0 which means no horizontal spacing.
Ascender:
height
minus 1.
CreateFont()
supports palette brushes as well as brushes with mask or alpha channel.
If the brush passed in brushid
is a 1-bit palette brush, you will also be able to
change the color of the font using SetFontColor() and other functions just
like you can do it for normal fonts. If the brush's depth is more than 1-bit, however,
the font will be treated as a color font that always uses the same color no matter what
the current font color is set to.
Note that CreateFont()
is quite flexible and could also be used as a tilemapper.
Just map each tile to a character and then draw the whole tilemap using a single
call to TextOut(). This should be much faster than drawing the tiles individually.
CreateFont(1, 2, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!-.:?",30,32,10) UseFont(1) NPrint("HELLO WORLD!")The code above constructs a new font from brush 2. There are 41 characters in the source brush and they are laid out as 10 characters per row and 30x32 pixels each. This means that the source brush must be at least 300x160 pixels. After creating the font, it will be selected as the current one and the text "HELLO WORLD!" will be printed.