Tutorial - Fonts

In the previous tutorial you encountered the identifier 'Font'. This refers to the current font in the same way that 'Pen' refers to the current pen. There is a standard type 'TFont' and the user can declare new font variables within any shape routine. A new font is created from an existing font using the same mechanism that is used for pens and brushes.

In the following we are starting with the default font and changing both the typeface and the size ( you might not have the same fonts as I do - you should be able use an editor or word processor to find the fonts available on your system ).

TFont myfont = Font { typeface -> "Pericles", size -> 24 };

Then to use the new font just add it to the list of graphics context items after the '=>' or include it in the values of a 'With' statement.

TextBlock("Quick test") => {100, 150}, myfont;

The following example illustrates the way the font is inherited by the called routine. Within the routine the font that was passed will be the default font and can be accessed via the identifier 'Font'. Note: font, like the other context objects will be a constant.

text_font_1.grs Output of text_font_1.grs text_font_1.png