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.

884 lines
26 KiB

  1. /*++
  2. Copyright (c) 1996-1999 Microsoft Corporation
  3. Module Name:
  4. cmdcb.c
  5. Abstract:
  6. Implementation of GPD command callback for "test.gpd":
  7. OEMCommandCallback
  8. Environment:
  9. Windows NT Unidrv driver
  10. Revision History:
  11. // NOTICE-2002/03/19-v-sueyas-
  12. // 04/07/97 -zhanw-
  13. // Created it.
  14. --*/
  15. #include <windows.h>
  16. #include "pdev.h"
  17. #include "compress.h"
  18. //////////////////////////////////////////////////////////////////////////
  19. // Function: BInitOEMExtraData
  20. //
  21. // Description: Initializes OEM Extra data.
  22. //
  23. //
  24. // Parameters:
  25. //
  26. // pOEMExtra Pointer to a OEM Extra data.
  27. //
  28. // dwSize Size of OEM extra data.
  29. //
  30. //
  31. // Returns: TRUE if successful; FALSE otherwise.
  32. //
  33. //
  34. // Comments:
  35. //
  36. //
  37. // History:
  38. // // NOTICE-2002/03/19-v-sueyas-
  39. // // 02/11/97 APresley Created.
  40. //
  41. //////////////////////////////////////////////////////////////////////////
  42. BOOL BInitOEMExtraData(POEM_EXTRADATA pOEMExtra)
  43. {
  44. // Initialize OEM Extra data.
  45. pOEMExtra->dmExtraHdr.dwSize = sizeof(OEM_EXTRADATA);
  46. pOEMExtra->dmExtraHdr.dwSignature = OEM_SIGNATURE;
  47. pOEMExtra->dmExtraHdr.dwVersion = OEM_VERSION;
  48. pOEMExtra->fCallback = FALSE;
  49. pOEMExtra->wCurrentRes = 0;
  50. pOEMExtra->lWidthBytes = 0;
  51. pOEMExtra->lHeightPixels = 0;
  52. #ifdef FONTPOS
  53. pOEMExtra->wFontHeight = 0;
  54. pOEMExtra->wYPos = 0;
  55. #endif
  56. // #278517: RectFill
  57. pOEMExtra->wRectWidth = 0;
  58. pOEMExtra->wRectHeight = 0;
  59. pOEMExtra->wUnit = 1;
  60. return TRUE;
  61. }
  62. //////////////////////////////////////////////////////////////////////////
  63. // Function: BMergeOEMExtraData
  64. //
  65. // Description: Validates and merges OEM Extra data.
  66. //
  67. //
  68. // Parameters:
  69. //
  70. // pdmIn pointer to an input OEM private devmode containing the settings
  71. // to be validated and merged. Its size is current.
  72. //
  73. // pdmOut pointer to the output OEM private devmode containing the
  74. // default settings.
  75. //
  76. //
  77. // Returns: TRUE if valid; FALSE otherwise.
  78. //
  79. //
  80. // Comments:
  81. //
  82. // //NOTICE-2002/03/19-v-sueyas-
  83. // //History:
  84. // // 02/11/97 APresley Created.
  85. // // 04/08/97 ZhanW Modified the interface
  86. //
  87. //////////////////////////////////////////////////////////////////////////
  88. BOOL BMergeOEMExtraData(
  89. POEM_EXTRADATA pdmIn,
  90. POEM_EXTRADATA pdmOut
  91. )
  92. {
  93. if(pdmIn) {
  94. //
  95. // copy over the private fields, if they are valid
  96. //
  97. pdmOut->fCallback = pdmIn->fCallback;
  98. pdmOut->wCurrentRes = pdmIn->wCurrentRes;
  99. pdmOut->lWidthBytes = pdmIn->lWidthBytes;
  100. pdmOut->lHeightPixels = pdmIn->lHeightPixels;
  101. #ifdef FONTPOS
  102. pdmOut->wFontHeight = pdmIn->wFontHeight;
  103. pdmOut->wYPos = pdmIn->wYPos;
  104. #endif
  105. // #278517: RectFill
  106. pdmOut->wRectWidth = pdmIn->wRectWidth;
  107. pdmOut->wRectHeight = pdmIn->wRectHeight;
  108. pdmOut->wUnit = pdmIn->wUnit;
  109. }
  110. return TRUE;
  111. }
  112. // #######
  113. #define WRITESPOOLBUF(p, s, n) \
  114. ((p)->pDrvProcs->DrvWriteSpoolBuf(p, s, n))
  115. #define PARAM(p,n) \
  116. (*((p)+(n)))
  117. /*********************************************************/
  118. /* RL_ECmd : main function */
  119. /* ARGS : LPBYTE - pointer to image */
  120. /* LPBYTE - pointer to BRL code */
  121. /* WORD - size of image */
  122. /* RET : WORD - size of BRL Code */
  123. /* 0 - COMPRESSION FAILED */
  124. /*********************************************************/
  125. DWORD RL_ECmd(PBYTE iptr, PBYTE cptr, DWORD isize, DWORD osize)
  126. {
  127. COMP_DATA CompData;
  128. if (VALID == RL_Init(iptr, cptr, isize, osize, &CompData))
  129. RL_Enc( &CompData );
  130. if (CompData.BUF_OVERFLOW)
  131. return 0;
  132. else
  133. return CompData.RL_CodeSize;
  134. }
  135. /*********************************************************/
  136. /* RL_Init : Initializer */
  137. /* ARGS : BYTE * - pointer to image */
  138. /* BYTE * - pointer to BRL code */
  139. /* WORD - size of image */
  140. /* RET : BYTE - VALID or INVALID */
  141. /*********************************************************/
  142. BYTE RL_Init(PBYTE iptr, PBYTE cptr, DWORD isize, DWORD osize,
  143. PCOMP_DATA pCompData)
  144. {
  145. pCompData->RL_ImagePtr = iptr;
  146. pCompData->RL_CodePtr = cptr;
  147. pCompData->RL_ImageSize = isize;
  148. pCompData->BUF_OVERFLOW = 0;
  149. pCompData->RL_BufEnd = cptr + osize;
  150. return VALID;
  151. }
  152. /*********************************************************/
  153. /* RL_Enc : Encoder */
  154. /* ARGS : void */
  155. /* RET : char COMP_SUCC or COMP_FAIL */
  156. /*********************************************************/
  157. char RL_Enc(PCOMP_DATA pCompData)
  158. {
  159. // #313252: RLE compressed data doesn't match with length.
  160. // Rewrite RLE compression algorithm.
  161. int count;
  162. BYTE rdata;
  163. PBYTE pdata, pcomp, pend;
  164. DWORD i;
  165. pdata = pCompData->RL_ImagePtr;
  166. pcomp = pCompData->RL_CodePtr;
  167. pend = pCompData->RL_BufEnd;
  168. count = 0;
  169. for (i = 0; i < pCompData->RL_ImageSize; i++, pdata++) {
  170. if (count == 0) {
  171. rdata = *pdata;
  172. count = 1;
  173. } else if (*pdata != rdata) {
  174. if (pcomp + 2 >= pend)
  175. goto overflow;
  176. *pcomp++ = count - 1;
  177. *pcomp++ = rdata;
  178. rdata = *pdata;
  179. count = 1;
  180. } else if (++count >= 256) {
  181. if (pcomp + 2 >= pend)
  182. goto overflow;
  183. *pcomp++ = count - 1;
  184. *pcomp++ = rdata;
  185. count = 0;
  186. }
  187. }
  188. if (count) {
  189. if (pcomp + 2 >= pend)
  190. goto overflow;
  191. *pcomp++ = count - 1;
  192. *pcomp++ = rdata;
  193. }
  194. pCompData->RL_CodeSize = (DWORD)(pcomp - pCompData->RL_CodePtr);
  195. pCompData->RL_CodePtr = pcomp;
  196. return COMP_SUCC;
  197. overflow:
  198. pCompData->BUF_OVERFLOW = 1;
  199. return COMP_FAIL;
  200. }
  201. //---------------------------*OEMSendFontCmd*----------------------------------
  202. // Action: send Pages-style font selection command.
  203. //-----------------------------------------------------------------------------
  204. // NTRAID#NTBUG9-581704-2002/03/19-v-sueyas-: Error handling
  205. BOOL APIENTRY bOEMSendFontCmd(pdevobj, pUFObj, pFInv)
  206. PDEVOBJ pdevobj;
  207. PUNIFONTOBJ pUFObj;
  208. PFINVOCATION pFInv;
  209. {
  210. DWORD i, ocmd;
  211. BYTE rgcmd[CCHMAXCMDLEN];
  212. PGETINFO_STDVAR pSV;
  213. //#287800 ->
  214. DWORD dwStdVariable[2 + 2 * 3];
  215. DWORD dwTxtRes ;
  216. //#287800 <-
  217. //#319705
  218. WORD wAscend, wDescend ;
  219. POEM_EXTRADATA pOEM;
  220. VERBOSE(("OEMSendFontCmd entry.\n"));
  221. // NTRAID#NTBUG9-581700-2002/03/19-v-sueyas-: Check for illegal parameters
  222. if (NULL == pdevobj)
  223. {
  224. ERR(("bOEMSendFontCmd: Invalid parameter(s).\n"));
  225. return FALSE;
  226. }
  227. pOEM = (POEM_EXTRADATA)(pdevobj->pOEMDM);
  228. // NTRAID#NTBUG9-581700-2002/03/19-v-sueyas-: Check for null pointers
  229. if (NULL == pOEM)
  230. {
  231. ERR(("bOEMSendFontCmd: pdevobj->pOEMDM = 0.\n"));
  232. return FALSE;
  233. }
  234. ASSERT(VALID_PDEVOBJ(pdevobj));
  235. if(!pUFObj || !pFInv)
  236. {
  237. ERR(("OEMSendFontCmd: pUFObj or pFInv is NULL."));
  238. return FALSE;
  239. }
  240. //#287800 ->
  241. pSV = (PGETINFO_STDVAR)dwStdVariable;
  242. pSV->dwSize = sizeof(GETINFO_STDVAR) + 2 * sizeof(DWORD) * (3 - 1);
  243. pSV->dwNumOfVariable = 3;
  244. pSV->StdVar[0].dwStdVarID = FNT_INFO_FONTHEIGHT;
  245. pSV->StdVar[1].dwStdVarID = FNT_INFO_FONTWIDTH;
  246. pSV->StdVar[2].dwStdVarID = FNT_INFO_TEXTYRES;
  247. //#287800 <-
  248. if (!pUFObj->pfnGetInfo(pUFObj, UFO_GETINFO_STDVARIABLE, pSV, pSV->dwSize, NULL))
  249. {
  250. ERR(("UFO_GETINFO_STDVARIABLE failed.\n"));
  251. return FALSE;
  252. }
  253. #ifdef FONTPOS
  254. pOEM->wFontHeight = (WORD)pSV->StdVar[0].lStdVariable;
  255. //#287800 ->
  256. dwTxtRes = pSV->StdVar[2].lStdVariable ;
  257. // NTRAID#NTBUG9-581703-2002/03/19-v-sueyas-: Check for deviding by zero
  258. if (0 == dwTxtRes)
  259. {
  260. ERR(("dwTxtRes = 0.\n"));
  261. return FALSE;
  262. }
  263. pOEM->wFontHeight = (WORD)((pOEM->wFontHeight * pOEM->wCurrentRes
  264. + dwTxtRes / 2) / dwTxtRes) ;
  265. //#287800 <-
  266. //#319705 For TTFS positioning ->
  267. // NTRAID#NTBUG9-581700-2002/03/19-v-sueyas-: Check for null pointers
  268. if (NULL == pUFObj->pIFIMetrics)
  269. {
  270. ERR(("pUFObj->pIFIMetrics = NULL.\n"));
  271. return FALSE;
  272. }
  273. wAscend = pUFObj->pIFIMetrics->fwdWinAscender ;
  274. wDescend = pUFObj->pIFIMetrics->fwdWinDescender ;
  275. // NTRAID#NTBUG9-581703-2002/03/19-v-sueyas-: Check for deviding by zero
  276. if (0 == (wAscend + wDescend))
  277. {
  278. ERR(("pUFObj->pIFIMetrics = NULL.\n"));
  279. return FALSE;
  280. }
  281. wDescend = pOEM->wFontHeight * wDescend / (wAscend + wDescend) ;
  282. pOEM->wFontHeight -= wDescend ;
  283. #endif
  284. #define SV_HEIGHT (pSV->StdVar[0].lStdVariable)
  285. #define SV_WIDTH (pSV->StdVar[1].lStdVariable)
  286. ocmd = 0;
  287. for (i = 0; i < pFInv->dwCount && ocmd < CCHMAXCMDLEN; )
  288. {
  289. WORD wTemp;
  290. if (pFInv->pubCommand[i] == '#')
  291. {
  292. if (pFInv->pubCommand[i+1] == 'V')
  293. {
  294. // character height setting
  295. wTemp = (WORD)SV_HEIGHT;
  296. if (pOEM->wCurrentRes == 300 || pOEM->wCurrentRes == 600)
  297. wTemp = wTemp * 1440 / 600;
  298. rgcmd[ocmd++] = HIBYTE(wTemp);
  299. rgcmd[ocmd++] = LOBYTE(wTemp);
  300. i += 2;
  301. }
  302. else if (pFInv->pubCommand[i+1] == 'H')
  303. {
  304. // (DBCS) character width setting
  305. wTemp = (WORD)(SV_WIDTH * 2);
  306. if (pOEM->wCurrentRes == 300 || pOEM->wCurrentRes == 600)
  307. wTemp = wTemp * 1440 / 600;
  308. rgcmd[ocmd++] = HIBYTE(wTemp);
  309. rgcmd[ocmd++] = LOBYTE(wTemp);
  310. i += 2;
  311. }
  312. else if (pFInv->pubCommand[i+1] == 'P')
  313. {
  314. // (DBCS) character pitch setting
  315. wTemp = (WORD)(SV_WIDTH * 2);
  316. if (pOEM->wCurrentRes == 300 || pOEM->wCurrentRes == 600)
  317. wTemp = wTemp * 1440 / 600;
  318. rgcmd[ocmd++] = HIBYTE(wTemp);
  319. rgcmd[ocmd++] = LOBYTE(wTemp);
  320. i += 2;
  321. }
  322. else if (pFInv->pubCommand[i+1] == 'L')
  323. {
  324. // Line pitch (spacing) setting
  325. wTemp = (WORD)SV_HEIGHT;
  326. if(pOEM->wCurrentRes == 300 || pOEM->wCurrentRes == 600)
  327. wTemp = wTemp * 1440 / 600;
  328. rgcmd[ocmd++] = HIBYTE(wTemp);
  329. rgcmd[ocmd++] = LOBYTE(wTemp);
  330. i += 2;
  331. }
  332. else {
  333. rgcmd[ocmd++] = pFInv->pubCommand[i++];
  334. }
  335. continue;
  336. }
  337. // just copy others
  338. rgcmd[ocmd++] = pFInv->pubCommand[i++];
  339. }
  340. WRITESPOOLBUF(pdevobj, rgcmd, ocmd);
  341. return TRUE;
  342. }
  343. // NTRAID#NTBUG9-581704-2002/03/19-v-sueyas-: Error handling
  344. BOOL APIENTRY bOEMOutputCharStr(
  345. PDEVOBJ pdevobj,
  346. PUNIFONTOBJ pUFObj,
  347. DWORD dwType,
  348. DWORD dwCount,
  349. PVOID pGlyph)
  350. {
  351. GETINFO_GLYPHSTRING GStr;
  352. PBYTE tempBuf;
  353. PTRANSDATA pTrans;
  354. DWORD i, j;
  355. DWORD rSize = 0;
  356. BOOL fLeadByteFlag;
  357. BYTE fDBCS[256];
  358. BYTE ESC_VERT_ON[] = "\x1B\x7E\x0E\x00\x01\x0B";
  359. BYTE ESC_VERT_OFF[] = "\x1B\x7E\x0E\x00\x01\x0C";
  360. #ifdef FONTPOS
  361. POEM_EXTRADATA pOEM;
  362. BYTE ESC_Y_ABS[] = "\x1b\x7e\x1d\x00\x03\x05\x00\x00";
  363. #endif
  364. BOOL bVFont, bDBChar;
  365. BYTE *pTemp;
  366. WORD wLen;
  367. VERBOSE(("OEMOutputCharStr() entry.\n"));
  368. // NTRAID#NTBUG9-581700-2002/03/19-v-sueyas-: Check for illegal parameters
  369. if(NULL == pdevobj || NULL == pUFObj)
  370. {
  371. ERR(("bOEMOutputCharStr: Invalid parameter(s).\n"));
  372. return FALSE;
  373. }
  374. #ifdef FONTPOS
  375. pOEM = (POEM_EXTRADATA)(pdevobj->pOEMDM);
  376. #endif
  377. // NTRAID#NTBUG9-581700-2002/03/19-v-sueyas-: Check for null pointers
  378. if(NULL == pOEM)
  379. {
  380. ERR(("bOEMOutputCharStr: pdevobj->pOEMDM = 0.\n"));
  381. return FALSE;
  382. }
  383. ASSERT(VALID_PDEVOBJ(pdevobj));
  384. // NTRAID#NTBUG9-751233-2002/12/05-yasuho-: Memory leak in pagesres.dll
  385. // Delete the redundant memory allocation.
  386. GStr.dwSize = sizeof(GETINFO_GLYPHSTRING);
  387. GStr.dwCount = dwCount;
  388. GStr.dwTypeIn = TYPE_GLYPHHANDLE;
  389. GStr.pGlyphIn = pGlyph;
  390. GStr.dwTypeOut = TYPE_TRANSDATA;
  391. GStr.pGlyphOut = NULL;
  392. GStr.dwGlyphOutSize = 0;
  393. /* Get TRANSDATA buffer size */
  394. if (FALSE != pUFObj->pfnGetInfo(pUFObj,
  395. UFO_GETINFO_GLYPHSTRING, &GStr, 0, NULL)
  396. || 0 == GStr.dwGlyphOutSize )
  397. {
  398. ERR(("Get Glyph String error\n"));
  399. return FALSE;
  400. }
  401. /* Alloc TRANSDATA buffer */
  402. if(!(tempBuf = (PBYTE)MemAllocZ(GStr.dwGlyphOutSize) ))
  403. {
  404. ERR(("Mem alloc failed.\n"));
  405. return FALSE;
  406. }
  407. /* Get actual TRANSDATA */
  408. GStr.pGlyphOut = tempBuf;
  409. if (!pUFObj->pfnGetInfo(pUFObj,
  410. UFO_GETINFO_GLYPHSTRING, &GStr, 0, NULL))
  411. {
  412. ERR(("GetInfo failed.\n"));
  413. // NTRAID#NTBUG9-751233-2002/12/05-yasuho-: Memory leak in pagesres.dll
  414. MemFree(tempBuf);
  415. }
  416. pTrans = (PTRANSDATA)GStr.pGlyphOut;
  417. #ifdef FONTPOS
  418. if(pOEM->wCurrentRes == 300 || pOEM->wCurrentRes == 600 )
  419. ESC_Y_ABS[5] = 0x25;
  420. // ntbug9#406475: Font printed the different position.
  421. if((pOEM->wYPos - pOEM->wFontHeight) >= 0)
  422. {
  423. ESC_Y_ABS[6] = HIBYTE((pOEM->wYPos - pOEM->wFontHeight));
  424. ESC_Y_ABS[7] = LOBYTE((pOEM->wYPos - pOEM->wFontHeight));
  425. WRITESPOOLBUF(pdevobj, ESC_Y_ABS, 8);
  426. }
  427. #endif //FONTPOS
  428. bVFont = BVERTFONT(pUFObj);
  429. bDBChar = FALSE;
  430. for(i = 0; i < dwCount; i++, pTrans++)
  431. {
  432. switch((pTrans->ubType & MTYPE_FORMAT_MASK))
  433. {
  434. case MTYPE_DIRECT: // SBCS character
  435. if (bVFont && bDBChar)
  436. {
  437. WRITESPOOLBUF(pdevobj, ESC_VERT_OFF, sizeof(ESC_VERT_OFF));
  438. bDBChar = FALSE;
  439. }
  440. WRITESPOOLBUF(pdevobj, &pTrans->uCode.ubCode, 1);
  441. break;
  442. case MTYPE_PAIRED: // DBCS character
  443. if (bVFont && !bDBChar)
  444. {
  445. WRITESPOOLBUF(pdevobj, ESC_VERT_ON, sizeof(ESC_VERT_ON));
  446. bDBChar = TRUE;
  447. }
  448. WRITESPOOLBUF(pdevobj, pTrans->uCode.ubPairs, 2);
  449. break;
  450. case MTYPE_COMPOSE:
  451. if (bVFont && bDBChar)
  452. {
  453. WRITESPOOLBUF(pdevobj, ESC_VERT_OFF, sizeof(ESC_VERT_OFF));
  454. bDBChar = FALSE;
  455. }
  456. pTemp = (BYTE *)(GStr.pGlyphOut) + pTrans->uCode.sCode;
  457. // first two bytes are the length of the string
  458. wLen = *pTemp + (*(pTemp + 1) << 8);
  459. pTemp += 2;
  460. WRITESPOOLBUF(pdevobj, pTemp, wLen);
  461. }
  462. }
  463. if (bDBChar)
  464. {
  465. WRITESPOOLBUF(pdevobj, ESC_VERT_OFF, sizeof(ESC_VERT_OFF));
  466. }
  467. MemFree(tempBuf);
  468. return TRUE;
  469. }
  470. BOOL APIENTRY OEMFilterGraphics(
  471. PDEVOBJ pdevobj, // Points to private data required by the Unidriver.dll
  472. PBYTE pBuf, // points to buffer of graphics data
  473. DWORD dwLen) // length of buffer in bytes
  474. {
  475. DWORD dwCompLen;
  476. LONG lHorzPixel;
  477. DWORD dwLength; // Let's use a temporary LEN
  478. PBYTE pCompImage;
  479. POEM_EXTRADATA pOEM;
  480. BYTE ESC_ESX86[] = "\x1B\x7E\x86\x00\x00\x01\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01";
  481. // #291170: Image data is not printed partly
  482. LONG li, lHeightPixel, lPixels, lBytes, lRemain, lSize;
  483. PBYTE pTemp;
  484. BYTE ESC_Y_REL[] = "\x1b\x7e\x1d\x00\x03\x06\x00\x00";
  485. // NTRAID#NTBUG9-581700-2002/03/19-v-sueyas-: Check for illegal parameters
  486. if (NULL == pdevobj || NULL == pBuf || 0 == dwLen)
  487. {
  488. ERR(("OEMFilterGraphics: Invalid parameter(s).\n"));
  489. return FALSE;
  490. }
  491. pOEM = (POEM_EXTRADATA)(pdevobj->pOEMDM);
  492. // NTRAID#NTBUG9-581700-2002/03/19-v-sueyas-: Check for null pointers
  493. if (NULL == pOEM)
  494. {
  495. ERR(("OEMFilterGraphics: pdevobj->pOEMDM = 0.\n"));
  496. return FALSE;
  497. }
  498. if(!pOEM->fCallback)
  499. {
  500. WRITESPOOLBUF(pdevobj, pBuf, dwLen);
  501. return TRUE;
  502. }
  503. if(!(pCompImage = (BYTE *)MemAllocZ(MAXIMGSIZE)))
  504. {
  505. ERR(("Memory alloc error\n"));
  506. return FALSE;
  507. }
  508. // #291170: Image data is not printed partly
  509. // Sent 'SendBlock' command separately if necessary.
  510. #define RLE_THRESH (MAXIMGSIZE / 2 - 2) // threshold for RLE should success
  511. /*_ Calculate i-axis direction size of the iage ISIZ */
  512. lBytes = pOEM->lWidthBytes;
  513. lHorzPixel = lBytes * 8;
  514. lHeightPixel = pOEM->lHeightPixels;
  515. if(pOEM->wCurrentRes == 300 || pOEM->wCurrentRes == 600)
  516. ESC_ESX86[5] = (pOEM->wCurrentRes == 300 ? 0x10 : 0x40);
  517. pTemp = pBuf;
  518. lRemain = lBytes * lHeightPixel;
  519. li = 0;
  520. while (li < lHeightPixel) {
  521. // NTRAID#NTBUG9-581703-2002/03/19-v-sueyas-: Check for deviding by zero
  522. if (0 == lBytes)
  523. {
  524. ERR(("OEMFilterGraphics: pOEM->lWidthBytes = 0.\n"));
  525. // NTRAID#NTBUG9-751233-2002/12/05-yasuho-: Memory leak in pagesres.dll
  526. MemFree(pCompImage);
  527. return FALSE;
  528. }
  529. /*_ Compress image data using Byte Run Length Algorithm */
  530. lPixels = min(lRemain, RLE_THRESH) / lBytes;
  531. lSize = lBytes * lPixels;
  532. dwCompLen = RL_ECmd(pTemp, pCompImage, lSize, MAXIMGSIZE);
  533. pTemp += lSize;
  534. lRemain -= lSize;
  535. li += lPixels;
  536. /*_ Set ISIZ of ESX86 command */
  537. ESC_ESX86[17] = HIBYTE(lHorzPixel);
  538. ESC_ESX86[18] = LOBYTE(lHorzPixel);
  539. ESC_ESX86[21] = HIBYTE(lPixels);
  540. ESC_ESX86[22] = LOBYTE(lPixels);
  541. /*_ Add parameter length to the data length after compression */
  542. dwLength = dwCompLen + 18;
  543. /*_ Set LEN of ESX86 command */
  544. ESC_ESX86[3] = HIBYTE(dwLength);
  545. ESC_ESX86[4] = LOBYTE(dwLength);
  546. /*_ Output ESX86 command */
  547. WRITESPOOLBUF(pdevobj, (PBYTE)ESC_ESX86, 23);
  548. /*_ Output compressed data */
  549. WRITESPOOLBUF(pdevobj, pCompImage, dwCompLen);
  550. /* Move Y position to the next graphics portion */
  551. if(pOEM->wCurrentRes == 300 || pOEM->wCurrentRes == 600)
  552. ESC_Y_REL[5] = 0x26;
  553. dwLength = lPixels * pOEM->wUnit; // Convert to MasterUnit
  554. ESC_Y_REL[6] = HIBYTE(dwLength);
  555. ESC_Y_REL[7] = LOBYTE(dwLength);
  556. WRITESPOOLBUF(pdevobj, ESC_Y_REL, 8);
  557. }
  558. MemFree(pCompImage);
  559. return TRUE;
  560. }
  561. /*****************************************************************************/
  562. /* */
  563. /* INT APIENTRY OEMCommandCallback( */
  564. /* PDEVOBJ pdevobj */
  565. /* DWORD dwCmdCbId */
  566. /* DWORD dwCount */
  567. /* PDWORD pdwParams */
  568. /* */
  569. /*****************************************************************************/
  570. INT APIENTRY
  571. OEMCommandCallback(
  572. PDEVOBJ pdevobj, // Points to private data required by the Unidriver.dll
  573. DWORD dwCmdCbId, // Callback ID
  574. DWORD dwCount, // Counts of command parameter
  575. PDWORD pdwParams) // points to values of command params
  576. {
  577. POEM_EXTRADATA pOEM;
  578. WORD wTemp =0;
  579. // #278517: Support RectFill
  580. WORD wUnit;
  581. BYTE ESC_X_ABS_NP[] = "\x1b\x7e\x1c\x00\x03\x25\x00\x00";
  582. BYTE ESC_X_REL_NP[] = "\x1b\x7e\x1c\x00\x03\x26\x00\x00";
  583. BYTE ESC_Y_ABS[] = "\x1b\x7e\x1d\x00\x03\x05\x00\x00";
  584. BYTE ESC_Y_REL[] = "\x1b\x7e\x1d\x00\x03\x06\x00\x00";
  585. // #278517: RectFill
  586. BYTE ESC_RECT_FILL[] =
  587. "\x1b\x7e\x32\x00\x08\x80\x40\x00\x02\x00\x00\x00\x00";
  588. BYTE ESC_BEGIN_RECT[] =
  589. "\x1b\x7e\x52\x00\x06\x00\x00\x17\x70\x17\x70";
  590. BYTE ESC_END_RECT[] =
  591. "\x1b\x7e\x52\x00\x06\x00\x00\x38\x40\x38\x40";
  592. // NTRAID#NTBUG9-581700-2002/03/19-v-sueyas-: Check for illegal parameters
  593. if (NULL == pdevobj)
  594. {
  595. ERR(("OEMCommandCallback: Invalid parameter(s).\n"));
  596. return 0;
  597. }
  598. pOEM = (POEM_EXTRADATA)(pdevobj->pOEMDM);
  599. // NTRAID#NTBUG9-581700-2002/03/19-v-sueyas-: Check for null pointers
  600. if (NULL == pOEM)
  601. {
  602. ERR(("OEMCommandCallback: pdevobj->pOEMDM = 0.\n"));
  603. return 0;
  604. }
  605. switch(dwCmdCbId)
  606. {
  607. case GRXFILTER_ON:
  608. pOEM->fCallback = TRUE;
  609. break;
  610. case CMD_SELECT_RES_300:
  611. pOEM->wCurrentRes = 300;
  612. pOEM->wUnit = 2;
  613. break;
  614. case CMD_SELECT_RES_600:
  615. pOEM->wCurrentRes = 600;
  616. pOEM->wUnit = 1;
  617. break;
  618. // #278517: Support RectFill
  619. case CMD_SELECT_RES_240:
  620. pOEM->wCurrentRes = 240;
  621. pOEM->wUnit = 6;
  622. break;
  623. case CMD_SELECT_RES_360:
  624. pOEM->wCurrentRes = 360;
  625. pOEM->wUnit = 4;
  626. break;
  627. case CMD_SEND_BLOCKDATA:
  628. if( !pdwParams || dwCount != 2)
  629. break;
  630. pOEM->fCallback = TRUE;
  631. pOEM->lHeightPixels = (LONG)PARAM(pdwParams, 0);
  632. pOEM->lWidthBytes = (LONG)PARAM(pdwParams, 1);
  633. break;
  634. case CURSOR_Y_ABS_MOVE:
  635. // NTRAID#NTBUG9-581700-2002/03/19-v-sueyas-: Check for illegal parameters
  636. if (dwCount < 1 || !pdwParams)
  637. break;
  638. wTemp = (WORD)*pdwParams;
  639. #ifdef FONTPOS
  640. pOEM->wYPos = wTemp;
  641. #endif
  642. if(pOEM->wCurrentRes == 300 || pOEM->wCurrentRes == 600)
  643. ESC_Y_ABS[5] = 0x25;
  644. ESC_Y_ABS[6] = HIBYTE(wTemp);
  645. ESC_Y_ABS[7] = LOBYTE(wTemp);
  646. WRITESPOOLBUF(pdevobj, ESC_Y_ABS, 8);
  647. return (INT)wTemp;
  648. case CURSOR_Y_REL_DOWN:
  649. // NTRAID#NTBUG9-581700-2002/03/19-v-sueyas-: Check for illegal parameters
  650. if (dwCount < 1 || !pdwParams)
  651. break;
  652. wTemp = (WORD)*pdwParams;
  653. #ifdef FONTPOS
  654. pOEM->wYPos += wTemp;
  655. #endif
  656. if(pOEM->wCurrentRes == 300 || pOEM->wCurrentRes == 600)
  657. ESC_Y_REL[5] = 0x26;
  658. ESC_Y_REL[6] = HIBYTE(wTemp);
  659. ESC_Y_REL[7] = LOBYTE(wTemp);
  660. WRITESPOOLBUF(pdevobj, ESC_Y_REL, 8);
  661. return (INT)wTemp;
  662. case CURSOR_X_ABS_MOVE:
  663. // NTRAID#NTBUG9-581700-2002/03/19-v-sueyas-: Check for illegal parameters
  664. if (dwCount < 1 || !pdwParams)
  665. break;
  666. wTemp = (WORD)*pdwParams;
  667. ESC_X_ABS_NP[6] = HIBYTE(wTemp);
  668. ESC_X_ABS_NP[7] = LOBYTE(wTemp);
  669. WRITESPOOLBUF(pdevobj, ESC_X_ABS_NP, 8);
  670. return (INT)wTemp;
  671. case CURSOR_X_REL_RIGHT:
  672. // NTRAID#NTBUG9-581700-2002/03/19-v-sueyas-: Check for illegal parameters
  673. if (dwCount < 1 || !pdwParams)
  674. break;
  675. wTemp = (WORD)*pdwParams;
  676. ESC_X_REL_NP[6] = HIBYTE(wTemp);
  677. ESC_X_REL_NP[7] = LOBYTE(wTemp);
  678. WRITESPOOLBUF(pdevobj, ESC_X_REL_NP, 8);
  679. return (INT)wTemp;
  680. // #278517: RectFill
  681. case CMD_RECT_WIDTH:
  682. pOEM->wRectWidth = (WORD)*pdwParams;
  683. break;
  684. case CMD_RECT_HEIGHT:
  685. pOEM->wRectHeight = (WORD)*pdwParams;
  686. break;
  687. case CMD_RECT_BLACK:
  688. case CMD_RECT_BLACK_2:
  689. //#292316
  690. // ESC_RECT_FILL[6] = 0x60;
  691. ESC_RECT_FILL[7] = 0x00; // Black
  692. goto fill;
  693. case CMD_RECT_WHITE:
  694. case CMD_RECT_WHITE_2:
  695. //#292316
  696. // ESC_RECT_FILL[6] = 0x40;
  697. ESC_RECT_FILL[7] = 0x0F; // White
  698. goto fill;
  699. case CMD_RECT_GRAY:
  700. case CMD_RECT_GRAY_2:
  701. //#292316
  702. // ESC_RECT_FILL[6] = 0x60;
  703. ESC_RECT_FILL[7] = (BYTE)((100 - *pdwParams) * 100 / 1111); // Gray
  704. goto fill;
  705. fill:
  706. if (dwCmdCbId >= CMD_RECT_BLACK_2)
  707. WRITESPOOLBUF(pdevobj, ESC_BEGIN_RECT, 11);
  708. wUnit = pOEM->wUnit ? pOEM->wUnit : 1; // for our safety
  709. //#292316
  710. // wTemp = pOEM->wRectWidth - 1;
  711. wTemp = pOEM->wRectWidth;
  712. wTemp = (WORD)(((LONG)wTemp + wUnit - 1) / wUnit * wUnit);
  713. ESC_RECT_FILL[9] = HIBYTE(wTemp);
  714. ESC_RECT_FILL[10] = LOBYTE(wTemp);
  715. //#292316
  716. // wTemp = pOEM->wRectHeight - 1;
  717. wTemp = pOEM->wRectHeight;
  718. wTemp = (WORD)(((LONG)wTemp + wUnit - 1) / wUnit * wUnit);
  719. ESC_RECT_FILL[11] = HIBYTE(wTemp);
  720. ESC_RECT_FILL[12] = LOBYTE(wTemp);
  721. WRITESPOOLBUF(pdevobj, ESC_RECT_FILL, 13);
  722. if (dwCmdCbId >= CMD_RECT_BLACK_2)
  723. WRITESPOOLBUF(pdevobj, ESC_END_RECT, 11);
  724. break;
  725. default:
  726. break;
  727. }
  728. return 0;
  729. }