18.3.7 Designing Portable Fonts

Most application developers need not be concerned with font-portability issues. This discussion is included here with other portability issues for those developers who need to create fonts that are portable between systems. Microsoft currently publishes a TrueType Font Files Specification, which teaches font vendors how to create a single TrueType font that will work in Windows, on the Macintosh computer, and in TrueImage.

Microsoft uses the same byte ordering in TrueType font files as Apple uses in its font files, to help make the fonts portable between the systems. As a result, Windows fonts can be moved directly to the Macintosh computer, where they can quickly be converted into font suitcases for installation. (The format of TrueType font files precisely follows the format of the Apple “sfnt” resource. To convert an MS-DOS binary TrueType font into an sfnt resource requires editing the file information, setting Type to sfnt and Creator to bass. The sfnt resource can then be integrated into a standard Macintosh font suitcase. To move a font suitcase to Windows, an application need only extract the sfnt portion from the data fork and move the suitcase, unaltered, to Windows. After the suitcase has been moved to Windows, it can be installed by using Control Panel or the CreateScalableFontResource and AddFontResource functions.

If a Macintosh font is installed that does not contain the Windows “cmap” mapping table, the system maps text fonts (for example, Times or ITC Zapf ChanceryÒ) from the Macintosh character set onto the Windows character set. Novelty fonts (like ITC Zapf DingbatsÒ), which have no formal character set, are not mapped; these fonts are taken along with the Macintosh character encodings. The decision whether to remap is based on a test that looks at the “post” table (which contains PostScript names). Whenever necessary, Windows compensates for missing metric tables based on other metric data in the font; anything that cannot be computed in a reasonable manner is given a default value.

The creation of portable fonts requires more than just the right characters and the right character-mapping tables. All the metrics needed by all systems must be included and must yield the same results. Matching metrics for the individual characters is not a problem; since the characters and their hints and metrics appear only once in the TrueType font, the same metrics are available across platforms. The more difficult problems in the creation of portable fonts have to do with line-spacing metrics, the determination of font styles, and making these factors match across systems.

The Apple System 7 core TrueType fonts ship with metrics designed to be compatible with the raster fonts in System 6. The “hdmx” table will be used to force widths onto TrueType fonts that match those for the bitmaps at bitmap sizes. The “name” table (and its ability to group fonts by separating the family and subfamily names) is not used. (The name used comes from the FOND Macintosh font resource.) Only the macStyle bits (from the “head” table) denoting regular, bold, italic, or bold italic are used.

Apple's line spacing recommendations are less robust than the line-spacing used by Microsoft. The following formula defines the default recommended line spacing for a Macintosh font:

line spacing = ascent – descent + leading

The values for ascent, descent and leading come directly from TrueType values:

Macintosh TrueType

ascent otmMacAscent
descent otmMacDescent
leading otmMacLineGap

For its TrueType fonts, Apple recommends that Ascender – Descender = unitsPerEm, and LineGap = 0. This recommendation is based on the definition of point size for Macintosh raster fonts. Macintosh documentation defines the point size of a font as being equal to the line spacing (ascent – descent + leading). Although this definition is compatible with previous Apple font metrics, it ties line spacing to the size of the em square. Because some fonts (for example, Palatino) have ascenders and descenders that extend beyond the em square, the line-spacing definition is inconsistent for these fonts.

Windows and the Macintosh have the same default line spacing for a font only if the following formula is true:

otmMacLineGap >= (tmAscent + tmDescent) – (otmMacAscent – otmMacDescent)

Microsoft TrueType fonts follow this formula to ensure that default line spacing is preserved between the Macintosh and Windows. The core fonts and all fonts from vendors that follow the Microsoft specification will have the same character widths, the same default line spacing, and the same character forms.

Unless the Windows and Macintosh font heights are equal, a font with a line gap of zero will yield different default line spacings in Windows and on the Macintosh.

Despite some incompatibilities, TrueType and GDI accept Macintosh-only fonts. Metrics that are not present in Macintosh-only fonts are set to default values. Although these default values are imperfect, using them allows Macintosh-only fonts to work in Windows.