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.

587 lines
13 KiB

  1. /*++ BUILD Version: 0003 // Increment this if a change has global effects
  2. Copyright (c) 1990-2003 Microsoft Corporation
  3. Module Name:
  4. plotlib.h
  5. Abstract:
  6. This module contains defines and prototype for the plotter library
  7. Author:
  8. 15-Nov-1993 Mon 22:52:46 created
  9. 29-Dec-1993 Wed 11:00:56 updated
  10. Change PLOTDBGBLK() macro by adding automatical semi in macro
  11. [Environment:]
  12. GDI Device Driver - Plotter.
  13. [Notes:]
  14. Revision History:
  15. --*/
  16. #ifndef _PLOTLIB_
  17. #define _PLOTLIB_
  18. #include <plotdm.h>
  19. #include <plotgpc.h>
  20. #define _WCPYSTR(pd,ps,n) wcsncpy((LPWSTR)(pd),(LPWSTR)(ps),(n)); \
  21. *(((LPWSTR)(pd))+(n)-1)=L'\0'
  22. #define WCPYFIELDNAME(pField,ps) _WCPYSTR((pField),(ps),COUNT_ARRAY(pField))
  23. #define SWAP(a,b,t) { (t)=(a); (a)=(b); (b)=(t); }
  24. #define CCHOF(x) (sizeof(x)/sizeof(*(x)))
  25. // Some other convinence defines
  26. #define DM_PAPER_FIELDS (DM_PAPERWIDTH | DM_PAPERLENGTH | \
  27. DM_PAPERSIZE | DM_FORMNAME)
  28. #define DM_PAPER_WL (DM_PAPERWIDTH | DM_PAPERLENGTH)
  29. //
  30. // new ddi stuff
  31. //
  32. #if defined(UMODE) || defined(USERMODE_DRIVER)
  33. #pragma message("*** MSPLOT: Compile in USER Mode ***")
  34. #define xEnumForms EnumForms
  35. #define xGetPrinter GetPrinter
  36. #define xGetPrinterData GetPrinterData
  37. #define xSetPrinterData SetPrinterData
  38. #define xGetLastError GetLastError
  39. #define AnsiToUniCode(pb,pw,cch) \
  40. MultiByteToWideChar(CP_ACP,0,(pb),(cch),(pw),(cch))
  41. #define UniCodeToAnsi(pb,pw,cch) \
  42. WideCharToMultiByte(CP_ACP,0,(pw),(cch),(pb),(cch),NULL,NULL)
  43. #else
  44. #pragma message("*** MSPLOT: Compile in KERNEL Mode ***")
  45. #define WritePrinter EngWritePrinter
  46. #define SetLastError EngSetLastError
  47. #define GetLastError EngGetLastError
  48. #define MulDiv EngMulDiv
  49. #define xEnumForms EngEnumForms
  50. #define xGetPrinter EngGetPrinter
  51. #define xGetPrinterData EngGetPrinterData
  52. #define xSetPrinterData EngSetPrinterData
  53. #define xGetLastError EngGetLastError
  54. #define AnsiToUniCode(pb,pw,cch) \
  55. EngMultiByteToUnicodeN((pw),(cch)*sizeof(WCHAR),NULL,(pb),(cch))
  56. #define UniCodeToAnsi(pb,pw,cch) \
  57. EngUnicodeToMultiByteN((pb),(cch),NULL,(pw),(cch)*sizeof(WCHAR))
  58. #define LocalAlloc(fl,c) \
  59. EngAllocMem(((fl) & LMEM_ZEROINIT) ? FL_ZERO_MEMORY:0,c,'tolp')
  60. #define LocalFree(p) EngFreeMem((PVOID)p)
  61. #define DebugBreak() EngDebugBreak()
  62. #endif // UMODE
  63. //===========================================================================
  64. // cacheGPC.c
  65. //===========================================================================
  66. BOOL
  67. InitCachedData(
  68. VOID
  69. );
  70. VOID
  71. DestroyCachedData(
  72. VOID
  73. );
  74. BOOL
  75. UnGetCachedPlotGPC(
  76. PPLOTGPC pPlotGPC
  77. );
  78. PPLOTGPC
  79. GetCachedPlotGPC(
  80. LPWSTR pwDataFile
  81. );
  82. #ifdef UMODE
  83. PPLOTGPC
  84. hPrinterToPlotGPC(
  85. HANDLE hPrinter,
  86. LPWSTR pwDeviceName,
  87. size_t cchDeviceName
  88. );
  89. #endif
  90. //===========================================================================
  91. // drvinfo.c
  92. //===========================================================================
  93. #ifdef UMODE
  94. LPBYTE
  95. GetDriverInfo(
  96. HANDLE hPrinter,
  97. UINT DrvInfoLevel
  98. );
  99. #endif
  100. //===========================================================================
  101. // RegData.c
  102. //===========================================================================
  103. #define PRKI_FIRST PRKI_CI
  104. #define PRKI_CI 0
  105. #define PRKI_DEVPELSDPI 1
  106. #define PRKI_HTPATSIZE 2
  107. #define PRKI_FORM 3
  108. #define PRKI_PPDATA 4
  109. #define PRKI_PENDATA_IDX 5
  110. #define PRKI_PENDATA1 6
  111. #define PRKI_PENDATA2 7
  112. #define PRKI_PENDATA3 8
  113. #define PRKI_PENDATA4 9
  114. #define PRKI_PENDATA5 10
  115. #define PRKI_PENDATA6 11
  116. #define PRKI_PENDATA7 12
  117. #define PRKI_PENDATA8 13
  118. #define PRKI_LAST PRKI_PENDATA8
  119. #define PRK_MAX_PENDATA_SET (PRKI_LAST - PRKI_PENDATA1 + 1)
  120. BOOL
  121. GetPlotRegData(
  122. HANDLE hPrinter,
  123. LPBYTE pData,
  124. DWORD RegIdx
  125. );
  126. BOOL
  127. UpdateFromRegistry(
  128. HANDLE hPrinter,
  129. PCOLORINFO pColorInfo,
  130. LPDWORD pDevPelsDPI,
  131. LPDWORD pHTPatSize,
  132. PPAPERINFO pCurPaper,
  133. PPPDATA pPPData,
  134. LPBYTE pIdxPlotData,
  135. DWORD cPenData,
  136. PPENDATA pPenData
  137. );
  138. #ifdef UMODE
  139. BOOL
  140. SetPlotRegData(
  141. HANDLE hPrinter,
  142. LPBYTE pData,
  143. DWORD RegIdx
  144. );
  145. BOOL
  146. SaveToRegistry(
  147. HANDLE hPrinter,
  148. PCOLORINFO pColorInfo,
  149. LPDWORD pDevPelsDPI,
  150. LPDWORD pHTPatSize,
  151. PPAPERINFO pCurPaper,
  152. PPPDATA pPPData,
  153. LPBYTE pIdxPlotData,
  154. DWORD cPenData,
  155. PPENDATA pPenData
  156. );
  157. #endif
  158. //===========================================================================
  159. // Forms.c
  160. //===========================================================================
  161. #define FI1F_VALID_SIZE 0x80000000
  162. #define FI1F_ENVELOPE 0x40000000
  163. #define FI1F_MASK 0xc0000000
  164. #define FI1F_ENUMFORMS_MASK 0x00000003
  165. typedef struct _ENUMFORMPARAM {
  166. PFORM_INFO_1 pFI1Base;
  167. DWORD Count;
  168. DWORD ValidCount;
  169. DWORD cMaxOut;
  170. PPLOTDEVMODE pPlotDM;
  171. PPLOTGPC pPlotGPC;
  172. PFORMSIZE pCurForm;
  173. SHORT FoundIndex;
  174. SHORT ReqIndex;
  175. PFORM_INFO_1 pSizeFI1;
  176. SIZEL ReqSize;
  177. } ENUMFORMPARAM, FAR *PENUMFORMPARAM;
  178. //
  179. // The following fields in ENUMFORMPARAM must set to valid pointer before
  180. // the PlotEnumForms() call
  181. //
  182. // 1. pPlotDM
  183. // 2. pPlotGPC
  184. // 3. pCurForm (can be NULL)
  185. //
  186. // if a callback function is supplied then only forms which not greater than
  187. // the device size will be passed to the callback function, for form which
  188. // smaller or equal to the device size will have FI1F_VALID_SIZE bit set in
  189. // the FORM_INFO_1 data structure's flag
  190. //
  191. //
  192. // Call back function for enum forms, if return value is
  193. //
  194. // (Ret < 0) --> Free pFI1Base pointer and stop enum
  195. // (Ret = 0) --> Keep pFI1Base and Stop Enum
  196. // (Ret > 0) --> Continue Enum until all Count is enumerated
  197. //
  198. // The last enum callback will have following parameters to give the callback
  199. // function a chance to return -1 (free the pFormInfo1 data)
  200. //
  201. // pFI1 = NULL
  202. // Index = pEnumFormParam->Count
  203. //
  204. typedef INT (CALLBACK *ENUMFORMPROC)(PFORM_INFO_1 pFI1,
  205. DWORD Index,
  206. PENUMFORMPARAM pEnumFormParam);
  207. //
  208. // If (EnumFormProc == NULL) then no enumeration will happened but just
  209. // return the pFI1/Count in pEnumFormParam, if both EnumFormProc and
  210. // pEnumFormParam == NULL then it return FALSE
  211. //
  212. BOOL
  213. PlotEnumForms(
  214. HANDLE hPrinter,
  215. ENUMFORMPROC EnumFormProc,
  216. PENUMFORMPARAM pEnumFormParam
  217. );
  218. //===========================================================================
  219. // plotdm.c
  220. //===========================================================================
  221. BOOL
  222. IsA4PaperDefault(
  223. VOID
  224. );
  225. BOOL
  226. IntersectRECTL(
  227. PRECTL prclDest,
  228. PRECTL prclSrc
  229. );
  230. #define RM_L90 0
  231. #define RM_180 1
  232. #define RM_R90 2
  233. BOOL
  234. RotatePaper(
  235. PSIZEL pSize,
  236. PRECTL pImageArea,
  237. UINT RotateMode
  238. );
  239. SHORT
  240. GetDefaultPaper(
  241. PPAPERINFO pPaperInfo
  242. );
  243. VOID
  244. GetDefaultPlotterForm(
  245. PPLOTGPC pPlotGPC,
  246. PPAPERINFO pPaperInfo
  247. );
  248. VOID
  249. SetDefaultDMForm(
  250. PPLOTDEVMODE pPlotDM,
  251. PFORMSIZE pCurForm
  252. );
  253. VOID
  254. SetDefaultPLOTDM(
  255. HANDLE hPrinter,
  256. PPLOTGPC pPlotGPC,
  257. LPWSTR pwDeviceName,
  258. PPLOTDEVMODE pPlotDM,
  259. PFORMSIZE pCurForm
  260. );
  261. DWORD
  262. ValidateSetPLOTDM(
  263. HANDLE hPrinter,
  264. PPLOTGPC pPlotGPC,
  265. LPWSTR pwDeviceName,
  266. PPLOTDEVMODE pPlotDMIn,
  267. PPLOTDEVMODE pPlotDMOut,
  268. PFORMSIZE pCurForm
  269. );
  270. //===========================================================================
  271. // WideChar.c - Unicode/Ansi conversion support
  272. //===========================================================================
  273. LPWSTR
  274. str2Wstr(
  275. LPWSTR pwStr,
  276. size_t cchDest,
  277. LPSTR pbStr
  278. );
  279. LPWSTR
  280. str2MemWstr(
  281. LPSTR pStr
  282. );
  283. LPSTR
  284. WStr2Str(
  285. LPSTR pbStr,
  286. size_t cchDest,
  287. LPWSTR pwStr
  288. );
  289. //===========================================================================
  290. // ReadGPC.c - PlotGPC reading/validating
  291. //===========================================================================
  292. BOOL
  293. ValidateFormSrc(
  294. PGPCVARSIZE pFormGPC,
  295. SIZEL DeviceSize,
  296. BOOL DevRollFeed
  297. );
  298. DWORD
  299. PickDefaultHTPatSize(
  300. WORD xDPI,
  301. WORD yDPI,
  302. BOOL HTFormat8BPP
  303. );
  304. BOOL
  305. ValidatePlotGPC(
  306. PPLOTGPC pPlotGPC
  307. );
  308. PPLOTGPC
  309. ReadPlotGPCFromFile(
  310. PWSTR pwsDataFile
  311. );
  312. //===========================================================================
  313. // file.c - file open/read/close
  314. //===========================================================================
  315. #if defined(UMODE) || defined(USERMODE_DRIVER)
  316. #define OpenPlotFile(pFileName) CreateFile((LPCTSTR)pFileName, \
  317. GENERIC_READ, \
  318. FILE_SHARE_READ, \
  319. NULL, \
  320. OPEN_EXISTING, \
  321. FILE_ATTRIBUTE_NORMAL, \
  322. NULL)
  323. #define ClosePlotFile(h) CloseHandle(h)
  324. #define ReadPlotFile(h,p,c,pc) ReadFile((h),(p),(c),(pc),NULL)
  325. #else
  326. typedef struct _PLOTFILE {
  327. HANDLE hModule;
  328. LPBYTE pbBeg;
  329. LPBYTE pbEnd;
  330. LPBYTE pbCur;
  331. } PLOTFILE, *PPLOTFILE;
  332. HANDLE
  333. OpenPlotFile(
  334. LPWSTR pFileName
  335. );
  336. BOOL
  337. ClosePlotFile(
  338. HANDLE hPlotFile
  339. );
  340. BOOL
  341. ReadPlotFile(
  342. HANDLE hPlotFile,
  343. LPVOID pBuf,
  344. DWORD cToRead,
  345. LPDWORD pcRead
  346. );
  347. #endif
  348. //===========================================================================
  349. // Devmode.c and halftone.c
  350. //===========================================================================
  351. BOOL
  352. ValidateColorAdj(
  353. PCOLORADJUSTMENT pca
  354. );
  355. LONG
  356. ConvertDevmode(
  357. PDEVMODE pdmIn,
  358. PDEVMODE pdmOut
  359. );
  360. #if defined(UMODE) || defined(USERMODE_DRIVER)
  361. #include <winspool.h>
  362. #include <commctrl.h>
  363. #include <winddiui.h>
  364. // Copy DEVMODE to an output buffer before return to the
  365. // caller of DrvDocumentPropertySheets
  366. BOOL
  367. ConvertDevmodeOut(
  368. PDEVMODE pdmSrc,
  369. PDEVMODE pdmIn,
  370. PDEVMODE pdmOut
  371. );
  372. typedef struct {
  373. WORD dmDriverVersion; // current driver version
  374. WORD dmDriverExtra; // size of current version private devmode
  375. WORD dmDriverVersion351; // 3.51 driver version
  376. WORD dmDriverExtra351; // size of 3.51 version private devmode
  377. } DRIVER_VERSION_INFO, *PDRIVER_VERSION_INFO;
  378. #define CDM_RESULT_FALSE 0
  379. #define CDM_RESULT_TRUE 1
  380. #define CDM_RESULT_NOT_HANDLED 2
  381. INT
  382. CommonDrvConvertDevmode(
  383. PWSTR pPrinterName,
  384. PDEVMODE pdmIn,
  385. PDEVMODE pdmOut,
  386. PLONG pcbNeeded,
  387. DWORD fMode,
  388. PDRIVER_VERSION_INFO pDriverVersions
  389. );
  390. #endif
  391. //===========================================================================
  392. // PlotDBG.c - debug output support
  393. //===========================================================================
  394. #if DBG
  395. VOID
  396. cdecl
  397. PlotDbgPrint(
  398. LPSTR pszFormat,
  399. ...
  400. );
  401. VOID
  402. PlotDbgType(
  403. INT Type
  404. );
  405. VOID
  406. _PlotAssert(
  407. LPSTR pMsg,
  408. LPSTR pFalseExp,
  409. LPSTR pFilename,
  410. UINT LineNo,
  411. DWORD_PTR Exp,
  412. BOOL Stop
  413. );
  414. extern BOOL DoPlotWarn;
  415. #define DBGP(x) (PlotDbgPrint x)
  416. #if 1
  417. #define DEFINE_DBGVAR(x) DWORD DBG_PLOTFILENAME=(x)
  418. #define PLOTDBG(x,y) if (x&DBG_PLOTFILENAME){PlotDbgType(0);DBGP(y);}
  419. #else
  420. #define DEFINE_DBGVAR(x)
  421. #define PLOTDBG(x,y) DBGP(y)
  422. #endif // DBG_PLOTFILENAME
  423. #define PLOTDBGBLK(x) x;
  424. #define PLOTWARN(x) if (DoPlotWarn) { PlotDbgType(1);DBGP(x); }
  425. #define PLOTERR(x) PlotDbgType(-1);DBGP(x)
  426. #define PLOTRIP(x) PLOTERR(x); DebugBreak()
  427. #define PLOTASSERT(b,x,e,i) \
  428. if (!(e)) { _PlotAssert(x,#e,__FILE__,(UINT)__LINE__,(DWORD_PTR)i,b); }
  429. #else // DBG
  430. #define PLOTDBGBLK(x)
  431. #define DEFINE_DBGVAR(x)
  432. #define PLOTDBG(x,y)
  433. #define PLOTWARN(x)
  434. #define PLOTERR(x)
  435. #define PLOTRIP(x)
  436. #define PLOTASSERT(b,x,e,i)
  437. #endif // DBG
  438. #endif // _PLOTLIB_