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.

486 lines
16 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: atmstub.c
  3. *
  4. * Copyright (c) 1998-1999 Microsoft Corporation
  5. \**************************************************************************/
  6. #include "engine.h"
  7. #include "atmstub.h"
  8. #define ARRAYSIZE(a) (sizeof(a) / sizeof(*(a)))
  9. #define ESC_NOT_SUPPORTED 0
  10. #define ESC_IS_SUPPORTED 1
  11. #define BEG_OF_ATM_ESCAPE_LIST 0x2500
  12. #define END_OF_ATM_ESCAPE_LIST 0x2600 //Allocated 256 escapes to ATM.
  13. DRVFN atmfdCallBlock[] =
  14. {
  15. {INDEX_DrvEnablePDEV, (PFN)atmfdEnablePDEV},
  16. {INDEX_DrvDisablePDEV, (PFN)atmfdDisablePDEV},
  17. {INDEX_DrvCompletePDEV, (PFN)atmfdCompletePDEV},
  18. {INDEX_DrvLoadFontFile, (PFN)atmfdLoadFontFile},
  19. {INDEX_DrvQueryFontCaps, (PFN)atmfdQueryFontCaps},
  20. {INDEX_DrvUnloadFontFile, (PFN)atmfdUnloadFontFile},
  21. {INDEX_DrvQueryFontFile, (PFN)atmfdQueryFontFile},
  22. {INDEX_DrvQueryFont, (PFN)atmfdQueryFont},
  23. {INDEX_DrvFree, (PFN)atmfdFree},
  24. {INDEX_DrvQueryFontTree, (PFN)atmfdQueryFontTree},
  25. {INDEX_DrvQueryFontData, (PFN)atmfdQueryFontData},
  26. {INDEX_DrvDestroyFont, (PFN)atmfdDestroyFont},
  27. {INDEX_DrvQueryAdvanceWidths, (PFN)atmfdQueryAdvanceWidths},
  28. {INDEX_DrvQueryTrueTypeOutline, (PFN)atmfdQueryTrueTypeOutline},
  29. {INDEX_DrvQueryTrueTypeTable, (PFN)atmfdQueryTrueTypeTable},
  30. {INDEX_DrvEscape, (PFN)atmfdEscape},
  31. {INDEX_DrvFontManagement, (PFN)atmfdFontManagement},
  32. {INDEX_DrvGetTrueTypeFile, (PFN)atmfdGetTrueTypeFile},
  33. {INDEX_DrvQueryGlyphAttrs, (PFN)atmfdQueryGlyphAttrs},
  34. };
  35. UINT ARRAYSIZE_atmfdCallBlock = ARRAYSIZE(atmfdCallBlock);
  36. //Typedefs for functions pointers...
  37. typedef BOOL (APIENTRY *DRV_ENABLE_DRIVER)(ULONG, ULONG, PDRVENABLEDATA);
  38. typedef LONG (APIENTRY *DRV_QUERY_FONT_CAPS)(ULONG, PULONG);
  39. typedef BOOL (APIENTRY *DRV_UNLOAD_FONT_FILE)(ULONG_PTR);
  40. typedef LONG (APIENTRY *DRV_QUERY_FONT_FILE)(ULONG_PTR, ULONG, ULONG, PULONG);
  41. typedef PIFIMETRICS (APIENTRY *DRV_QUERY_FONT)(DHPDEV, ULONG_PTR, ULONG, ULONG_PTR*);
  42. typedef VOID (APIENTRY *DRV_FREE)(PVOID, ULONG_PTR);
  43. typedef PVOID (APIENTRY *DRV_QUERY_FONT_TREE)(DHPDEV, ULONG_PTR, ULONG, ULONG, ULONG_PTR*);
  44. typedef LONG (APIENTRY *DRV_QUERY_FONT_DATA)(DHPDEV, FONTOBJ*, ULONG, HGLYPH, GLYPHDATA*, PVOID, ULONG);
  45. typedef VOID (APIENTRY *DRV_DESTROY_FONT)(FONTOBJ*);
  46. typedef BOOL (APIENTRY *DRV_QUERY_ADVANCE_WIDTHS)(DHPDEV, FONTOBJ*, ULONG, PHGLYPH, PVOID, ULONG);
  47. typedef LONG (APIENTRY *DRV_QUERY_TRUE_TYPE_OUTLINE)(DHPDEV, FONTOBJ*, HGLYPH, BOOL, GLYPHDATA*, ULONG, TTPOLYGONHEADER*);
  48. typedef ULONG (APIENTRY *DRV_ESCAPE)(SURFOBJ*, ULONG, ULONG, PVOID, ULONG, PVOID);
  49. typedef ULONG (APIENTRY *DRV_FONT_MANAGEMENT)(SURFOBJ*, FONTOBJ*, ULONG, ULONG, PVOID, ULONG, PVOID);
  50. typedef PVOID (APIENTRY *DRV_GET_TRUE_TYPE_FILE)(ULONG_PTR, PULONG);
  51. typedef ULONG_PTR (APIENTRY *DRV_LOAD_FONT_FILE)(ULONG, PULONG_PTR, PVOID*, PULONG, PDESIGNVECTOR, ULONG, ULONG);
  52. typedef LONG (APIENTRY *DRV_QUERY_TRUE_TYPE_TABLE)(ULONG_PTR, ULONG, ULONG, PTRDIFF, ULONG, PBYTE, PBYTE*, PULONG);
  53. typedef PFD_GLYPHATTR (APIENTRY *DRV_QUERY_GLYPH_ATTRS)(FONTOBJ*, ULONG);
  54. //Globals...
  55. //Function pointers....
  56. DRV_ENABLE_DRIVER pAtmfdEnableDriver = NULL;
  57. DRV_LOAD_FONT_FILE pAtmfdLoadFontFile = NULL;
  58. DRV_UNLOAD_FONT_FILE pAtmfdUnloadFontFile = NULL;
  59. DRV_QUERY_FONT_FILE pAtmfdQueryFontFile = NULL;
  60. DRV_QUERY_FONT pAtmfdQueryFont = NULL;
  61. DRV_FREE pAtmfdFree = NULL;
  62. DRV_QUERY_FONT_TREE pAtmfdQueryFontTree = NULL;
  63. DRV_QUERY_FONT_DATA pAtmfdQueryFontData = NULL;
  64. DRV_DESTROY_FONT pAtmfdDestroyFont = NULL;
  65. DRV_QUERY_ADVANCE_WIDTHS pAtmfdQueryAdvanceWidths = NULL;
  66. DRV_QUERY_TRUE_TYPE_OUTLINE pAtmfdQueryTrueTypeOutline = NULL;
  67. DRV_QUERY_TRUE_TYPE_TABLE pAtmfdQueryTrueTypeTable = NULL;
  68. DRV_ESCAPE pAtmfdEscape = NULL;
  69. DRV_FONT_MANAGEMENT pAtmfdFontManagement = NULL;
  70. DRV_GET_TRUE_TYPE_FILE pAtmfdGetTrueTypeFile = NULL;
  71. DRV_QUERY_GLYPH_ATTRS pAtmfdQueryGlyphAttrs = NULL;
  72. HANDLE atmfdHandle = NULL;
  73. BOOL driverFailedLoad = FALSE;
  74. ULONG engineVersion = 0;
  75. DRVENABLEDATA atmfdFuncData = {0};
  76. //------------------------------------------------------------------------------
  77. static PVOID FindFunc(
  78. ULONG funcIndex)
  79. {
  80. PVOID result = NULL;
  81. UINT i;
  82. for (i = 0; i < ARRAYSIZE_atmfdCallBlock; i++)
  83. {
  84. if (atmfdFuncData.pdrvfn[i].iFunc == funcIndex)
  85. {
  86. result = (PVOID)atmfdFuncData.pdrvfn[i].pfn;
  87. break;
  88. }
  89. }
  90. return result;
  91. }
  92. //------------------------------------------------------------------------------
  93. static BOOL InitializeDriver(void)
  94. {
  95. BOOL result = FALSE;
  96. GreAcquireSemaphore(ghsemAtmfdInit);
  97. //Has the driver already been loaded?
  98. if (atmfdHandle != NULL)
  99. {
  100. result = TRUE;
  101. goto ExitPoint;
  102. }
  103. //Have we attempted to load the driver previously but failed?
  104. if (driverFailedLoad == TRUE)
  105. goto ExitPoint;
  106. //Load an image of the ATM font driver...
  107. if ((atmfdHandle = EngLoadImage(L"ATMFD.DLL")) == NULL)
  108. goto ExitPoint;
  109. //Get a pointer to the DrvEnableDriver function...
  110. if ((pAtmfdEnableDriver = EngFindImageProcAddress(atmfdHandle, "DrvEnableDriver")) == NULL)
  111. goto ExitPoint;
  112. //Initialize the ATMFD driver...
  113. if ((*pAtmfdEnableDriver)(engineVersion, sizeof(atmfdFuncData), &atmfdFuncData) == FALSE)
  114. goto ExitPoint;
  115. //Check driver version number...
  116. if (atmfdFuncData.iDriverVersion != DDI_DRIVER_VERSION_NT5)
  117. goto ExitPoint;
  118. //Now get the rest of the function pointers...
  119. if ((pAtmfdLoadFontFile = FindFunc(INDEX_DrvLoadFontFile)) == NULL)
  120. goto ExitPoint;
  121. if ((pAtmfdUnloadFontFile = FindFunc(INDEX_DrvUnloadFontFile)) == NULL)
  122. goto ExitPoint;
  123. if ((pAtmfdQueryFontFile = FindFunc(INDEX_DrvQueryFontFile)) == NULL)
  124. goto ExitPoint;
  125. if ((pAtmfdQueryFont = FindFunc(INDEX_DrvQueryFont)) == NULL)
  126. goto ExitPoint;
  127. if ((pAtmfdFree = FindFunc(INDEX_DrvFree)) == NULL)
  128. goto ExitPoint;
  129. if ((pAtmfdQueryFontTree = FindFunc(INDEX_DrvQueryFontTree)) == NULL)
  130. goto ExitPoint;
  131. if ((pAtmfdQueryFontData = FindFunc(INDEX_DrvQueryFontData)) == NULL)
  132. goto ExitPoint;
  133. if ((pAtmfdDestroyFont = FindFunc(INDEX_DrvDestroyFont)) == NULL)
  134. goto ExitPoint;
  135. if ((pAtmfdQueryAdvanceWidths = FindFunc(INDEX_DrvQueryAdvanceWidths)) == NULL)
  136. goto ExitPoint;
  137. if ((pAtmfdQueryTrueTypeOutline = FindFunc(INDEX_DrvQueryTrueTypeOutline)) == NULL)
  138. goto ExitPoint;
  139. if ((pAtmfdQueryTrueTypeTable = FindFunc(INDEX_DrvQueryTrueTypeTable)) == NULL)
  140. goto ExitPoint;
  141. if ((pAtmfdEscape = FindFunc(INDEX_DrvEscape)) == NULL)
  142. goto ExitPoint;
  143. if ((pAtmfdFontManagement = FindFunc(INDEX_DrvFontManagement)) == NULL)
  144. goto ExitPoint;
  145. if ((pAtmfdGetTrueTypeFile = FindFunc(INDEX_DrvGetTrueTypeFile)) == NULL)
  146. goto ExitPoint;
  147. if ((pAtmfdQueryGlyphAttrs = FindFunc(INDEX_DrvQueryGlyphAttrs)) == NULL)
  148. goto ExitPoint;
  149. result = TRUE;
  150. ExitPoint:
  151. if (result == FALSE)
  152. {
  153. driverFailedLoad = TRUE;
  154. if (atmfdHandle != NULL)
  155. {
  156. EngUnloadImage(atmfdHandle);
  157. atmfdHandle = NULL;
  158. }
  159. }
  160. GreReleaseSemaphore(ghsemAtmfdInit);
  161. return result;
  162. }
  163. //------------------------------------------------------------------------------
  164. BOOL APIENTRY atmfdEnableDriver(
  165. ULONG iEngineVersion,
  166. ULONG cj,
  167. PDRVENABLEDATA pded)
  168. // Requests that the driver fill a structure with pointers to supported
  169. // functions and other control information. The function returns TRUE if
  170. // the driver is enabled FALSE otherwise.
  171. {
  172. engineVersion = iEngineVersion;
  173. if (cj >= sizeof(DRVENABLEDATA))
  174. {
  175. pded->pdrvfn = atmfdCallBlock;
  176. pded->c = ARRAYSIZE_atmfdCallBlock;
  177. pded->iDriverVersion = DDI_DRIVER_VERSION_NT5;
  178. return TRUE;
  179. }
  180. return FALSE;
  181. }
  182. //------------------------------------------------------------------------------
  183. VOID APIENTRY atmfdDisableDriver(void)
  184. {
  185. if (atmfdHandle)
  186. {
  187. EngUnloadImage(atmfdHandle);
  188. atmfdHandle = NULL;
  189. }
  190. }
  191. //------------------------------------------------------------------------------
  192. DHPDEV APIENTRY atmfdEnablePDEV(
  193. DEVMODEW* pdm,
  194. PWSTR pwszLogAddr,
  195. ULONG cPat,
  196. HSURF* phsurfPatterns,
  197. ULONG cjCaps,
  198. ULONG* pdevcaps,
  199. ULONG cjDevInfo,
  200. DEVINFO* pdi,
  201. HDEV hdev,
  202. PWSTR pwszDeviceName,
  203. HANDLE hDriver)
  204. {
  205. return ((DHPDEV) EngAllocMem(FL_ZERO_MEMORY, 4, 'AerG'));
  206. }
  207. //------------------------------------------------------------------------------
  208. VOID APIENTRY atmfdDisablePDEV(
  209. DHPDEV dhpdev)
  210. {
  211. EngFreeMem(dhpdev);
  212. }
  213. //------------------------------------------------------------------------------
  214. VOID APIENTRY atmfdCompletePDEV(
  215. DHPDEV dhpdev,
  216. HDEV hdev)
  217. {
  218. return;
  219. }
  220. //------------------------------------------------------------------------------
  221. ULONG_PTR APIENTRY atmfdLoadFontFile( //Returns IFILE value
  222. ULONG cFiles, // number of font files associated with this font
  223. PULONG_PTR piFile, // handles for individual files, cFiles of them
  224. PVOID *ppvView, // array of cFiles views
  225. PULONG pcjView, // array of their sizes
  226. PDESIGNVECTOR pdv,
  227. ULONG ulLangID,
  228. ULONG ulFastCheckSum)
  229. {
  230. if (InitializeDriver())
  231. return (*pAtmfdLoadFontFile)(cFiles, piFile, ppvView, pcjView, pdv, ulLangID, ulFastCheckSum);
  232. else
  233. return 0;
  234. }
  235. //------------------------------------------------------------------------------
  236. LONG APIENTRY atmfdQueryFontCaps(
  237. ULONG culCaps,
  238. PULONG pulCaps)
  239. {
  240. if (culCaps >= 2)
  241. {
  242. pulCaps[0] = 2L;
  243. pulCaps[1] = QC_OUTLINES | QC_1BIT | QC_4BIT;
  244. return 2;
  245. }
  246. else
  247. return FD_ERROR;
  248. }
  249. //------------------------------------------------------------------------------
  250. BOOL APIENTRY atmfdUnloadFontFile(
  251. ULONG_PTR iFile)
  252. {
  253. return (*pAtmfdUnloadFontFile)(iFile);
  254. }
  255. //------------------------------------------------------------------------------
  256. LONG APIENTRY atmfdQueryFontFile(
  257. ULONG_PTR iFile,
  258. ULONG ulMode,
  259. ULONG cjBuf,
  260. PULONG pulBuf)
  261. {
  262. return (*pAtmfdQueryFontFile)(iFile, ulMode, cjBuf, pulBuf);
  263. }
  264. //------------------------------------------------------------------------------
  265. PIFIMETRICS APIENTRY atmfdQueryFont(
  266. DHPDEV dhpdev,
  267. ULONG_PTR iFile,
  268. ULONG iFace,
  269. ULONG_PTR *pid)
  270. {
  271. return (*pAtmfdQueryFont)(dhpdev, iFile, iFace, pid);
  272. }
  273. //------------------------------------------------------------------------------
  274. VOID APIENTRY atmfdFree(
  275. PVOID pv,
  276. ULONG_PTR id)
  277. {
  278. (*pAtmfdFree)(pv, id);
  279. }
  280. //------------------------------------------------------------------------------
  281. PVOID APIENTRY atmfdQueryFontTree(
  282. DHPDEV dhpdev,
  283. ULONG_PTR iFile,
  284. ULONG iFace,
  285. ULONG iMode,
  286. ULONG_PTR *pid)
  287. {
  288. return (*pAtmfdQueryFontTree)(dhpdev, iFile, iFace, iMode, pid);
  289. }
  290. //------------------------------------------------------------------------------
  291. LONG APIENTRY atmfdQueryFontData(
  292. DHPDEV dhpdev,
  293. FONTOBJ *pfo,
  294. ULONG iMode,
  295. HGLYPH hg,
  296. GLYPHDATA *pgd,
  297. PVOID pv,
  298. ULONG cjSize)
  299. {
  300. return (*pAtmfdQueryFontData)(dhpdev, pfo, iMode, hg, pgd, pv, cjSize);
  301. }
  302. //------------------------------------------------------------------------------
  303. VOID APIENTRY atmfdDestroyFont(
  304. FONTOBJ *pfo)
  305. {
  306. (*pAtmfdDestroyFont)(pfo);
  307. }
  308. //------------------------------------------------------------------------------
  309. BOOL APIENTRY atmfdQueryAdvanceWidths(
  310. DHPDEV dhpdev,
  311. FONTOBJ *pfo,
  312. ULONG iMode,
  313. PHGLYPH pGlyphHandle,
  314. PVOID widths,
  315. ULONG numOfGlyphs)
  316. {
  317. return (*pAtmfdQueryAdvanceWidths)(dhpdev, pfo, iMode, pGlyphHandle, widths, numOfGlyphs);
  318. }
  319. //------------------------------------------------------------------------------
  320. LONG APIENTRY atmfdQueryTrueTypeOutline(
  321. DHPDEV dhpdev,
  322. FONTOBJ *pfo,
  323. HGLYPH hg,
  324. BOOL metricsOnly,
  325. GLYPHDATA *pgd,
  326. ULONG cjSize,
  327. TTPOLYGONHEADER *pgHead)
  328. {
  329. return (*pAtmfdQueryTrueTypeOutline)(dhpdev, pfo, hg, metricsOnly, pgd, cjSize, pgHead);
  330. }
  331. //------------------------------------------------------------------------------
  332. LONG APIENTRY atmfdQueryTrueTypeTable(
  333. ULONG_PTR iFile,
  334. ULONG ulFont,
  335. ULONG ulTag,
  336. PTRDIFF dpStart,
  337. ULONG cjBuf,
  338. PBYTE pjBuf,
  339. PBYTE *ppjTable,
  340. PULONG pcjTable)
  341. {
  342. return (*pAtmfdQueryTrueTypeTable)(iFile, ulFont, ulTag, dpStart, cjBuf, pjBuf, ppjTable, pcjTable);
  343. }
  344. //------------------------------------------------------------------------------
  345. PFD_GLYPHATTR APIENTRY atmfdQueryGlyphAttrs(
  346. FONTOBJ *pfo,
  347. ULONG iMode)
  348. {
  349. return (*pAtmfdQueryGlyphAttrs)(pfo, iMode);
  350. }
  351. //------------------------------------------------------------------------------
  352. ULONG APIENTRY atmfdEscape(
  353. SURFOBJ *pso,
  354. ULONG iEsc,
  355. ULONG cjIn,
  356. PVOID pvIn,
  357. ULONG cjOut,
  358. PVOID pvOut)
  359. {
  360. return atmfdFontManagement(pso, NULL, iEsc, cjIn, pvIn, cjOut, pvOut);
  361. }
  362. //------------------------------------------------------------------------------
  363. ULONG APIENTRY atmfdFontManagement(
  364. SURFOBJ *pso,
  365. FONTOBJ *pfo,
  366. ULONG iEsc,
  367. ULONG cjIn,
  368. PVOID pvIn,
  369. ULONG cjOut,
  370. PVOID pvOut)
  371. {
  372. ULONG result = ESC_NOT_SUPPORTED;
  373. BOOL callDriver = FALSE;
  374. switch(iEsc)
  375. {
  376. case QUERYESCSUPPORT:
  377. {
  378. switch (*((PULONG)pvIn))
  379. {
  380. case QUERYESCSUPPORT:
  381. case GETEXTENDEDTEXTMETRICS:
  382. result = ESC_IS_SUPPORTED;
  383. break;
  384. default:
  385. if ((*((PULONG)pvIn) > BEG_OF_ATM_ESCAPE_LIST) && (*((PULONG)pvIn) < END_OF_ATM_ESCAPE_LIST))
  386. result = ESC_IS_SUPPORTED;
  387. }
  388. break;
  389. }
  390. case GETEXTENDEDTEXTMETRICS:
  391. {
  392. callDriver = TRUE;
  393. break;
  394. }
  395. default:
  396. {
  397. if ((iEsc <= BEG_OF_ATM_ESCAPE_LIST) || (iEsc >= END_OF_ATM_ESCAPE_LIST))
  398. break;
  399. callDriver = TRUE;
  400. break;
  401. }
  402. }
  403. if (callDriver)
  404. {
  405. if (InitializeDriver() == TRUE)
  406. {
  407. return (*pAtmfdFontManagement)(pso, pfo, iEsc, cjIn, pvIn, cjOut, pvOut);
  408. }
  409. }
  410. return result;
  411. }
  412. //------------------------------------------------------------------------------
  413. PVOID APIENTRY atmfdGetTrueTypeFile(
  414. ULONG_PTR iFile,
  415. PULONG pcj)
  416. {
  417. return (*pAtmfdGetTrueTypeFile)(iFile, pcj);
  418. }