Name
CreateFont -- create font from brush (V10.0)
Synopsis
[id] = CreateFont(id, brushid, charmap, width, height, cols[, t])
Function
This function can be used to create a new font from a brush source. This can be useful if you need to work with custom fonts that are distributed as image files instead of common font formats like it was often the case in games from the 1980s and early 1990s and in scene demos. You have to pass the desired identifier for the new font in the 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:
This allows you to give your font a name. By default, the font's name will be set to "Font".

RowSpacing:
If there is some spacing between the different rows of characters in the brush, you can tell 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:
If there is some spacing between the individual characters in the brush, you can tell 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:
This tag allows you to set the desired ascender for the font. The ascender of a font is the maximum character extent from the baseline to the top of the line. Hollywood uses the ascender value to determine where to draw the line for the underline text style, for example. This defaults to the character height passed in 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.

Inputs
id
identifier for the font or Nil for auto id selection
brushid
identifier of the source brush
charmap
string describing all characters in the brush
width
width of each font character
height
height of each font character
cols
number of characters per row
t
optional: table containing further options (see above)
Results
id
optional: identifier of the font; will only be returned if you pass Nil as argument 1 (see above)
Example
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.

Show TOC