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.

363 lines
11 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: cpanel.cxx
  3. *
  4. * Control panel private entry point(s).
  5. *
  6. * Created: 21-Apr-1992 16:49:18
  7. * Author: Gilman Wong [gilmanw]
  8. *
  9. * Copyright (c) 1992-1999 Microsoft Corporation
  10. *
  11. \**************************************************************************/
  12. #include "precomp.hxx"
  13. /******************************Public*Routine******************************\
  14. * GetFontResourceInfoW
  15. *
  16. * The GetFontResourceInfo copies LOGFONTs, IFIMETRICs, or description
  17. * strings into a return buffer for all the fonts in the specified font
  18. * resource file.
  19. *
  20. * Parameters:
  21. *
  22. * lpFilename
  23. *
  24. * Specifies the filename of the font resource being queried. It
  25. * must be a NULL-terminated ANSI string.
  26. *
  27. * lpBytes
  28. * If lpBytes is 0 upon entry to the function, then the number of
  29. * BYTE's required for the requested information is returned via
  30. * this parameter. The lpBuffer is ignored for this case.
  31. *
  32. * If lpBytes is not 0 upon entry, then it specifies the size of
  33. * the buffer pointed to by lpBuffer. The number of bytes copied
  34. * to the buffer is returned via this parameter upon exit.
  35. *
  36. * lpBuffer
  37. *
  38. * The return buffer into which the requested information is copied.
  39. * If lpBytes is 0, then this parameter is ignored.
  40. *
  41. * iType
  42. *
  43. * Must be one of the following:
  44. *
  45. * GFRI_NUMFONTS
  46. *
  47. * Copy into the return buffer a ULONG containing the
  48. * number of fonts in the font resource file. Caller
  49. * should pass in the address of a ULONG for lpBuffer
  50. * and sizeof(ULONG) for *lpBytes.
  51. *
  52. * GFRI_DESCRIPTION
  53. *
  54. * Copy the font resource's description string into the
  55. * return buffer. This may be a empty string.
  56. *
  57. * GFRI_LOGFONTS
  58. *
  59. * Copy an array of LOGFONTs corresponding to each of the
  60. * fonts in the font resource. Note that the LOGFONTs
  61. * must be returned in the font's NOTIONAL COORDINATES
  62. * since there is no DC specified.
  63. *
  64. * GFRI_ISTRUETYPE
  65. *
  66. * Returns TRUE via lpBuffer if font resource is TrueType.
  67. * FALSE otherwise. All other parameters are ignored.
  68. * Caller should pass in the address of a BOOL for lpBuffer
  69. * and sizeof(BOOL) for *lpBytes.
  70. *
  71. * GFRI_TTFILENAME
  72. *
  73. * Returns the .TTF filename imbedded as a string resource
  74. * in .FOT 16-bit TrueType font files. The filename is
  75. * copied into the lpBuffer. The function returns FALSE
  76. * if a filename could not be extracted.
  77. *
  78. * GFRI_ISREMOVED
  79. *
  80. * Returns TRUE via lpBuffer if the font file is no longer
  81. * in the engine font table (or was never there). FALSE is
  82. * returned via lpBuffer if the font file is still in the
  83. * font table. Caller should pass in the address of a BOOL
  84. * for lpBuffer and sizeof(BOOL for *lpBytes.
  85. *
  86. * Returns:
  87. * TRUE if the function is successful, FALSE otherwise.
  88. *
  89. * Comments:
  90. * This function is intended as a private entry point for Control Panel.
  91. *
  92. * History:
  93. * 2-Sep-1993 -by- Gerrit van Wingerden [gerritv]
  94. * Turned it into a "W" function.
  95. *
  96. * 15-Jul-1991 -by- Gilman Wong [gilmanw]
  97. * Wrote it.
  98. \**************************************************************************/
  99. BOOL GetFontResourceInfoInternalW(
  100. LPWSTR lpFilename,
  101. ULONG cwc,
  102. ULONG cFiles,
  103. UINT cjIn,
  104. PSIZE_T lpBytes,
  105. LPVOID lpBuffer,
  106. DWORD iType)
  107. {
  108. BOOL bRet = FALSE;
  109. PFF *pPFF;
  110. // Stabilize public PFT.
  111. SEMOBJ so(ghsemPublicPFT);
  112. // Create and validate user object for public PFT.
  113. PUBLIC_PFTOBJ pfto;
  114. ASSERTGDI(pfto.bValid(), "How could it not be valid");
  115. // Find the correct PFF.
  116. if (pPFF = pfto.pPFFGet(lpFilename, cwc, cFiles, NULL, 0))
  117. {
  118. PFFOBJ pffo(pPFF);
  119. ASSERTGDI (
  120. pffo.bValid(),
  121. "gdisrv!GetFontResourceInfoInternal(): bad HPFF handle\n"
  122. );
  123. {
  124. // What info is requested?
  125. switch (iType)
  126. {
  127. case GFRI_NUMFONTS:
  128. // Is there a buffer?
  129. if (cjIn)
  130. {
  131. // If buffer big enough, return the count of fonts.
  132. if ( cjIn >= sizeof(ULONG) )
  133. *((PULONG) lpBuffer) = pffo.cFonts();
  134. else
  135. return bRet;
  136. }
  137. // In either case, return size of ULONG.
  138. *((SIZE_T *) lpBytes) = sizeof(ULONG);
  139. bRet = TRUE;
  140. break;
  141. case GFRI_DESCRIPTION:
  142. {
  143. ULONG cjRet;
  144. PDEVOBJ pdo(pPFF->hdev);
  145. cjRet = pdo.QueryFontFile(
  146. (ULONG_PTR) pPFF->hff,
  147. QFF_DESCRIPTION,
  148. 0,
  149. (PULONG) NULL);
  150. if (cjRet != FD_ERROR )
  151. {
  152. //
  153. // If buffer exists, we need to copy into it.
  154. //
  155. if (cjIn)
  156. {
  157. //
  158. // Get description string in UNICODE.
  159. //
  160. if (cjRet <= cjIn)
  161. {
  162. cjRet = pdo.QueryFontFile(
  163. (ULONG_PTR) pPFF->hff,
  164. QFF_DESCRIPTION,
  165. cjIn,
  166. (PULONG) lpBuffer);
  167. }
  168. else
  169. {
  170. // the buffer passed in is not big enough to contain the description for that font
  171. cjRet = FD_ERROR;
  172. }
  173. }
  174. }
  175. if (cjRet != FD_ERROR )
  176. {
  177. //
  178. // Return size (byte count) of description string.
  179. //
  180. *((SIZE_T *) lpBytes) = (SIZE_T) cjRet;
  181. bRet = TRUE;
  182. }
  183. }
  184. break;
  185. case GFRI_LOGFONTS:
  186. if (cjIn == 0)
  187. *((SIZE_T *) lpBytes) = (SIZE_T) pffo.cFonts() * sizeof(LOGFONTW);
  188. else
  189. {
  190. PLOGFONTW plf = (PLOGFONTW) lpBuffer; // LOGFONTW ptr into lpBuffer
  191. ULONG iFont; // index to font
  192. SIZE_T cjCopy = 0; // bytes copied
  193. // Make sure buffer is big enough.
  194. if (cjIn < (pffo.cFonts() * sizeof(LOGFONTW)))
  195. {
  196. WARNING("gdisrv!GetFontResourceInfoInternal(): buffer too small\n");
  197. return bRet;
  198. }
  199. // Run the list of PFEs.
  200. for (iFont=0; iFont<pffo.cFonts(); iFont++)
  201. {
  202. PFEOBJ pfeo(pffo.ppfe(iFont));
  203. ASSERTGDI (
  204. pfeo.bValid(),
  205. "gdisrv!GetFontResourceInfoInternal(): bad HPFE handle\n"
  206. );
  207. // If data converted to LOGFONTW, increment size and
  208. // move pointer to next.
  209. vIFIMetricsToLogFontW(plf, pfeo.pifi());
  210. cjCopy += sizeof(*plf);
  211. plf++;
  212. }
  213. *((SIZE_T *) lpBytes) = (SIZE_T) cjCopy;
  214. }
  215. bRet = TRUE;
  216. break;
  217. case GFRI_ISTRUETYPE:
  218. // Is there a buffer?
  219. if (cjIn)
  220. {
  221. // If buffer not NULL, return the BOOL.
  222. if ( (lpBuffer != (LPVOID) NULL) && (cjIn >= sizeof(BOOL)) )
  223. *((BOOL *) lpBuffer) = (pffo.hdev() == (HDEV) gppdevTrueType);
  224. else
  225. return bRet;
  226. }
  227. // In either case, return size of ULONG.
  228. *((SIZE_T *) lpBytes) = sizeof(BOOL);
  229. bRet = TRUE;
  230. break;
  231. case GFRI_ISREMOVED:
  232. // We found the font file and we are in GFRI_ISREMOVED mode, that
  233. // means we should return a FALSE boolean signifying that the font
  234. // is still present in the system (i.e., the load count is still
  235. // non-zero for this font file).
  236. // Is there a buffer?
  237. if (cjIn)
  238. {
  239. // If buffer not NULL, return the BOOL.
  240. if ( (lpBuffer != (LPVOID) NULL) && (cjIn >= sizeof(BOOL)) )
  241. *((BOOL *) lpBuffer) = FALSE;
  242. else
  243. return bRet;
  244. }
  245. // In either case, return size of ULONG.
  246. *((SIZE_T *) lpBytes) = sizeof(BOOL);
  247. bRet = TRUE;
  248. break;
  249. default:
  250. WARNING("gdisrv!GetFontResourceInfoInternal(): unknown query type\n");
  251. SAVE_ERROR_CODE(ERROR_INVALID_PARAMETER);
  252. break; // bRet is FALSE
  253. } /* switch */
  254. // Ich bin "outahere"!
  255. return bRet;
  256. } /* if */
  257. } /* for */
  258. // Couldn't find the font file in the public PFT. If we are in GFRI_ISREMOVED
  259. // mode, that means we should return a TRUE boolean signifying that the font
  260. // if no longer (or was never) added to the system.
  261. if ( iType == GFRI_ISREMOVED )
  262. {
  263. // Is there a buffer?
  264. if (cjIn)
  265. {
  266. // If buffer not NULL, return the BOOL.
  267. if ( (lpBuffer != (LPVOID) NULL) && (cjIn >= sizeof(BOOL)) )
  268. *((BOOL *) lpBuffer) = TRUE;
  269. else
  270. return bRet;
  271. }
  272. // In either case, return size of ULONG.
  273. *((SIZE_T *) lpBytes) = sizeof(BOOL);
  274. bRet = TRUE;
  275. }
  276. #if DBG
  277. // If not in GFRI_ISREMOVED mode, then this is a problem. Why were we not able
  278. // to find the font in the table. Lets alert the debugger.
  279. if ( iType != GFRI_ISREMOVED )
  280. {
  281. DbgPrint("gdisrv!GetFontResourceInfoInternal(): no entry found for %s\n", lpFilename);
  282. }
  283. #endif
  284. // Ich bin "outahere"!
  285. return bRet;
  286. }