SetFont

Bitmaps
Aptilis 1

SetFont(BitmapHandle, PathToFontFile[, FontSize])

SetFont attaches a font to a bitmap.
The default font is a bitmaped one, which can not be enlarged. All its letters have a width of 8 pixels and a height of 16.
Aptilis uses a True Type Library developped by David Turner, Robert Wilhelm and Werner Lemberg (See Link at bottom of page) which provides us with a very useful feature: we can use True Type fonts in bitmaps under Windows (NT/95) as well as under Unix!
Windows users can use the fonts usually stored in their \windows\system directory. Unix users will have to buy their True Type fonts or download some from the Internet, for example from 1001 Fonts, but make sure you download True Type fonts, and not, say, Adobe Type 1 fonts...
True Type fonts are vectorial, that means they can be enlarged without looking 'blocky'.
aptilis now integrates the FreeType 1.1 engine that produces great output. Aptilis might have some problems rendering fonts on couloured backgrounds, since it uses a limited palette for the sake of simplicity.
To revert to the system font, call setFont with an empty string as the font name:
setFont(bitmap, "")
Because an aptilis script has no way to know which kind of display it is going to be used with (every one connected to the net has got a different set-up), SetFont expects a font size in pixels.
It is much easier to understand (1 pixel = 1 point on the screen) but graphics may look tiny on high resolution screens or big on low resolution devices. That always was, and might still be for some time, a designer's challenge.

Determining the width of a string to be written with a True Type font is not as straightforward as calculating the width of a system string (you multiply the length of the string by 8), so there is a sub that does it for you: getStringMetrics.
Aptilis supports True Type fonts stored in ttf files, and currently does not implement font collections. (It takes the first font available in any case).

Return Value:
0 if everything was OK or -1 if you indicated a non-valid bitmap, or an invalid font file or some other error happened. _errno will give details.

Example:

changeDirectory("C:\\windows\\system")
n = getFileList(fonts[], "*.ttf")



// Let's assume no font will have a height bigger than 20 pixels
height = (n + 1) * 22

print("n=", n, "\n")

b = createBitmap(300, height)
if b = -1
print("Oops, it was impossible to create a bitmap...\n")
else

white = RGB(255, 255, 255)
black = RGB(0, 0, 0)


clearBitmap(b, white)

for i=0 to 12
setFont(b, fonts[i]$, 20)
printAt(b, 5, (i + 1) * 20, "Aptilis", black)
end for

// back to the system font
setFont(b, "")
printAt(b, 5, (i + 1) * 20, "Aptilis - system", black)

saveGIFFile("c:\\aptilis\\setfont.gif", b)

deleteBitmap(b)
end if
Result:

For more details see the Bitmap topic.
See also:
The Freetype Home Page.