Returning a font’s character height and average width

fontmetrics()

Return a font’s character height and average character width


SYNTAX

fontmetrics(font, ave_charwidth, charheight)

This function returns the average character width and character height of a specified font definition. The returned values are in pixels.

font

A font definition. This usually states the font name and size, for example “Arial@8”, “Verdana@10”. A font style, such as bold or italic, may also be included, e.g. “Times,b@11”. If the size is omitted, Sculptor selects the size that bests fits the display resolution, See Structure of a font definition.

ave_charwidth

The average character width for this font is returned in this field.

charheight

The character height for this font is returned in this field.

In a program that uses pixel co-ordinates, these values can be used to set a window width and height to suit a user-selected font. See the example below.


EXAMPLE

!temp AveCharWidth,,u2
!temp CharHeight,,u2

     fontmetrics("Arial@9", AveCharWidth, CharHeight)

     Window3->max_width = AveCharWidth * 120   /* Set width for a 120-column window */
     Window3->max_height = CharHeight * 40     /* And height for 40 rows */

RELATED TOPICS