Returning a font’s character height and average width


Return a font’s character height and average character width


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.


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.


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


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.


!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 */