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.

410 lines
11 KiB

  1. //
  2. // Font Handler
  3. //
  4. #ifndef _H_FH
  5. #define _H_FH
  6. //
  7. // This is needed to define LPCOM_ORDER
  8. //
  9. #include <oa.h>
  10. //
  11. // Constants.
  12. //
  13. //
  14. // The sent ID field is set up when we copy fonts to send; if we don't send
  15. // the font we set it to this value:
  16. //
  17. #define FONT_NOT_SENT (-1)
  18. //
  19. // Because a font can match to font ID zero, actually having an explicit
  20. // 'no match' constant acts as an extra 'firewall'. The remote match array
  21. // is of UINTs, so we have to make this constant positive...
  22. //
  23. #define NO_FONT_MATCH (0xffff)
  24. //
  25. // This dummy font id is used instead of a remote ID of 0 when we need to
  26. // distinguish between a remote ID of 0, and a remote ID that on conversion
  27. // to local gives zero.
  28. //
  29. #define DUMMY_FONT_ID 0xFFFF
  30. //
  31. // Font Width Table type.
  32. //
  33. typedef struct tagFHWIDTHTABLE
  34. {
  35. BYTE charWidths[256];
  36. } FHWIDTHTABLE, FAR * PFHWIDTHTABLE;
  37. //
  38. // The local font structure contains the extra info we need for font
  39. // matching; we can't change the NETWORKFONT structure because we have to
  40. // maintain back compatibility
  41. //
  42. // This comment is slight tosh. We can and do change NETWORKFONT (though
  43. // only in a carefully managed way!). The point is that the data outside
  44. // of the Details field is only needed locally - it is not transmitted
  45. // across the wire.
  46. //
  47. // Note that in FH_Init, we do a qsort, which assumes
  48. // that the first thing in the LOCALFONT structure is the facename. So
  49. // bear this in mind if you change it. We assume that the NETWORKFONT
  50. // structure will always start with the facename.
  51. //
  52. typedef struct _LOCALFONT
  53. {
  54. NETWORKFONT Details; // old structure - sent over wire
  55. TSHR_UINT16 lMaxBaselineExt; // max height of this font
  56. char RealName[FH_FACESIZE]; // Real font name
  57. TSHR_UINT32 SupportCode; // font is supported - see below
  58. }
  59. LOCALFONT;
  60. typedef LOCALFONT FAR * LPLOCALFONT;
  61. //
  62. // The following values are set in the SupportCode field of the LOCALFONT
  63. // structure to indicate whether a font is supported in the current
  64. // share. The values are designed to make it easy to calculate the lowest
  65. // common denominator of two support codes (l.c.d. = code1 & code2).
  66. //
  67. // A SupportCode contains the bit flag
  68. // FH_SC_MATCH if it describes any sort of match at all
  69. // FH_SC_ALL_CHARS if the match applies to all characters in the font,
  70. // as opposed to just the ASCII alphanumeric characters
  71. // FH_SC_EXACT if the match is considered exact,
  72. // as opposed to an approximate match
  73. //
  74. //
  75. #define FH_SC_MATCH 1
  76. #define FH_SC_ALL_CHARS 2
  77. #define FH_SC_EXACT 4
  78. //
  79. // Forget it: no viable match.
  80. //
  81. #define FH_SC_NO_MATCH 0
  82. //
  83. // Every char is a good but not exact match.
  84. //
  85. #define FH_SC_APPROX_MATCH (FH_SC_MATCH | FH_SC_ALL_CHARS)
  86. //
  87. // Every char is likely to be an accurate match.
  88. //
  89. #define FH_SC_EXACT_MATCH (FH_SC_MATCH | FH_SC_ALL_CHARS | FH_SC_EXACT)
  90. //
  91. // Chars 20->7F are likely to be an accurate match.
  92. //
  93. #define FH_SC_EXACT_ASCII_MATCH (FH_SC_MATCH | FH_SC_EXACT)
  94. //
  95. // Chars 20->7F are likely to be good but not exact matches.
  96. //
  97. #define FH_SC_APPROX_ASCII_MATCH (FH_SC_MATCH)
  98. //
  99. // Structures and typedefs.
  100. //
  101. // The FONTNAME structure is used for each entry in the array of font
  102. // names.
  103. //
  104. typedef struct tagFONTNAME
  105. {
  106. char szFontName[FH_FACESIZE];
  107. }
  108. FONTNAME;
  109. typedef FONTNAME FAR * LPFONTNAME;
  110. //
  111. // Maximum number of fonts that we can handle at all.
  112. //
  113. #define FH_MAX_FONTS \
  114. (((TSHR_MAX_SEND_PKT - sizeof(FHPACKET)) / sizeof(NETWORKFONT)) + 1 )
  115. //
  116. // Size of index into local font table
  117. //
  118. #define FH_LOCAL_INDEX_SIZE 256
  119. typedef struct tagFHFAMILIES
  120. {
  121. STRUCTURE_STAMP
  122. UINT fhcFamilies;
  123. FONTNAME afhFamilies[FH_MAX_FONTS];
  124. }
  125. FHFAMILIES;
  126. typedef FHFAMILIES FAR * LPFHFAMILIES;
  127. //
  128. // Local font list
  129. //
  130. // NOTE: The font index is an array of bookmarks that indicate the first
  131. // entry in the local font table that starts with a particular character.
  132. // For example, afhFontIndex[65] gives the first index in afhFonts
  133. // that starts with the character 'A'.
  134. //
  135. //
  136. typedef struct tagFHLOCALFONTS
  137. {
  138. STRUCTURE_STAMP
  139. UINT fhNumFonts;
  140. TSHR_UINT16 afhFontIndex[FH_LOCAL_INDEX_SIZE];
  141. LOCALFONT afhFonts[FH_MAX_FONTS];
  142. }
  143. FHLOCALFONTS;
  144. typedef FHLOCALFONTS FAR * LPFHLOCALFONTS;
  145. //
  146. // FUNCTION: FH_GetFaceNameFromLocalHandle
  147. //
  148. // DESCRIPTION:
  149. //
  150. // Given an FH font handle (ie a handle originating from the locally
  151. // supported font structure which was sent to the remote machine at the
  152. // start of the call) this function returns the face name of the font.
  153. //
  154. // PARAMETERS:
  155. //
  156. // fontHandle - font handle being queried.
  157. //
  158. // pFaceNameLength - pointer to variable to receive the length of the face
  159. // name returned.
  160. //
  161. // RETURNS: pointer to face name.
  162. //
  163. //
  164. LPSTR FH_GetFaceNameFromLocalHandle(UINT fontHandle,
  165. LPUINT faceNameLength);
  166. UINT FH_GetMaxHeightFromLocalHandle(UINT fontHandle);
  167. //
  168. // FUNCTION: FH_GetFontFlagsFromLocalHandle
  169. //
  170. // DESCRIPTION:
  171. //
  172. // Given an FH font handle (ie a handle originating from the locally
  173. // supported font structure which was sent to the remote machine at the
  174. // start of the call) this function returns the FontFlags value stored with
  175. // the LOCALFONT details
  176. //
  177. // PARAMETERS:
  178. //
  179. // fontHandle - font handle being queried.
  180. //
  181. // RETURNS: font flags
  182. //
  183. //
  184. UINT FH_GetFontFlagsFromLocalHandle(UINT fontHandle);
  185. //
  186. // FUNCTION: FH_GetCodePageFromLocalHandle
  187. //
  188. // DESCRIPTION:
  189. //
  190. // Given an FH font handle (ie a handle originating from the locally
  191. // supported font structure which was sent to the remote machine at the
  192. // start of the call) this function returns the CharSet value stored with
  193. // the LOCALFONT details
  194. //
  195. // PARAMETERS:
  196. //
  197. // fontHandle - font handle being queried.
  198. //
  199. // RETURNS: CodePage
  200. //
  201. //
  202. UINT FH_GetCodePageFromLocalHandle(UINT fontHandle);
  203. //
  204. // FUNCTION: FH_Init
  205. //
  206. // DESCRIPTION:
  207. //
  208. // This routine finds all the fonts in the local system. It is called from
  209. // USR.
  210. //
  211. // PARAMETERS: VOID
  212. //
  213. // RETURNS: Number of fonts found
  214. //
  215. //
  216. UINT FH_Init(void);
  217. void FH_Term(void);
  218. //
  219. // API FUNCTION: FH_CreateAndSelectFont
  220. //
  221. // DESCRIPTION:
  222. //
  223. // Creates a logical font for the HPS/HDC supplied.
  224. //
  225. // PARAMETERS:
  226. //
  227. // surface - surface to create logical font for.
  228. //
  229. // pHNewFont - pointer to new font handle to use. This is returned.
  230. //
  231. // pHOldFont - pointer to old font handle (which was previously selected
  232. // into the HPS or HDC).
  233. //
  234. // fontName - the facename of the font.
  235. //
  236. // codepage - codepage (though in most case just holds charset)
  237. //
  238. // fontMaxHeight - the max baseline extent of the font. (Do not confuse
  239. // with fontHeight which is the cell height of the font).
  240. //
  241. // fontWidth,fontWeight,fontFlags - take the same values as the equivalent
  242. // fields in a TEXTOUT or EXTTEXTOUT order.
  243. //
  244. // RETURNS: TRUE - success, FALSE - failure.
  245. //
  246. BOOL FH_CreateAndSelectFont(HDC hdc,
  247. HFONT * pHNewFont,
  248. HFONT * pHOldFont,
  249. LPSTR fontName,
  250. UINT codepage,
  251. UINT fontMaxHeight,
  252. UINT fontHeight,
  253. UINT fontWidth,
  254. UINT fontWeight,
  255. UINT fontFlags);
  256. //
  257. // API FUNCTION: FH_DeleteFont
  258. //
  259. // DESCRIPTION:
  260. //
  261. // Deletes/frees the supplied system font handle.
  262. //
  263. // PARAMETERS:
  264. //
  265. // sysFontHandle - system font handle to delete/free
  266. //
  267. // RETURNS:
  268. //
  269. // None
  270. //
  271. void FH_DeleteFont(HFONT hFont);
  272. //
  273. // API FUNCTION: FH_SelectFont
  274. //
  275. // DESCRIPTION:
  276. //
  277. // Selects a font identified by its system font handle into a surface.
  278. //
  279. // PARAMETERS:
  280. //
  281. // surface - the surface to select the font into
  282. // sysFontHandle - system font handle
  283. //
  284. // RETURNS:
  285. //
  286. // None
  287. //
  288. void FH_SelectFont(HDC hdc, HFONT hFont);
  289. void FHAddFontToLocalTable( LPSTR faceName,
  290. TSHR_UINT16 fontFlags,
  291. TSHR_UINT16 codePage,
  292. TSHR_UINT16 maxHeight,
  293. TSHR_UINT16 aveHeight,
  294. TSHR_UINT16 aveWidth,
  295. TSHR_UINT16 aspectX,
  296. TSHR_UINT16 aspectY,
  297. TSHR_UINT16 maxAscent);
  298. void FHConsiderAllLocalFonts(void);
  299. void FHSortAndIndexLocalFonts(void);
  300. int FHComp(LPVOID p1, LPVOID p2);
  301. void FH_qsort(LPVOID base, UINT num, UINT size);
  302. // prototypes UT_qsort routines
  303. void shortsort(char *lo, char *hi, unsigned width);
  304. void swap(char *p, char *q, unsigned int width);
  305. // this parameter defines the cutoff between using quick sort and
  306. // insertion sort for arrays; arrays with lengths shorter or equal to the
  307. // below value use insertion sort
  308. #define CUTOFF 8
  309. BOOL FHGenerateFontWidthTable(PFHWIDTHTABLE pTable,
  310. LPLOCALFONT pFontInfo,
  311. UINT fontHeight,
  312. UINT fontWidth,
  313. UINT fontWeight,
  314. UINT fontFlags,
  315. LPTSHR_UINT16 pMaxAscent);
  316. BOOL FHGetStringSpacing(UINT fontHandle,
  317. UINT fontHeight,
  318. UINT fontWidth,
  319. UINT fontWeight,
  320. UINT fontFlags,
  321. UINT stringLength,
  322. LPSTR string,
  323. LPTSHR_INT16 deltaXArray);
  324. //
  325. // FHCalculateSignatures - see fh.c.
  326. //
  327. void FHCalculateSignatures(PFHWIDTHTABLE pTable,
  328. LPTSHR_INT16 pSigFats,
  329. LPTSHR_INT16 pSigThins,
  330. LPTSHR_INT16 pSigSymbol);
  331. //
  332. // Although wingdi.h defines the first two parameters for an ENUMFONTPROC
  333. // as LOGFONT and TEXTMETRIC (thereby disagreeing with MSDN), tests show
  334. // that the structures are actually as defined in MSDN (i.e. we get valid
  335. // information when accessing the extended fields)
  336. //
  337. int CALLBACK FHEachFontFamily(
  338. const ENUMLOGFONT FAR * enumlogFont,
  339. const NEWTEXTMETRIC FAR * TextMetric,
  340. int FontType,
  341. LPARAM lParam);
  342. int CALLBACK FHEachFont(const ENUMLOGFONT FAR * enumlogFont,
  343. const NEWTEXTMETRIC FAR * TextMetric,
  344. int FontType,
  345. LPARAM lParam);
  346. #endif // _H_FH