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.

204 lines
4.9 KiB

  1. /*++
  2. Copyright (c) 1990-2003 Microsoft Corporation
  3. All Rights Reserved
  4. // @@BEGIN_DDKSPLIT
  5. Module Name:
  6. windows\spooler\prtprocs\winprint\raw.c
  7. // @@END_DDKSPLIT
  8. Abstract:
  9. Routines to facilitate printing of raw jobs.
  10. // @@BEGIN_DDKSPLIT
  11. Author:
  12. Tommy Evans (vtommye) 10-22-1993
  13. Revision History:
  14. // @@END_DDKSPLIT
  15. --*/
  16. #include "local.h"
  17. // @@BEGIN_DDKSPLIT
  18. #include <winsplp.h>
  19. // @@END_DDKSPLIT
  20. #include <wchar.h>
  21. // @@BEGIN_DDKSPLIT
  22. #include "msnull.h"
  23. // @@END_DDKSPLIT
  24. BYTE abyFF[1] = { 0xc };
  25. /*++
  26. *******************************************************************
  27. P r i n t R a w J o b
  28. Routine Description:
  29. Prints out a job with RAW data type.
  30. Arguments:
  31. pData => Print Processor data structure
  32. pPrinterName => name of printer to print on
  33. Return Value:
  34. TRUE if successful
  35. FALSE if failed - GetLastError will return reason
  36. *******************************************************************
  37. --*/
  38. BOOL
  39. PrintRawJob(
  40. IN PPRINTPROCESSORDATA pData,
  41. IN LPWSTR pPrinterName,
  42. IN UINT uDataType)
  43. {
  44. DOC_INFO_1 DocInfo;
  45. DWORD Copies;
  46. DWORD NoRead, NoWritten;
  47. DWORD i;
  48. BOOL rc;
  49. HANDLE hPrinter;
  50. BYTE *ReadBuffer = NULL;
  51. BOOL bRet = FALSE;
  52. BOOL bStartDoc = FALSE;
  53. // @@BEGIN_DDKSPLIT
  54. BOOL bAddFF = FALSE;
  55. BOOL bCheckFF;
  56. PBYTE pByte;
  57. DCI DCIData;
  58. // @@END_DDKSPLIT
  59. DocInfo.pDocName = pData->pDocument; /* Document name */
  60. DocInfo.pOutputFile = pData->pOutputFile; /* Output file */
  61. DocInfo.pDatatype = pData->pDatatype; /* Document data type */
  62. /** Let the printer know we are starting a new document **/
  63. if (!StartDocPrinter(pData->hPrinter, 1, (LPBYTE)&DocInfo)) {
  64. goto Done;
  65. }
  66. bStartDoc = TRUE;
  67. // @@BEGIN_DDKSPLIT
  68. bCheckFF = (uDataType == PRINTPROCESSOR_TYPE_RAW_FF ||
  69. uDataType == PRINTPROCESSOR_TYPE_RAW_FF_AUTO);
  70. /** Setup the formfeed stuff **/
  71. if (bCheckFF) {
  72. DCIData.ParserState = prdg_Text;
  73. DCIData.ParserSequence = NULL;
  74. DCIData.FFstate = prdg_FFtext;
  75. DCIData.uType = uDataType;
  76. }
  77. // @@END_DDKSPLIT
  78. /** Allocate the read buffer, dynamically allocated to conserve stack space **/
  79. ReadBuffer = AllocSplMem(READ_BUFFER_SIZE);
  80. if (!ReadBuffer) {
  81. goto Done;
  82. }
  83. /** Print the data pData->Copies times **/
  84. Copies = pData->Copies;
  85. while (Copies--) {
  86. /**
  87. Open the printer. If it fails, return. This also sets up the
  88. pointer for the ReadPrinter calls.
  89. **/
  90. if (!OpenPrinter(pPrinterName, &hPrinter, NULL)) {
  91. goto Done;
  92. }
  93. /**
  94. Loop, getting data and sending it to the printer. This also
  95. takes care of pausing and cancelling print jobs by checking
  96. the processor's status flags while printing.
  97. **/
  98. while ((rc = ReadPrinter(hPrinter, ReadBuffer, READ_BUFFER_SIZE, &NoRead)) &&
  99. NoRead) {
  100. // @@BEGIN_DDKSPLIT
  101. if (bCheckFF) {
  102. for(i=0, pByte = ReadBuffer;
  103. i< NoRead;
  104. i++, pByte++) {
  105. CheckFormFeedStream(&DCIData, *pByte);
  106. }
  107. }
  108. // @@END_DDKSPLIT
  109. /** If the print processor is paused, wait for it to be resumed **/
  110. if (pData->fsStatus & PRINTPROCESSOR_PAUSED) {
  111. WaitForSingleObject(pData->semPaused, INFINITE);
  112. }
  113. /** If the job has been aborted, don't write anymore **/
  114. if (pData->fsStatus & PRINTPROCESSOR_ABORTED) {
  115. break;
  116. }
  117. /** Write the data to the printer **/
  118. WritePrinter(pData->hPrinter, ReadBuffer, NoRead, &NoWritten);
  119. }
  120. // @@BEGIN_DDKSPLIT
  121. /**
  122. If we are type _FF* then we may need to add a form feed.
  123. **/
  124. if (bCheckFF && CheckFormFeed(&DCIData)) {
  125. WritePrinter(pData->hPrinter, abyFF, sizeof(abyFF), &NoWritten);
  126. }
  127. // @@END_DDKSPLIT
  128. /**
  129. Close the printer - we open/close the printer for each
  130. copy so the data pointer will rewind.
  131. **/
  132. ClosePrinter(hPrinter);
  133. } /* While copies to print */
  134. bRet = TRUE;
  135. Done:
  136. /** Close the buffer we allocated **/
  137. if (ReadBuffer) {
  138. FreeSplMem(ReadBuffer);
  139. }
  140. /** Let the printer know that we are done printing **/
  141. if (bStartDoc) {
  142. EndDocPrinter(pData->hPrinter);
  143. }
  144. return bRet;
  145. }