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.

1140 lines
30 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. unilib.c
  5. Abstract:
  6. This file handles the shared KM and UM code for Unidrv
  7. Environment:
  8. Win32 subsystem, Unidrv driver
  9. Revision History:
  10. 02/04/97 -davidx-
  11. Devmode changes to support OEM plugins.
  12. 10/17/96 -amandan-
  13. Created it.
  14. --*/
  15. #include "precomp.h"
  16. #ifndef KERNEL_MODE
  17. #include <winddiui.h>
  18. #endif
  19. #include <printoem.h>
  20. #include "oemutil.h"
  21. #include "gpd.h"
  22. //
  23. // Internal data structure
  24. //
  25. typedef union {
  26. WORD w;
  27. BYTE b[2];
  28. } UW;
  29. typedef union {
  30. DWORD dw;
  31. BYTE b[4];
  32. } UDW;
  33. #if !defined(DEVSTUDIO) // MDS doesn't need these
  34. //
  35. // Information about UniDriver private devmode
  36. //
  37. CONST DRIVER_DEVMODE_INFO gDriverDMInfo =
  38. {
  39. UNIDRIVER_VERSION, sizeof(UNIDRVEXTRA),
  40. UNIDRIVER_VERSION_500, sizeof(UNIDRVEXTRA500),
  41. UNIDRIVER_VERSION_400, sizeof(UNIDRVEXTRA400),
  42. UNIDRIVER_VERSION_351, sizeof(UNIDRVEXTRA351),
  43. };
  44. CONST DWORD gdwDriverDMSignature = UNIDEVMODE_SIGNATURE;
  45. CONST WORD gwDriverVersion = UNIDRIVER_VERSION;
  46. //
  47. // Functions
  48. //
  49. BOOL
  50. BInitDriverDefaultDevmode(
  51. OUT PDEVMODE pdm,
  52. IN LPCTSTR pDeviceName,
  53. IN PUIINFO pUIInfo,
  54. IN PRAWBINARYDATA pRawData,
  55. IN BOOL bMetric
  56. )
  57. /*++
  58. Routine Description:
  59. This function intializes the devmode with
  60. the UNIDRV default devmode
  61. Arguments:
  62. pdm pointer to Unidrv DEVMODE
  63. pDeviceName pointer to device name
  64. pUIInfo pointer to UIINFO
  65. pRawData pointer to RAWBINARYDATA
  66. bMetric indicates whether system is running in a metric country
  67. Return Value:
  68. TRUE if successful, FALSE if there is an error
  69. Note:
  70. This function should initialize both public devmode fields
  71. and driver private devmode fields. It's also assumed that
  72. output buffer has already been zero initialized by the caller.
  73. --*/
  74. {
  75. PDEVMODE pdmPublic;
  76. PUNIDRVEXTRA pdmPrivate;
  77. PWSTR pwstrFormName;
  78. PFEATURE pFeature;
  79. PGPDDRIVERINFO pDriverInfo;
  80. pDriverInfo = GET_DRIVER_INFO_FROM_INFOHEADER(pUIInfo->pInfoHeader);
  81. pdmPublic = pdm;
  82. /*********************/
  83. /* PUBLIC DEVMODE */
  84. /*********************/
  85. if (pDeviceName)
  86. CopyStringW(pdmPublic->dmDeviceName, pDeviceName, CCHDEVICENAME);
  87. pdmPublic->dmDriverVersion = UNIDRIVER_VERSION;
  88. pdmPublic->dmSpecVersion = DM_SPECVERSION;
  89. pdmPublic->dmSize = sizeof(DEVMODE);
  90. pdmPublic->dmDriverExtra = sizeof(UNIDRVEXTRA);
  91. pdmPublic->dmFields =
  92. DM_COPIES | DM_ORIENTATION | DM_PAPERSIZE | DM_COLLATE | DM_DITHERTYPE |
  93. DM_COLOR | DM_FORMNAME | DM_TTOPTION | DM_DEFAULTSOURCE |
  94. #ifndef WINNT_40
  95. DM_NUP |
  96. #endif
  97. DM_PRINTQUALITY;
  98. pdmPublic->dmOrientation = DMORIENT_PORTRAIT;
  99. pdmPublic->dmDuplex = DMDUP_SIMPLEX;
  100. pdmPublic->dmCollate = DMCOLLATE_TRUE;
  101. pdmPublic->dmMediaType = DMMEDIA_STANDARD;
  102. pdmPublic->dmTTOption = DMTT_SUBDEV;
  103. pdmPublic->dmColor = DMCOLOR_MONOCHROME;
  104. pdmPublic->dmDefaultSource = DMBIN_FORMSOURCE;
  105. pdmPublic->dmScale = 100;
  106. pdmPublic->dmCopies = 1;
  107. #ifndef WINNT_40
  108. pdmPublic->dmNup = DMNUP_SYSTEM;
  109. #endif
  110. //
  111. // We always set ICM off. The spooler will turn it on at install time
  112. // if there are color profiles installed with this printer
  113. //
  114. pdmPublic->dmICMMethod = DMICMMETHOD_NONE;
  115. pdmPublic->dmICMIntent = DMICM_CONTRAST;
  116. pdmPublic->dmDitherType = pUIInfo->defaultQuality + QUALITY_MACRO_START;
  117. if (pUIInfo->liBestQualitySettings == END_OF_LIST &&
  118. pUIInfo->liBetterQualitySettings == END_OF_LIST &&
  119. pUIInfo->liDraftQualitySettings == END_OF_LIST)
  120. pdmPublic->dmDitherType = QUALITY_MACRO_CUSTOM;
  121. #ifndef WINNT_40
  122. pdmPublic->dmFields |= (DM_ICMMETHOD | DM_ICMINTENT);
  123. #endif
  124. if (pDriverInfo && pDriverInfo->Globals.bTTFSEnabled == FALSE)
  125. pdmPublic->dmTTOption = DMTT_DOWNLOAD;
  126. if (pFeature = GET_PREDEFINED_FEATURE(pUIInfo, GID_RESOLUTION))
  127. {
  128. PRESOLUTION pRes;
  129. //
  130. // Use the default resolution specified in the PPD file
  131. //
  132. if (pRes = PGetIndexedOption(pUIInfo, pFeature, pFeature->dwDefaultOptIndex))
  133. {
  134. pdmPublic->dmPrintQuality = (short)pRes->iXdpi;
  135. pdmPublic->dmYResolution = (short)pRes->iYdpi;
  136. }
  137. }
  138. if (pFeature = GET_PREDEFINED_FEATURE(pUIInfo, GID_DUPLEX))
  139. {
  140. PDUPLEX pDuplex;
  141. //
  142. // Use the default duplex option specified in the GPD file
  143. //
  144. pdmPublic->dmFields |= DM_DUPLEX;
  145. if (pDuplex = PGetIndexedOption(pUIInfo, pFeature, pFeature->dwDefaultOptIndex))
  146. pdmPublic->dmDuplex = (SHORT) pDuplex->dwDuplexID;
  147. }
  148. //
  149. // Always set DM_COLLATE flag since we can simulate it if the
  150. // device cannot.
  151. //
  152. if (pFeature = GET_PREDEFINED_FEATURE(pUIInfo, GID_MEDIATYPE))
  153. {
  154. PMEDIATYPE pMediaType;
  155. //
  156. // Use the default media type specified in the PPD file
  157. //
  158. pdmPublic->dmFields |= DM_MEDIATYPE;
  159. if (pMediaType = PGetIndexedOption(pUIInfo, pFeature, pFeature->dwDefaultOptIndex))
  160. pdmPublic->dmMediaType = (SHORT)pMediaType->dwMediaTypeID;
  161. }
  162. if (pUIInfo->dwFlags & FLAG_COLOR_DEVICE)
  163. {
  164. if (pFeature = GET_PREDEFINED_FEATURE(pUIInfo, GID_COLORMODE))
  165. {
  166. POPTION pColorMode;
  167. PCOLORMODEEX pColorModeEx;
  168. if ((pColorMode = PGetIndexedOption(pUIInfo, pFeature, pFeature->dwDefaultOptIndex)) &&
  169. (pColorModeEx = OFFSET_TO_POINTER(pUIInfo->pInfoHeader, pColorMode->loRenderOffset)) &&
  170. (pColorModeEx->bColor))
  171. {
  172. pdmPublic->dmColor = DMCOLOR_COLOR;
  173. }
  174. }
  175. pdmPublic->dmFields |= DM_COLOR;
  176. }
  177. //
  178. // Initialize form-related fields
  179. //
  180. VDefaultDevmodeFormFields(pUIInfo, pdmPublic, bMetric);
  181. /*********************/
  182. /* PRIVATE DEVMODE */
  183. /*********************/
  184. //
  185. // Fill in the private portion of devmode
  186. //
  187. pdmPrivate = (PUNIDRVEXTRA) GET_DRIVER_PRIVATE_DEVMODE(pdm);
  188. pdmPrivate->wVer = UNIDRVEXTRA_VERSION ;
  189. pdmPrivate->wSize = sizeof(UNIDRVEXTRA);
  190. pdmPrivate->wOEMExtra = 0;
  191. ZeroMemory(pdmPrivate->wReserved, sizeof(pdmPrivate->wReserved));
  192. pdmPrivate->iLayout = ONE_UP;
  193. pdmPrivate->bReversePrint = FALSE;
  194. pdmPrivate->iQuality = pUIInfo->defaultQuality;
  195. //
  196. // Initialize default sFlags
  197. //
  198. if (pUIInfo->dwFlags & FLAG_FONT_DOWNLOADABLE)
  199. pdmPrivate->dwFlags &= DXF_DOWNLOADTT;
  200. pdmPrivate->dwSignature = UNIDEVMODE_SIGNATURE;
  201. pdmPrivate->dwChecksum32 = pRawData->dwChecksum32;
  202. pdmPrivate->dwOptions = pRawData->dwDocumentFeatures;
  203. InitDefaultOptions(pRawData,
  204. pdmPrivate->aOptions,
  205. MAX_PRINTER_OPTIONS,
  206. MODE_DOCUMENT_STICKY);
  207. return TRUE;
  208. }
  209. VOID
  210. VMergePublicDevmodeFields (
  211. PDEVMODE pdmSrc,
  212. PDEVMODE pdmDest,
  213. PUIINFO pUIInfo,
  214. PRAWBINARYDATA pRawData
  215. )
  216. /*++
  217. Routine Description:
  218. This function merges the public devmode fields from SRC to DEST
  219. It is assumed that the devmode has been converted to the current
  220. version before this function is called
  221. Arguments:
  222. pdmSrc pointer to src DEVMODE
  223. pdmDest pointer to destination DEVMODE
  224. pUIInfo pointer to UIINFO
  225. pRawData pointer to raw binary printer description data
  226. Return Value:
  227. None
  228. Note:
  229. --*/
  230. {
  231. PFEATURE pFeature;
  232. #ifndef WINNT_40
  233. if ( (pdmSrc->dmFields & DM_NUP) &&
  234. (pdmSrc->dmNup == DMNUP_SYSTEM ||
  235. pdmSrc->dmNup == DMNUP_ONEUP))
  236. {
  237. pdmDest->dmNup = pdmSrc->dmNup;
  238. pdmDest->dmFields |= DM_NUP;
  239. }
  240. #endif
  241. //
  242. // Copy dmDefaultSource field
  243. //
  244. if ( pdmSrc->dmFields & DM_DEFAULTSOURCE &&
  245. ((pdmSrc->dmDefaultSource >= DMBIN_FIRST &&
  246. pdmSrc->dmDefaultSource <= DMBIN_LAST) ||
  247. pdmSrc->dmDefaultSource >= DMBIN_USER))
  248. {
  249. pdmDest->dmDefaultSource = pdmSrc->dmDefaultSource;
  250. pdmDest->dmFields |= DM_DEFAULTSOURCE;
  251. }
  252. //
  253. // Copy the dmDitherType field
  254. //
  255. if ((pdmSrc->dmFields & DM_DITHERTYPE) &&
  256. ((pdmSrc->dmDitherType >= QUALITY_MACRO_START &&
  257. pdmSrc->dmDitherType < QUALITY_MACRO_END) ||
  258. (pdmSrc->dmDitherType <= HT_PATSIZE_MAX_INDEX)))
  259. {
  260. pdmDest->dmFields |= DM_DITHERTYPE;
  261. pdmDest->dmDitherType = pdmSrc->dmDitherType;
  262. }
  263. //
  264. // Copy dmOrientation field
  265. //
  266. if ((pdmSrc->dmFields & DM_ORIENTATION) &&
  267. (pdmSrc->dmOrientation == DMORIENT_PORTRAIT ||
  268. pdmSrc->dmOrientation == DMORIENT_LANDSCAPE))
  269. {
  270. pdmDest->dmFields |= DM_ORIENTATION;
  271. pdmDest->dmOrientation = pdmSrc->dmOrientation;
  272. }
  273. //
  274. // If both DM_PAPERLENGTH and DM_PAPERWIDTH are set, copy
  275. // dmPaperLength and dmPaperWidth fields. If DM_PAPERSIZE
  276. // is set, copy dmPaperSize field. Otherwise, if DM_FORMNAME
  277. // is set, copy dmFormName field.
  278. //
  279. //
  280. // If both DM_PAPERLENGTH and DM_PAPERWIDTH are set, copy
  281. // dmPaperLength and dmPaperWidth fields. If DM_PAPERSIZE
  282. // is set, copy dmPaperSize field. Otherwise, if DM_FORMNAME
  283. // is set, copy dmFormName field.
  284. //
  285. if ((pdmSrc->dmFields & DM_PAPERWIDTH) &&
  286. (pdmSrc->dmFields & DM_PAPERLENGTH) &&
  287. (pdmSrc->dmPaperWidth > 0) &&
  288. (pdmSrc->dmPaperLength > 0))
  289. {
  290. pdmDest->dmFields |= (DM_PAPERLENGTH | DM_PAPERWIDTH);
  291. pdmDest->dmFields &= ~(DM_PAPERSIZE | DM_FORMNAME);
  292. pdmDest->dmPaperWidth = pdmSrc->dmPaperWidth;
  293. pdmDest->dmPaperLength = pdmSrc->dmPaperLength;
  294. }
  295. else if (pdmSrc->dmFields & DM_PAPERSIZE)
  296. {
  297. pdmDest->dmFields |= DM_PAPERSIZE;
  298. pdmDest->dmFields &= ~(DM_PAPERLENGTH | DM_PAPERWIDTH | DM_FORMNAME);
  299. pdmDest->dmPaperSize = pdmSrc->dmPaperSize;
  300. }
  301. else if (pdmSrc->dmFields & DM_FORMNAME)
  302. {
  303. pdmDest->dmFields |= DM_FORMNAME;
  304. pdmDest->dmFields &= ~(DM_PAPERLENGTH | DM_PAPERWIDTH | DM_PAPERSIZE);
  305. CopyString(pdmDest->dmFormName, pdmSrc->dmFormName, CCHFORMNAME);
  306. }
  307. //
  308. // Copy dmScale field
  309. //
  310. if ((pdmSrc->dmFields & DM_SCALE) &&
  311. (pdmSrc->dmScale >= MIN_SCALE) &&
  312. (pdmSrc->dmScale <= MAX_SCALE))
  313. {
  314. //
  315. // Unidrv can't have DM_SCALE flag set for app compat reasons. That is
  316. // the same behavior we saw when testing other OEM PCL drivers.
  317. // (See bug #35241 for details.)
  318. //
  319. // pdmDest->dmFields |= DM_SCALE;
  320. //
  321. pdmDest->dmScale = pdmSrc->dmScale;
  322. }
  323. //
  324. // Copy dmCopies field
  325. //
  326. if ((pdmSrc->dmFields & DM_COPIES) &&
  327. (pdmSrc->dmCopies >= 1) &&
  328. (pdmSrc->dmCopies <= max(MAX_COPIES, (SHORT)pUIInfo->dwMaxCopies)))
  329. {
  330. pdmDest->dmFields |= DM_COPIES;
  331. pdmDest->dmCopies = pdmSrc->dmCopies;
  332. }
  333. if ((pdmSrc->dmFields & DM_COLOR) &&
  334. (pdmSrc->dmColor == DMCOLOR_COLOR ||
  335. pdmSrc->dmColor == DMCOLOR_MONOCHROME))
  336. {
  337. pdmDest->dmFields |= DM_COLOR;
  338. pdmDest->dmColor = pdmSrc->dmColor;
  339. }
  340. if ((pdmSrc->dmFields & DM_DUPLEX) &&
  341. (GET_PREDEFINED_FEATURE(pUIInfo, GID_DUPLEX) != NULL) &&
  342. (pdmSrc->dmDuplex == DMDUP_SIMPLEX ||
  343. pdmSrc->dmDuplex == DMDUP_HORIZONTAL ||
  344. pdmSrc->dmDuplex == DMDUP_VERTICAL))
  345. {
  346. pdmDest->dmFields |= DM_DUPLEX;
  347. pdmDest->dmDuplex = pdmSrc->dmDuplex;
  348. }
  349. if ((pdmSrc->dmFields & DM_COLLATE) &&
  350. (pdmSrc->dmCollate == DMCOLLATE_TRUE ||
  351. pdmSrc->dmCollate == DMCOLLATE_FALSE))
  352. {
  353. pdmDest->dmFields |= DM_COLLATE;
  354. pdmDest->dmCollate = pdmSrc->dmCollate;
  355. }
  356. //
  357. // Copy dmTTOption field
  358. //
  359. if (pdmSrc->dmFields & DM_TTOPTION &&
  360. (pdmSrc->dmTTOption == DMTT_BITMAP ||
  361. pdmSrc->dmTTOption == DMTT_DOWNLOAD ||
  362. pdmSrc->dmTTOption == DMTT_SUBDEV) )
  363. {
  364. pdmDest->dmTTOption = pdmSrc->dmTTOption;
  365. pdmDest->dmFields |= DM_TTOPTION;
  366. }
  367. if ((pdmSrc->dmFields & DM_ICMMETHOD) &&
  368. (pdmSrc->dmICMMethod == DMICMMETHOD_NONE ||
  369. pdmSrc->dmICMMethod == DMICMMETHOD_SYSTEM ||
  370. pdmSrc->dmICMMethod == DMICMMETHOD_DRIVER ||
  371. pdmSrc->dmICMMethod == DMICMMETHOD_DEVICE))
  372. {
  373. pdmDest->dmFields |= DM_ICMMETHOD;
  374. pdmDest->dmICMMethod = pdmSrc->dmICMMethod;
  375. }
  376. if ((pdmSrc->dmFields & DM_ICMINTENT) &&
  377. (pdmSrc->dmICMIntent == DMICM_SATURATE ||
  378. #ifndef WINNT_40
  379. pdmSrc->dmICMIntent == DMICM_COLORIMETRIC ||
  380. pdmSrc->dmICMIntent == DMICM_ABS_COLORIMETRIC ||
  381. #endif
  382. pdmSrc->dmICMIntent == DMICM_CONTRAST
  383. ))
  384. {
  385. pdmDest->dmFields |= DM_ICMINTENT;
  386. pdmDest->dmICMIntent = pdmSrc->dmICMIntent;
  387. }
  388. //
  389. // Resolution
  390. //
  391. if ((pdmSrc->dmFields & (DM_PRINTQUALITY|DM_YRESOLUTION)) &&
  392. (pFeature = GET_PREDEFINED_FEATURE(pUIInfo, GID_RESOLUTION)))
  393. {
  394. PRESOLUTION pRes;
  395. DWORD dwIndex;
  396. INT iXdpi, iYdpi;
  397. switch (pdmSrc->dmFields & (DM_PRINTQUALITY|DM_YRESOLUTION))
  398. {
  399. case DM_PRINTQUALITY:
  400. iXdpi = iYdpi = pdmSrc->dmPrintQuality;
  401. break;
  402. case DM_YRESOLUTION:
  403. iXdpi = iYdpi = pdmSrc->dmYResolution;
  404. break;
  405. default:
  406. iXdpi = pdmSrc->dmPrintQuality;
  407. iYdpi = pdmSrc->dmYResolution;
  408. break;
  409. }
  410. dwIndex = MapToDeviceOptIndex(pUIInfo->pInfoHeader, GID_RESOLUTION, iXdpi, iYdpi, NULL);
  411. if (pRes = PGetIndexedOption(pUIInfo, pFeature, dwIndex))
  412. {
  413. pdmDest->dmFields |= (DM_PRINTQUALITY|DM_YRESOLUTION);
  414. pdmDest->dmPrintQuality = GETQUALITY_X(pRes);
  415. pdmDest->dmYResolution = GETQUALITY_Y(pRes);
  416. }
  417. }
  418. //
  419. // Media type
  420. //
  421. if ((pdmSrc->dmFields & DM_MEDIATYPE) &&
  422. (pFeature = GET_PREDEFINED_FEATURE(pUIInfo, GID_MEDIATYPE)) &&
  423. (pdmSrc->dmMediaType == DMMEDIA_STANDARD ||
  424. pdmSrc->dmMediaType == DMMEDIA_TRANSPARENCY ||
  425. pdmSrc->dmMediaType == DMMEDIA_GLOSSY ||
  426. pdmSrc->dmMediaType >= DMMEDIA_USER) )
  427. {
  428. pdmDest->dmFields |= DM_MEDIATYPE;
  429. pdmDest->dmMediaType = pdmSrc->dmMediaType;
  430. }
  431. }
  432. BOOL
  433. BMergeDriverDevmode(
  434. IN OUT PDEVMODE pdmDest,
  435. IN PUIINFO pUIInfo,
  436. IN PRAWBINARYDATA pRawData,
  437. IN PDEVMODE pdmSrc
  438. )
  439. /*++
  440. Routine Description:
  441. This function validates the source devmode and
  442. merge it with the destination devmode for UNIDRV
  443. Arguments:
  444. pdmDest pointer to destination Unidrv DEVMODE
  445. pUIInfo pointer to UIINFO
  446. pRawData pointer to RAWBINARYDATA
  447. pdmSrc pointer to src DEVMODE
  448. Return Value:
  449. TRUE if successful, FALSE if there is a fatal error
  450. Note:
  451. This function should take care of both public devmode fields
  452. and driver private devmode fields. It can assume the input
  453. devmode has already been convert to the current size.
  454. --*/
  455. {
  456. PUNIDRVEXTRA pPrivDest, pPrivSrc;
  457. ASSERT(pdmDest != NULL &&
  458. pdmDest->dmSize == sizeof(DEVMODE) &&
  459. pdmDest->dmDriverExtra >= sizeof(UNIDRVEXTRA) &&
  460. pdmSrc != NULL &&
  461. pdmSrc->dmSize == sizeof(DEVMODE) &&
  462. pdmSrc->dmDriverExtra >= sizeof(UNIDRVEXTRA));
  463. /**********************************/
  464. /* TRANSFER PUBLIC DEVMODE FIELDS */
  465. /**********************************/
  466. VMergePublicDevmodeFields(pdmSrc, pdmDest, pUIInfo, pRawData);
  467. /***************************/
  468. /* GET PRIVATE DEVMODE */
  469. /***************************/
  470. //
  471. // If the source devmode has a private portion, then check
  472. // to see if belongs to us. Copy the private portion to
  473. // the destination devmode if it does.
  474. //
  475. pPrivSrc = (PUNIDRVEXTRA) GET_DRIVER_PRIVATE_DEVMODE(pdmSrc);
  476. pPrivDest = (PUNIDRVEXTRA) GET_DRIVER_PRIVATE_DEVMODE(pdmDest);
  477. //
  478. // Validate private portion of input devmode
  479. // If it's not our private devmode, then return the default already in
  480. // privDest
  481. //
  482. if (pPrivSrc->dwSignature == UNIDEVMODE_SIGNATURE)
  483. {
  484. memcpy(pPrivDest, pPrivSrc, sizeof(UNIDRVEXTRA));
  485. if (pPrivDest->dwChecksum32 != pRawData->dwChecksum32)
  486. {
  487. WARNING(( "UNIDRV: Devmode checksum mismatch.\n"));
  488. pPrivDest->dwChecksum32 = pRawData->dwChecksum32;
  489. pPrivDest->dwOptions = pRawData->dwDocumentFeatures;
  490. InitDefaultOptions(pRawData,
  491. pPrivDest->aOptions,
  492. MAX_PRINTER_OPTIONS,
  493. MODE_DOCUMENT_STICKY);
  494. }
  495. }
  496. return TRUE;
  497. }
  498. #endif // !defined(DEVSTUDIO)
  499. //
  500. // Alignment functions
  501. //
  502. WORD
  503. DwAlign2(
  504. IN PBYTE pubData)
  505. /*++
  506. Routine Description:
  507. Converts a non-aligned, big endian (e.g. 80386) value and returns
  508. it as an integer, with the correct byte alignment.
  509. Arguments:
  510. pubData - a pointer to a data buffer to convert
  511. Return Value:
  512. The converted value.
  513. --*/
  514. {
  515. static INT iType = 0;
  516. UW Uw;
  517. if( iType == 0 )
  518. {
  519. //
  520. // Need to determine byte/word relationships
  521. //
  522. Uw.b[ 0 ] = 0x01;
  523. Uw.b[ 1 ] = 0x02;
  524. iType = Uw.w == 0x0102 ? 1 : 2;
  525. }
  526. if( iType == 2 )
  527. {
  528. Uw.b[ 0 ] = *pubData++;
  529. Uw.b[ 1 ] = *pubData;
  530. }
  531. else
  532. {
  533. Uw.b[ 1 ] = *pubData++;
  534. Uw.b[ 0 ] = *pubData;
  535. }
  536. return Uw.w;
  537. }
  538. DWORD
  539. DwAlign4(
  540. IN PBYTE pubData)
  541. {
  542. static INT iType = 0;
  543. UDW Udw;
  544. if( iType == 0 )
  545. {
  546. //
  547. // Need to determine byte/word relationships
  548. //
  549. Udw.b[ 0 ] = 0x01;
  550. Udw.b[ 1 ] = 0x02;
  551. Udw.b[ 2 ] = 0x03;
  552. Udw.b[ 3 ] = 0x04;
  553. iType = Udw.dw == 0x01020304 ? 1 : 2;
  554. }
  555. if( iType == 2 )
  556. {
  557. Udw.b[ 0 ] = *pubData++;
  558. Udw.b[ 1 ] = *pubData++;
  559. Udw.b[ 2 ] = *pubData++;
  560. Udw.b[ 3 ] = *pubData;
  561. }
  562. else
  563. {
  564. Udw.b[ 3 ] = *pubData++;
  565. Udw.b[ 2 ] = *pubData++;
  566. Udw.b[ 1 ] = *pubData++;
  567. Udw.b[ 0 ] = *pubData;
  568. }
  569. return Udw.dw;
  570. }
  571. #if !defined(DEVSTUDIO) // Not necessary for MDS
  572. BOOL
  573. BGetDevmodeSettingForOEM(
  574. IN PDEVMODE pdm,
  575. IN DWORD dwIndex,
  576. OUT PVOID pOutput,
  577. IN DWORD cbSize,
  578. OUT PDWORD pcbNeeded
  579. )
  580. /*++
  581. Routine Description:
  582. Function to provide OEM plugins access to driver private devmode settings
  583. Arguments:
  584. pdm - Points to the devmode to be access
  585. dwIndex - Predefined index to specify which devmode the caller is interested in
  586. pOutput - Points to output buffer
  587. cbSize - Size of output buffer
  588. pcbNeeded - Returns the expected size of output buffer
  589. Return Value:
  590. TRUE if successful, FALSE if there is an error
  591. --*/
  592. #define MAPPSDEVMODEFIELD(index, field) \
  593. { index, offsetof(UNIDRVEXTRA, field), sizeof(pdmPrivate->field) }
  594. {
  595. PUNIDRVEXTRA pdmPrivate;
  596. INT i;
  597. static const struct {
  598. DWORD dwIndex;
  599. DWORD dwOffset;
  600. DWORD dwSize;
  601. } aIndexMap[] = {
  602. MAPPSDEVMODEFIELD(OEMGDS_UNIDM_GPDVER, wVer),
  603. MAPPSDEVMODEFIELD(OEMGDS_UNIDM_FLAGS, dwFlags),
  604. { 0, 0, 0 }
  605. };
  606. pdmPrivate = (PUNIDRVEXTRA) GET_DRIVER_PRIVATE_DEVMODE(pdm);
  607. i = 0;
  608. while (aIndexMap[i].dwSize != 0)
  609. {
  610. if (aIndexMap[i].dwIndex == dwIndex)
  611. {
  612. *pcbNeeded = aIndexMap[i].dwSize;
  613. if (cbSize < aIndexMap[i].dwSize || pOutput == NULL)
  614. {
  615. SetLastError(ERROR_INSUFFICIENT_BUFFER);
  616. return FALSE;
  617. }
  618. CopyMemory(pOutput, (PBYTE) pdmPrivate + aIndexMap[i].dwOffset, aIndexMap[i].dwSize);
  619. return TRUE;
  620. }
  621. i++;
  622. }
  623. WARNING(("Unknown unidrv devmode index: %d\n", dwIndex));
  624. SetLastError(ERROR_NOT_SUPPORTED);
  625. return FALSE;
  626. }
  627. BOOL
  628. BConvertPrinterPropertiesData(
  629. IN HANDLE hPrinter,
  630. IN PRAWBINARYDATA pRawData,
  631. OUT PPRINTERDATA pPrinterData,
  632. IN PVOID pvSrcData,
  633. IN DWORD dwSrcSize
  634. )
  635. /*++
  636. Routine Description:
  637. Convert an older or newer version PRINTERDATA structure to current version
  638. Arguments:
  639. hPrinter - Handle to the current printer
  640. pRawData - Points to raw printer description data
  641. pPrinterData - Points to destination buffer
  642. pvSrcData - Points to source data to be converted
  643. dwSrcSize - Size of the source data in bytes
  644. Return Value:
  645. TRUE if conversion was successful, FALSE otherwise
  646. Note:
  647. This function is called after the library function has already
  648. done a generic conversion.
  649. --*/
  650. {
  651. return TRUE;
  652. }
  653. VOID
  654. VUpdatePrivatePrinterData(
  655. IN HANDLE hPrinter,
  656. IN OUT PPRINTERDATA pPrinterData,
  657. IN DWORD dwMode,
  658. IN PUIINFO pUIInfo,
  659. IN POPTSELECT pCombinedOptions
  660. )
  661. /*++
  662. Routine Description:
  663. Update the registry with the keywords
  664. Arguments:
  665. hPrinter - Handle to the current printer
  666. pPrinterData - Points to PRINTERDATA
  667. dwMode - MODE_READ/MODE_WRITE
  668. Return Value:
  669. None
  670. TRUE if conversion was successful, FALSE otherwise
  671. --*/
  672. {
  673. //
  674. // UniDriver read/write registry steps for point and print to NT4 drivers
  675. // 1. Writes ModelName to registry if necessary
  676. // 2. Upgrade PageProtection
  677. // 3. Upgrade FreeMem
  678. //
  679. PTSTR ptstrModelName = NULL;
  680. PPAGEPROTECT pPageProtect = NULL;
  681. PMEMOPTION pMemOption = NULL;
  682. PFEATURE pPPFeature, pMemFeature;
  683. DWORD dwFeatureIndex,dwSelection,dwIndex,dwError;
  684. DWORD dwFlag, dwType, cbNeeded;
  685. if (!pUIInfo || !pCombinedOptions)
  686. return;
  687. if (pPPFeature = GET_PREDEFINED_FEATURE(pUIInfo, GID_PAGEPROTECTION))
  688. pPageProtect = PGetIndexedOption(pUIInfo, pPPFeature, 0);
  689. if (pMemFeature = GET_PREDEFINED_FEATURE(pUIInfo, GID_MEMOPTION))
  690. pMemOption = PGetIndexedOption(pUIInfo, pMemFeature, 0);
  691. dwType = REG_BINARY;
  692. if (pPageProtect)
  693. {
  694. dwFeatureIndex = GET_INDEX_FROM_FEATURE(pUIInfo, pPPFeature);
  695. dwError = GetPrinterData(hPrinter, REGVAL_PAGE_PROTECTION, &dwType,
  696. (BYTE *)&dwFlag, sizeof(dwFlag), &cbNeeded);
  697. if (dwMode == MODE_READ )
  698. {
  699. if (dwError == ERROR_SUCCESS)
  700. {
  701. if (dwFlag & DXF_PAGEPROT)
  702. dwSelection = PAGEPRO_ON;
  703. else
  704. dwSelection = PAGEPRO_OFF;
  705. for (dwIndex = 0; dwIndex < pPPFeature->Options.dwCount; dwIndex++, pPageProtect++)
  706. {
  707. if (dwSelection == pPageProtect->dwPageProtectID)
  708. break;
  709. }
  710. if (dwIndex == pPPFeature->Options.dwCount)
  711. dwIndex = pPPFeature->dwDefaultOptIndex;
  712. pCombinedOptions[dwFeatureIndex].ubCurOptIndex = (BYTE)dwIndex;
  713. }
  714. }
  715. else // MODE_WRITE
  716. {
  717. #ifndef KERNEL_MODE
  718. SHORT sRasddFlag;
  719. if (dwError != ERROR_SUCCESS)
  720. sRasddFlag = 0;
  721. else
  722. sRasddFlag = (SHORT)dwFlag;
  723. pPageProtect = PGetIndexedOption(pUIInfo,
  724. pPPFeature,
  725. pCombinedOptions[dwFeatureIndex].ubCurOptIndex);
  726. if (pPageProtect && pPageProtect->dwPageProtectID == PAGEPRO_ON)
  727. sRasddFlag |= DXF_PAGEPROT;
  728. else
  729. sRasddFlag &= ~DXF_PAGEPROT;
  730. SetPrinterData(hPrinter,
  731. REGVAL_PAGE_PROTECTION,
  732. REG_BINARY,
  733. (BYTE *)&sRasddFlag,
  734. sizeof(sRasddFlag));
  735. #endif
  736. }
  737. }
  738. if ( pMemOption)
  739. {
  740. dwFeatureIndex = GET_INDEX_FROM_FEATURE(pUIInfo, pMemFeature);
  741. dwError = GetPrinterData(hPrinter, REGVAL_RASDD_FREEMEM, &dwType,
  742. (BYTE *)&dwFlag, sizeof(dwFlag), &cbNeeded);
  743. if (dwMode == MODE_READ )
  744. {
  745. if (dwError == ERROR_SUCCESS)
  746. {
  747. for (dwIndex = 0; dwIndex < pMemFeature->Options.dwCount; dwIndex++, pMemOption++)
  748. {
  749. if (dwFlag == (pMemOption->dwInstalledMem/KBYTES))
  750. break;
  751. }
  752. if (dwIndex == pMemFeature->Options.dwCount)
  753. dwIndex = pMemFeature->dwDefaultOptIndex;
  754. pCombinedOptions[dwFeatureIndex].ubCurOptIndex = (BYTE)dwIndex;
  755. }
  756. }
  757. else // MODE_WRITE
  758. {
  759. #ifndef KERNEL_MODE
  760. pMemOption = PGetIndexedOption(pUIInfo,
  761. pMemFeature,
  762. pCombinedOptions[dwFeatureIndex].ubCurOptIndex);
  763. if (pMemOption)
  764. dwFlag = (pMemOption->dwInstalledMem/KBYTES);
  765. SetPrinterData(hPrinter,
  766. REGVAL_RASDD_FREEMEM,
  767. REG_BINARY,
  768. (BYTE *)&dwFlag,
  769. sizeof(dwFlag));
  770. #endif
  771. }
  772. }
  773. //
  774. // Rasdd requires ModelName, so check if it's there and write it if it's not.
  775. //
  776. if (!(ptstrModelName = PtstrGetPrinterDataString(hPrinter, REGVAL_MODELNAME, &dwFlag)))
  777. {
  778. #ifndef KERNEL_MODE
  779. PGPDDRIVERINFO pDriverInfo;
  780. pDriverInfo = OFFSET_TO_POINTER(pUIInfo->pInfoHeader,
  781. pUIInfo->pInfoHeader->loDriverOffset);
  782. BSetPrinterDataString(hPrinter,
  783. REGVAL_MODELNAME,
  784. pDriverInfo->Globals.pwstrModelName,
  785. REG_SZ);
  786. #endif
  787. }
  788. if (ptstrModelName)
  789. MemFree(ptstrModelName);
  790. return;
  791. }
  792. VOID
  793. VDefaultDevmodeFormFields(
  794. PUIINFO pUIInfo,
  795. PDEVMODE pDevmode,
  796. BOOL bMetric
  797. )
  798. /*++
  799. Routine Description:
  800. Initialized the form-related devmode fields with their default values
  801. Arguments:
  802. pUIInfo - Points for UIINFO
  803. pDevmode - Points to the DEVMODE whose form-related fields are to be initialized
  804. bMetric - Specifies whether the system is running in metric mode
  805. Return Value:
  806. NONE
  807. --*/
  808. {
  809. PFEATURE pFeature;
  810. PPAGESIZE pPageSize;
  811. if (bMetric && (pUIInfo->dwFlags & FLAG_A4_SIZE_EXISTS))
  812. {
  813. CopyString(pDevmode->dmFormName, A4_FORMNAME, CCHFORMNAME);
  814. pDevmode->dmPaperSize = DMPAPER_A4;
  815. pDevmode->dmPaperWidth = 2100; // 210mm measured in 0.1mm units
  816. pDevmode->dmPaperLength = 2970; // 297mm
  817. }
  818. else if (!bMetric && (pUIInfo->dwFlags & FLAG_LETTER_SIZE_EXISTS))
  819. {
  820. CopyString(pDevmode->dmFormName, LETTER_FORMNAME, CCHFORMNAME);
  821. pDevmode->dmPaperSize = DMPAPER_LETTER;
  822. pDevmode->dmPaperWidth = 2159; // 8.5"
  823. pDevmode->dmPaperLength = 2794; // 11"
  824. }
  825. else
  826. {
  827. if (pFeature = GET_PREDEFINED_FEATURE(pUIInfo, GID_PAGESIZE))
  828. {
  829. //
  830. // Skip writing the dmFormName here because
  831. // ValidateDevmodeFormField will take care of it.
  832. //
  833. pPageSize = PGetIndexedOption(pUIInfo, pFeature, pFeature->dwDefaultOptIndex);
  834. if (pPageSize)
  835. {
  836. pDevmode->dmPaperSize = (SHORT)pPageSize->dwPaperSizeID;
  837. pDevmode->dmPaperWidth = (SHORT)(MASTER_UNIT_TO_MICRON(pPageSize->szPaperSize.cx,
  838. pUIInfo->ptMasterUnits.x)
  839. / DEVMODE_PAPER_UNIT);
  840. pDevmode->dmPaperLength = (SHORT)(MASTER_UNIT_TO_MICRON(pPageSize->szPaperSize.cy,
  841. pUIInfo->ptMasterUnits.y)
  842. / DEVMODE_PAPER_UNIT);
  843. pDevmode->dmFields |= (DM_PAPERWIDTH | DM_PAPERLENGTH | DM_PAPERSIZE);
  844. pDevmode->dmFields &= ~DM_FORMNAME;
  845. return;
  846. }
  847. }
  848. }
  849. pDevmode->dmFields &= ~(DM_PAPERWIDTH | DM_PAPERLENGTH);
  850. pDevmode->dmFields |= (DM_PAPERSIZE | DM_FORMNAME);
  851. }
  852. #endif // !defined(DEVSTUDIO)