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.

270 lines
7.0 KiB

  1. /*++
  2. Copyright (c) 1996-1997 Microsoft Corporation
  3. Module Name:
  4. devmode.c
  5. Abstract:
  6. Devmode related library functions
  7. Environment:
  8. Windows NT printer drivers
  9. Revision History:
  10. 07/22/98 -fengy-
  11. Move OEM related devmode functions into "oemutil.c".
  12. 02/04/97 -davidx-
  13. Devmode changes to support OEM plugins.
  14. 09/20/96 -davidx-
  15. Seperated from libutil.c and implement BValidateDevmodeFormFields.
  16. --*/
  17. #include "lib.h"
  18. #ifndef KERNEL_MODE
  19. #include <winddiui.h>
  20. #endif
  21. #include <printoem.h>
  22. #include "oemutil.h"
  23. //
  24. // Default halftone parameters
  25. //
  26. DEVHTINFO gDefaultDevHTInfo =
  27. {
  28. HT_FLAG_HAS_BLACK_DYE,
  29. HT_PATSIZE_6x6_M,
  30. 0, // DevPelsDPI
  31. { { 6380, 3350, 0 }, // xr, yr, Yr
  32. { 2345, 6075, 0 }, // xg, yg, Yg
  33. { 1410, 932, 0 }, // xb, yb, Yb
  34. { 2000, 2450, 0 }, // xc, yc, Yc Y=0=HT default
  35. { 5210, 2100, 0 }, // xm, ym, Ym
  36. { 4750, 5100, 0 }, // xy, yy, Yy
  37. { 3127, 3290, 0 }, // xw, yw, Yw=0=default
  38. 12500, // R gamma
  39. 12500, // G gamma
  40. 12500, // B gamma, 12500=Default
  41. 585, 120, // M/C, Y/C
  42. 0, 0, // C/M, Y/M
  43. 0, 10000 // C/Y, M/Y 10000=default
  44. }
  45. };
  46. COLORADJUSTMENT gDefaultHTColorAdjustment =
  47. {
  48. sizeof(COLORADJUSTMENT),
  49. 0,
  50. ILLUMINANT_DEVICE_DEFAULT,
  51. 10000,
  52. 10000,
  53. 10000,
  54. REFERENCE_BLACK_MIN,
  55. REFERENCE_WHITE_MAX,
  56. 0,
  57. 0,
  58. 0,
  59. 0
  60. };
  61. BOOL
  62. BValidateDevmodeFormFields(
  63. HANDLE hPrinter,
  64. PDEVMODE pDevmode,
  65. PRECTL prcImageArea,
  66. FORM_INFO_1 *pForms,
  67. DWORD dwForms
  68. )
  69. /*++
  70. Routine Description:
  71. Validate the form-related fields in the input devmode and
  72. make sure they're consistent with each other.
  73. Arguments:
  74. hPrinter - Handle to a printer
  75. pDevmode - Specifies the devmode whose form-related fields are to be validated
  76. prcImageArea - Returns the logical imageable area associated with the form
  77. pForms - Points to list of spooler forms
  78. dwForms - Number of spooler spooler
  79. Return Value:
  80. TRUE if successful, FALSE if there is an error
  81. Note:
  82. prcImageArea could be NULL in which case the caller is not interested
  83. in the imageable area information.
  84. If the caller doesn't want to provide the list of spooler forms,
  85. it can set pForms parameter to NULL and dwForms to 0.
  86. --*/
  87. #define FORMFLAG_ERROR 0
  88. #define FORMFLAG_VALID 1
  89. #define FORMFLAG_CUSTOM 2
  90. {
  91. DWORD dwIndex;
  92. PFORM_INFO_1 pAllocedForms = NULL;
  93. INT iResult = FORMFLAG_ERROR;
  94. //
  95. // Get the list of spooler forms if the caller hasn't provided it
  96. //
  97. if (pForms == NULL)
  98. {
  99. pAllocedForms = pForms = MyEnumForms(hPrinter, 1, &dwForms);
  100. if (pForms == NULL)
  101. return FALSE;
  102. }
  103. if ((pDevmode->dmFields & DM_PAPERWIDTH) &&
  104. (pDevmode->dmFields & DM_PAPERLENGTH) &&
  105. (pDevmode->dmPaperWidth > 0) &&
  106. (pDevmode->dmPaperLength > 0))
  107. {
  108. LONG lWidth, lHeight;
  109. //
  110. // Devmode is requesting form using width and height.
  111. // Go through the forms database and check if one of
  112. // the forms has the same size as what's being requested.
  113. //
  114. // The tolerance is 1mm. Also remember that our internal
  115. // unit for paper measurement is micron while the unit
  116. // for width and height fields in a DEVMODE is 0.1mm.
  117. //
  118. lWidth = pDevmode->dmPaperWidth * DEVMODE_PAPER_UNIT;
  119. lHeight = pDevmode->dmPaperLength * DEVMODE_PAPER_UNIT;
  120. for (dwIndex = 0; dwIndex < dwForms; dwIndex++)
  121. {
  122. if (abs(lWidth - pForms[dwIndex].Size.cx) <= 1000 &&
  123. abs(lHeight - pForms[dwIndex].Size.cy) <= 1000)
  124. {
  125. iResult = FORMFLAG_VALID;
  126. break;
  127. }
  128. }
  129. //
  130. // Custom size doesn't match that of any predefined forms.
  131. //
  132. if (iResult != FORMFLAG_VALID)
  133. {
  134. iResult = FORMFLAG_CUSTOM;
  135. pDevmode->dmFields &= ~(DM_PAPERSIZE|DM_FORMNAME);
  136. pDevmode->dmPaperSize = DMPAPER_USER;
  137. ZeroMemory(pDevmode->dmFormName, sizeof(pDevmode->dmFormName));
  138. //
  139. // Assume the logical imageable area is the entire page in this case
  140. //
  141. if (prcImageArea)
  142. {
  143. prcImageArea->left = prcImageArea->top = 0;
  144. prcImageArea->right = lWidth;
  145. prcImageArea->bottom = lHeight;
  146. }
  147. }
  148. }
  149. else if (pDevmode->dmFields & DM_PAPERSIZE)
  150. {
  151. //
  152. // Devmode is requesting form using paper size index
  153. //
  154. dwIndex = pDevmode->dmPaperSize;
  155. if ((dwIndex >= DMPAPER_FIRST) && (dwIndex < DMPAPER_FIRST + dwForms))
  156. {
  157. dwIndex -= DMPAPER_FIRST;
  158. iResult = FORMFLAG_VALID;
  159. }
  160. else
  161. {
  162. ERR(("Paper size index out-of-range: %d\n", dwIndex));
  163. }
  164. }
  165. else if (pDevmode->dmFields & DM_FORMNAME)
  166. {
  167. //
  168. // Devmode is requesting form using form name. Go through
  169. // the forms database and check if the requested form
  170. // name matches that of a database form.
  171. //
  172. for (dwIndex = 0; dwIndex < dwForms; dwIndex++)
  173. {
  174. if (_wcsicmp(pDevmode->dmFormName, pForms[dwIndex].pName) == EQUAL_STRING)
  175. {
  176. iResult = FORMFLAG_VALID;
  177. break;
  178. }
  179. }
  180. if (iResult != FORMFLAG_VALID)
  181. {
  182. ERR(("Unrecognized form name: %ws\n", pDevmode->dmFormName));
  183. }
  184. }
  185. else
  186. {
  187. ERR(("Invalid form requested in the devmode.\n"));
  188. }
  189. //
  190. // If a valid form is found, fill in the form-related field
  191. // in the devmode to make sure they're consistent.
  192. //
  193. // Remember the conversion from micron to 0.1mm here.
  194. //
  195. if (iResult == FORMFLAG_VALID)
  196. {
  197. pDevmode->dmFields &= ~(DM_PAPERWIDTH|DM_PAPERLENGTH);
  198. pDevmode->dmFields |= (DM_PAPERSIZE|DM_FORMNAME);
  199. pDevmode->dmPaperWidth = (SHORT) (pForms[dwIndex].Size.cx / DEVMODE_PAPER_UNIT);
  200. pDevmode->dmPaperLength = (SHORT) (pForms[dwIndex].Size.cy / DEVMODE_PAPER_UNIT);
  201. pDevmode->dmPaperSize = (SHORT) (dwIndex + DMPAPER_FIRST);
  202. CopyString(pDevmode->dmFormName, pForms[dwIndex].pName, CCHFORMNAME);
  203. if (prcImageArea)
  204. *prcImageArea = pForms[dwIndex].ImageableArea;
  205. }
  206. MemFree(pAllocedForms);
  207. return (iResult != FORMFLAG_ERROR);
  208. }