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.

382 lines
7.8 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. page.c
  5. Abstract:
  6. Implementation of document and page related DDI entry points:
  7. DrvStartDoc
  8. DrvEndDoc
  9. DrvStartPage
  10. DrvSendPage
  11. Environment:
  12. Fax driver, kernel mode
  13. Revision History:
  14. 01/09/96 -davidx-
  15. Created it.
  16. mm/dd/yy -author-
  17. description
  18. --*/
  19. #include "faxdrv.h"
  20. BOOL
  21. DrvStartDoc(
  22. SURFOBJ *pso,
  23. PWSTR pDocName,
  24. DWORD jobId
  25. )
  26. /*++
  27. Routine Description:
  28. Implementation of DDI entry point DrvStartDoc.
  29. Please refer to DDK documentation for more details.
  30. Arguments:
  31. pso - Defines the surface object
  32. pDocName - Specifies a Unicode document name
  33. jobId - Identifies the print job
  34. Return Value:
  35. TRUE if successful, FALSE if there is an error
  36. --*/
  37. {
  38. PDEVDATA pdev;
  39. Verbose(("Entering DrvStartDoc...\n"));
  40. //
  41. // Verify input parameters
  42. //
  43. Assert(pso != NULL);
  44. pdev = (PDEVDATA) pso->dhpdev;
  45. if (! ValidDevData(pdev)) {
  46. Error(("ValidDevData failed\n"));
  47. SetLastError(ERROR_INVALID_PARAMETER);
  48. return FALSE;
  49. }
  50. //
  51. // Initialize page count and other information
  52. //
  53. if (! (pdev->flags & PDEV_RESETPDEV)) {
  54. pdev->pageCount = 0;
  55. pdev->jobId = jobId;
  56. }
  57. //
  58. // Check if print preview was requested
  59. //
  60. if (NULL == pdev->pTiffPageHeader)
  61. {
  62. Assert(FALSE == pdev->bPrintPreview);
  63. }
  64. else
  65. {
  66. //
  67. // Validate preview mapping
  68. //
  69. if (sizeof(MAP_TIFF_PAGE_HEADER) != pdev->pTiffPageHeader->cb)
  70. {
  71. Error(("Preview mapping corrupted\n"));
  72. pdev->bPrintPreview = FALSE;
  73. }
  74. else
  75. {
  76. //
  77. // This is the place to check if print preview was requested: DrvStartDoc() is called
  78. // immediately after the UI dll sets pTiffPageHeader->bPreview value in DOCUMENTEVENT_STARTDOCPRE, or after ResetDC
  79. //
  80. pdev->bPrintPreview = pdev->pTiffPageHeader->bPreview;
  81. //
  82. // Reset page count in map file to 0. This causes the UI dll to ignore the first
  83. // DOCUMENTEVENT_STARTPAGE event when there is no real preview page ready.
  84. // The true page count will be updated every call to DrvStartPage().
  85. // If DrvStartDoc() called as a result of ResetDC(), we should restore the previous page count.
  86. //
  87. pdev->pTiffPageHeader->iPageCount = pdev->pageCount;
  88. //
  89. // If DrvStartDoc() called as a result of ResetDC(), we should restore the previous page file pointer
  90. //
  91. pdev->pbTiffPageFP = (((LPBYTE)(pdev->pTiffPageHeader + 1)) + pdev->pTiffPageHeader->dwDataSize);
  92. }
  93. }
  94. return TRUE;
  95. }
  96. BOOL
  97. DrvStartPage(
  98. SURFOBJ *pso
  99. )
  100. /*++
  101. Routine Description:
  102. Implementation of DDI entry point DrvStartPage.
  103. Please refer to DDK documentation for more details.
  104. Arguments:
  105. pso - Defines the surface object
  106. Return Value:
  107. TRUE if successful, FALSE if there is an error
  108. --*/
  109. {
  110. PDEVDATA pdev;
  111. RECTL pageRect;
  112. Verbose(("Entering DrvStartPage...\n"));
  113. //
  114. // Verify input parameters
  115. //
  116. Assert(pso != NULL);
  117. pdev = (PDEVDATA) pso->dhpdev;
  118. if (! ValidDevData(pdev)) {
  119. Error(("ValidDevData failed\n"));
  120. SetLastError(ERROR_INVALID_PARAMETER);
  121. return FALSE;
  122. }
  123. if (pdev->flags & PDEV_CANCELLED)
  124. return FALSE;
  125. //
  126. // Ignore nested calls to DrvStartPage
  127. //
  128. if (pdev->flags & PDEV_WITHINPAGE) {
  129. Error(("Nested call to DrvStartPage\n"));
  130. return TRUE;
  131. }
  132. pdev->flags |= PDEV_WITHINPAGE;
  133. //
  134. // Erase the page to all white
  135. //
  136. pageRect.left = pageRect.top = 0;
  137. pageRect.right = pdev->imageSize.cx;
  138. pageRect.bottom = pdev->imageSize.cy;
  139. EngEraseSurface(pso, &pageRect, WHITE_INDEX);
  140. pdev->pageCount++;
  141. //
  142. // Reset our 'Mapping file pointer' if we have an open mapping and print preview is enabled
  143. //
  144. if (pdev->bPrintPreview)
  145. {
  146. Assert(pdev->pTiffPageHeader);
  147. //
  148. // Validate preview mapping
  149. //
  150. if (sizeof(MAP_TIFF_PAGE_HEADER) != pdev->pTiffPageHeader->cb)
  151. {
  152. Error(("Preview mapping corrupted\n"));
  153. pdev->bPrintPreview = FALSE;
  154. }
  155. else
  156. {
  157. if (FALSE == pdev->pTiffPageHeader->bPreview)
  158. {
  159. //
  160. // Preview operation was cancled by the UI dll
  161. //
  162. pdev->bPrintPreview = FALSE;
  163. }
  164. else
  165. {
  166. pdev->pbTiffPageFP = (LPBYTE) (pdev->pTiffPageHeader + 1);
  167. pdev->pTiffPageHeader->dwDataSize = 0;
  168. pdev->pTiffPageHeader->iPageCount = pdev->pageCount;
  169. }
  170. }
  171. }
  172. return TRUE;
  173. }
  174. BOOL
  175. DrvSendPage(
  176. SURFOBJ *pso
  177. )
  178. /*++
  179. Routine Description:
  180. Implementation of DDI entry point DrvSendPage.
  181. Please refer to DDK documentation for more details.
  182. Arguments:
  183. pso - Defines the surface object
  184. Return Value:
  185. TRUE if successful, FALSE if there is an error
  186. --*/
  187. {
  188. PDEVDATA pdev;
  189. Verbose(("Entering DrvSendPage...\n"));
  190. //
  191. // Verify input parameters
  192. //
  193. Assert(pso != NULL);
  194. pdev = (PDEVDATA) pso->dhpdev;
  195. if (! ValidDevData(pdev)) {
  196. Error(("ValidDevData failed\n"));
  197. SetLastError(ERROR_INVALID_PARAMETER);
  198. return FALSE;
  199. }
  200. Assert(pdev->flags & PDEV_WITHINPAGE);
  201. pdev->flags &= ~PDEV_WITHINPAGE;
  202. if (pdev->flags & PDEV_CANCELLED)
  203. return FALSE;
  204. //
  205. // Validate preview mapping
  206. //
  207. if (pdev->bPrintPreview && sizeof(MAP_TIFF_PAGE_HEADER) != pdev->pTiffPageHeader->cb)
  208. {
  209. Error(("Preview mapping corrupted\n"));
  210. pdev->bPrintPreview = FALSE;
  211. }
  212. //
  213. // Output code to end a page
  214. //
  215. Assert(pso->lDelta == pdev->lineOffset);
  216. Assert(pso->fjBitmap & BMF_TOPDOWN);
  217. return OutputPageBitmap(pdev, pso->pvBits);
  218. }
  219. BOOL
  220. DrvEndDoc(
  221. SURFOBJ *pso,
  222. FLONG flags
  223. )
  224. /*++
  225. Routine Description:
  226. Implementation of DDI entry point DrvEndDoc.
  227. Please refer to DDK documentation for more details.
  228. Arguments:
  229. pso - Defines the surface object
  230. flags - A set of flag bits
  231. Return Value:
  232. TRUE if successful, FALSE if there is an error
  233. --*/
  234. {
  235. PDEVDATA pdev;
  236. Verbose(("Entering DrvEndDoc...\n"));
  237. //
  238. // Verify input parameters
  239. //
  240. Assert(pso != NULL);
  241. pdev = (PDEVDATA) pso->dhpdev;
  242. if (! ValidDevData(pdev)) {
  243. Error(("ValidDevData failed\n"));
  244. SetLastError(ERROR_INVALID_PARAMETER);
  245. return FALSE;
  246. }
  247. //
  248. // Validate preview mapping
  249. //
  250. if (pdev->bPrintPreview && sizeof(MAP_TIFF_PAGE_HEADER) != pdev->pTiffPageHeader->cb)
  251. {
  252. Error(("Preview mapping corrupted\n"));
  253. pdev->bPrintPreview = FALSE;
  254. }
  255. if ((pdev->flags & PDEV_CANCELLED) || (flags & ED_ABORTDOC)) {
  256. Error(("Print job was cancelled\n"));
  257. } else if (pdev->pageCount) {
  258. //
  259. // Perform any necessary work at the end of a document
  260. //
  261. Verbose(("Number of pages printed: %d\n", pdev->pageCount));
  262. if (!OutputDocTrailer(pdev)) {
  263. Error(("OutputDocTrailer failed\n"));
  264. return FALSE;
  265. }
  266. }
  267. //
  268. // Clean up
  269. //
  270. pdev->pageCount = 0;
  271. pdev->flags = 0;
  272. return TRUE;
  273. }