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.

437 lines
14 KiB

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright 1997-2003 Microsoft Corporation. All Rights Reserved.
  7. //
  8. // FILE: TTYUD.cpp
  9. //
  10. //
  11. // PURPOSE: Main file for TTY kernel mode module.
  12. //
  13. //
  14. // Functions:
  15. //
  16. //
  17. //
  18. //
  19. // PLATFORMS: Windows 2000, Windows XP, Windows Server 2003
  20. //
  21. //
  22. #include <stdarg.h>
  23. #include <stddef.h>
  24. #include <stdlib.h>
  25. #include <stdarg.h>
  26. #include <windef.h>
  27. #include <winerror.h>
  28. #include <winbase.h>
  29. #include <wingdi.h>
  30. #include <winspool.h>
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. #include <winddi.h>
  35. #ifdef __cplusplus
  36. }
  37. #endif
  38. #include <tchar.h>
  39. #include <excpt.h>
  40. #include <PRINTOEM.H>
  41. #include "ttyui.h"
  42. #include "TTYUD.h"
  43. #include "debug.h"
  44. #include <STRSAFE.H>
  45. DWORD gdwDrvMemPoolTag = 'Oem5'; // for MemAlloc debugging purposes
  46. #define TTY_INFO_MARGINS 1
  47. #define TTY_INFO_CODEPAGE 2
  48. #define TTY_INFO_NUM_UFMS 3
  49. #define TTY_INFO_UFM_IDS 4
  50. #define NUM_UFMS 3 // for internal use only. use TTY_INFO_NUM_UFMS
  51. // to query number of font sizes supported.
  52. ////////////////////////////////////////////////////////
  53. // INTERNAL PROTOTYPES
  54. ////////////////////////////////////////////////////////
  55. BOOL APIENTRY OEMGetInfo(IN DWORD dwInfo, OUT PVOID pBuffer, IN DWORD cbSize,
  56. OUT PDWORD pcbNeeded) ;
  57. PDEVOEM APIENTRY OEMEnablePDEV(PDEVOBJ pdevobj, PWSTR pPrinterName, ULONG cPatterns,
  58. HSURF *phsurfPatterns, ULONG cjGdiInfo, GDIINFO *pGdiInfo,
  59. ULONG cjDevInfo, DEVINFO *pDevInfo, DRVENABLEDATA *pded) ;
  60. VOID APIENTRY OEMDisablePDEV(PDEVOBJ pdevobj) ;
  61. BOOL APIENTRY OEMEnableDriver(DWORD dwOEMintfVersion, DWORD dwSize, PDRVENABLEDATA pded) ;
  62. PBYTE APIENTRY OEMImageProcessing(PDEVOBJ pdevobj, PBYTE pSrcBitmap, PBITMAPINFOHEADER pBitmapInfo,
  63. PBYTE pColorTable, DWORD dwCallbackID, PIPPARAMS pIPParams) ;
  64. BOOL APIENTRY OEMFilterGraphics(PDEVOBJ pdevobj, PBYTE pBuf, DWORD dwLen) ;
  65. // Need to export these functions as c declarations.
  66. extern "C" {
  67. PBYTE APIENTRY OEMImageProcessing(PDEVOBJ pdevobj, PBYTE pSrcBitmap, PBITMAPINFOHEADER pBitmapInfo,
  68. PBYTE pColorTable, DWORD dwCallbackID, PIPPARAMS pIPParams)
  69. {
  70. VERBOSE(DLLTEXT("OEMImageProcessing() entry.\r\n"));
  71. return ((PBYTE)TRUE);
  72. }
  73. BOOL APIENTRY OEMFilterGraphics(PDEVOBJ pdevobj, PBYTE pBuf, DWORD dwLen)
  74. {
  75. VERBOSE(DLLTEXT("OEMFilterGraphics() entry.\r\n"));
  76. return TRUE;
  77. }
  78. BOOL APIENTRY OEMGetInfo(IN DWORD dwInfo, OUT PVOID pBuffer, IN DWORD cbSize,
  79. OUT PDWORD pcbNeeded)
  80. {
  81. // Validate parameters.
  82. if( ( (OEMGI_GETSIGNATURE != dwInfo)
  83. &&
  84. (OEMGI_GETINTERFACEVERSION != dwInfo)
  85. &&
  86. (OEMGI_GETVERSION != dwInfo)
  87. )
  88. ||
  89. (NULL == pcbNeeded)
  90. )
  91. {
  92. VERBOSE(ERRORTEXT("OEMGetInfo() ERROR_INVALID_PARAMETER.\r\n"));
  93. // Did not write any bytes.
  94. if(NULL != pcbNeeded)
  95. *pcbNeeded = 0;
  96. return FALSE;
  97. }
  98. // Need/wrote 4 bytes.
  99. *pcbNeeded = 4;
  100. // Validate buffer size. Minimum size is four bytes.
  101. if( (NULL == pBuffer)
  102. ||
  103. (4 > cbSize)
  104. )
  105. {
  106. // VERBOSE(ERRORTEXT("OEMGetInfo() ERROR_INSUFFICIENT_BUFFER.\r\n"));
  107. EngSetLastError(ERROR_INSUFFICIENT_BUFFER);
  108. return FALSE;
  109. }
  110. // Write information to buffer.
  111. switch(dwInfo)
  112. {
  113. case OEMGI_GETSIGNATURE:
  114. *(LPDWORD)pBuffer = OEM_SIGNATURE;
  115. break;
  116. case OEMGI_GETINTERFACEVERSION:
  117. *(LPDWORD)pBuffer = PRINTER_OEMINTF_VERSION;
  118. break;
  119. case OEMGI_GETVERSION:
  120. *(LPDWORD)pBuffer = OEM_VERSION;
  121. break;
  122. }
  123. return TRUE;
  124. }
  125. PDEVOEM APIENTRY OEMEnablePDEV(PDEVOBJ pdevobj, PWSTR pPrinterName, ULONG cPatterns,
  126. HSURF *phsurfPatterns, ULONG cjGdiInfo, GDIINFO *pGdiInfo,
  127. ULONG cjDevInfo, DEVINFO *pDevInfo, DRVENABLEDATA *pded)
  128. {
  129. PREGSTRUCT pMyStuff; // sebset of pGlobals
  130. DWORD dwStatus, cbNeeded, dwType ;
  131. LPTSTR pValueName = TEXT("TTY DeviceConfig");
  132. // these strings must match strings in oemui.cpp - VinitMyStuff()
  133. VERBOSE(DLLTEXT("OEMEnablePDEV() entry.\r\n"));
  134. pMyStuff = (PREGSTRUCT)MemAlloc(sizeof(REGSTRUCT)) ;
  135. if(!pMyStuff)
  136. return ((PDEVOEM)NULL) ; // failed.
  137. pdevobj->pdevOEM = (PDEVOEM)pMyStuff ;
  138. dwStatus = EngGetPrinterData(
  139. pdevobj->hPrinter, // handle of printer object
  140. pValueName, // address of value name
  141. &dwType, // address receiving value type
  142. (LPBYTE)pMyStuff,
  143. // address of array of bytes that receives data
  144. sizeof(REGSTRUCT), // size, in bytes, of array
  145. &cbNeeded // address of variable
  146. // with number of bytes retrieved (or required)
  147. );
  148. if (dwStatus != ERROR_SUCCESS || pMyStuff->dwVersion != TTYSTRUCT_VER
  149. || dwType != REG_BINARY
  150. || cbNeeded != sizeof(REGSTRUCT))
  151. {
  152. // Init secret block with defaults
  153. pMyStuff->dwVersion = TTYSTRUCT_VER ;
  154. // version stamp to avoid incompatible structures.
  155. pMyStuff->bIsMM = TRUE ; // default to mm units
  156. // read margin values from registry and store into temp RECT
  157. pMyStuff->iCodePage = 1252 ; // keep in sync with oemui.cpp - VinitMyStuff()
  158. pMyStuff->rcMargin.left = pMyStuff->rcMargin.top =
  159. pMyStuff->rcMargin.right = pMyStuff->rcMargin.bottom = 0 ;
  160. pMyStuff->BeginJob.dwLen =
  161. pMyStuff->EndJob.dwLen =
  162. pMyStuff->PaperSelect.dwLen =
  163. pMyStuff->FeedSelect.dwLen =
  164. pMyStuff->Sel_10_cpi.dwLen =
  165. pMyStuff->Sel_12_cpi.dwLen =
  166. pMyStuff->Sel_17_cpi.dwLen =
  167. pMyStuff->Bold_ON.dwLen =
  168. pMyStuff->Bold_OFF.dwLen =
  169. pMyStuff->Underline_ON.dwLen =
  170. pMyStuff->Underline_OFF.dwLen = 0 ;
  171. // more fields here!
  172. pMyStuff->dwGlyphBufSiz =
  173. pMyStuff->dwSpoolBufSiz = 0 ;
  174. pMyStuff->aubGlyphBuf =
  175. pMyStuff->aubSpoolBuf = NULL ;
  176. }
  177. return ((PDEVOEM)pMyStuff) ;
  178. }
  179. VOID APIENTRY OEMDisablePDEV(PDEVOBJ pdevobj)
  180. {
  181. VERBOSE(DLLTEXT("OEMDisablePDEV() entry.\r\n"));
  182. PREGSTRUCT pMyStuff; // sebset of pGlobals
  183. pMyStuff = (PREGSTRUCT)pdevobj->pdevOEM ;
  184. if(pMyStuff->aubGlyphBuf)
  185. MemFree(pMyStuff->aubGlyphBuf) ;
  186. if(pMyStuff->aubSpoolBuf)
  187. MemFree(pMyStuff->aubSpoolBuf) ;
  188. MemFree(pdevobj->pdevOEM);
  189. }
  190. BOOL APIENTRY OEMEnableDriver(DWORD dwOEMintfVersion, DWORD dwSize, PDRVENABLEDATA pded)
  191. {
  192. VERBOSE(DLLTEXT("OEMEnableDriver() entry.\r\n"));
  193. // Validate paramters.
  194. if( (PRINTER_OEMINTF_VERSION != dwOEMintfVersion) ||
  195. // above check not needed for COM
  196. (sizeof(DRVENABLEDATA) > dwSize)
  197. ||
  198. (NULL == pded)
  199. )
  200. {
  201. // VERBOSE(ERRORTEXT("OEMEnableDriver() ERROR_INVALID_PARAMETER.\r\n"));
  202. return FALSE;
  203. }
  204. pded->iDriverVersion = PRINTER_OEMINTF_VERSION ; // not DDI_DRIVER_VERSION;
  205. pded->c = 0;
  206. return TRUE;
  207. }
  208. BOOL APIENTRY OEMTTYGetInfo(PDEVOBJ pdevobj, DWORD dwInfoIndex,
  209. PVOID pOutBuf, DWORD dwSize, DWORD *pcbNeeded
  210. )
  211. {
  212. PREGSTRUCT pMyStuff; // sebset of pGlobals
  213. REGSTRUCT MyStuff; // temp structure to hold registry data
  214. pMyStuff = (PREGSTRUCT)pdevobj->pdevOEM ;
  215. if(!pMyStuff)
  216. {
  217. DWORD dwStatus, cbNeeded, dwType ;
  218. LPTSTR pValueName = TEXT("TTY DeviceConfig");
  219. // these strings must match strings in oemui.cpp - VinitMyStuff()
  220. // and OEMEnablePDEV()
  221. pMyStuff = &MyStuff;
  222. pMyStuff->dwVersion = 0 ;
  223. dwStatus = EngGetPrinterData(
  224. pdevobj->hPrinter, // handle of printer object
  225. pValueName, // address of value name
  226. &dwType, // address receiving value type
  227. (LPBYTE)pMyStuff ,
  228. // address of array of bytes that receives data
  229. sizeof(REGSTRUCT), // size, in bytes, of array
  230. &cbNeeded // address of variable
  231. // with number of bytes retrieved (or required)
  232. );
  233. if (dwStatus != ERROR_SUCCESS || pMyStuff->dwVersion != TTYSTRUCT_VER
  234. || dwType != REG_BINARY
  235. || cbNeeded != sizeof(REGSTRUCT))
  236. {
  237. // set to defaults
  238. pMyStuff->iCodePage = 1252 ; // keep in sync with oemui.cpp - VinitMyStuff()
  239. pMyStuff->rcMargin.left = pMyStuff->rcMargin.top =
  240. pMyStuff->rcMargin.right = pMyStuff->rcMargin.bottom = 0 ;
  241. }
  242. }
  243. switch (dwInfoIndex)
  244. {
  245. case TTY_INFO_MARGINS:
  246. *pcbNeeded = sizeof(RECT) ;
  247. if(!pOutBuf || dwSize < *pcbNeeded)
  248. return(FALSE) ;
  249. *(LPRECT)pOutBuf = pMyStuff->rcMargin ;
  250. break;
  251. case TTY_INFO_CODEPAGE:
  252. *pcbNeeded = sizeof(INT) ;
  253. if(!pOutBuf || dwSize < *pcbNeeded)
  254. return(FALSE) ;
  255. *(INT *)pOutBuf = pMyStuff->iCodePage ;
  256. break;
  257. case TTY_INFO_NUM_UFMS:
  258. *pcbNeeded = sizeof(DWORD) ;
  259. if(!pOutBuf || dwSize < *pcbNeeded)
  260. return(FALSE) ;
  261. *(DWORD *)pOutBuf = NUM_UFMS ; // Number of resource IDs returned
  262. // during a query for TTY_INFO_UFM_IDS
  263. break;
  264. case TTY_INFO_UFM_IDS:
  265. // return resource IDs of the UFMs for 10,12, 17 cpi fonts.
  266. *pcbNeeded = NUM_UFMS * sizeof(DWORD) ;
  267. if(!pOutBuf || dwSize < *pcbNeeded)
  268. return(FALSE) ;
  269. switch(pMyStuff->iCodePage)
  270. {
  271. case (-1): // codepage 437
  272. ((DWORD *)pOutBuf)[0] = 4 ; // see tty\rc\tty.rc for resID assignments
  273. ((DWORD *)pOutBuf)[1] = 5;
  274. ((DWORD *)pOutBuf)[2] = 6;
  275. break;
  276. case (850): // codepage 850
  277. ((DWORD *)pOutBuf)[0] = 7; // see tty\rc\tty.rc for resID assignments
  278. ((DWORD *)pOutBuf)[1] = 8;
  279. ((DWORD *)pOutBuf)[2] = 9;
  280. break;
  281. case (-3): // codepage 863
  282. ((DWORD *)pOutBuf)[0] = 7; // see tty\rc\tty.rc for resID assignments
  283. ((DWORD *)pOutBuf)[1] = 8;
  284. ((DWORD *)pOutBuf)[2] = 9;
  285. break;
  286. case (-17): // codepage 932
  287. ((DWORD *)pOutBuf)[0] = 13 ; // see tty\rc\tty.rc for resID assignments
  288. ((DWORD *)pOutBuf)[1] = 14 ;
  289. ((DWORD *)pOutBuf)[2] = 15 ;
  290. break;
  291. case (-16): // codepage 936
  292. ((DWORD *)pOutBuf)[0] = 16 ; // see tty\rc\tty.rc for resID assignments
  293. ((DWORD *)pOutBuf)[1] = 17 ;
  294. ((DWORD *)pOutBuf)[2] = 18 ;
  295. break;
  296. case (-18): // codepage 949
  297. ((DWORD *)pOutBuf)[0] = 19 ; // see tty\rc\tty.rc for resID assignments
  298. ((DWORD *)pOutBuf)[1] = 20 ;
  299. ((DWORD *)pOutBuf)[2] = 21 ;
  300. break;
  301. case (-10): // codepage 950
  302. ((DWORD *)pOutBuf)[0] = 22 ; // see tty\rc\tty.rc for resID assignments
  303. ((DWORD *)pOutBuf)[1] = 23 ;
  304. ((DWORD *)pOutBuf)[2] = 24 ;
  305. break;
  306. case (1250): // codepage 1250
  307. ((DWORD *)pOutBuf)[0] = 25 ; // see tty\rc\tty.rc for resID assignments
  308. ((DWORD *)pOutBuf)[1] = 26;
  309. ((DWORD *)pOutBuf)[2] = 27;
  310. break;
  311. case (1251): // codepage 1251
  312. ((DWORD *)pOutBuf)[0] = 28; // see tty\rc\tty.rc for resID assignments
  313. ((DWORD *)pOutBuf)[1] = 29;
  314. ((DWORD *)pOutBuf)[2] = 30;
  315. break;
  316. case (1252): // codepage 1252
  317. ((DWORD *)pOutBuf)[0] = 31; // see tty\rc\tty.rc for resID assignments
  318. ((DWORD *)pOutBuf)[1] = 32;
  319. ((DWORD *)pOutBuf)[2] = 33;
  320. break;
  321. case (1253): // codepage 1253
  322. ((DWORD *)pOutBuf)[0] = 34 ; // see tty\rc\tty.rc for resID assignments
  323. ((DWORD *)pOutBuf)[1] = 35;
  324. ((DWORD *)pOutBuf)[2] = 36;
  325. break;
  326. case (1254): // codepage 1254
  327. ((DWORD *)pOutBuf)[0] = 37 ; // see tty\rc\tty.rc for resID assignments
  328. ((DWORD *)pOutBuf)[1] = 38;
  329. ((DWORD *)pOutBuf)[2] = 39;
  330. break;
  331. case (852): // codepage 852
  332. ((DWORD *)pOutBuf)[0] = 40 ; // see tty\rc\tty.rc for resID assignments
  333. ((DWORD *)pOutBuf)[1] = 41;
  334. ((DWORD *)pOutBuf)[2] = 42;
  335. break;
  336. case (857): // codepage 857
  337. ((DWORD *)pOutBuf)[0] = 43 ; // see tty\rc\tty.rc for resID assignments
  338. ((DWORD *)pOutBuf)[1] = 44;
  339. ((DWORD *)pOutBuf)[2] = 45;
  340. break;
  341. default:
  342. ((DWORD *)pOutBuf)[0] = 1 ; // '10 cpi'
  343. ((DWORD *)pOutBuf)[1] = 2 ; // '12 cpi'
  344. ((DWORD *)pOutBuf)[2] = 3 ; // '17 cpi'
  345. break;
  346. }
  347. break;
  348. default:
  349. *pcbNeeded = 0 ; // no data availible
  350. return(FALSE) ; // unsupported index
  351. }
  352. return(TRUE);
  353. }
  354. } // End of extern "C"