Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

460 lines
18 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: winfont.h
  3. *
  4. * font file headers for 2.0 and 3.0 windows *.fnt files
  5. *
  6. * Created: 25-Oct-1990 11:08:08
  7. * Author: Bodin Dresevic [BodinD]
  8. *
  9. * Copyright (c) Microsoft Corporation. All rights reserved.
  10. *
  11. * (General description of its use)
  12. *
  13. *
  14. \**************************************************************************/
  15. /******************************Public*Macro********************************\
  16. * WRITE_WORD
  17. *
  18. * Writes a word to the misaligned address, pv.
  19. *
  20. * !!! Note: this only works for little-endian.
  21. *
  22. * History:
  23. * 11-Feb-1992 -by- Gilman Wong [gilmanw]
  24. * Wrote it.
  25. \**************************************************************************/
  26. #define WRITE_WORD(pv, word) \
  27. { \
  28. *(PBYTE) (pv) = (BYTE) ((word) & 0x00ff); \
  29. *((PBYTE) (pv) + 1) = (BYTE) (((word) & 0xff00) >> 8); \
  30. }
  31. /******************************Public*Macro********************************\
  32. * READ_WORD
  33. *
  34. * Reads a word from the misaligned address, pv.
  35. *
  36. * !!! Note: this only works for little-endian.
  37. *
  38. * History:
  39. * 11-Feb-1992 -by- Gilman Wong [gilmanw]
  40. * Wrote it.
  41. \**************************************************************************/
  42. #define READ_WORD(pv) \
  43. ( (WORD) \
  44. ( ((WORD)*(PBYTE) (pv)) & (WORD)0x00ff ) | \
  45. ( ((WORD)*((PBYTE) (pv) + (WORD)1) & (WORD)0x00ff) << 8 ) \
  46. )
  47. /******************************Public*Macro********************************\
  48. * WRITE_DWORD
  49. *
  50. * Writes a dword to the misaligned address, pv.
  51. *
  52. * !!! Note: this only works for little-endian.
  53. *
  54. * History:
  55. * 11-Feb-1992 -by- Gilman Wong [gilmanw]
  56. * Wrote it.
  57. \**************************************************************************/
  58. #define WRITE_DWORD(pv, dword) \
  59. { \
  60. *(PBYTE) (pv) = (BYTE) ((dword) & 0x000000ff); \
  61. *((PBYTE) (pv) + 1) = (BYTE) (((dword) & 0x0000ff00) >> 8 ); \
  62. *((PBYTE) (pv) + 2) = (BYTE) (((dword) & 0x00ff0000) >> 16); \
  63. *((PBYTE) (pv) + 3) = (BYTE) (((dword) & 0xff000000) >> 24); \
  64. }
  65. /******************************Public*Macro********************************\
  66. * READ_DWORD
  67. *
  68. * Reads a DWORD from the misaligned address, pv.
  69. *
  70. * !!! Note: this only works for little-endian.
  71. *
  72. * History:
  73. * 11-Feb-1992 -by- Gilman Wong [gilmanw]
  74. * Wrote it.
  75. \**************************************************************************/
  76. #define READ_DWORD(pv) \
  77. ( (DWORD) \
  78. ( (*(PBYTE) (pv)) & 0x000000ff ) | \
  79. ( (*((PBYTE) (pv) + 1) & 0x000000ff) << 8 ) | \
  80. ( (*((PBYTE) (pv) + 2) & 0x000000ff) << 16) | \
  81. ( (*((PBYTE) (pv) + 3) & 0x000000ff) << 24) \
  82. )
  83. // font file header (2.0 ddk adaptation guide, 7.7.3.
  84. // and 3.0 ddk, Adaptation Guide section 13.3)
  85. // CAUTION: These structures, as they are defined in the Adaptation Guide are
  86. // out of allignment.(Not even WORD alligned,let alone DWORD alligned.)
  87. // Here we make our own structures, so that when
  88. // disk files are read in the data is copied in correctly, and so that
  89. // the data can be accessed in memory regardless of the architecture.
  90. /**************************************************************************\
  91. // the original structure was
  92. typedef struct {
  93. WORD Version; // Always 17985 for the Nonce
  94. DWORD Size; // Size of whole file
  95. char Copyright[60];
  96. WORD Type; // Raster Font if Type & 1 == 0
  97. WORD Points; // Nominal Point size
  98. WORD VertRes; // Nominal Vertical resolution
  99. WORD HorizRes; // Nominal Horizontal resolution
  100. WORD Ascent; // Height of Ascent
  101. WORD IntLeading; // Internal (Microsoft) Leading
  102. WORD ExtLeading; // External (Microsoft) Leading
  103. BYTE Italic; // Italic font if set
  104. BYTE Underline; // Etc.
  105. BYTE StrikeOut; // Etc.
  106. WORD Weight; // Weight: 200 = regular
  107. BYTE CharSet; // ANSI=0. other=255
  108. WORD PixWidth; // Fixed width. 0 ==> Variable
  109. WORD PixHeight; // Fixed Height
  110. BYTE Family; // Pitch and Family
  111. WORD AvgWidth; // Width of character 'X'
  112. WORD MaxWidth; // Maximum width
  113. BYTE FirstChar; // First character defined in font
  114. BYTE LastChar; // Last character defined in font
  115. BYTE DefaultChar; // Sub. for out of range chars.
  116. BYTE BreakChar; // Word Break Character
  117. WORD WidthBytes; // No.Bytes/row of Bitmap
  118. DWORD Device; // Pointer to Device Name string
  119. DWORD Face; // Pointer to Face Name String
  120. DWORD BitsPointer; // Pointer to Bit Map
  121. DWORD BitsOffset; // Offset to Bit Map
  122. } FontHeaderType; // Above pointers all rel. to start of file
  123. // the original 3.0 header:
  124. typedef struct {
  125. WORD fsVersion;
  126. DWORD fsSize;
  127. char fsCopyright[60];
  128. WORD fsType; // Type field for the font
  129. WORD fsPoints; // Point size of font
  130. WORD fsVertRes; // Vertical digitization
  131. WORD fsHorizRes; // Horizontal digitization
  132. WORD fsAscent; // Baseline offset from char cell top
  133. WORD fsInternalLeading; // Internal leading included in font
  134. WORD fsExternalLeading; // Prefered extra space between lines
  135. BYTE fsItalic; // Flag specifying if italic
  136. BYTE fsUnderline; // Flag specifying if underlined
  137. BYTE fsStrikeOut; // Flag specifying if struck out
  138. WORD fsWeight; // Weight of font
  139. BYTE fsCharSet; // Character set of font
  140. WORD fsPixWidth; // Width field for the font
  141. WORD fsPixHeight; // Height field for the font
  142. BYTE fsPitchAndFamily; // Flag specifying pitch and family
  143. WORD fsAvgWidth; // Average character width
  144. WORD fsMaxWidth; // Maximum character width
  145. BYTE fsFirstChar; // First character in the font
  146. BYTE fsLastChar; // Last character in the font
  147. BYTE fsDefaultChar; // Default character for out of range
  148. BYTE fsBreakChar; // Character to define wordbreaks
  149. WORD fsWidthBytes; // Number of bytes in each row
  150. DWORD fsDevice; // Offset to device name
  151. DWORD fsFace; // Offset to face name
  152. DWORD fsBitsPointer; // Bits pointer
  153. DWORD fsBitsOffset; // Offset to the begining of the bitmap
  154. BYTE fsDBfiller; // Word alignment for the offset table
  155. DWORD fsFlags; // Bit flags
  156. WORD fsAspace; // Global A space, if any
  157. WORD fsBspace; // Global B space, if any
  158. WORD fsCspace; // Global C space, if any
  159. DWORD fsColorPointer; // offset to color table, if any
  160. DWORD fsReserved[4]; //
  161. BYTE fsCharOffset; // Area for storing the char. offsets
  162. } FontHeader30;
  163. typedef struct tagFFH {
  164. WORD fhVersion ;
  165. DWORD fhSize ;
  166. char fhCopyright[60] ;
  167. WORD fhType ;
  168. WORD fhPoints ;
  169. WORD fhVertRes ;
  170. WORD fhHorizRes ;
  171. WORD fhAscent ;
  172. WORD fhInternalLeading;
  173. WORD fhExternalLeading;
  174. BYTE fhItalic ;
  175. BYTE fhUnderline ;
  176. BYTE fhStrikeOut ;
  177. WORD fhWeight ;
  178. BYTE fhCharSet ;
  179. WORD fhPixWidth ;
  180. WORD fhPixHeight ;
  181. BYTE fhPitchAndFamily ;
  182. WORD fhAvgWidth ;
  183. WORD fhMaxWidth ;
  184. BYTE fhFirstChar ;
  185. BYTE fhLastChar ;
  186. BYTE fhDefaultChar ;
  187. BYTE fhBreakChar ;
  188. WORD fhWidthBytes ;
  189. DWORD fhDevice ;
  190. DWORD fhFace ;
  191. DWORD fhBitsPointer ;
  192. } FFH;
  193. \**************************************************************************/
  194. // type of the font file
  195. #define TYPE_RASTER 0x0000
  196. #define TYPE_VECTOR 0x0001
  197. #define TYPE_BITS_IN_ROM 0x0004
  198. #define TYPE_REALIZED_BY_DEVICE 0x0080
  199. // reserved fields in the fsType field, used are 0-th,2-nd, and 7-th bit
  200. #define BITS_RESERVED (~(TYPE_VECTOR|TYPE_BITS_IN_ROM|TYPE_REALIZED_BY_DEVICE))
  201. // supported in win 3.0
  202. #define DFF_FIXED 0x01 // fixed font
  203. #define DFF_PROPORTIONAL 0x02 // proportional font
  204. // not supported in win 3.0, except maybe if someone has
  205. // custom created such a font, using font editor or a similar tool
  206. #define DFF_ABCFIXED 0x04 // ABC fixed font
  207. #define DFF_ABCPROPORTIONAL 0x08 // ABC proportional font
  208. #define DFF_1COLOR 0x10
  209. #define DFF_16COLOR 0x20
  210. #define DFF_256COLOR 0x40
  211. #define DFF_RGBCOLOR 0x80
  212. // here we list offsets of all fields of the original structures
  213. // as they are computed under the assumption that the C compiler does not
  214. // insert any paddings between fields
  215. #define OFF_Version 0L // WORD Always 17985 for the Nonce
  216. #define OFF_Size 2L // DWORD Size of whole file
  217. #define OFF_Copyright 6L // char[60]
  218. // Note: Win 3.1 hack. The LSB of Type is used by Win 3.1 as an engine type
  219. // and font embedding flag. Font embedding is a form of a "hidden
  220. // font file". The MSB of Type is the same as the fsSelection from
  221. // IFIMETRICS. (Strictly speaking, the MSB of Type is equal to the
  222. // LSB of IFIMETRICS.fsSelection).
  223. #define OFF_Type 66L // WORD Raster Font if Type & 1 == 0
  224. #define OFF_Points 68L // WORD Nominal Point size
  225. #define OFF_VertRes 70L // WORD Nominal Vertical resolution
  226. #define OFF_HorizRes 72L // WORD Nominal Horizontal resolution
  227. #define OFF_Ascent 74L // WORD Height of Ascent
  228. #define OFF_IntLeading 76L // WORD Internal (Microsoft) Leading
  229. #define OFF_ExtLeading 78L // WORD External (Microsoft) Leading
  230. #define OFF_Italic 80L // BYTE Italic font if set
  231. #define OFF_Underline 81L // BYTE Etc.
  232. #define OFF_StrikeOut 82L // BYTE Etc.
  233. #define OFF_Weight 83L // WORD Weight: 200 = regular
  234. #define OFF_CharSet 85L // BYTE ANSI=0. other=255
  235. #define OFF_PixWidth 86L // WORD Fixed width. 0 ==> Variable
  236. #define OFF_PixHeight 88L // WORD Fixed Height
  237. #define OFF_Family 90L // BYTE Pitch and Family
  238. #define OFF_AvgWidth 91L // WORD Width of character 'X'
  239. #define OFF_MaxWidth 93L // WORD Maximum width
  240. #define OFF_FirstChar 95L // BYTE First character defined in font
  241. #define OFF_LastChar 96L // BYTE Last character defined in font
  242. #define OFF_DefaultChar 97L // BYTE Sub. for out of range chars.
  243. #define OFF_BreakChar 98L // BYTE Word Break Character
  244. #define OFF_WidthBytes 99L // WORD No.Bytes/row of Bitmap
  245. #define OFF_Device 101L // DWORD Pointer to Device Name string
  246. #define OFF_Face 105L // DWORD Pointer to Face Name String
  247. #define OFF_BitsPointer 109L // DWORD Pointer to Bit Map
  248. #define OFF_BitsOffset 113L // DWORD Offset to Bit Map
  249. #define OFF_jUnused20 117L // BYTE byte filler
  250. #define OFF_OffTable20 118L // WORD here begins char table for 2.0
  251. // 3.0 addition
  252. #define OFF_jUnused30 117L // BYTE enforces word allignment
  253. #define OFF_Flags 118L // DWORD Bit flags
  254. #define OFF_Aspace 122L // WORD Global A space, if any
  255. #define OFF_Bspace 124L // WORD Global B space, if any
  256. #define OFF_Cspace 126L // WORD Global C space, if any
  257. #define OFF_ColorPointer 128L // DWORD offset to color table, if any
  258. #define OFF_Reserved 132L // DWORD[4]
  259. #define OFF_OffTable30 148L // WORD Area for storing the char. offsets in 3.0
  260. // latest offset for pscript device font pfm files [bodind]
  261. #if 0
  262. // This is from win31 sources \drivers\printers\pstt\utils\pfm.c [bodind]
  263. ........
  264. WORD dfWidthBytes;
  265. DWORD dfDevice;
  266. DWORD dfFace;
  267. DWORD dfBitsPointer;
  268. DWORD dfBitsOffset; // up to here the offsets are the same as in *.fon files
  269. WORD dfSizeFields;
  270. DWORD dfExtMetricsOffset;
  271. DWORD dfExtentTable;
  272. DWORD dfOriginTable;
  273. DWORD dfPairKernTable;
  274. DWORD dfTrackKernTable;
  275. DWORD dfDriverInfo;
  276. DWORD dfReserved;
  277. #endif
  278. #define OFF_SizeFields 117L
  279. #define OFF_ExtMetricsOffset 119L
  280. #define OFF_ExtentTable 123L
  281. #define OFF_OriginTable 127L
  282. #define OFF_PairKernTable 131L
  283. #define OFF_TrackKernTable 135L
  284. #define OFF_DriverInfo 139L
  285. #define OFF_ReservedPscript 143L
  286. // FFH offsets
  287. #define OFF_FFH_Version 0L // WORD Always 17985 for the Nonce
  288. #define OFF_FFH_Size 2L // DWORD Size of whole file
  289. #define OFF_FFH_Copyright 6L // char[60]
  290. #define OFF_FFH_Type 66L // WORD Raster Font if Type & 1 == 0
  291. #define OFF_FFH_Points 68L // WORD Nominal Point size
  292. #define OFF_FFH_VertRes 70L // WORD Nominal Vertical resolution
  293. #define OFF_FFH_HorizRes 72L // WORD Nominal Horizontal resolution
  294. #define OFF_FFH_Ascent 74L // WORD Height of Ascent
  295. #define OFF_FFH_IntLeading 76L // WORD Internal (Microsoft) Leading
  296. #define OFF_FFH_ExtLeading 78L // WORD External (Microsoft) Leading
  297. #define OFF_FFH_Italic 80L // BYTE Italic font if set
  298. #define OFF_FFH_Underline 81L // BYTE Etc.
  299. #define OFF_FFH_StrikeOut 82L // BYTE Etc.
  300. #define OFF_FFH_Weight 83L // WORD Weight: 200 = regular
  301. #define OFF_FFH_CharSet 85L // BYTE ANSI=0. other=255
  302. #define OFF_FFH_PixWidth 86L // WORD Fixed width. 0 ==> Variable
  303. #define OFF_FFH_PixHeight 88L // WORD Fixed Height
  304. #define OFF_FFH_Family 90L // BYTE Pitch and Family
  305. #define OFF_FFH_AvgWidth 91L // WORD Width of character 'X'
  306. #define OFF_FFH_MaxWidth 93L // WORD Maximum width
  307. #define OFF_FFH_FirstChar 95L // BYTE First character defined in font
  308. #define OFF_FFH_LastChar 96L // BYTE Last character defined in font
  309. #define OFF_FFH_DefaultChar 97L // BYTE Sub. for out of range chars.
  310. #define OFF_FFH_BreakChar 98L // BYTE Word Break Character
  311. #define OFF_FFH_WidthBytes 99L // WORD No.Bytes/row of Bitmap
  312. #define OFF_FFH_Device 101L // DWORD Pointer to Device Name string
  313. #define OFF_FFH_Face 105L // DWORD Pointer to Face Name String
  314. #define OFF_FFH_BitsPointer 109L // DWORD Pointer to Bit Map
  315. #define SIZEFFH (OFF_FFH_BitsPointer + 4)
  316. // This is used in NtGdiMakeFontDir
  317. #define CJ_FONTDIR (SIZEFFH + LF_FACESIZE + LF_FULLFACESIZE + LF_FACESIZE + 10)
  318. // header sizes in bytes of the original headers
  319. #define HDRSIZE20 117L // or 113L ?
  320. #define HDRSIZE30 148L // CharOffset is not counted as header
  321. #define HDRSIZEDIFF (HDRSIZE30 - HDRSIZE20) // 31 byte
  322. // ranges for some quantities
  323. #define MAX_PT_SIZE 999 // max size in points
  324. // weight range
  325. #define MIN_WEIGHT 1 // adaptation guide
  326. #define MAX_WEIGHT 1000 // adaptation guide
  327. // maximal size of bitmap font in pixels, (bound on cx and cy)
  328. #define MAX_PEL_SIZE 64
  329. // 2.0 fonts have offsets that fit into 64k
  330. #define SEGMENT_SIZE 65536L // IN bytes
  331. // offset limit for 2.0 font files
  332. #define MAX_20_OFFSET 65534 // 64K - 2
  333. // sizes of the offset table entries for the 2.0 and 3.0 fonts respectively
  334. #define CJ_ENTRY_20 4 // two bytes for cx + two bytes for the offset
  335. #define CJ_ENTRY_30 6 // two bytes for cx + four bytes for the offset
  336. #define WINWT_TO_PANWT(x) ((x)/100 + 1)
  337. // From [Windows 3.1] gdifeng.inc
  338. #define WIN_VERSION 0x0310
  339. #define GDI_VERSION 0x0101
  340. // From [Windows 3.1] gdipfont.inc
  341. #define PF_ENGINE_TYPE 0x03
  342. #define PF_ENCAPSULATED 0x80 // used in FFH.fhType to identify hidden (embedded) font
  343. #define PANDFTYPESHIFT 1
  344. // for embeded fonts
  345. #define PF_TID 0x40 // if set use TID ( WOW apps )
  346. // otherwise use PID ( NT apps )
  347. // From [Windows 3.1] fonteng2.asm
  348. #define DEF_BRK_CHARACTER 0x0201 // default char for all TT fonts
  349. // BITMAP size related macros
  350. // number of bytes in a scan of a monobitmap that actually contain some info
  351. // Note that this is the same as ((((cx) + 7) & ~7) >> 3), the last two bits
  352. // are lost anyway because of >> 3
  353. #define CJ_SCAN(cx) (((cx) + 7) >> 3)
  354. // move this to a common place so we don't have it in multiple places
  355. // given a byte count, compute the minimum 4 byte (DWORD) aligned size (in bytes)
  356. #define ALIGN4(X) (((X) + 3) & ~3)
  357. // size of the whole bimtap, only dword pad the last scan
  358. #define CJ_BMP(cx,cy) ALIGN4(CJ_SCAN(cx) * (cy))
  359. // get the size of GLYPHDATA structure that at the bottom has appended
  360. // a dib format bitmap for the glyph
  361. // Add offsetof(GLYPHDATA,aulBMData[2]) to cjDIB to account for cx and cy
  362. // are stored in aulBMData[0] and aulBMData[1] respectively
  363. #define CJ_GLYPHDATA(cx,cy) (offsetof(GLYPHBITS,aj) + CJ_BMP(cx,cy))