Jump to content

GPIGuide - Fonts

From EDM2

Reprint Courtesy of International Business Machines Corporation, © International Business Machines Corporation

GPI Guide and Reference
  1. How to Use the GPI Guide and Reference
  2. Graphics Functions
  3. Data Types
  4. Graphics Orders
  5. Graphics Orders Data Types
  6. Errors
  7. Area and Polygon Primitives
  8. Bit Maps
  9. Creating and Drawing Retained Graphics
  10. Character String Primitives
  11. Clipping and Boundary Determination
  12. Color and Mix Attributes
  13. Correlation
  14. Coordinate Spaces and Transformations
  15. Editing Retained Graphics and Graphics Segments
  16. Fonts
  17. Graphics Attributes
  18. Line and Arc Primitives
  19. Marker Primitives
  20. Matrix Multiplication
  21. Metafiles
  22. Print Job Submission and Manipulation
  23. Presentation Spaces and Device Contexts
  24. Paths
  25. Regions
  26. Notices
  27. Glossary

Fonts

In typography, a font is a collection of characters that share a common height, line weight, and appearance. In Presentation Manager, fonts are an lcid-identified resource, like bit maps, and are used in conjunction with the character string primitive data structures to define the appearance of displayed and printed text. The primary role of the PM with regard to fonts is to evaluate whether a particular font is appropriate for a given situation.

The following topics are related to information in this chapter:

  • Presentation spaces and device contexts
  • Character string primitives
  • Coordinate spaces and transformations
  • Color and mix attributes

About Fonts

Font height is specified in printer's points, referred to in this book as points. A point equals approximately 1/72 of an inch. The line weight and appearance of a font are specified by the categories listed in the following table.

Examples of Line Weight and Font Appearance Categories

Attribute Category Description
Line Weight Normal Characters drawn with a normal line weight
Bold Characters drawn with a heavier line weight
Appearance Condensed Characters drawn with half the average character width
Expanded Characters drawn with twice the average character width
Italic Characters drawn with a normal line weight and sloped to the right

A font family is a collection of fonts that share common design characteristics such as stroke width and serif. Stroke width refers to the width of lines used to draw the characters and symbols of a font. A serif is a short cross-line drawn at the ends of the main strokes forming a character or symbol.

Text output is drawn with the characters and symbols of a font. The operating system stores fonts either in memory or on devices. Applications can access fonts through a device context associated with the current presentation space. When an application creates a presentation space, using GpiCreatePS or WinGetPS, the operating system assigns the presentation space a default font from one of the available fonts. An application can retrieve information about the default font using GpiQueryFontMetrics.

Image Font and Outline Font Implementation

The operating system can define and implement the characters of a font as either images or outlines.

Each of the characters in an image font (sometimes called a raster font) is created by alternating the ON and OFF settings of pels to produce the image. The image characters are stored as a bit map. Sometimes image fonts are even referred to as bit-map fonts.

The characters in an image font must be drawn in a fixed size—you cannot rotate or scale them, for example—but usually they are of good quality. They are displayed faster than outline characters, and frequently they look better at low resolutions.

The characters in an outline font, on the other hand, are drawn using a sequence of lines and arcs. Then the characters are filled if so requested. The outline characters are stored as a collection of line, fillet, and spline functions. Outline fonts are transformable because the outline characters can be scaled, rotated, and sheared. Outline fonts can be implemented as vectors, drawn by a series of small, straight lines. If that is the case, they can be referred to correctly as vector fonts. Vector fonts can be drawn much faster than fonts requiring the inclusion of actual curves and arcs.

A major advantage of outline fonts is their device independence. Unlike image fonts, whose appearance depends on the device's pel definition.

The following figure is an example of a character in both an image font and an outline font.

Image and Outline Characters

The image character is produced by manipulating pels. The outline character is produced by drawing a sequence of lines and arcs. (The resultant shape of an outline character can be filled if desired.)

Most of the functions and data structures described in this chapter relate only to outline fonts.

PM-Supplied Fonts

The PM provides a number of both image and outline typographic-quality character fonts. On some devices, image fonts in small font sizes have a better appearance than their outline-font equivalents.

Type size is measured in points. There are approximately 72 points to an inch, so each character in a 24-point font, for example, is 1/3-inch high. Each incremental unit of a presentation page in PU_TWIPS format is 1/20 of a printer's point (1/1440 inch).

The following image fonts are available on all OS/2-supported display adapters:

Font Family Name Point Sizes Available
Tms Rmn 8, 10, 12, 14, 18, 24
Helv 8, 10, 12, 14, 18, 24
Courier (monospace) 8, 10, 12
System Monospace 10

In addition, a default system font is used in window components such as title bars and menus. It is a proportionally spaced Swiss font.

The outline fonts provided by the PM are Adobe*** Type 1. The appearance and performance characteristics of these fonts are more flexible than for image fonts.

The following table lists the outline fonts available with the operating system and their equivalent fonts from earlier versions of the OS/2 operating system:

Outline Font Family Name OS/2 Fonts Available Equivalent Name
Times New Roman** Times New Roman Tms Rmn
Times New Roman Bold Tms Rmn Bold
Times New Roman Bold Italic Tms Rmn Bold Italic
Times New Roman Italic Tms Rmn Italic
Helvetica** Helvetica Helv
Helvetica Bold Helv Bold
Helvetica Bold Italic Helv Bold Italic
Helvetica Italic Helv Italic
Courier Courier Courier
Courier Bold Courier Bold
Courier Bold Italic Courier Bold Italic
Courier Italic Courier Italic
Symbol Symbol None
The outline font names provided with earlier versions of the OS/2 operating system are still supported, but the corresponding new fonts are obtained when the previous font names are selected.

Availability of Additional Fonts

Over 600 Adobe Type 1 fonts are available from font vendors, and user systems could have a large number of these installed. Applications must be capable of functioning properly with whatever font the user selects.

An application can examine the font metrics to see what a font looks like or display different font characters from which the user can choose. When dealing with an interactive or user-driven application, the recommended method of choosing a font is to call WinFontDlg, which displays an example of the font in a dialog box.

Additional Adobe Type 1 fonts can be used just like other outline fonts. Notice, however, that some of those fonts are more stylized; that is, the fonts have a greater variation in the widths of different characters within the same font, which is provided by kerning.

Adobe Type 1 fonts, provided with and for a particular application, can be loaded with GpiLoadFonts, provided that the following rules are observed:

  • The .AFM file of the font must be specified as the font file.
  • The .PFB file must be in the same directory as the .AFM file.

Font Data Structures and Attributes

The attributes of fonts are contained in the FONTMETRICS data structure. The appearance of the actual text is influenced also by the attributes of the individual characters, which can be found in the CHARBUNDLE data structure.

An application can determine whether to use a particular font by examining its font metrics, which are the measurements that define the features of that font. The measurements are decided on by a font designer, whose most important criteria might be ensuring that the font is pleasing to the eye.

Unlike the attributes of a character string primitive, the individual font metrics attributes cannot be changed using specific GPI functions. Your application can determine the values of the current logical font attributes by calling GpiQueryFontMetrics, which accepts as input the amount of data to be returned as well as a pointer to the data area. Unlike other GPI calls, GpiQueryFontMetrics does not return the size necessary for all font metrics data. Querying with a sizeof operator, instead of calling the query twice, returns the size data.

The following table defines and explains the uses of the various font metric attributes:

Attribute Description
Face name The full typeface name of a font, such as Courier Bold Italic.
Family name A broader equivalent of the face name (e.g., Courier).
Code page The mapping between a set of codepoints and a set of graphic characters.
Character cell Controls the height and width of outline font characters.
Character cell ascent Distance between the baseline to the top of the character cell.
Character cell descent Distance between the baseline and the bottom of the character cell.
Maximum baseline extent Maximum vertical extent of font characters in world coordinates.
Maximum ascender Maximum distance a font character ascends above the baseline.
Maximum descender Maximum distance a font character descends below the baseline.
Internal leading Vertical distance equal to the difference between the maximum baseline extent and the em height.
Em height Equivalent to the character cell height.
Em width Equivalent to the character cell width.
X height Height above the baseline of any lowercase character.
Lowercase ascent Maximum distance of a lowercase character above the baseline.
Lowercase descent Maximum distance of a lowercase character below the baseline.
External leading Maximum vertical font spacing that can be added without adversely affecting the appearance of the text.
Average character width Average width of font characters in world coordinates.
Character slope Initial slope of a character with respect to a vertical line.
Inline direction Character angle measured with respect to a horizontal line.
Weight class Specifies the thickness of each stroke of a font character.
First, last, default, and break characters See the topic Glyphs, Code Pages, and Code Points.

The face name attribute is the typeface name by which a particular font design is known. Two examples are Times New Roman Bold and Times New Roman Italic. Roman is the family name of these fonts. You always should provide a face name because most outline fonts are known by it.

The code page to be associated with the font is identified by this metric. Some fonts are specific to a particular code page and should be used with only that code page. Other fonts are universal and can be used with any supported code page.

Every character in a font is drawn within a rectangular region called a character cell. The character-cell height is the distance from the bottom of the character cell to its top. The width of the character cell is the distance from one side to the other.

An imaginary horizontal line, called a baseline, is drawn through the lower portion of the character cell. The operating system uses the baseline to position characters. All uppercase and most lowercase letters in a given font rest approximately on the baseline. Some lowercase letters, such as g and y, descend below the baseline.

The distance from the baseline to the top of the character cell is the character-cell ascent. Similarly, the character-cell descent is the distance from the baseline to the bottom of the character cell.

The maximum baseline extent is the sum of the maximum ascender and the maximum descender values. The internal leading is the space allowed for diacritics above capital letters. When an application draws a string of text, the operating system positions the leftmost point of the baseline over a predetermined point for each character in the string.

A font's Em height is a measure of its visual height. This measurement was given its name because, historically, the height of an uppercase letter M usually was equal to the average height of all uppercase characters in the font. However, this is no longer the case.

The value of Em height represents the font point size in world coordinates and is the same as the character cell height. For an outline font, this can be set by the character cell height attribute. The value of Em Width is the equivalent horizontal dimension and is the same as the character cell width. For an outline font this also can be set by the character cell width attribute. These are, in fact, the dimensions of the em square (a typographic term) and, like point size, cannot be defined in terms of any measurable characteristic of a visible character of the font.

The average distance from the baseline to the top of any lowercase character is called a font's x height. This measurement was given its name because the height of a lowercase x usually is equal to the average height of all lowercase characters in the font.

The maximum ascender is the height of the tallest character in a font. The maximum descender is the depth (below the baseline) of the lowest character in a font.

The lowercase ascent is the height of the tallest lowercase character in a font. The lowercase descent is the depth (below the baseline) of the lowest lowercase character in a font.

Many fonts reserve part of the space in the top of each character cell for accent marks. This reserved space is called internal leading. Some fonts require a certain amount of space to be left between rows of text. This space, called external leading, is not included in the character-cell height or ascent measurements. The external leading is the recommended space to leave between rows of text to preserve its pleasing appearance.

The average character width is stored in the lAveCharWidth field in the FONTMETRICS structure. The average character width is a measure of character width based on the normal frequency of lowercase letter usage in the English language. You can use this value to approximate the average width of a character in string length calculations.

The maximum baseline extent for a font is the sum of the maximum ascender and the maximum descender. Maximum baseline extent is not equal to cell height for outline fonts, but is for image fonts.

The character slope is an angle measured clockwise with respect to a typical vertical line. The slope of a normal font is 0; the slope of an italic font is other than 0. The character slope in the FONTMETRICS data structure can be thought of as the initial slope, since the slope can be changed in the CHARBUNDLE data structure.

The inline direction is an angle measured clockwise with respect to a horizontal line. The inline direction for a Swiss, Helvetica, or Roman font is normally 0—exactly horizontal. The inline direction for a Hebrew font is normally 180, because Hebrew text is oriented right to left.

The character-rotation angle is an angle measured counterclockwise with respect to a horizontal line. The baselines of characters are aligned with the vector drawn at the angle of rotation.

The weight class specifies the thickness of each stroke that forms part of each character in a font.

The first, last, default, and break character all are associated with glyphs for UGL fonts and code pages.

A superscript is a character drawn immediately above and to the right of a normal character in a string of text. Superscripts are identified by a width and height and by vertical and horizontal offsets.

A sub #subscript is a character drawn immediately below and to the right of a normal character in a string of text. Subscripts are identified by a width and height and by vertical and horizontal offsets.

Glyphs, Code Pages, and Code Points

The image or picture that you associate with each character or symbol in a font is called a glyph. The mapping between a set of glyphs and their code points is called a code page.

For a single byte character set (SBCS), each code page contains up to 256 code points. Normally these are 8-bit integers in the range 0 through 255, with one code point identifying one glyph in that code page. The code pages can be either ASCII or EBCDIC. Because a code point repeats on a new code page, you need both the code page and code point to uniquely identify a glyph.

There usually is one code page per font. However, double byte character sets (DBCS) are sometimes used for Asian languages with large character sets. Fonts are a set of glyph definitions and a default code page mapping. The same set of font glyph definitions is remapped for different code pages.

Each font contains four special glyph points:

  • First glyph
  • Last glyph
  • Default glyph
  • Break glyph

First and last glyph points are of more interest to the font designers than application programmers because they apply to the set of font glyph definitions rather than a particular code page. The last character is the maximum code point of the font that has a glyph associated with it and may be bigger than 256.

The default glyph appears in text when an application specifies a glyph point that does not exist in the font.

The break glyph usually is the space character and often has the same code point as the default character.

Actually a font can have more or less than 256 definitions, but any particular code page may have less than 256 but no more. There may be a translation between the code point in the code page and the code point (between the first and last glyphs) that references the glyph in the font.

The operating system assigns unique identifiers to each of its code pages. Common code pages are 437—the United States code page, and 850—the multilingual code page. The default code page is 850.

An application can determine the current code page by calling GpiQueryCp, or it can assign a new code page using GpiSetCp. If you default the code page in the FATTRS structure when calling GpiCreateLogFont, you get the current code page as specified by GpiSetCp (or returned by GpiQueryCp). You can specify any one of the code page identifiers returned to you from WinQueryCpList.

When using a font other than the system font, you specify the required code page in the FATTRS structure of GpiCreateLogFont. You can determine the code page for that font (if it is the current logical font) by using GpiQueryFontMetrics.

Proportional and Monospace Fonts

When text is drawn, the operating system aligns each character by positioning its character cell next to that of the previous character.

A monospace font provides the same amount of space for each character, whatever its shape. These fonts also are called fixed fonts. Courier and System Monospaced are monospace fonts. Monospace fonts, in fact, are essential for some purposes—for example program listings, where vertical alignment is important.

A proportionally-spaced font is one in which some characters are allotted less space than others, so that each character occupies the proportion of space that is correct for its shape. For example, a lowercase letter l does not need the same space as a lowercase letter m. Many graphics fonts supplied by the PM, including the system font, support proportional spacing.

The font metrics value maxcharinc specifies the width of the widest character in the font, and the value avecharwidth specifies an average width of the characters in the font.

You can retrieve information about the widths of the characters in the current font by calling GpiQueryWidthTable. You provide the code point of the first character you are interested in and the number of characters for which you want width-table information.

Kerning

Kerning, like proportional spacing, is a type of letter spacing. In a kerned font, some characters are allowed to overhang others and, therefore, occupy an area that is less than each character's increment for that font. Usually this feature is restricted to pairs of characters whose appearance might benefit from greater proximity. The five character pairs that most commonly benefit from kerning are Yo, We, To, Tr, and Ta.

Kerning is not available in the system-provided image fonts. The Helvetica and Times New Roman outline fonts provided with the system do include kerning information. You can specify kerning as a requirement on the GpiCreateLogFont. Selecting a kerned font lets kerning take place whenever it is defined.

The a-space is the area of the character cell before the character; the b-space is the area of the character cell occupied by the character; the c-space is the area of the character cell after the character.

The best way to implement kerning is to use a kerning-pair table. The kerning table will exist only for certain pairs of characters for which adjustments are desirable.

Each of the entries in a kerning-pair table contains the code points of a pair of kerned characters and an adjustment that should be applied to the character width of the first character of the pair. A negative value means that the space is decreased, and a positive value means it is increased, whenever the two characters in a kerning pair are produced together. A kerning-pair table might be provided with a purchased font. If so, it will be recorded in the font header.

If kerning is specified on a character-pair basis (that is, if the font has a kerning-pair table), the font has a specific number of kerned pairs. GpiQueryKerningPairs returns kerning-pair information from the current logical font. For each pair of kerned characters, you are given the characters themselves and an adjustment in world coordinates that must be applied to the character width of the first character of the pair.

When you specify negative a- and c-space values, the values affect any character paired with the kerned character. Because this form of kerning cannot be applied selectively, you have to choose the kerned characters carefully. For example, an italic letter f (Ÿ) is a good candidate for this sort of kerning, because it can overhang most of the characters that precede and follow it.

An application can adjust the amount of space between all characters in a font with GpiSetCharExtra. Any extra space is added to font kerning values. An application also can adjust the width of a font's break character (space) with GpiSetCharBreakExtra.

Kerning is not available on all devices. On devices that support kerning, kerning is enabled by default. When kerning is not supported on a device, kerning support is switched off by default. When kerning support is switched off, the kerning information supplied with a font is ignored. To determine whether a device supports kerning, use DevQueryCaps.

The kerning information can be implemented by your application when a character string primitive is written to an output device. This is called rendering the text. GpiCharStringPos and GpiCharStringPosAt, permit specification of the starting position for each character. The entire character string can be searched for character pairs that also are kerning pairs for the kerning information to be applied.

FATTRS Data Structure

The FATTRS structure is used to identify the characteristics of a requested font. Certain attributes of a font that govern many individual character string primitives are contained in FATTRS, as follows:

  • Record length
  • Selection indicators
  • Match value
  • Face name
  • Registry identifier
  • Code page
  • Maximum baseline extent
  • Average character width
  • Type indicator
  • Font use indicator

Record Length

Record length determines the length of the FATTRS structure. An application normally specifies this with the sizeof operator.

Selection Indicators

There are five selection indicators:

  • FATTR_SEL_ITALIC: A font with an italic appearance. This is intended for use with an image font and results in a simulation of an italic font.
  • FATTR_SEL_BOLD: A boldface version of the font. This is intended for use with an image font and results in a simulation of a boldface font.
  • FATTR_SEL_OUTLINE: Hollow characters when using an outline font. This only can be used with outline fonts. This indicator is less important than the others because improved performance is now available (from Adobe Type Manager) on filled outline fonts than was originally available when this option (FATTR_SEL_OUTLINE) was introduced.
  • FATTR_SEL_STRIKEOUT: A font in which the characters are struck through. This option also might be selected on the character string primitive.
  • FATTR_SEL_UNDERSCORE: A font in which the characters are underscored. This option also might be selected on the character string primitive.

Any combination of these indicators can be set. When set, they cause a simulation of the selected feature. For example, if you require a bold, italicized version of a PM image font, PM simulates that feature because bold, italic image fonts are not supplied.

Match Value

The match value is a number that identifies a physical font. It is allocated to the font when the font is loaded. If the match value is less than 0, the font is a device font; and, if the match value is greater than 0, the font is a generic font.

A device font is exclusive to the device with which it is associated, and its match number is guaranteed to be unique only within the device driver. If an application prints on a different printer, the application cannot guarantee that the font will be identical just by specifying the match value. A generic font is available on more than one device. The PM-supplied fonts, for example, are generic fonts. Printer fonts always are device fonts, but you also can and should use generic fonts with printers.

You can choose whether or not to use the match value to specify the font when calling GpiCreateLogFont. Specifying the match value is easier but less flexible than the alternative, which is to specify the font name and outline characteristics. For an image font, the alternative is to specify the maximum baseline extent and average character width of the required font.

Face Name

The face name value in the FATTRS data structure is identical to the face name of the FONTMETRICS data structure when describing a specific font.

Registry Identifier

The registry identifier is a unique number by which the font is registered with IBM. The registry identifier of a particular font can be retrieved by calling GpiQueryFonts. If you do not have a registry number, set this value to 0.

Code Page

The code page is the identifier of the code page to be associated with the font. You can default the code page in GpiCreateLogFont by specifying 0. Like the face name, the code page in the FATTRS data structure is identical to the code page in the FONTMETRICS data structure when describing a specific font.

Maximum Baseline Extent

The maximum baseline extent is the vertical space occupied by characters in the font. If you are setting the font-use indicator FATTR_FONTUSE_OUTLINE, you should set the maximum baseline extent to 0. Outline fonts take an equivalent value from the character cell attribute that is current when text is written to an output device.

The maximum baseline extent value is required to select an image font and must be specified in world coordinates. For image fonts, this is the vertical height in world coordinates of character images in the font. This field must be specified when requesting an image font with GpiCreateLogFont.

The maximum baseline extent measurement is shown in a previous figure. The maximum baseline extent in the FATTRS data structure is used for programming, unlike the maximum baseline extent in the FONTMETRICS data structure, which is only measurement as recommended by the font's designer.

Average Character Width

The average character width of a font is the average character increment in world coordinates. The character increment is the sum of the a-space, b-space, and c-space of a character. If you are setting the font-use indicator FATTR_FONTUSE_OUTLINE, you can set the average character width to 0 because the outline fonts take an equivalent value from the character cell attribute that is current when text is written to an output device.

This field should be specified when requesting an image font using GpiCreateLogFont. It must be specified in world coordinates.

Type Indicator

PM provides a type indicator to allow the further specification of font most appropriate to your application. The type indicators found in the FATTRS data structure are not interchangeable with the type indicators in the FONTMETRICS data structure.

The most commonly used type indicator, FATTR_TYPE_KERNING, causes kerning to take effect for those fonts that contain kerning-pair information. FATTR_TYPE_KERNING is supported only for PostScript devices.

There are three other type indicators provided:

  • FATTR_TYPE_ANTIALIASED: An anti-aliased font is required
  • FATTR_TYPE_MBCS: A mixed single- or double-byte code page is required
  • FATTR_TYPE_DBCS: A double-byte code page is required

Font-Use Indicators

The font-use indicators tell the PM what you intend to do with the font, and determine whether you get an image font or an outline font. There are three font-use indicators:

  • FATTR_FONTUSE_OUTLINE: Forces selection of an outline font. This value must be set if you intend to use graphics characters in a path definition.
  • FATTR_FONTUSE_TRANSFORMABLE: Allows the scaling, rotating, or shearing of font characters. Set this value ON if the current character mode is CM_MODE3.
  • FATTR_FONTUSE_NOMIX: Allows the PM to ignore current mix-mode values. Set this value ON if the graphics text is not going to be written over or underneath other graphics, because it improves the performance of text drawing.

FATTR_FONTUSE_TRANSFORMABLE and FATTR_FONTUSE_OUTLINE normally are both specified to select an outline font. Specify neither if you want to select an image font.

Public and Private Fonts

The fonts supplied by PM are loaded automatically when the system is started and are available to any application at any time. They are said to be public fonts. Any font that you define locally has to be loaded before you can use it. If you load a locally defined font using the Install option of the Workplace Font Palette, that font is available to any application in the system, and, therefore is a public font. Some devices provide their own fonts. All device fonts are public fonts.

Any font loaded using GpiLoadFonts from within an application is a private font. A private font is available only to the application that loads it. The file in which you store a locally created font definition can contain more than one font definition. GpiLoadFonts loads a named font file and, therefore, loads all fonts defined in that file. GpiQueryFontFileDescriptions provides the family name and the face name of each font in a locally defined font file. Use this function to determine if a particular file contains the font you want to use before you load it.

To unload a previously loaded private font file, call GpiUnloadFonts. You cannot unload public fonts with this function.

You cannot use private fonts in a document that you want to print using the spooler. If you want to print the document from a printer server, using the PM_Q_STD format, all the fonts used in the document must be installed as public fonts on the server. You can use either public or private fonts if you specify the data format PM_Q_RAW or if you want to print without the spooler.

Drawing a Character String Primitive

To draw a string of one or more graphics characters from the current font, call GpiCharString. The string starts at the current position and, when it has been drawn, the new current position is the point at which the next character would be, had there been one.

To draw the string starting at a position other than the current position, call GpiCharStringAt. This is equivalent to calling GpiSetCurrentPosition or GpiMove, followed by GpiCharString. You supply the text of the character string as a parameter to the appropriate GPI function.

Note
You also can call WinDrawText, which draws text to the screen a line at a time. WinDrawText differs from the GpiCharString functions in that WinDrawText ignores the DM_RETAIN drawing mode and can only be used to draw to a window device context.

This example shows the string Presentation Manager drawn from different logical fonts.

Font Files and Dynamic-Link Libraries

You can use the Font Editor to alter and customize image-font files. Files created with the Font Editor have a .FNT extension. After you create a custom font, put it into a dynamic-link library (DLL) that the application can load. Once the application loads this library, it can use any of the custom fonts the library contains.

DLLs that contain fonts are unique; they contain data segments and empty (or useless) code segments. They are unique because they contain no executable code, unlike normal DLLs. Also you are able to install the font file as a public font if desired; GpiLoadFonts will make it available only as a private font. The operating system naming convention for a DLL that contains font information end with a .FON extension.

To create a DLL, you must use an assembler, a linker, and the operating system Resource Compiler. For this example, assume that your custom font file is named NEWFONT.FNT.

After creating your custom font file, you need to create a special assembler language file with your editor. Call this file MYFONT.ASM, for example. The following figure shows an example of the source code for this file: ```asm

  code segment word      ;Makes dummy code segment aligned on word boundary
  db 'empty_segment'     ;Initializes a string in dummy segment
  code ends              ;Dummy segment ends here
  end                    ;Terminates source file

```

After you have created MYFONT.ASM, assemble it by using the following command: ```bash

   masm myfont

```

After assembling the MYFONT.ASM file, create a module-definition file. Call this file MYFONT.DEF, for example. It should contain the statements in the following figure: ```def

   LIBRARY myfont
   SEGMENTS CODE MOVEABLE

```

The first statement tells the linker that you are creating a library with the module name, MYFONT. The second statement tells the linker that the segments in this library are movable code segments.

After creating MYFONT.DEF, start the linker with the command in the following figure: ```bash

   link myfont,,,,myfont.def

```

This command creates an empty executable file called MYFONT.EXE.

After creating the empty executable file, which is the template for a DLL, create a resource file and call it MYFONT.RC. For example, if your font file is called NEWFONT.FNT, you would place the statement in the following figure in MYFONT.RC: ```rc

   FONT    200     NEWFONT.FNT

```

This statement assigns the identifier, 200, to the font resource NEWFONT.FNT.

Finally, use the Resource Compiler to add the font file (NEWFONT.FNT) to the empty DLL as in the following figure: ```bash

   rc  myfont.rc

```

The executable file, MYFONT.EXE, now contains your custom fonts. After you have renamed this file, MYFONT.FON, you can load the fonts into your application using GpiLoadFonts and pass it a pointer to the path and library name as the second argument—for example, c:\os2\dll\myfont.fon.

Using Fonts

You can use the font functions to:

  • Determine the characteristics of available fonts
  • Select a font for text output
  • Delete or unload a font when finished
  • Create a font
  • Create marker sets and pattern sets
  • Use a bit map as a fill pattern
  • Use a clip path as a fill pattern

Selecting a Font

Every presentation space has a current font, and graphics characters must be drawn in that font. By default, the current font is the system font. Before an application can use any font other than the system font, it has to identify the other font as the new current font.

There are two distinct ways to identify the other font:

  • Call GpiQueryFonts to request information about the available physical fonts, and then explicitly select one of those fonts by supplying its identifier as input to GpiCreateLogFont. This process has 11 steps and is covered in the topic Explicit Font Selection. This method of selecting a font is most useful for selecting image fonts. If you must have an image font, you are urged to use this explicit selection method, because you need to specify a maximum baseline extent and an average character width in the FATTRS structure. These values can be determined only by calling GpiQueryFonts. If you specify values that are not valid, you are likely to be given an outline font.
  • Use GpiCreateLogFont to specify the features you require in a font, and permit the PM programming interface to make an appropriate font available to you. This process has two steps and is covered in the topic Closest Matching Font Selection.

Explicit Font Selection

An application can select either a public or a private font with GpiCreateLogFont. A public font is available to all applications. A private font is loaded by an application for its exclusive use.

Use the Presentation Manager Control Panel to load a public font. Four DLLs contain the Times Roman, Helvetica, Courier, and System Monospaced image fonts. The names of these libraries are:

  • TIMES.FON
  • HELV.FON
  • COURIER.FON
  • SYSMONO.FON

Unlike most DLLs, font libraries typically use the file name extension .FON. If the user loads all four libraries, a total of 76 public fonts are available. An application can use both outline and image formats of these fonts. Characters in the image format are available in sizes ranging from 8 to 24 points. Characters in the outline format can be any size.

Call GpiLoadFonts to load a private font. Pass the function the path and name of the DLL that contains the font. After the application loads the DLL of fonts, it can determine the characteristics of the fonts in that library by calling GpiQueryFonts.

To select a public font from all of the available public fonts, do the following: 1. Call GpiQueryFonts, passing the QF_PUBLIC flag, a NULL pointer to the font's face name, and a count of 0 to determine the number of available public fonts, as shown in the following figure:

#define INCL_GPILCIDS
#include <os2.h>
void fncFONT06(void){
    FONTMETRICS fm, afm[80];
    LONG cFonts = 0, cPublicFonts;
    HPS hps;
    cPublicFonts = GpiQueryFonts(hps,      /* Queries all public fonts */
    QF_PUBLIC,
    (PSZ) NULL,
    &cFonts,
    sizeof(fm),
    (PFONTMETRICS) NULL);
} /* fncFONT06 */
Note
To load and use a private font, follow the same procedure, but specify QF_PRIVATE, instead of QF_PUBLIC, in the calls to GpiQueryFonts.

2. Copy the value returned by GpiQueryFonts into a LONG integer variable. 3. Allocate memory for the FONTMETRICS data structures. 4. Call GpiQueryFonts again, passing the QF_PUBLIC flag, a NULL pointer to the font's face name, the count returned by the previous call, and the address of an array of FONTMETRICS structures.

GpiQueryFonts the font metrics of every font available the array of FONTMETRICS structures. The font metrics define in detail the physical characteristics of a font.

Because the font metrics are so detailed, the amount of information returned to you from GpiQueryFonts can be extensive. You can restrict the amount of information returned by this function by:

  • Specifying an absolute number of fonts about which you require information.
  • Asking for information about fonts of a specific face name only.
  • Limiting the length of the font-metrics buffer.

If you request information for more fonts than are available on the system, GpiQueryFonts returns all the information about the available fonts and a value indicating how many fonts it has returned.

If you request information for fewer fonts than are available on the system (that match the specified face name, and so forth), GpiQueryFonts returns a value indicating the number of fonts that it was unable to return.

The following figure is an example of this technique of selecting a font:

#define INCL_GPILCIDS
#include <os2.h>

PFONTMETRICS fncFONT07 (HPS hps, PLONG pcPublicFonts) {
   PFONTMETRICS afm = NULL;
   LONG         fonts = 1000;

   *pcPublicFonts = GpiQueryFonts(hps,
                                  QF_PUBLIC,
                                  (PSZ) NULL,
                                  &fonts,
                                  sizeof(*afm),
                                  (PFONTMETRICS) NULL);

   if (!DosAllocMem(&afm,
                    sizeof(*afm)*(*pcPublicFonts),
                    PAG_COMMIT | PAG_WRITE )) {
       GpiQueryFonts(hps,
                    QF_PUBLIC,
                    (PSZ) NULL,
                    pcPublicFonts,
                    sizeof(*afm),
                    afm);
   } /* endif */
   return afm;
}

5. Examine the array of FONTMETRICS structures.

  a. For an outline font, examine the face name and other attributes of the font your application requires.
  b. For an image font, examine the device resolution fields. These fields are the ones that determine if a particular font and its metrics match the device with which you wish to use it.
Note
If your application is interactive, organize the face names and other information relevant to those fonts (such as point sizes) in a menu. When the operator has selected a font, supply the relevant information from the font metrics of that font in the FATTRS structure of GpiCreateLogFont.

6. After determining which font to use, your application must fill in the fields of the FATTRS structure. Some of the data for these fields will be copied (explicitly) from the FONTMETRICS structure. Then call GpiCreateLogFont.

If you do not supply a face name, the default font is used. If you supply a face name, and the presentation driver cannot find a matching font, a default font is selected.

The FATTRS structure describes a logical font. An application can have up to 254 logical fonts defined at any one time in a single presentation space. A logical font is a list of font attributes, whereas a physical font is the bit-map or vector information that the system uses to draw characters.

7. The fonts supplied by the PM programming interface, the fonts you load using the Control Panel, and any fonts you load with GpiLoadFonts are all physical fonts.

Copying the entries in the FATTRS structure ensures that, if a particular font is unavailable, an attempt is made to find the most suitable substitute. Without the FATTRS information, PM is less likely to locate a suitable font.

8. Initialize a local identifier (lcid) for the new font. 9. Call GpiCreateLogFont and pass as input parameters:

  * The lcid for the font
  * The address of an 8-character array containing the name you want to give to the logical font, (or, if you do not want to specify a name, the value NULL)
  * The address of the FATTRS structure

10. Examine the return value from GpiCreateLogFont. The value will be 2 if the function is successful; 1, if the default font was used. 11. Pass the lcid to GpiSetCharSet, assigning the font to your application's presentation space. Then the application can use it for text output. (This step identifies a logical font as the current font.)

The following figure shows how to select an image font at least 14 device coordinate units high:

#define INCL_GPILCIDS
#include <os2.h>

LONG fncFONT08(HPS hps, LONG lcid, LONG xres, LONG yres) {
   FATTRS       fat;
   PFONTMETRICS afm;
   LONG         cFonts;
   LONG         i;
   LONG         rc = 0;

   afm = fncFONT07(hps, &cFonts);
   if (afm) {
      for (i=0; i<cFonts; i++) {
         if (!(afm[i].fsDefn & FM_DEFN_OUTLINE)
            afm[i].sXDeviceRes == xres &&
            afm[i].sYDeviceRes == yres &&
            afm[i].lMaxBaselineExt >= 14)  {
           fat.usRecordLength = sizeof(fat);
           fat.fsSelection = 0;
           fat.lMatch = 0;
           strcpy(fat.szFacename, afm[i].szFacename);
           fat.idRegistry = afm[i].idRegistry;
           fat.usCodePage = 0;
           fat.lMaxBaselineExt = afm[i].lMaxBaselineExt;
           fat.lAveCharWidth = afm[i].lAveCharWidth;
           fat.fsType = 0;
           fat.fsFontUse = 0;

           rc = GpiCreateLogFont(hps, (PSTR8) NULL, lcid, &fat);
           if (rc) {
              GpiSetCharSet(hps, lcid);
           } /* endif */
        } /* endfor */
     } /* endif */
     return rc;
}

GpiQueryFonts returns device coordinates for image fonts. For outline fonts, it returns notional coordinates. Notional coordinates are the coordinate in which the font was defined. Usually outline fonts are defined over a 1000-by-1000 matrix, with the unit of the matrix a 1/1000 of the em height.

Reassociating the Presentation Space

The match value of any device font is guaranteed to be unique only for the current device. If you associate the presentation space with a different device context, any logical fonts that also are device fonts are no longer available. On the new device, the match number could identify a different device font (which may not be suitable) or no font at all. Therefore, you should redefine a logical font and select it as the current font if you reassociate the presentation space when the current font is a device font. Otherwise, the default font is used.

If you do not intend to use the font on the new device, however, you need not redefine it. You will be able to continue using the font if you reassociate the presentation space with the original device context.

Any generic fonts can continue to be used after the presentation space is reassociated if they are suitable for the new device. An image font, for example, can be used only on devices that are all-points addressable.

Font Resolution

Device fonts, particularly printer fonts, usually are designed for a specific resolution, namely the resolution of the device on which they are to be used. By contrast, generic outline fonts are not device-specific. Generic image fonts are designed for a particular resolution value and, therefore, are really applicable only to devices with a matching resolution value.

The horizontal and vertical font resolution values for the device are returned by DevQueryCaps. The desired horizontal and vertical device resolution values in the font metrics of the font concerned are returned by GpiQueryFonts. Compare these the device and the desired resolution values only for an image font. If they are identical then this image font is designed for use with this device (for example, the point size in the font metrics will be accurate for this device). To select a font, do the following: 1. Query the available fonts using GpiQueryFonts. 2. If you want an outline font, search the metrics of fonts returned by GpiQueryFonts for a font that is an outline font and that has the required face name. 3. If you want an image font, search the metrics of the fonts returned by GpiQueryFonts for a font that is an image font and that has the following:

  * Required face name
  * Required point size
  * Horizontal device resolution font metric that matches the horizontal resolution for the device
  * Vertical device resolution font metric that matches the vertical resolution for the device.

4. As an alternative to the above for an image font, search the metrics of the fonts returned by GpiQueryFonts for a font that is an image font and that has the following:

  * Required face name
  * Required em height in world coordinates.

Before you define a logical font, determine the resolution of the current device by using DevQueryCaps with the CAPS_VERTICAL_FONT_RES and CAPS_HORIZONTAL_FONT_RES parameters.

Compare the values returned from this function with the xDeviceRes and yDeviceRes values in the font metrics of the available fonts. These two values contain the resolution of the device for which the font was designed. All measurements are in pels per inch. By comparing the font resolution with the device resolution, you can identify the image font best suited to the current device.

Closest-Matching Font Selection

The alternative to selecting a specific font is to set the match value to 0. To have the Presentation Manager programming interface select the closest-matching font available, do the following: 1. Define a logical font with GpiCreateLogFont. This function establishes a link between the calling application and an appropriate physical font. GpiCreateLogFont accepts a number of options as input, including the font attributes, which describe the physical features and capabilities of the font. 2. Complete the FATTRS structure of GpiCreateLogFont. The FATTRS structure describes a logical font, which the system uses to find the closest matching physical font. Depending on whether you are selecting a font using a match number, fill in the FATTRS structure, observing the rules listed in the following table:

Filling in the FATTRS Structure
If using a match number If not using a match number
Set the match number to the required FONTMETRICS value. The FONTMETRICS value is the value in the FONTMETRICS structure for the required font returned by GpiQueryFonts. Set the match number to zero.
Set the maximum baseline extent to zero. If your font is an image font: Set the maximum baseline extent to the required FONTMETRICS value.
Set the average character width to zero. Set the average character width to the required FONTMETRICS value.
Note: A negative lMatch is only unique for a device. A positive lMatch is only unique on a particular system at a particular time.

Also observe the rules concerning the font-use indicator that are listed in the following table:

Font-Use Indicator Considerations
If you have not set the FATTR_FONTUSE_OUTLINE indicator: If you have set the FATTR_FONTUSE_OUTLINE indicator:
PM looks for an image font that has the required selection indicators and whose maximum baseline extent and average character width match those you have specified. PM looks for a suitable outline font whose selection indicators match those you have specified.
If no suitable image font is found, PM looks for an outline font with the required face name and selection indicators. If no suitable outline font is found, the default font is used. No attempt is made to substitute an image font.
If no suitable outline font is found, the default font is made available to you.

Outline fonts are affected by the current character attributes (for example, character box, shear, and angle). Because an outline font might be made available to you, even when you requested an image font, call GpiQueryFontMetrics to determine whether the font is an image font or an outline font. GpiQueryFontMetrics returns the metrics of the current logical font in world coordinates.

The setting of the definition indicators in the FONTMETRICS structure tell you whether the font is either an image or outline font, or a device or generic font. If the font is an outline font, specify values for the character attributes before using the font. Outline fonts are unaffected by the maximum baseline extent and average character width values specified in GpiCreateLogFont.

If the default font provided is an image font, and you also have specified FATTR_FONTUSE_TRANSFORMABLE, any attempt to draw graphics characters in CM_MODE3 raises an error condition. This is an exception to the general rule that a FATTR_FONTUSE_TRANSFORMABLE font must be used in CM_MODE3 only.

Selecting the New Current Font

In addition to completing the FATTRS structure, you must supply as input to GpiCreateLogFont a unique lcid for the font. The identifier is a number in the range of 1 through 254. Because you can have more than one logical font definition in a presentation space, you must select the current font by supplying the font's lcid as input to GpiSetCharSet.

You do not have to call GpiSetCharSet to use the default font. When you want to reset the current font to its default value, however, call GpiSetCharSet with the value LCID_DEFAULT. The current font, like other modal attributes, reverts automatically to its default value when specific GPI functions are called.

Deleting Logical Fonts and Unloading Physical Fonts

A logical font can be used only by the application that defines it. The logical font definition is stored in the presentation space and is saved on the LIFO stack with its lcid when GpiSavePS is called. Unlike a physical font definition, a logical font definition is temporary and is lost when the presentation space is deleted.

To specifically delete a logical font, call GpiDeleteSetId, which deletes the logical font, and makes its lcid available for reuse. Sometimes this is necessary because there are only 255 lcids available. The logical font must not be the current font when you call GpiDeleteSetId.

Logical fonts are deleted to release the lcid and free memory. Unload private fonts using GpiUnloadFonts to free memory and to make them no longer available. Uninstall public fonts using the Control Panel to free memory and to make them no longer available.

You must end the association between physical and logical fonts before calling GpiUnloadFonts.

If you call GpiUnloadFonts to unload a private font file, you must end the association between the physical fonts in that file and the logical fonts defined by the application. Do the following:

  • Call GpiSetCharSet to select a current font (such as the default font) that is not linked to the physical fonts you are unloading
  • Call GpiDeleteSetId to delete each logical font that refers to any of the physical fonts in the font resource file. If you fail to do this, an error is returned to your application from GpiUnloadFonts.

Creating Fonts

   Creating Fonts
   Creating Marker Sets and Pattern Sets
   Using Bit Maps as Area-Fill Patterns
   Using Paths with Fill Patterns 

Font-File Format

   Metric Information Contained in Fonts
   Font Character Definitions
       Font Definition Header
       Image Data Format 
   The Kerning Pair Table
   Additional Metrics
   Font Directory
   Definitions of Terms Used When Describing Fonts