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.

913 lines
24 KiB

  1. /*++
  2. Copyright (c) 1990-2003 Microsoft Corporation
  3. All Rights Reserved
  4. // @@BEGIN_DDKSPLIT
  5. Module Name:
  6. windows\spooler\prtprocs\winprint\winprint.c
  7. // @@END_DDKSPLIT
  8. Abstract:
  9. Win32 print processor support functions.
  10. --*/
  11. #include "local.h"
  12. #include <excpt.h>
  13. // @@BEGIN_DDKSPLIT
  14. /**
  15. Used for enumerating, checking supported data types
  16. !! Warning !! Must match PRINTPROCESSOR_TYPE_* defined in winprint.h
  17. If the EMF version is rev-ed, corresponding changes need to be made in
  18. spoolss\client\winspool.c (GetPrinterDataW)
  19. localspl\port.c (PortThread)
  20. localspl\schedule.c (CheckMemoryAvailable)
  21. ntgdi\client\output.c (StartDocW)
  22. !! HACK !!
  23. NT EMF 1.003 isn't really supported. Localspl is hardcoded to reject this
  24. call, but we keep it so that HP LJ 1100 monolithic driver can still install.
  25. (During install, they set the DRIVER_INFO_3 datatype to 1.003, and this
  26. fails if it isn't supported by somebody.)
  27. In localspl's LocalStartDocPrinter call, we actually reject this datatype.
  28. **/
  29. // @@END_DDKSPLIT
  30. LPWSTR Datatypes[]={
  31. L"RAW",
  32. // @@BEGIN_DDKSPLIT
  33. L"RAW [FF appended]",
  34. L"RAW [FF auto]",
  35. L"NT EMF 1.003",
  36. // @@END_DDKSPLIT
  37. L"NT EMF 1.006",
  38. L"NT EMF 1.007",
  39. L"NT EMF 1.008",
  40. L"TEXT",
  41. 0};
  42. /** Misc. constants **/
  43. #define BASE_TAB_SIZE 8
  44. /**
  45. * For localization:
  46. **/
  47. PWCHAR pTabsKey = L"TABS";
  48. PWCHAR pCopiesKey = L"COPIES";
  49. /**
  50. Prototypes
  51. **/
  52. /** Functions found in parsparm.c **/
  53. extern USHORT GetKeyValue(
  54. IN PWCHAR,
  55. IN PWCHAR,
  56. IN USHORT,
  57. IN OUT PUSHORT,
  58. OUT PVOID);
  59. /** Functions found in raw.c **/
  60. extern BOOL PrintRawJob(
  61. IN PPRINTPROCESSORDATA,
  62. IN LPWSTR,
  63. IN UINT);
  64. /** Functions found in text.c **/
  65. extern BOOL PrintTextJob(
  66. IN PPRINTPROCESSORDATA,
  67. IN LPWSTR);
  68. /** Functions found in emf.c */
  69. extern BOOL PrintEMFJob(
  70. IN PPRINTPROCESSORDATA,
  71. IN LPWSTR);
  72. /** Functions found in support.c **/
  73. extern PUCHAR GetPrinterInfo(
  74. IN HANDLE hPrinter,
  75. IN ULONG,
  76. OUT PULONG);
  77. BOOL BReleasePPData(
  78. IN PPRINTPROCESSORDATA * ppData );
  79. //@@BEGIN_DDKSPLIT
  80. /* DllMain only to be compiled for DDK.
  81. //@@END_DDKSPLIT
  82. BOOL
  83. DllMain(
  84. HANDLE hModule,
  85. DWORD dwReason,
  86. LPVOID lpRes
  87. )
  88. {
  89. return TRUE;
  90. }
  91. //@@BEGIN_DDKSPLIT
  92. */
  93. //@@END_DDKSPLIT
  94. /*++
  95. *******************************************************************
  96. E n u m P r i n t P r o c e s s o r D a t a t y p e s W
  97. Routine Description:
  98. Enumerates the data types supported by the print processor.
  99. Arguments:
  100. pName => server name
  101. pPrintProcessorName => print processor name
  102. Level => level of data to return (must be 1)
  103. pDatatypes => structure array to fill in
  104. cbBuf => length of structure array in bytes
  105. pcbNeeded => buffer length copied/required
  106. pcReturned => number of structures returned
  107. Return Value:
  108. TRUE if successful
  109. FALSE if failed - caller must use GetLastError for reason
  110. *******************************************************************
  111. --*/
  112. BOOL
  113. EnumPrintProcessorDatatypes(
  114. LPWSTR pName,
  115. LPWSTR pPrintProcessorName,
  116. DWORD Level,
  117. LPBYTE pDatatypes,
  118. DWORD cbBuf,
  119. LPDWORD pcbNeeded,
  120. LPDWORD pcReturned
  121. )
  122. {
  123. DATATYPES_INFO_1 *pInfo1 = (DATATYPES_INFO_1 *)pDatatypes;
  124. LPWSTR *pMyDatatypes = Datatypes;
  125. DWORD cbTotal=0;
  126. ULONG cchBuf =0;
  127. LPBYTE pEnd;
  128. if ( NULL == pcbNeeded ||
  129. NULL == pcReturned )
  130. {
  131. return FALSE;
  132. SetLastError (ERROR_INVALID_PARAMETER);
  133. }
  134. /** Start assuming failure, no entries returned **/
  135. *pcReturned = 0;
  136. /** Add up the minimum buffer required **/
  137. while (*pMyDatatypes) {
  138. cbTotal += wcslen(*pMyDatatypes) * sizeof(WCHAR) + sizeof(WCHAR) +
  139. sizeof(DATATYPES_INFO_1);
  140. pMyDatatypes++;
  141. }
  142. /** Set the buffer length returned/required **/
  143. *pcbNeeded = cbTotal;
  144. /** Fill in the array only if there is sufficient space **/
  145. if (cbTotal <= cbBuf) {
  146. if ( NULL == pInfo1 ) //pInfo1 is same as pDatatypes
  147. {
  148. SetLastError (ERROR_INVALID_PARAMETER);
  149. return FALSE;
  150. }
  151. /** Pick up pointer to end of the given buffer **/
  152. pEnd = (LPBYTE)pInfo1 + cbBuf;
  153. /** Pick up our list of supported data types **/
  154. pMyDatatypes = Datatypes;
  155. /**
  156. Fill in the given buffer. We put the data names at the end of
  157. the buffer, working towards the front. The structures are put
  158. at the front, working towards the end.
  159. **/
  160. while (*pMyDatatypes) {
  161. cchBuf = wcslen(*pMyDatatypes) + 1; //+1 is for \0.
  162. pEnd -= cchBuf*sizeof(WCHAR);
  163. StringCchCopy ( (LPWSTR)pEnd, cchBuf, *pMyDatatypes);
  164. pInfo1->pName = (LPWSTR)pEnd;
  165. pInfo1++;
  166. (*pcReturned)++;
  167. pMyDatatypes++;
  168. }
  169. } else {
  170. /** Caller didn't have large enough buffer, set error and return **/
  171. SetLastError(ERROR_INSUFFICIENT_BUFFER);
  172. return FALSE;
  173. }
  174. /** Return success **/
  175. return TRUE;
  176. }
  177. /*++
  178. *******************************************************************
  179. O p e n P r i n t P r o c e s s o r
  180. Routine Description:
  181. Arguments:
  182. pPrinterName => name of printer we are
  183. opening for
  184. pPrintProcessorOpenData => information used for opening
  185. the print processor
  186. Return Value:
  187. PPRINTPROCESSORDATA => processor data of opened
  188. processor if successful
  189. NULL if failed - caller uses GetLastError for reason
  190. NOTE: OpenPrinter will be called iff this returns a valid handle
  191. (and we're not journal)
  192. @@BEGIN_DDKSPLIT
  193. ClosePrintProcessor MUST be called if we succeed here,
  194. (or else things don't get cleaned up--like pIniJob->cRef
  195. for RAW jobs, which causes the queue to stick!)
  196. @@END_DDKSPLIT
  197. *******************************************************************
  198. --*/
  199. HANDLE
  200. OpenPrintProcessor(
  201. LPWSTR pPrinterName,
  202. PPRINTPROCESSOROPENDATA pPrintProcessorOpenData
  203. )
  204. {
  205. PPRINTPROCESSORDATA pData;
  206. LPWSTR *pMyDatatypes=Datatypes;
  207. DWORD uDatatype=0;
  208. HANDLE hPrinter=0;
  209. HDC hDC = 0;
  210. PDEVMODEW pDevmode = NULL;
  211. /** If the caller passed a NULL for the open data, fail the call.
  212. pPrintProcessorOpenData->pDevMode can be NULL **/
  213. if (!pPrintProcessorOpenData ||
  214. !pPrintProcessorOpenData->pDatatype ||
  215. !*pPrintProcessorOpenData->pDatatype) {
  216. SetLastError(ERROR_INVALID_PARAMETER);
  217. return NULL;
  218. }
  219. /** Search for the data type index we are opening for **/
  220. while (*pMyDatatypes) {
  221. if (!_wcsicmp(*pMyDatatypes,pPrintProcessorOpenData->pDatatype)) {
  222. break;
  223. }
  224. pMyDatatypes++;
  225. uDatatype++;
  226. }
  227. /** Allocate a buffer for the print processor data to return **/
  228. pData = (PPRINTPROCESSORDATA)AllocSplMem(sizeof(PRINTPROCESSORDATA));
  229. if (!pData) {
  230. ODS(("Alloc failed in OpenPrintProcessor, while printing on %ws\n", pPrinterName));
  231. return NULL;
  232. }
  233. ZeroMemory ( pData, sizeof (PRINTPROCESSORDATA) );
  234. /** Open the processor accordingly **/
  235. switch (uDatatype) {
  236. case PRINTPROCESSOR_TYPE_RAW:
  237. // @@BEGIN_DDKSPLIT
  238. case PRINTPROCESSOR_TYPE_RAW_FF:
  239. case PRINTPROCESSOR_TYPE_RAW_FF_AUTO:
  240. // @@END_DDKSPLIT
  241. if (!OpenPrinter(pPrinterName, &hPrinter, NULL))
  242. goto Fail;
  243. break;
  244. case PRINTPROCESSOR_TYPE_EMF_50_1:
  245. case PRINTPROCESSOR_TYPE_EMF_50_2:
  246. case PRINTPROCESSOR_TYPE_EMF_50_3:
  247. if(pPrintProcessorOpenData->pDevMode)
  248. {
  249. if(!(pDevmode=AllocSplMem(pPrintProcessorOpenData->pDevMode->dmSize+
  250. pPrintProcessorOpenData->pDevMode->dmDriverExtra)))
  251. {
  252. goto Fail;
  253. }
  254. memcpy(pDevmode,
  255. pPrintProcessorOpenData->pDevMode,
  256. pPrintProcessorOpenData->pDevMode->dmSize+
  257. pPrintProcessorOpenData->pDevMode->dmDriverExtra);
  258. }
  259. break;
  260. case PRINTPROCESSOR_TYPE_TEXT:
  261. if (!(hDC = CreateDC(L"", pPrinterName, L"",
  262. pPrintProcessorOpenData->pDevMode)))
  263. goto Fail;
  264. break;
  265. default:
  266. SetLastError(ERROR_INVALID_DATATYPE);
  267. goto Fail;
  268. }
  269. /** Fill in the print processors information **/
  270. pData->cb = sizeof(PRINTPROCESSORDATA);
  271. pData->signature = PRINTPROCESSORDATA_SIGNATURE;
  272. pData->JobId = pPrintProcessorOpenData->JobId;
  273. pData->hPrinter = hPrinter;
  274. pData->semPaused = CreateEvent(NULL, TRUE, TRUE,NULL);
  275. pData->uDatatype = uDatatype;
  276. pData->hDC = hDC;
  277. pData->Copies = 1;
  278. pData->TabSize = BASE_TAB_SIZE;
  279. /** Allocate and fill in the processors strings **/
  280. pData->pPrinterName = AllocSplStr(pPrinterName);
  281. pData->pDatatype = AllocSplStr(pPrintProcessorOpenData->pDatatype);
  282. pData->pDocument = AllocSplStr(pPrintProcessorOpenData->pDocumentName);
  283. pData->pOutputFile = AllocSplStr(pPrintProcessorOpenData->pOutputFile);
  284. pData->pParameters = AllocSplStr(pPrintProcessorOpenData->pParameters);
  285. pData->pDevmode = pDevmode;
  286. pData->pPrinterNameFromOpenData = AllocSplStr(pPrintProcessorOpenData->pPrinterName);
  287. //
  288. // Check for validity of pData. In the AllocSplStr above, if RHS is non-null, then LHS
  289. // should be non-null.
  290. //
  291. if ( NULL == pData->semPaused ||
  292. ( NULL != pPrinterName && NULL == pData->pPrinterName ) ||
  293. ( NULL != pPrintProcessorOpenData->pDatatype && NULL == pData->pDatatype ) ||
  294. ( NULL != pPrintProcessorOpenData->pDocumentName && NULL == pData->pDocument ) ||
  295. ( NULL != pPrintProcessorOpenData->pOutputFile && NULL == pData->pOutputFile ) ||
  296. ( NULL != pPrintProcessorOpenData->pParameters && NULL == pData->pParameters ) ||
  297. ( NULL != pPrintProcessorOpenData->pPrinterName && NULL == pData->pPrinterNameFromOpenData)
  298. )
  299. {
  300. goto Fail;
  301. }
  302. // @@BEGIN_DDKSPLIT
  303. /**
  304. WORKWORK : Currently, the pParameters field has
  305. the name of the printer driver. This will be fixed, and
  306. should come up here the same as the user submitted in the
  307. job's Printer Info structure.
  308. **/
  309. // @@END_DDKSPLIT
  310. /** Parse the parameters string **/
  311. if (pData->pParameters) {
  312. ULONG value;
  313. USHORT length = sizeof(ULONG);
  314. /**
  315. Look to see if there is a COPIES=n key/value in the
  316. Parameters field of this job. This tells us the number
  317. of times to play the data.
  318. **/
  319. if (pData->pParameters) {
  320. GetKeyValue(pData->pParameters,
  321. pCopiesKey,
  322. VALUE_ULONG,
  323. &length,
  324. &value);
  325. if (length == sizeof(ULONG)) {
  326. pData->Copies = value;
  327. }
  328. }
  329. /** If this is a text job, see if the tab size is in there **/
  330. if (uDatatype == PRINTPROCESSOR_TYPE_TEXT) {
  331. length = sizeof(ULONG);
  332. GetKeyValue(pData->pParameters,
  333. pTabsKey,
  334. VALUE_ULONG,
  335. &length,
  336. &value);
  337. if ((length == sizeof(ULONG)) && value) {
  338. pData->TabSize = value;
  339. }
  340. }
  341. } /* If we have a parameter string */
  342. /**
  343. If we are doing copies, we need to check to see if
  344. this is a direct or spooled job. If it is direct, then
  345. we can't do copies because we can't rewind the data stream.
  346. **/
  347. if (pData->Copies > 1) {
  348. ULONG Error;
  349. PPRINTER_INFO_2 pPrinterInfo2;
  350. /** If we don't already have the printer open, open it **/
  351. if (uDatatype != PRINTPROCESSOR_TYPE_RAW
  352. // @@BEGIN_DDKSPLIT
  353. &&
  354. uDatatype != PRINTPROCESSOR_TYPE_RAW_FF &&
  355. uDatatype != PRINTPROCESSOR_TYPE_RAW_FF_AUTO
  356. // @@END_DDKSPLIT
  357. ) {
  358. OpenPrinter(pPrinterName, &hPrinter, NULL);
  359. }
  360. if (hPrinter && hPrinter != INVALID_HANDLE_VALUE) {
  361. /** Get the printer info - this returns an allocated buffer **/
  362. pPrinterInfo2 = (PPRINTER_INFO_2)GetPrinterInfo(hPrinter, 2, &Error);
  363. /** If we couldn't get the info, be safe and don't do copies **/
  364. if (!pPrinterInfo2) {
  365. ODS(("GetPrinter failed - falling back to 1 copy\n"));
  366. pData->Copies = 1;
  367. }
  368. else {
  369. if (pPrinterInfo2->Attributes & PRINTER_ATTRIBUTE_DIRECT) {
  370. pData->Copies = 1;
  371. }
  372. FreeSplMem((PUCHAR)pPrinterInfo2);
  373. }
  374. /** If we just opened the printer, close it **/
  375. if (uDatatype != PRINTPROCESSOR_TYPE_RAW
  376. // @@BEGIN_DDKSPLIT
  377. &&
  378. uDatatype != PRINTPROCESSOR_TYPE_RAW_FF &&
  379. uDatatype != PRINTPROCESSOR_TYPE_RAW_FF_AUTO
  380. // @@END_DDKSPLIT
  381. ) {
  382. ClosePrinter(hPrinter);
  383. }
  384. }
  385. else {
  386. pData->Copies = 1;
  387. }
  388. }
  389. return (HANDLE)pData;
  390. Fail:
  391. BReleasePPData(&pData);
  392. return FALSE;
  393. }
  394. /*++
  395. *******************************************************************
  396. P r i n t D o c u m e n t O n P r i n t P r o c e s s o r
  397. Routine Description:
  398. Arguments:
  399. hPrintProcessor
  400. pDocumentName
  401. Return Value:
  402. TRUE if successful
  403. FALSE if failed - GetLastError() will return reason
  404. *******************************************************************
  405. --*/
  406. BOOL
  407. PrintDocumentOnPrintProcessor(
  408. HANDLE hPrintProcessor,
  409. LPWSTR pDocumentName
  410. )
  411. {
  412. PPRINTPROCESSORDATA pData;
  413. /**
  414. Make sure the handle is valid and pick up
  415. the Print Processors data area.
  416. **/
  417. if (!(pData = ValidateHandle(hPrintProcessor))) {
  418. return FALSE;
  419. }
  420. /**
  421. Print the job based on its data type.
  422. **/
  423. switch (pData->uDatatype) {
  424. case PRINTPROCESSOR_TYPE_EMF_50_1:
  425. case PRINTPROCESSOR_TYPE_EMF_50_2:
  426. case PRINTPROCESSOR_TYPE_EMF_50_3:
  427. return PrintEMFJob( pData, pDocumentName );
  428. break;
  429. case PRINTPROCESSOR_TYPE_RAW:
  430. // @@BEGIN_DDKSPLIT
  431. case PRINTPROCESSOR_TYPE_RAW_FF:
  432. case PRINTPROCESSOR_TYPE_RAW_FF_AUTO:
  433. // @@END_DDKSPLIT
  434. return PrintRawJob(pData, pDocumentName, pData->uDatatype);
  435. break;
  436. case PRINTPROCESSOR_TYPE_TEXT:
  437. return PrintTextJob(pData, pDocumentName);
  438. break;
  439. } /* Case on data type */
  440. /** Return success **/
  441. return TRUE;
  442. }
  443. /*++
  444. *******************************************************************
  445. C l o s e P r i n t P r o c e s s o r
  446. Routine Description:
  447. Frees the resources used by an open print processor.
  448. Arguments:
  449. hPrintProcessor (HANDLE) => print processor to close
  450. Return Value:
  451. TRUE if successful
  452. FALSE if failed - caller uses GetLastError for reason.
  453. *******************************************************************
  454. --*/
  455. BOOL
  456. ClosePrintProcessor(
  457. HANDLE hPrintProcessor
  458. )
  459. {
  460. PPRINTPROCESSORDATA pData;
  461. /**
  462. Make sure the handle is valid and pick up
  463. the Print Processors data area.
  464. **/
  465. if (!(pData= ValidateHandle(hPrintProcessor))) {
  466. return FALSE;
  467. }
  468. return BReleasePPData(&pData);
  469. }
  470. BOOL BReleasePPData(
  471. IN PPRINTPROCESSORDATA * ppData )
  472. {
  473. PPRINTPROCESSORDATA pData = NULL;
  474. if ( NULL == ppData || NULL == *ppData)
  475. {
  476. return FALSE;
  477. }
  478. pData = *ppData;
  479. pData->signature = 0;
  480. /* Release any allocated resources */
  481. if (pData->hPrinter)
  482. ClosePrinter(pData->hPrinter);
  483. if (pData->hDC)
  484. DeleteDC(pData->hDC);
  485. if (pData->pDevmode)
  486. FreeSplMem(pData->pDevmode);
  487. if (pData->pPrinterNameFromOpenData)
  488. FreeSplStr(pData->pPrinterNameFromOpenData);
  489. if (pData->semPaused)
  490. CloseHandle(pData->semPaused);
  491. if (pData->pPrinterName)
  492. FreeSplStr(pData->pPrinterName);
  493. if (pData->pDatatype)
  494. FreeSplStr(pData->pDatatype);
  495. if (pData->pDocument)
  496. FreeSplStr(pData->pDocument);
  497. if (pData->pOutputFile)
  498. FreeSplStr(pData->pOutputFile);
  499. if (pData->pParameters)
  500. FreeSplStr(pData->pParameters);
  501. ZeroMemory ( pData, sizeof (PRINTPROCESSORDATA) );
  502. FreeSplMem(pData);
  503. *ppData = pData = NULL;
  504. return TRUE;
  505. }
  506. /*++
  507. *******************************************************************
  508. C o n t r o l P r i n t P r o c e s s o r
  509. Routine Description:
  510. Handles commands to pause, resume, and cancel print jobs.
  511. Arguments:
  512. hPrintProcessor = HANDLE to the PrintProcessor the
  513. command is issued for.
  514. Return Value:
  515. TRUE if command succeeded
  516. FALSE if command failed (invalid command)
  517. *******************************************************************
  518. --*/
  519. BOOL
  520. ControlPrintProcessor(
  521. HANDLE hPrintProcessor,
  522. DWORD Command
  523. )
  524. {
  525. PPRINTPROCESSORDATA pData;
  526. /**
  527. Make sure the handle is valid and pick up
  528. the Print Processors data area.
  529. **/
  530. if (pData = ValidateHandle(hPrintProcessor)) {
  531. switch (Command) {
  532. case JOB_CONTROL_PAUSE:
  533. ResetEvent(pData->semPaused);
  534. pData->fsStatus |= PRINTPROCESSOR_PAUSED;
  535. return TRUE;
  536. break;
  537. case JOB_CONTROL_CANCEL:
  538. pData->fsStatus |= PRINTPROCESSOR_ABORTED;
  539. if ((pData->uDatatype == PRINTPROCESSOR_TYPE_EMF_50_1) ||
  540. (pData->uDatatype == PRINTPROCESSOR_TYPE_EMF_50_2) ||
  541. (pData->uDatatype == PRINTPROCESSOR_TYPE_EMF_50_3))
  542. CancelDC(pData->hDC);
  543. /* Fall through to release job if paused */
  544. case JOB_CONTROL_RESUME:
  545. if (pData->fsStatus & PRINTPROCESSOR_PAUSED) {
  546. SetEvent(pData->semPaused);
  547. pData->fsStatus &= ~PRINTPROCESSOR_PAUSED;
  548. }
  549. return TRUE;
  550. break;
  551. default:
  552. return FALSE;
  553. break;
  554. }
  555. }
  556. return FALSE;
  557. }
  558. /*++
  559. *******************************************************************
  560. V a l i d a t e H a n d l e
  561. Routine Description:
  562. Validates the given Print Processor HANDLE (which is
  563. really a pointer to the Print Processor's data) by
  564. checking for our signature.
  565. Arguments:
  566. hQProc (HANDLE) => Print Processor data structure. This
  567. is verified as really being a pointer to the Print
  568. Processor's data.
  569. Return Value:
  570. PPRINTPROCESSORDATA if successful (valid pointer passed)
  571. NULL if failed - pointer was not valid
  572. *******************************************************************
  573. --*/
  574. PPRINTPROCESSORDATA
  575. ValidateHandle(
  576. HANDLE hQProc
  577. )
  578. {
  579. /** Pick up the pointer **/
  580. PPRINTPROCESSORDATA pData = (PPRINTPROCESSORDATA)hQProc;
  581. //
  582. // Note that spooler has to leave the critical section to call into print
  583. // proc. So the handle passed by spooler could be invalid since one
  584. // thread could call SetJob to pause/resume a job while port thread
  585. // is printing it
  586. //
  587. try {
  588. /** See if our signature exists in the suspected data region **/
  589. if (pData && pData->signature != PRINTPROCESSORDATA_SIGNATURE) {
  590. /** Bad pointer - return failed **/
  591. pData = NULL;
  592. }
  593. }except (1) {
  594. /** Bad pointer - return failed **/
  595. pData = NULL;
  596. }
  597. if ( pData == NULL )
  598. SetLastError( ERROR_INVALID_HANDLE );
  599. return pData;
  600. }
  601. DWORD
  602. GetPrintProcessorCapabilities(
  603. LPTSTR pValueName,
  604. DWORD dwAttributes,
  605. LPBYTE pData,
  606. DWORD nSize,
  607. LPDWORD pcbNeeded
  608. )
  609. /*++
  610. Function Description: GetPrintProcessorCapabilities returns information about the
  611. options supported by the print processor for the given datatype
  612. in a PRINTPROCESSOR_CAPS_1 struct.
  613. Parameters: pValueName -- datatype like RAW|NT EMF 1.006|TEXT|...
  614. dwAttributes -- printer attributes
  615. pData -- pointer to the buffer
  616. nSize -- size of the buffer
  617. pcbNeeded -- pointer to the variable to store the required buffer size
  618. Return Values: Error Codes.
  619. --*/
  620. {
  621. LPWSTR *pDatatypes = Datatypes;
  622. DWORD dwDatatype = 0;
  623. DWORD dwReturn;
  624. PPRINTPROCESSOR_CAPS_1 ppcInfo;
  625. // Check for valid parameters.
  626. if ( !pcbNeeded || !pData || !pValueName) {
  627. dwReturn = ERROR_INVALID_PARAMETER;
  628. goto CleanUp;
  629. }
  630. *pcbNeeded = sizeof(PRINTPROCESSOR_CAPS_1);
  631. // Check for sufficient buffer.
  632. if (nSize < *pcbNeeded) {
  633. dwReturn = ERROR_MORE_DATA;
  634. goto CleanUp;
  635. }
  636. // Loop to find the index of the datatype.
  637. while (*pDatatypes) {
  638. if (!_wcsicmp(*pDatatypes,pValueName)) {
  639. break;
  640. }
  641. pDatatypes++;
  642. dwDatatype++;
  643. }
  644. ppcInfo = (PPRINTPROCESSOR_CAPS_1) pData;
  645. // Level is 1 for PRINTPROCESSOR_CAPS_1.
  646. ppcInfo->dwLevel = 1;
  647. switch (dwDatatype) {
  648. case PRINTPROCESSOR_TYPE_RAW:
  649. // @@BEGIN_DDKSPLIT
  650. case PRINTPROCESSOR_TYPE_RAW_FF:
  651. case PRINTPROCESSOR_TYPE_RAW_FF_AUTO:
  652. // @@END_DDKSPLIT
  653. case PRINTPROCESSOR_TYPE_TEXT:
  654. ppcInfo->dwNupOptions = 1;
  655. ppcInfo->dwNumberOfCopies = 0xffffffff; // maximum number of copies.
  656. ppcInfo->dwPageOrderFlags = NORMAL_PRINT;
  657. break;
  658. case PRINTPROCESSOR_TYPE_EMF_50_1:
  659. case PRINTPROCESSOR_TYPE_EMF_50_2:
  660. case PRINTPROCESSOR_TYPE_EMF_50_3:
  661. // For direct printing, masq. printers and print RAW only,
  662. // EMF is not spooled. Dont expose EMF features in the UI.
  663. if ((dwAttributes & PRINTER_ATTRIBUTE_DIRECT) ||
  664. (dwAttributes & PRINTER_ATTRIBUTE_RAW_ONLY) ||
  665. ((dwAttributes & PRINTER_ATTRIBUTE_LOCAL) &&
  666. (dwAttributes & PRINTER_ATTRIBUTE_NETWORK))) {
  667. ppcInfo->dwNupOptions = 1;
  668. ppcInfo->dwNumberOfCopies = 1;
  669. ppcInfo->dwPageOrderFlags = NORMAL_PRINT;
  670. } else {
  671. ppcInfo->dwNupOptions = 0x0000812b; // for 1,2,4,6,9,16 up options.
  672. ppcInfo->dwNumberOfCopies = 0xffffffff; // maximum number of copies.
  673. ppcInfo->dwPageOrderFlags = REVERSE_PRINT | BOOKLET_PRINT;
  674. }
  675. break;
  676. default:
  677. // Should not happen since the spooler must check if the datatype is
  678. // supported before calling this print processor.
  679. dwReturn = ERROR_INVALID_DATATYPE;
  680. goto CleanUp;
  681. }
  682. dwReturn = ERROR_SUCCESS;
  683. CleanUp:
  684. return dwReturn;
  685. }