home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 September / Chip_2000-09_cd1.bin / sharewar / Slunec / app / 16 / MISC.SWG / 0011_FONT.pas < prev    next >
Pascal/Delphi Source File  |  1997-02-15  |  16KB  |  280 lines

  1. .FNT Font-File Format
  2.  
  3. This  topic describes the file formats  for raster and vector fonts used
  4. by  the  Microsoft Windows operating system.  These  file formats may be
  5. used  by smart text generators in  some support modules for the graphics
  6. device  interface  (GDI). Vector formats,  however,  are more frequently
  7. used  by  GDI  than  by the  support  modules.  TrueType  font files are
  8. described in TrueType Font Files, available from Microsoft Corporation.
  9.  
  10. Organization of a Font File
  11.  
  12. Raster  and  vector font files begin  with information that is common to
  13. both  types of file and then  continue with information that differs for
  14. each  type.  These  font  files are  stored  with  an .FNT extension. In
  15. Windows  versions  3.0  and later, the  font-file  header for raster and
  16. vector  fonts  includes  six new  members:  dFlags, dfAspace , dfBspace,
  17. dfCspace,  dfColorPointer,  and dfReserved1.  All device drivers support
  18. the  fonts  in  Windows 2.x. However,  not  all drivers support those in
  19. versions  3.0  and later. In Windows,  font  files for raster and vector
  20. fonts  include the glyph table in the dfCharTable member, which consists
  21. of  structures  describing the bits for  characters in the font file.The
  22. use  of 32-bit offsets to the character glyphs in the dfCharTable member
  23. enables fonts to exceed 64K, the size limit of Windows 2.x fonts.
  24.  
  25. Because  of  their 32-bit offsets and  potentially large size, the newer
  26. fonts  are designed for use on systems that are running Windows versions
  27. 3.0 and later in protected (standard or 386-enhanced) mode and are using
  28. an  80386  (or higher) processor whose  32-bit  registers can access the
  29. character  glyphs.  Typically, newer drivers use  the newer version of a
  30. font only when both of these conditions are true.
  31.  
  32. Font-File Structure
  33.  
  34. Font  information  is found at the  beginning  of both raster and vector
  35. font files. Following are the members of the FONTINFO structure:
  36.  
  37. dfVersion       Specifies the version (0x0200 or 0x0300) of the file.
  38. dfSize  Specifies the total size of the file, in bytes.
  39. dfCopyright     Specifies copyright information.
  40. dfType  Specifies the type of font file. This information is organized as follows:
  41.  
  42. Byte    Description
  43.  
  44. Low-order       Exclusively for GDI use. If the low-order bit of the word is zero, it is a bitmap (raster) font
  45. file. If the low-order bit is 1, it is a vector font file. The second bit is reserved and must be
  46. zero. If no bits follow in the file and the bits are located in memory at a fixed address
  47. specified by the dfBitsOffset member, the third bit is set to 1. Otherwise, the bit is set to
  48. zero. If the font is realized by a device, the high-order bit of the low-order byte is set. The
  49. remaining bits in the low-order byte are then reserved and set to zero.
  50. High-order      Reserved for device use and is always set to zero for standard fonts realized by GDI.
  51. Physical fonts that set the high-order bit of the low-order byte may use this byte to
  52. describe themselves. GDI never inspects the high-order byte.
  53.  
  54. dfPoints        Specifies the nominal point size (that is, the number identifying the point size) at which this character set
  55. looks best.
  56. dfVertRes       Specifies the nominal vertical resolution (that is, the number identifying the vertical resolution), in dots per
  57. inch, at which this character set was digitized.
  58. dfHorizRes      Specifies the nominal horizontal resolution (that is, the number identifying the horizontal resolution), in
  59. dots per inch, at which this character set was digitized.
  60. dfAscent        Specifies the distance from the top of a character-definition cell to the base line of the typographical font.
  61. The dfAscent member is useful for aligning the base lines of fonts with different heights.
  62.  
  63. dfInternalLeading       Specifies the amount of leading inside the bounds set by the dfPixHeight member. Accent marks can
  64. occur in this area. The designer can set the value to zero.
  65. dfExternalLeading       Specifies the amount of extra leading that the designer requests the application to add between rows.
  66. Since this area is outside the font proper, it contains no marks and is not altered by text-output calls in
  67. either opaque or transparent mode. The designer can set the value to zero.
  68. dfItalic        Specifies whether the character-definition data represents an italic font. If the flag is set, the low-order bit
  69. is 1. All other bits are zero.
  70. dfUnderline     Specifies whether the character-definition data represents an underlined font. If the flag is set, the
  71. low-order bit is 1. All other bits are zero.
  72.  
  73. dfStrikeOut     Specifies whether the character-definition data represents a strikeout font. If the flag is set, the low-order
  74. bit is 1. All other bits are zero.
  75. dfWeight        Specifies the weight of the characters in the character-definition data, on a scale of 1 through 1000. A
  76. dfWeight value of 400 specifies a regular weight.
  77. dfCharSet       Specifies the character set defined by this font.
  78. dfPixWidth      Specifies the width of the grid on which a vector font was digitized. For raster fonts, if the dfPixWidth
  79. member is nonzero, it represents the width for all the characters in the bitmap. If the member is zero, the
  80. font has variable-width characters whose widths are specified in the array for the dfCharTable
  81. member.
  82.  
  83. dfPixHeight     Specifies the height of the character bitmap for raster fonts or the height of the grid on which a vector font
  84. was digitized.
  85. dfPitchAndFamily        Specifies the pitch and font family. If the font is variable pitch, the low bit is set. The four high bits give the
  86. family name of the font. Font families describe the general look of a font. They identify fonts when the
  87. exact name is not available. The font families are described as follows:
  88.  
  89. Family  Description
  90.  
  91. FF_DONTCARE     Unknown.
  92. FF_ROMAN        Proportionally spaced fonts with serifs.
  93. FF_SWISS        Proportionally spaced fonts without serifs.
  94. FF_MODERN       Fixed-pitch fonts.
  95. FF_SCRIPT       Cursive or script fonts. (Both are designed to look similar to handwriting. Script
  96. fonts have joined letters; cursive fonts do not.)
  97. FF_DECORATIVE   Novelty fonts.
  98.  
  99. dfAvgWidth      Specifies the width of characters in the font. For fixed-pitch fonts, this value is the same as the value for
  100. the dfPixWidth member. For variable-pitch fonts, it is the width of the character "X".
  101. dfMaxWidth      Specifies the maximum pixel width of any character in the font. For fixed-pitch fonts, this value is the same
  102. as the value of the dfPixWidth member.
  103. dfFirstChar     Specifies the first character code defined by the font. Character definitions are stored only for the
  104. characters actually present in the font. Use this member, therefore, when calculating indexes for either
  105. the dfBits or dfCharOffset member.
  106. dfLastChar      Specifies the last character code defined by the font. All characters with codes between the values for
  107. the dfFirstChar and dfLastChar members must be present in the character definitions for the font.
  108.  
  109. dfDefaultChar   Specifies the character to substitute whenever a string contains a character that is out of range. The
  110. character is given relative to the dfFirstChar member so that the dfDefaultChar member is the actual
  111. value of the character less the value of the dfFirstChar member. The dfDefaultChar member
  112. indicates a special character that is not a space.
  113. dfBreakChar     Specifies the character that defines word breaks for word wrapping and word-spacing justification. The
  114. character is given relative to the dfFirstChar member so that the dfBreakChar member is the actual
  115. value of the character less that of the dfFirstChar member. The dfBreakChar member is normally 32
  116. minus the value of the dfFirstChar member (the ASCII space character).
  117.  
  118. dfWidthBytes    Specifies the number of bytes in each row of the bitmap. This value is always even so that the rows start
  119. on word boundaries. For vector fonts, this member has no meaning.
  120. dfDevice        Specifies the offset in the file to the string giving the device name. For a generic font, this value is zero.
  121. dfFace  Specifies the offset in the file to the null-terminated string that names the face.
  122. dfBitsPointer   Specifies the absolute machine address of the bitmap. This is set by GDI at load time. The value of the
  123. dfBitsPointer member is guaranteed to be even.
  124. dfBitsOffset    Specifies the offset in the file to the beginning of the bitmap information. If the third bit in the dfType
  125. member is set, the dfBitsOffset member is an absolute address of the bitmap (probably in read-only
  126. memory).
  127.  
  128. For  raster fonts, the dfBitsOffset member points to a sequence of bytes
  129. that  make  up the bitmap of the font.  The  height of the bitmap is the
  130. height  of  the  font,  and its width is  the  sum  of the widths of the
  131. characters in the font, rounded up to the next word boundary. For vector
  132. fonts,  the  dfBitsOffset  member points to  a  string of bytes or words
  133. (depending on the size of the grid on which the font was digitized) that
  134. specify  the  strokes for each character of  the  font. The value of the
  135. dfBitsOffset member must be even.
  136.  
  137. dfReserved      Not used.
  138. dfFlags Specifies the bit flags that define the format of the glyph bitmap, as follows:
  139.  
  140. Pitch value     Address
  141.  
  142. DFF_FIXED       0x0001
  143. DFF_PROPORTIONAL        0x0002
  144. DFF_ABCFIXED    0x0004
  145. DFF_ABCPROPORTIONAL     0x0008
  146. DFF_1COLOR      0x0010
  147. DFF_16COLOR     0x0020
  148. DFF_256COLOR    0x0040
  149. DFF_RGBCOLOR    0x0080
  150.  
  151. dfAspace        Specifies the global A space, if any. The value of the dfAspace member is the distance from the
  152. current position to the left edge of the bitmap.
  153. dfBspace        Specifies the global B space, if any. The value of the dfBspace member is the width of the character.
  154. dfCspace        Specifies the global C space, if any. The value of the dfCspace member is the distance from the right
  155. edge of the bitmap to the new current position. The increment of a character is the sum of the A, B, and C
  156. spaces. These spaces apply to all glyphs, including DFF_ABCFIXED.
  157. dfColorPointer  Specifies the offset to the color table for color fonts, if any. The format of the bits is like a
  158. device-independent bitmap (DIB), but without the header. (That is, the characters are not split into disjoint
  159. bytes; instead, they are left intact.) If no color table is needed, this entry is NULL.
  160.  
  161. dfReserved1     Not used.
  162. dfCharTable     Specifies an array of entries for raster, fixed-pitch vector, and proportionally spaced vector fonts, as
  163. follows:
  164.  
  165. Font type       Description
  166.  
  167. Raster  Each entry in the array consists of two 2-byte words for Windows
  168. 2.x  and three 2-byte words for Windows 3.0 and later. The first word of
  169. each  entry is the character width. The second word of each entry is the
  170. byte  offset  from  the  beginning  of  the  FONTINFO  structure  to the
  171. character  bitmap. For Windows 3.0 and later, the second and third words
  172. are used for the offset.
  173. Fixed-pitch vector      Each 2-byte entry in the array specifies the offset from the start of the
  174. bitmap to the beginning of the string of stroke specification units for the
  175. character. The number of bytes or words to be used for a particular
  176. character is calculated by subtracting its entry from the next one, so
  177. that there is a sentinel at the end of the array of values.
  178.  
  179. Proportionally-spaced  vector Each 4-byte entry  in the array is divided
  180. into  two 2-byte fields. The first  field gives the starting offset from
  181. the start of the bitmap of the character strokes. The second field gives
  182. the pixel width of the character.
  183.  
  184. One extra entry at the end of the character table describes an absolute-space character, which is
  185. guaranteed to be blank. This character is not part of the normal character set.
  186. The number of entries in the table is calculated as follows: (dfLastChar - dfFirstChar) + 2. This number
  187. includes a "spare," the sentinel offset.
  188. For more information on the dfCharTable member, see Section 4.3, "Version-Specific Glyph Tables."
  189.  
  190. facename        Specifies an ASCII character string that constitutes the name of the font face. The size of this member is
  191. the length of the string plus a null terminating character.
  192. devicename      Specifies an ASCII character string that constitutes the name of the device if this font file is for a specific
  193. one. The size of this member is the length of the string plus a null terminating character.
  194. bitmaps Specifies character bitmap definitions. Unlike the old font format, each character is stored as a
  195. contiguous set of bytes.
  196.  
  197. The  first  byte contains the first 8  bits of the first scan line (that
  198. is, the top line of the character). The second byte contains the first 8
  199. bits of the second scan line. This continues until the first "column" is
  200. completely  defined. The subsequent byte contains the next 8 bits of the
  201. first scan line, padded with zeros on the right if necessary (and so on,
  202. down  through  the second "column"). If  the glyph is quite narrow, each
  203. scan line is covered by one byte, with bits set to zero as necessary for
  204. padding.  If the glyph is very wide, a third or even fourth set of bytes
  205. can  be  present.  Character  bitmaps  must  be  stored contiguously and
  206. arranged  in  ascending order. The bytes  for a 12-pixel by 14-pixel "A"
  207. character,  for example, are given in two sets, because the character is
  208. less than 17 pixels wide:
  209.  
  210.  
  211.  
  212. 00 06 09 10 20 20 20 3F 20 20 20 00 00 00
  213. 00 00 00 80 40 40 40 C0 40 40 40 00 00 00
  214.  
  215. Note  that  in the second set of bytes,  the second digit of the byte is
  216. always  zero.  The zeros correspond  to the thirteenth through sixteenth
  217. pixels  on  the right side of the  character, which are not used by this
  218. character bitmap.
  219.  
  220. Version-Specific Glyph Tables
  221.  
  222. The dfCharTable member for Windows 2.x has a GlyphEntry structure with the following format:
  223.  
  224.  
  225.  
  226. GlyphEntry      struc
  227. geWidth                 dw      ?  ; width of char bitmap, pixels
  228. geOffset                dw      ?  ; pointer to the bits
  229. GlyphEntry      ends
  230.  
  231. The dfCharTable member in Windows 3.0 and later is dependent on the format of the glyph bitmap. The only formats supported
  232. are DFF_FIXED and DFF_PROPORTIONAL.
  233.  
  234.  
  235.  
  236. DFF_FIXED
  237. DFF_PROPORTIONAL
  238.  
  239. GlyphEntry      struc
  240. geWidth                 dw      ?  ; width of char bitmap, pixels
  241. geOffset                dd      ?  ; pointer to the bits
  242. GlyphEntry      ends
  243.  
  244. DFF_ABCFIXED
  245. DFF_ABCPROPORTIONAL
  246.  
  247. GlyphEntry      struc
  248. geWidth                 dw      ?  ; width of char bitmap, pixels
  249. geOffset                dd      ?  ; pointer to the bits
  250. geAspace                dd      ?  ; A space, fract pixels (16.16)
  251. geBspace                dd      ?  ; B space, fract pixels (16.16)
  252. geCspace                dw      ?  ; C space, fract pixels (16.16)
  253.  
  254. GlyphEntry      ends
  255.  
  256. Fractional  pixels  are  expressed  as  32-bit  signed  numbers  with an
  257. implicit  binary point between bits 15 and  16. This is referred to as a
  258. 16.16 ("sixteen dot sixteen") fixed-point number. The ABC spacing in the
  259. following  example is the same  as defined previously. However, specific
  260. sets are defined for each character:
  261.  
  262.  
  263.  
  264. DFF_1COLOR                         ; 8 pixels per byte
  265. DFF_16COLOR                        ; 2 pixels per byte
  266. DFF_256COLOR                       ; 1 pixel per byte
  267. DFF_RGBCOLOR                       ; RGB quads
  268.  
  269. GlyphEntry      struc
  270. geWidth                 dw      ?  ; width of char bitmap, pixels
  271. geOffset                dd      ?  ; pointer to the bits
  272. geHeight                dw      ?  ; height of char bitmap, pixels
  273. geAspace                dd      ?  ; A space, fract pixels (16.16)
  274. geBspace                dd      ?  ; B space, fract pixels (16.16)
  275.  
  276. geCspace                dd      ?  ; C space, fract pixels (16.16)
  277. GlyphEntry      ends
  278.  
  279.  
  280.