Skip to content

FONT ​

Sets the style when drawing text.

Syntax ​

leo-grammar
FONT [ strValue ] [ style:strValue ] [ h:measureValue ] [ color:ColorSpec ]
    [ line-orientation:realValue ] .

Parameters ​

  • <main-parameter> (strValue, optional) - The font name to use for text. The default is "Arial".
  • style (strValue, optional) - Specifies the style for text, like bold or italic. Multiple values can be mixed together. The default is "".
  • h (measureValue, optional) - The height for text. The default is 10pt (or 3.5277777mm).
  • color (ColorSpec, optional) - The color used to draw text. The default is "black".
  • line-orientation (realValue, optional) - Rotates the text by the specified amount of degrees. The default is 0.0.

Details ​

This command determines which type of font is used for text commands following it. Specifically it applies to the commands TEXT and ATTR, but also TEXTBOX and ATTRBOX.

The <main-parameter> specifies the font to be used, such as "Helvetica", "Times New Roman", "Arial" and so on. If the font is not available on a system, then it will fall back to the default font "Arial".

The following font styles are available for style:

  • "bold": bold text.
  • "italic": italic text.
  • "underline": underlines the text.
  • "strikeout": line striking through the text.
  • "outline": uses the color as an outline for the text instead.
  • "shadow": adds a shadow to the text.

These tokens can be used in any combination by joining them with a semi-colon (;), like "bold;italic;underline;shadow" to have a bold and italic text with an underline and a shadow. The order in which they are listed is irrelevant. However, shadow suppresses outline. Also the shadow style of a text is independent of the SHADOW command.

The font's height is specified by the parameter h. Usually the font height is specified in pt, but it is possible to choose between any type of measure value (m, cm, mm and pt).

The color is specified through a ColorSpec, which has to evaluate to a strValue or an intValue (see LEO Colors for details).

The font color can also be set arbitrarily depending on an instance attribute. For example the color can be entered by the user as an RGB value or color name through the Notebook (see Notebook and ATTR documentation for details). The value from there can then be retrieved using the AVAL command and passed as the color to the FONT command. There is also an example available.

With line-orientation the text can be rotated. The value of this parameter determines the rotation angle (counter-clockwise) in degree for TEXT or ATTR. A value of 0 (default) means horizontally from left to right. However, the line-orientation is not properly applied to TEXTBOX and ATTRBOX commands, so the values returned by those commands are not entirely correct.

The command FONT style:"shadow" is not supported in SVG Graphics. Instead, the text is shown without a shadow.

See Also ​

Examples ​

Draws a "V" in the font type "Times New Roman" with a font height of 32pt, centred at point (0cm, -0.07cm).
The letter V in Times New Roman

leo
GRAPHREP
# Note: SHADOW is on by default.

FONT "Times New Roman" h:32pt
TEXT "V" x:0cm y:-0.07cm w:c h:c

Texts using different fonts and styles.
The same text displayed using three different fonts, styles, sizes and colors

leo
GRAPHREP
SHADOW off

FONT "Times New Roman" style:"bold" h:14pt
TEXT "A simple text to display"
FONT
TEXT "A simple text to display" y:0.6cm
# Note: The following font might not be available on every system!
FONT "Bauhaus 93" style:"italic;underline" h:12pt color:"red"
TEXT "A simple text to display" y:1cm

Draw a blue box with an outlined and 90° rotated "Hello" text of size 24pt and to the top-left of the box the text "Description" and "Line 2" in bold rotated at a 45° angle with a size of 12pt.
The letter V in Times New Roman

leo
GRAPHREP
SHADOW off

PEN w:0.1cm color:"$000080"
FILL color:"$6060d0"
RECTANGLE x:0cm y:-1cm w:2.8cm h:2.4cm
LINE x1:1cm y1:-1cm x2:1cm y2:1.4cm

FONT "Arial" style:"outline" h:24pt color:"$000080" line-orientation:90
TEXT "Hello!" y:1.2cm
FONT "Arial" style:"bold" h:12pt line-orientation:45
TEXT "Description\nLine 2" x:-2cm y:-0.5cm w:3cm

Example for loading values from instance attributes and using them to configure the font. The attribute "Font color" is of type short string and displayed in the Notebook via dialog:color.
Three different example objects whose name is shown in various fonts and styles based on the specified attribute values

leo
GRAPHREP
SHADOW off

AVAL sFontFamily:"Font family"
AVAL sFontStyle:"Font style"
AVAL as-original-type iFontHeight:"Font height"
AVAL sFontColor:"Font color"
# Replace certain characters from Font style to build the proper value.
# This is necessary because the attribute type is ENUMERATIONLIST.
SET sFontStyle:(replall(replall(sFontStyle, "\r", ""), "\n", ";"))

FONT (sFontFamily) style:(sFontStyle) h:(PT iFontHeight) color:(sFontColor)
ATTR "Name" w:c:3cm line-break:rigorous

Versions and Changes ​

Available since ADOxx 1.3