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.

427 lines
10 KiB

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