FunctionPackage: cgToCDocOverviewCGDocRelNotesFAQIndexPermutedIndex
Allegro CL version 10.0
Unrevised from 9.0 to 10.0.
9.0 version

make-font-ex

Arguments: family face size &optional style size-is-cell-height-p angle

Both make-font and make-font-ex return a font object with the given components. family and face specify the family and face of the font. The two functions differ only in the interpretation of the size of a font. See below under the heading Font sizes for information on size and the size-is-cell-height-p argument to make-font-ex.

Other than size, fonts are canonicalized so that those with the same components are eq.

The family argument is a general specification for the style of the font, and is used only if the requested face is not installed in the operating system. (On GTK, the family is never used.) It may be one of the symbols

or else nil if there is no preference.

The face argument specifies the unique name of an individual typeface that may be installed in the operating system. The name may be a string or symbol, though a string is now preferred and the symbol option is provided mainly for backward compatibility. The string is not case sensitive. If the requested face is not installed, then a default face for the requested family is used.

A list of all currently installed font face names is returned by the form (see font-faces, screen, and *system*):

(font-faces (screen *system*))

If the exact font that was requested is not available, the operating system substitutes an approximate font. Once the returned font has been assigned to a stream by calling (setf font), exact-font may be called on the font to return a font object whose family, face, size, and other attributes reflect the actual font being used.

Platform note: Font face names are different on different platforms. If the following common Microsoft Windows font face names are specified on the GTK platform, an attempt will be made to map to a comparable GTK font automatically: Arial, Arial Black, Times New Roman, MS Serif, MS Sans Serif, Courier New, System, and Fixedsys. (No similar attempt is made on Windows to map common GTK font faces to Windows font faces.) If you need to hardcode other font names, you may need to conditionalize the code with #+mswindows and #+gtk.

The size should be a positive real number that indicates the height of the font in pixels. On Windows the value is typically an integer, though non-integer real numbers work as well. On GTK, fonts seem to look better when the point size is an integer, though this argument is measured in pixels rather than points. So on GTK it may be a good idea to pass a desired integer point size to the function points-to-pixels and then pass the returned real pixel size to make-font-ex/make-font. See the information under the heading Font Sizes below for more information.

The style may be either a list of any of the style keywords shown below, or a single number derived by adding the associated weights, or nil to indicate none of the optional styles. The keywords and their integer equivalents are:

The angle argument specifies the angle at which to draw all strings that are drawn in this font. If nil or unspecified, then text is drawn at the usual horizontal angle. Otherwise angle should be an integer indicating degrees counterclockwise to rotate text from the usual horizontal angle. (So 90 for vertical, first letter lowest, 180 for upside down, and 270 for vertical, first letter highest. These are examples; angles which are not multiples of 90 are also supported.) The text will be rotated about the upper-left corner of the string. draw-string-in-box is therefore not suitable for drawing text at non-zero angles, and Common Lisp stream output functions such as format and princ should be used instead; these functions which will draw from the current-position of the stream at the angle of the font. font-angle applied to a font returns the angle.

See also ask-user-for-font and vary-font.

Font sizes

You may notice that the size specified to a Common Font dialog is different from the size specified to make-font to get the same result. For example, if you call ask-user-for-font (which displays a Common Font dialog), and ask for Times regular, size 11, you get the same font as returned by (make-font :roman :times 17).

Why the difference? There are two causes: first, Allegro CL measures font sizes in pixels while the Common Dialog measures in points, (see pixels-to-points and points-to-pixels); and second, the size shown in the Common Dialog indicates the "character height" (the height of the pixels that are actually drawn for a character) while the size used by make-font indicated the "cell height" (the character height plus an unpredictable number of blank pixel rows of "leading").

The function make-font-ex harmonizes Allegro CL with the Windows Common Font dialog. It uses character height rather than cell height (unless the size-is-cell-height-p optional argument is specified true, which forces the older cell-height interpretation and makes make-font-ex equivalent to make-font). The units are still pixels, though, rather than points.

How a font object is printed

Font objects are printed #.([make-font-form]) or #.([make-font-ex-form]). Every font created by make-font prints as #.([make-font-form]).

Fonts made by make-font-ex print as #.([make-font-ex-form]) or #.([make-font-form]) depending on which definition of size is used (controlled by the size-is-cell-height-p optional argument).

A font returned by a Common Font dialog prints as a make-font-ex form. Fonts made or created from other existing fonts will use the format of the starting font.

See also Text and Fonts in cg-drawing.htm.

GTK Note

On X platforms, using many different fonts (including different sizes and styles of the same face) may slow down redisplay greatly if the fonts do not all fit simultaneously into the X server's cache for font data.


Copyright (c) 1998-2019, Franz Inc. Oakland, CA., USA. All rights reserved.
This page was not revised from the 9.0 page.
Created 2015.5.21.

ToCDocOverviewCGDocRelNotesFAQIndexPermutedIndex
Allegro CL version 10.0
Unrevised from 9.0 to 10.0.
9.0 version