home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2000 February
/
PCWorld_2000-02_cd.bin
/
Software
/
Servis
/
FFE
/
MISC.SWG
/
0011_FONT.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1997-02-15
|
16KB
|
280 lines
.FNT Font-File Format
This topic describes the file formats for raster and vector fonts used
by the Microsoft Windows operating system. These file formats may be
used by smart text generators in some support modules for the graphics
device interface (GDI). Vector formats, however, are more frequently
used by GDI than by the support modules. TrueType font files are
described in TrueType Font Files, available from Microsoft Corporation.
Organization of a Font File
Raster and vector font files begin with information that is common to
both types of file and then continue with information that differs for
each type. These font files are stored with an .FNT extension. In
Windows versions 3.0 and later, the font-file header for raster and
vector fonts includes six new members: dFlags, dfAspace , dfBspace,
dfCspace, dfColorPointer, and dfReserved1. All device drivers support
the fonts in Windows 2.x. However, not all drivers support those in
versions 3.0 and later. In Windows, font files for raster and vector
fonts include the glyph table in the dfCharTable member, which consists
of structures describing the bits for characters in the font file.The
use of 32-bit offsets to the character glyphs in the dfCharTable member
enables fonts to exceed 64K, the size limit of Windows 2.x fonts.
Because of their 32-bit offsets and potentially large size, the newer
fonts are designed for use on systems that are running Windows versions
3.0 and later in protected (standard or 386-enhanced) mode and are using
an 80386 (or higher) processor whose 32-bit registers can access the
character glyphs. Typically, newer drivers use the newer version of a
font only when both of these conditions are true.
Font-File Structure
Font information is found at the beginning of both raster and vector
font files. Following are the members of the FONTINFO structure:
dfVersion Specifies the version (0x0200 or 0x0300) of the file.
dfSize Specifies the total size of the file, in bytes.
dfCopyright Specifies copyright information.
dfType Specifies the type of font file. This information is organized as follows:
Byte Description
Low-order Exclusively for GDI use. If the low-order bit of the word is zero, it is a bitmap (raster) font
file. If the low-order bit is 1, it is a vector font file. The second bit is reserved and must be
zero. If no bits follow in the file and the bits are located in memory at a fixed address
specified by the dfBitsOffset member, the third bit is set to 1. Otherwise, the bit is set to
zero. If the font is realized by a device, the high-order bit of the low-order byte is set. The
remaining bits in the low-order byte are then reserved and set to zero.
High-order Reserved for device use and is always set to zero for standard fonts realized by GDI.
Physical fonts that set the high-order bit of the low-order byte may use this byte to
describe themselves. GDI never inspects the high-order byte.
dfPoints Specifies the nominal point size (that is, the number identifying the point size) at which this character set
looks best.
dfVertRes Specifies the nominal vertical resolution (that is, the number identifying the vertical resolution), in dots per
inch, at which this character set was digitized.
dfHorizRes Specifies the nominal horizontal resolution (that is, the number identifying the horizontal resolution), in
dots per inch, at which this character set was digitized.
dfAscent Specifies the distance from the top of a character-definition cell to the base line of the typographical font.
The dfAscent member is useful for aligning the base lines of fonts with different heights.
dfInternalLeading Specifies the amount of leading inside the bounds set by the dfPixHeight member. Accent marks can
occur in this area. The designer can set the value to zero.
dfExternalLeading Specifies the amount of extra leading that the designer requests the application to add between rows.
Since this area is outside the font proper, it contains no marks and is not altered by text-output calls in
either opaque or transparent mode. The designer can set the value to zero.
dfItalic Specifies whether the character-definition data represents an italic font. If the flag is set, the low-order bit
is 1. All other bits are zero.
dfUnderline Specifies whether the character-definition data represents an underlined font. If the flag is set, the
low-order bit is 1. All other bits are zero.
dfStrikeOut Specifies whether the character-definition data represents a strikeout font. If the flag is set, the low-order
bit is 1. All other bits are zero.
dfWeight Specifies the weight of the characters in the character-definition data, on a scale of 1 through 1000. A
dfWeight value of 400 specifies a regular weight.
dfCharSet Specifies the character set defined by this font.
dfPixWidth Specifies the width of the grid on which a vector font was digitized. For raster fonts, if the dfPixWidth
member is nonzero, it represents the width for all the characters in the bitmap. If the member is zero, the
font has variable-width characters whose widths are specified in the array for the dfCharTable
member.
dfPixHeight Specifies the height of the character bitmap for raster fonts or the height of the grid on which a vector font
was digitized.
dfPitchAndFamily Specifies the pitch and font family. If the font is variable pitch, the low bit is set. The four high bits give the
family name of the font. Font families describe the general look of a font. They identify fonts when the
exact name is not available. The font families are described as follows:
Family Description
FF_DONTCARE Unknown.
FF_ROMAN Proportionally spaced fonts with serifs.
FF_SWISS Proportionally spaced fonts without serifs.
FF_MODERN Fixed-pitch fonts.
FF_SCRIPT Cursive or script fonts. (Both are designed to look similar to handwriting. Script
fonts have joined letters; cursive fonts do not.)
FF_DECORATIVE Novelty fonts.
dfAvgWidth Specifies the width of characters in the font. For fixed-pitch fonts, this value is the same as the value for
the dfPixWidth member. For variable-pitch fonts, it is the width of the character "X".
dfMaxWidth Specifies the maximum pixel width of any character in the font. For fixed-pitch fonts, this value is the same
as the value of the dfPixWidth member.
dfFirstChar Specifies the first character code defined by the font. Character definitions are stored only for the
characters actually present in the font. Use this member, therefore, when calculating indexes for either
the dfBits or dfCharOffset member.
dfLastChar Specifies the last character code defined by the font. All characters with codes between the values for
the dfFirstChar and dfLastChar members must be present in the character definitions for the font.
dfDefaultChar Specifies the character to substitute whenever a string contains a character that is out of range. The
character is given relative to the dfFirstChar member so that the dfDefaultChar member is the actual
value of the character less the value of the dfFirstChar member. The dfDefaultChar member
indicates a special character that is not a space.
dfBreakChar Specifies the character that defines word breaks for word wrapping and word-spacing justification. The
character is given relative to the dfFirstChar member so that the dfBreakChar member is the actual
value of the character less that of the dfFirstChar member. The dfBreakChar member is normally 32
minus the value of the dfFirstChar member (the ASCII space character).
dfWidthBytes Specifies the number of bytes in each row of the bitmap. This value is always even so that the rows start
on word boundaries. For vector fonts, this member has no meaning.
dfDevice Specifies the offset in the file to the string giving the device name. For a generic font, this value is zero.
dfFace Specifies the offset in the file to the null-terminated string that names the face.
dfBitsPointer Specifies the absolute machine address of the bitmap. This is set by GDI at load time. The value of the
dfBitsPointer member is guaranteed to be even.
dfBitsOffset Specifies the offset in the file to the beginning of the bitmap information. If the third bit in the dfType
member is set, the dfBitsOffset member is an absolute address of the bitmap (probably in read-only
memory).
For raster fonts, the dfBitsOffset member points to a sequence of bytes
that make up the bitmap of the font. The height of the bitmap is the
height of the font, and its width is the sum of the widths of the
characters in the font, rounded up to the next word boundary. For vector
fonts, the dfBitsOffset member points to a string of bytes or words
(depending on the size of the grid on which the font was digitized) that
specify the strokes for each character of the font. The value of the
dfBitsOffset member must be even.
dfReserved Not used.
dfFlags Specifies the bit flags that define the format of the glyph bitmap, as follows:
Pitch value Address
DFF_FIXED 0x0001
DFF_PROPORTIONAL 0x0002
DFF_ABCFIXED 0x0004
DFF_ABCPROPORTIONAL 0x0008
DFF_1COLOR 0x0010
DFF_16COLOR 0x0020
DFF_256COLOR 0x0040
DFF_RGBCOLOR 0x0080
dfAspace Specifies the global A space, if any. The value of the dfAspace member is the distance from the
current position to the left edge of the bitmap.
dfBspace Specifies the global B space, if any. The value of the dfBspace member is the width of the character.
dfCspace Specifies the global C space, if any. The value of the dfCspace member is the distance from the right
edge of the bitmap to the new current position. The increment of a character is the sum of the A, B, and C
spaces. These spaces apply to all glyphs, including DFF_ABCFIXED.
dfColorPointer Specifies the offset to the color table for color fonts, if any. The format of the bits is like a
device-independent bitmap (DIB), but without the header. (That is, the characters are not split into disjoint
bytes; instead, they are left intact.) If no color table is needed, this entry is NULL.
dfReserved1 Not used.
dfCharTable Specifies an array of entries for raster, fixed-pitch vector, and proportionally spaced vector fonts, as
follows:
Font type Description
Raster Each entry in the array consists of two 2-byte words for Windows
2.x and three 2-byte words for Windows 3.0 and later. The first word of
each entry is the character width. The second word of each entry is the
byte offset from the beginning of the FONTINFO structure to the
character bitmap. For Windows 3.0 and later, the second and third words
are used for the offset.
Fixed-pitch vector Each 2-byte entry in the array specifies the offset from the start of the
bitmap to the beginning of the string of stroke specification units for the
character. The number of bytes or words to be used for a particular
character is calculated by subtracting its entry from the next one, so
that there is a sentinel at the end of the array of values.
Proportionally-spaced vector Each 4-byte entry in the array is divided
into two 2-byte fields. The first field gives the starting offset from
the start of the bitmap of the character strokes. The second field gives
the pixel width of the character.
One extra entry at the end of the character table describes an absolute-space character, which is
guaranteed to be blank. This character is not part of the normal character set.
The number of entries in the table is calculated as follows: (dfLastChar - dfFirstChar) + 2. This number
includes a "spare," the sentinel offset.
For more information on the dfCharTable member, see Section 4.3, "Version-Specific Glyph Tables."
facename Specifies an ASCII character string that constitutes the name of the font face. The size of this member is
the length of the string plus a null terminating character.
devicename Specifies an ASCII character string that constitutes the name of the device if this font file is for a specific
one. The size of this member is the length of the string plus a null terminating character.
bitmaps Specifies character bitmap definitions. Unlike the old font format, each character is stored as a
contiguous set of bytes.
The first byte contains the first 8 bits of the first scan line (that
is, the top line of the character). The second byte contains the first 8
bits of the second scan line. This continues until the first "column" is
completely defined. The subsequent byte contains the next 8 bits of the
first scan line, padded with zeros on the right if necessary (and so on,
down through the second "column"). If the glyph is quite narrow, each
scan line is covered by one byte, with bits set to zero as necessary for
padding. If the glyph is very wide, a third or even fourth set of bytes
can be present. Character bitmaps must be stored contiguously and
arranged in ascending order. The bytes for a 12-pixel by 14-pixel "A"
character, for example, are given in two sets, because the character is
less than 17 pixels wide:
00 06 09 10 20 20 20 3F 20 20 20 00 00 00
00 00 00 80 40 40 40 C0 40 40 40 00 00 00
Note that in the second set of bytes, the second digit of the byte is
always zero. The zeros correspond to the thirteenth through sixteenth
pixels on the right side of the character, which are not used by this
character bitmap.
Version-Specific Glyph Tables
The dfCharTable member for Windows 2.x has a GlyphEntry structure with the following format:
GlyphEntry struc
geWidth dw ? ; width of char bitmap, pixels
geOffset dw ? ; pointer to the bits
GlyphEntry ends
The dfCharTable member in Windows 3.0 and later is dependent on the format of the glyph bitmap. The only formats supported
are DFF_FIXED and DFF_PROPORTIONAL.
DFF_FIXED
DFF_PROPORTIONAL
GlyphEntry struc
geWidth dw ? ; width of char bitmap, pixels
geOffset dd ? ; pointer to the bits
GlyphEntry ends
DFF_ABCFIXED
DFF_ABCPROPORTIONAL
GlyphEntry struc
geWidth dw ? ; width of char bitmap, pixels
geOffset dd ? ; pointer to the bits
geAspace dd ? ; A space, fract pixels (16.16)
geBspace dd ? ; B space, fract pixels (16.16)
geCspace dw ? ; C space, fract pixels (16.16)
GlyphEntry ends
Fractional pixels are expressed as 32-bit signed numbers with an
implicit binary point between bits 15 and 16. This is referred to as a
16.16 ("sixteen dot sixteen") fixed-point number. The ABC spacing in the
following example is the same as defined previously. However, specific
sets are defined for each character:
DFF_1COLOR ; 8 pixels per byte
DFF_16COLOR ; 2 pixels per byte
DFF_256COLOR ; 1 pixel per byte
DFF_RGBCOLOR ; RGB quads
GlyphEntry struc
geWidth dw ? ; width of char bitmap, pixels
geOffset dd ? ; pointer to the bits
geHeight dw ? ; height of char bitmap, pixels
geAspace dd ? ; A space, fract pixels (16.16)
geBspace dd ? ; B space, fract pixels (16.16)
geCspace dd ? ; C space, fract pixels (16.16)
GlyphEntry ends