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.

474 lines
12 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: fontfile.c *
  3. * *
  4. * Contains exported font driver entry points and memory allocation/locking *
  5. * methods from engine's handle manager. Adapted from BodinD's bitmap font *
  6. * driver. *
  7. * *
  8. * Copyright (c) 1993-1995 Microsoft Corporation *
  9. \**************************************************************************/
  10. #include "fd.h"
  11. HSEMAPHORE ghsemVTFD;
  12. VOID vVtfdMarkFontGone(FONTFILE *pff, DWORD iExceptionCode)
  13. {
  14. ASSERTDD(pff, "vVtfdMarkFontGone, pff\n");
  15. // this font has disappeared, probably net failure or somebody pulled the
  16. // floppy with vt file out of the floppy drive
  17. if (iExceptionCode == STATUS_IN_PAGE_ERROR) // file disappeared
  18. {
  19. // prevent any further queries about this font:
  20. pff->fl |= FF_EXCEPTION_IN_PAGE_ERROR;
  21. if ((pff->iType == TYPE_FNT) || (pff->iType == TYPE_DLL16))
  22. {
  23. EngUnmapFontFileFD(pff->iFile);
  24. }
  25. }
  26. if (iExceptionCode == STATUS_ACCESS_VIOLATION)
  27. {
  28. RIP("VTFD!this is probably a buggy vector font file\n");
  29. }
  30. }
  31. BOOL bvtfdMapFontFileFD(PFONTFILE pff)
  32. {
  33. return (pff ? (EngMapFontFileFD(pff->iFile, (PULONG*)&pff->pvView, &pff->cjView))
  34. : FALSE);
  35. }
  36. /******************************Public*Routine******************************\
  37. *
  38. * vtfdQueryFontDataTE, try except wrapper
  39. *
  40. * Effects:
  41. *
  42. * Warnings:
  43. *
  44. * History:
  45. * 04-Apr-1993 -by- Bodin Dresevic [BodinD]
  46. * Wrote it.
  47. \**************************************************************************/
  48. LONG vtfdQueryFontDataTE (
  49. DHPDEV dhpdev,
  50. FONTOBJ *pfo,
  51. ULONG iMode,
  52. HGLYPH hg,
  53. GLYPHDATA *pgd,
  54. PVOID pv,
  55. ULONG cjSize
  56. )
  57. {
  58. LONG lRet = FD_ERROR;
  59. if (bvtfdMapFontFileFD((PFONTFILE)pfo->iFile))
  60. {
  61. EngAcquireSemaphore(ghsemVTFD);
  62. #ifndef VTFD_NO_TRY_EXCEPT
  63. try
  64. {
  65. #endif
  66. lRet = vtfdQueryFontData (
  67. pfo,
  68. iMode,
  69. hg,
  70. pgd,
  71. pv,
  72. cjSize
  73. );
  74. #ifndef VTFD_NO_TRY_EXCEPT
  75. }
  76. except (EXCEPTION_EXECUTE_HANDLER)
  77. {
  78. WARNING("exception in vtfdQueryFontDataTE \n");
  79. vVtfdMarkFontGone((FONTFILE *)pfo->iFile, GetExceptionCode());
  80. }
  81. #endif
  82. EngReleaseSemaphore(ghsemVTFD);
  83. EngUnmapFontFileFD(PFF(pfo->iFile)->iFile);
  84. }
  85. return lRet;
  86. }
  87. /******************************Public*Routine******************************\
  88. *
  89. * HFF vtfdLoadFontFileTE, try except wrapper
  90. *
  91. *
  92. * History:
  93. * 05-Apr-1993 -by- Bodin Dresevic [BodinD]
  94. * Wrote it.
  95. \**************************************************************************/
  96. ULONG ExceptionFilter_VtfdLoadFontFile(PEXCEPTION_POINTERS ExceptionPointers)
  97. {
  98. #if DBG
  99. const static char Function[] = __FUNCTION__;
  100. ULONG ExceptionCode;
  101. ExceptionCode = ExceptionPointers->ExceptionRecord->ExceptionCode;
  102. if (ExceptionCode != STATUS_IN_PAGE_ERROR)
  103. {
  104. VtfdDebugPrint(
  105. "%s: .exr %p\n%s: .cxr %p\n",
  106. Function,
  107. ExceptionPointers->ExceptionRecord,
  108. Function,
  109. ExceptionPointers->ContextRecord
  110. );
  111. ASSERTDD(ExceptionCode == STATUS_IN_PAGE_ERROR,
  112. "vtfdLoadFontFile, strange exception code\n");
  113. }
  114. #endif
  115. return EXCEPTION_EXECUTE_HANDLER;
  116. }
  117. HFF vtfdLoadFontFileTE(
  118. ULONG cFiles,
  119. ULONG_PTR *piFile,
  120. PVOID *ppvView,
  121. ULONG *pcjView,
  122. DESIGNVECTOR *pdv,
  123. ULONG ulLangId,
  124. ULONG ulFastCheckSum
  125. )
  126. {
  127. HFF hff = (HFF)NULL;
  128. ULONG_PTR iFile;
  129. PVOID pvView;
  130. ULONG cjView;
  131. BOOL bRet;
  132. if ((cFiles != 1) || pdv)
  133. return hff;
  134. iFile = *piFile;
  135. pvView = *ppvView;
  136. cjView = *pcjView;
  137. EngAcquireSemaphore(ghsemVTFD);
  138. #ifndef VTFD_NO_TRY_EXCEPT
  139. try
  140. {
  141. #endif
  142. bRet = vtfdLoadFontFile(iFile, pvView, cjView, &hff);
  143. if (!bRet)
  144. {
  145. ASSERTDD(hff == (HFF)NULL, "vtfdLoadFontFile, hff != NULL\n");
  146. }
  147. #ifndef VTFD_NO_TRY_EXCEPT
  148. }
  149. except (ExceptionFilter_VtfdLoadFontFile(GetExceptionInformation()))
  150. {
  151. WARNING("exception in vtfdLoadFontFile \n");
  152. // if the file disappeared after mem was allocated, free the mem
  153. if (hff)
  154. {
  155. vFree(hff);
  156. hff = (HFF) NULL;
  157. }
  158. }
  159. #endif
  160. EngReleaseSemaphore(ghsemVTFD);
  161. return hff;
  162. }
  163. /******************************Public*Routine******************************\
  164. *
  165. * BOOL vtfdUnloadFontFileTE , try/except wrapper
  166. *
  167. *
  168. * History:
  169. * 05-Apr-1993 -by- Bodin Dresevic [BodinD]
  170. * Wrote it.
  171. \**************************************************************************/
  172. BOOL vtfdUnloadFontFileTE (HFF hff)
  173. {
  174. BOOL bRet;
  175. EngAcquireSemaphore(ghsemVTFD);
  176. #ifndef VTFD_NO_TRY_EXCEPT
  177. try
  178. {
  179. #endif
  180. bRet = vtfdUnloadFontFile(hff);
  181. #ifndef VTFD_NO_TRY_EXCEPT
  182. }
  183. except (EXCEPTION_EXECUTE_HANDLER)
  184. {
  185. WARNING("exception in vtfdUnloadFontFile\n");
  186. bRet = FALSE;
  187. }
  188. #endif
  189. EngReleaseSemaphore(ghsemVTFD);
  190. return bRet;
  191. }
  192. /******************************Public*Routine******************************\
  193. *
  194. * LONG vtfdQueryFontFileTE, try/except wrapper
  195. *
  196. * History:
  197. * 05-Apr-1993 -by- Bodin Dresevic [BodinD]
  198. * Wrote it.
  199. \**************************************************************************/
  200. LONG vtfdQueryFontFileTE (
  201. HFF hff, // handle to font file
  202. ULONG ulMode, // type of query
  203. ULONG cjBuf, // size of buffer (in BYTEs)
  204. PULONG pulBuf // return buffer (NULL if requesting size of data)
  205. )
  206. {
  207. LONG lRet = FD_ERROR;
  208. if ((ulMode != QFF_DESCRIPTION) ||
  209. bvtfdMapFontFileFD(PFF(hff)))
  210. {
  211. EngAcquireSemaphore(ghsemVTFD);
  212. #ifndef VTFD_NO_TRY_EXCEPT
  213. try
  214. {
  215. #endif
  216. lRet = vtfdQueryFontFile (hff,ulMode, cjBuf,pulBuf);
  217. #ifndef VTFD_NO_TRY_EXCEPT
  218. }
  219. except (EXCEPTION_EXECUTE_HANDLER)
  220. {
  221. WARNING("exception in vtfdQueryFontFile\n");
  222. vVtfdMarkFontGone((FONTFILE *)hff, GetExceptionCode());
  223. }
  224. #endif
  225. EngReleaseSemaphore(ghsemVTFD);
  226. if (ulMode == QFF_DESCRIPTION)
  227. {
  228. EngUnmapFontFileFD(PFF(hff)->iFile);
  229. }
  230. }
  231. return lRet;
  232. }
  233. /******************************Public*Routine******************************\
  234. *
  235. * BOOL vtfdQueryAdvanceWidthsTE, try/except wrapper
  236. *
  237. * History:
  238. * 05-Apr-1993 -by- Bodin Dresevic [BodinD]
  239. * Wrote it.
  240. \**************************************************************************/
  241. BOOL vtfdQueryAdvanceWidthsTE
  242. (
  243. DHPDEV dhpdev,
  244. FONTOBJ *pfo,
  245. ULONG iMode,
  246. HGLYPH *phg,
  247. LONG *plWidths,
  248. ULONG cGlyphs
  249. )
  250. {
  251. BOOL bRet = FD_ERROR;
  252. if ((iMode <= QAW_GETEASYWIDTHS) &&
  253. bvtfdMapFontFileFD((PFONTFILE)pfo->iFile))
  254. {
  255. EngAcquireSemaphore(ghsemVTFD);
  256. #ifndef VTFD_NO_TRY_EXCEPT
  257. try
  258. {
  259. #endif
  260. bRet = vtfdQueryAdvanceWidths (pfo,iMode, phg, plWidths, cGlyphs);
  261. #ifndef VTFD_NO_TRY_EXCEPT
  262. }
  263. except (EXCEPTION_EXECUTE_HANDLER)
  264. {
  265. WARNING("exception in vtfdQueryAdvanceWidths \n");
  266. vVtfdMarkFontGone((FONTFILE *)pfo->iFile, GetExceptionCode());
  267. }
  268. #endif
  269. EngReleaseSemaphore(ghsemVTFD);
  270. EngUnmapFontFileFD(PFF(pfo->iFile)->iFile);
  271. }
  272. return bRet;
  273. }
  274. /******************************Public*Routine******************************\
  275. * DHPDEV DrvEnablePDEV
  276. *
  277. * Initializes a bunch of fields for GDI
  278. *
  279. \**************************************************************************/
  280. DHPDEV
  281. vtfdEnablePDEV(
  282. DEVMODEW* pdm,
  283. PWSTR pwszLogAddr,
  284. ULONG cPat,
  285. HSURF* phsurfPatterns,
  286. ULONG cjCaps,
  287. ULONG* pdevcaps,
  288. ULONG cjDevInfo,
  289. DEVINFO* pdi,
  290. HDEV hdev,
  291. PWSTR pwszDeviceName,
  292. HANDLE hDriver)
  293. {
  294. PVOID* ppdev;
  295. //
  296. // Allocate a four byte PDEV for now
  297. // We can grow it if we ever need to put information in it.
  298. //
  299. ppdev = (PVOID*) EngAllocMem(0, sizeof(PVOID), 'dftV');
  300. return ((DHPDEV) ppdev);
  301. }
  302. /******************************Public*Routine******************************\
  303. * DrvDisablePDEV
  304. *
  305. * Release the resources allocated in DrvEnablePDEV. If a surface has been
  306. * enabled DrvDisableSurface will have already been called.
  307. *
  308. \**************************************************************************/
  309. VOID
  310. vtfdDisablePDEV(
  311. DHPDEV dhpdev)
  312. {
  313. EngFreeMem(dhpdev);
  314. }
  315. /******************************Public*Routine******************************\
  316. * VOID DrvCompletePDEV
  317. *
  318. * Store the HPDEV, the engines handle for this PDEV, in the DHPDEV.
  319. *
  320. \**************************************************************************/
  321. VOID
  322. vtfdCompletePDEV(
  323. DHPDEV dhpdev,
  324. HDEV hdev)
  325. {
  326. return;
  327. }
  328. // The driver function table with all function index/address pairs
  329. DRVFN gadrvfnVTFD[] =
  330. {
  331. { INDEX_DrvEnablePDEV, (PFN) vtfdEnablePDEV, },
  332. { INDEX_DrvDisablePDEV, (PFN) vtfdDisablePDEV, },
  333. { INDEX_DrvCompletePDEV, (PFN) vtfdCompletePDEV, },
  334. { INDEX_DrvQueryFont, (PFN) vtfdQueryFont, },
  335. { INDEX_DrvQueryFontTree, (PFN) vtfdQueryFontTree, },
  336. { INDEX_DrvQueryFontData, (PFN) vtfdQueryFontDataTE, },
  337. { INDEX_DrvDestroyFont, (PFN) vtfdDestroyFont, },
  338. { INDEX_DrvQueryFontCaps, (PFN) vtfdQueryFontCaps, },
  339. { INDEX_DrvLoadFontFile, (PFN) vtfdLoadFontFileTE, },
  340. { INDEX_DrvUnloadFontFile, (PFN) vtfdUnloadFontFileTE, },
  341. { INDEX_DrvQueryFontFile, (PFN) vtfdQueryFontFileTE, },
  342. { INDEX_DrvQueryAdvanceWidths , (PFN) vtfdQueryAdvanceWidthsTE }
  343. };
  344. /******************************Public*Routine******************************\
  345. * vtfdEnableDriver
  346. *
  347. * Enables the driver by retrieving the drivers function table and version.
  348. *
  349. * Sun 25-Apr-1993 -by- Patrick Haluptzok [patrickh]
  350. * Change to be same as DDI Enable.
  351. *
  352. * History:
  353. * 12-Dec-1990 -by- Bodin Dresevic [BodinD]
  354. * Wrote it.
  355. \**************************************************************************/
  356. BOOL vtfdEnableDriver(
  357. ULONG iEngineVersion,
  358. ULONG cj,
  359. PDRVENABLEDATA pded)
  360. {
  361. // Engine Version is passed down so future drivers can support previous
  362. // engine versions. A next generation driver can support both the old
  363. // and new engine conventions if told what version of engine it is
  364. // working with. For the first version the driver does nothing with it.
  365. iEngineVersion;
  366. if ((ghsemVTFD = EngCreateSemaphore()) == (HSEMAPHORE) 0)
  367. {
  368. return(FALSE);
  369. }
  370. pded->pdrvfn = gadrvfnVTFD;
  371. pded->c = sizeof(gadrvfnVTFD) / sizeof(DRVFN);
  372. pded->iDriverVersion = DDI_DRIVER_VERSION_NT5;
  373. return(TRUE);
  374. }
  375. #if DBG
  376. VOID
  377. VtfdDebugPrint(
  378. PCHAR DebugMessage,
  379. ...
  380. )
  381. {
  382. va_list ap;
  383. va_start(ap, DebugMessage);
  384. EngDebugPrint("VTFD: ", DebugMessage, ap);
  385. va_end(ap);
  386. }
  387. #endif