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.

1748 lines
48 KiB

  1. //-----------------------------------------------------------------------------
  2. // This files contains the module name for this mini driver. Each mini driver
  3. // must have a unique module name. The module name is used to obtain the
  4. // module handle of this Mini Driver. The module handle is used by the
  5. // generic library to load in tables from the Mini Driver.
  6. //-----------------------------------------------------------------------------
  7. /*++
  8. Copyright (c) 1996-1998 Microsoft Corporation
  9. Module Name:
  10. cmdcb.c
  11. Abstract:
  12. Implementation of GPD command callback for "ncdlxxxx.gpd":
  13. OEMCommandCallback
  14. Environment:
  15. Windows NT Unidrv driver
  16. Revision History:
  17. // NOTICE-2002/3/18-v-sueyas-
  18. // 04/07/97 -zhanw-
  19. // Created it.
  20. --*/
  21. #include "pdev.h"
  22. //
  23. // Misc definitions and declarations.
  24. //
  25. #define ALLOCMEM EngAllocMem
  26. #define FREEMEM EngFreeMem
  27. #define WRITESPOOLBUF(p, s, n) \
  28. ((p)->pDrvProcs->DrvWriteSpoolBuf(p, s, n))
  29. #define PARAM(p,n) \
  30. (*((p)+(n)))
  31. //
  32. // command callback ID's
  33. //
  34. #define CMD_MOVE_X 23
  35. #define CMD_MOVE_Y 24
  36. #define CMD_BEGIN_RASTER 26
  37. #define CMD_RES_600 27
  38. #define CMD_RES_400 28
  39. #define CMD_RES_240 29
  40. #define CMD_SEND_BLOCK_DATA 30
  41. #define CMD_BEGIN_RASTER_NO_COMP 31
  42. #define CMD_INIT_COORDINATE 32
  43. #define CMD_PC_PRN_DIRECTION 50
  44. #define CMD_CR 51
  45. #define CMD_FF 52
  46. // #278517: RectFill
  47. #define CMD_RECTWIDTH 60
  48. #define CMD_RECTHEIGHT 61
  49. #define CMD_RECTWHITE 62
  50. #define CMD_RECTBLACK 63
  51. #define CMD_RECTGRAY 64
  52. // MW2250H, MW2300
  53. #define CMD_RES_1200 70
  54. // Text color
  55. #define CMD_WHITE_ON 80
  56. #define CMD_WHITE_OFF 81
  57. // Font Attrib
  58. #define CMD_BOLD_ON 82
  59. #define CMD_ITALIC_ON 83
  60. #define CMD_CLEAR_ATTRIB 84
  61. #define CMD_CLEAR_ATTRIB_P 85
  62. //////////////////////////////////////////////////////////////////////////
  63. // Function: BInitOEMExtraData
  64. //
  65. // Description: Initializes OEM Extra data.
  66. //
  67. //
  68. // Parameters:
  69. //
  70. // pOEMExtra Pointer to a OEM Extra data.
  71. //
  72. // dwSize Size of OEM extra data.
  73. //
  74. //
  75. // Returns: TRUE if successful; FALSE otherwise.
  76. //
  77. //
  78. // Comments:
  79. //
  80. //
  81. // History:
  82. // 02/11/97 APresley Created.
  83. //
  84. //////////////////////////////////////////////////////////////////////////
  85. BOOL BInitOEMExtraData(POEMUD_EXTRADATA pOEMExtra)
  86. {
  87. // Initialize OEM Extra data.
  88. pOEMExtra->dmExtraHdr.dwSize = sizeof(OEMUD_EXTRADATA);
  89. pOEMExtra->dmExtraHdr.dwSignature = OEM_SIGNATURE;
  90. pOEMExtra->dmExtraHdr.dwVersion = OEM_VERSION;
  91. pOEMExtra->wRes = 1;
  92. pOEMExtra->pCompBuf = NULL;
  93. pOEMExtra->dwCompBufLen = 0;
  94. pOEMExtra->dwScanLen = 0;
  95. pOEMExtra->dwDeviceDestX = 0;
  96. pOEMExtra->dwDeviceDestY = 0;
  97. pOEMExtra->dwDevicePrevX = 0;
  98. pOEMExtra->dwDevicePrevY = 0;
  99. pOEMExtra->iGray = 0;
  100. pOEMExtra->cSubPath = 0;
  101. return TRUE;
  102. }
  103. //////////////////////////////////////////////////////////////////////////
  104. // Function: BMergeOEMExtraData
  105. //
  106. // Description: Validates and merges OEM Extra data.
  107. //
  108. //
  109. // Parameters:
  110. //
  111. // pdmIn pointer to an input OEM private devmode containing the settings
  112. // to be validated and merged. Its size is current.
  113. //
  114. // pdmOut pointer to the output OEM private devmode containing the
  115. // default settings.
  116. //
  117. //
  118. // Returns: TRUE if valid; FALSE otherwise.
  119. //
  120. //
  121. // Comments:
  122. //
  123. //
  124. // NOTICE-2002/3/18-v-sueyas-
  125. // History:
  126. // 02/11/97 APresley Created.
  127. // 04/08/97 ZhanW Modified the interface
  128. //
  129. //////////////////////////////////////////////////////////////////////////
  130. BOOL BMergeOEMExtraData(
  131. POEMUD_EXTRADATA pdmIn,
  132. POEMUD_EXTRADATA pdmOut
  133. )
  134. {
  135. if(pdmIn) {
  136. //
  137. // copy over the private fields, if they are valid
  138. //
  139. pdmOut->wRes = pdmIn->wRes;
  140. pdmOut->wScale = pdmIn->wScale;
  141. pdmOut->lPointsx = pdmIn->lPointsx;
  142. pdmOut->lPointsy = pdmIn->lPointsy;
  143. pdmOut->dwSBCSX = pdmIn->dwSBCSX;
  144. pdmOut->dwDBCSX = pdmIn->dwDBCSX;
  145. pdmOut->lSBCSXMove = pdmIn->lSBCSXMove;
  146. pdmOut->lSBCSYMove = pdmIn->lSBCSYMove;
  147. pdmOut->lDBCSXMove = pdmIn->lDBCSXMove;
  148. pdmOut->lDBCSYMove = pdmIn->lDBCSYMove;
  149. pdmOut->lPrevXMove = pdmIn->lPrevXMove;
  150. pdmOut->lPrevYMove = pdmIn->lPrevYMove;
  151. pdmOut->fGeneral = pdmIn->fGeneral;
  152. pdmOut->wCurrentAddMode = pdmIn->wCurrentAddMode;
  153. pdmOut->dwDeviceDestX = pdmIn->dwDeviceDestX;
  154. pdmOut->dwDeviceDestY = pdmIn->dwDeviceDestY;
  155. pdmOut->dwDevicePrevX = pdmIn->dwDevicePrevX;
  156. pdmOut->dwDevicePrevY = pdmIn->dwDevicePrevY;
  157. }
  158. return TRUE;
  159. }
  160. //-----------------------------------------------------------------------------
  161. //
  162. // Function: iDwtoA
  163. //
  164. // Description: Convert from numeral into a character
  165. //-----------------------------------------------------------------------------
  166. static int
  167. iDwtoA(LPSTR buf, DWORD n)
  168. {
  169. int i, j;
  170. for( i = 0; n; i++ ) {
  171. buf[i] = (char)(n % 10 + '0');
  172. n /= 10;
  173. }
  174. /* n was zero */
  175. if( i == 0 )
  176. buf[i++] = '0';
  177. for( j = 0; j < i / 2; j++ ) {
  178. int tmp;
  179. tmp = buf[j];
  180. buf[j] = buf[i - j - 1];
  181. buf[i - j - 1] = (char)tmp;
  182. }
  183. buf[i] = '\0';
  184. return i;
  185. }
  186. //-----------------------------------------------------------------------------
  187. //
  188. // Function: iDwtoA_FillZero
  189. //
  190. // Description: Convert from numeral into a character and
  191. // fill a field which was specified with 0
  192. //-----------------------------------------------------------------------------
  193. static int
  194. iDwtoA_FillZero(LPSTR buf, DWORD n, int fw)
  195. {
  196. int i , j, k, l;
  197. l = n; // for later
  198. for( i = 0; n; i++ ) {
  199. buf[i] = (char)(n % 10 + '0');
  200. n /= 10;
  201. }
  202. /* n was zero */
  203. if( i == 0 )
  204. buf[i++] = '0';
  205. for( j = 0; j < i / 2; j++ ) {
  206. int tmp;
  207. tmp = buf[j];
  208. buf[j] = buf[i - j - 1];
  209. buf[i - j - 1] = (char)tmp;
  210. }
  211. buf[i] = '\0';
  212. for( k = 0; l; k++ ) {
  213. l /= 10;
  214. }
  215. if( k < 1) k++;
  216. k = fw - k;
  217. if(k > 0){;
  218. for (j = i; 0 < j + 1; j--){
  219. buf[j + k] = buf[j];
  220. }
  221. for ( j = 0; j < k; j++){
  222. buf[j] = '0';
  223. }
  224. i = i + k;
  225. }
  226. return i;
  227. }
  228. //-----------------------------------------------------------------------------
  229. //
  230. // Function: memcopy
  231. //
  232. // Description: Copy the memory from Src to Dest
  233. //-----------------------------------------------------------------------------
  234. static int
  235. memcopy(LPSTR lpDst, LPSTR lpSrc, WORD wLen)
  236. {
  237. WORD rLen;
  238. rLen = wLen;
  239. while(wLen--) *lpDst++ = *lpSrc++;
  240. return rLen;
  241. }
  242. //------------------------------------------------------------------
  243. // RLE1
  244. // Action : compress image data with RLE1
  245. //------------------------------------------------------------------
  246. DWORD RLE1(
  247. PBYTE pDst,
  248. PBYTE pSrc,
  249. DWORD dwLen)
  250. {
  251. PBYTE pTemp, pEnd, pDsto;
  252. DWORD len, deflen;
  253. pDsto = pDst;
  254. pEnd = pSrc + dwLen;
  255. while(pSrc < pEnd)
  256. {
  257. pTemp = pSrc++;
  258. if(pSrc == pEnd)
  259. {
  260. *pDst++ = 0x41;
  261. *pDst++ = *pTemp;
  262. break;
  263. }
  264. if(*pTemp == *pSrc)
  265. {
  266. pSrc++;
  267. while(pSrc < pEnd && *pTemp == *pSrc) pSrc++;
  268. len = (DWORD)(pSrc - pTemp);
  269. if(len < 63)
  270. {
  271. *pDst++ = 0x80 + (BYTE)len;
  272. goto T1;
  273. }
  274. *pDst++ = 0xbf;
  275. len -= 63;
  276. while(len >= 255)
  277. {
  278. *pDst++ = 0xff;
  279. len -= 255;
  280. }
  281. *pDst++ = (BYTE)len;
  282. T1:
  283. *pDst++ = *pTemp;
  284. continue;
  285. }
  286. pSrc++;
  287. while(pSrc < pEnd)
  288. {
  289. if(*pSrc == *(pSrc - 1))
  290. {
  291. pSrc--;
  292. break;
  293. }
  294. pSrc++;
  295. }
  296. deflen = len = (DWORD)(pSrc - pTemp);
  297. if(len < 63)
  298. {
  299. *pDst++ = 0x40 + (BYTE)len;
  300. goto T2;
  301. }
  302. *pDst++ = 0x7f;
  303. len -= 63;
  304. while(len >= 255)
  305. {
  306. *pDst++ = 0xff;
  307. len -= 255;
  308. }
  309. *pDst++ = (BYTE)len;
  310. T2:
  311. memcpy(pDst, pTemp, deflen);
  312. pDst += deflen;
  313. }
  314. return (DWORD)(pDst - pDsto);
  315. }
  316. //------------------------------------------------------------------
  317. // RLC2Comp
  318. // Action : compress image data with RLE2
  319. //------------------------------------------------------------------
  320. DWORD
  321. RLC2Comp(
  322. PBYTE pOutBuf,
  323. PBYTE pInBuf,
  324. DWORD dwInLen,
  325. DWORD dwScanLen
  326. )
  327. {
  328. DWORD dwlen, dwDatalen, dwCounter;
  329. PBYTE pLBuff;
  330. PBYTE pBuff, pTemp, pBuffo, pEnd;
  331. PBYTE pBuff2, pBuff2o;
  332. VERBOSE(("RLC2Comp() In +++\r\n"));
  333. dwCounter = dwInLen / dwScanLen;
  334. pLBuff = pBuffo = pBuff = pTemp = pInBuf; // Copy Src first pointer
  335. pBuff2o = pBuff2 = pOutBuf; // Copy Dst first pointer
  336. /*
  337. * We compare contents of First line with 0x00
  338. */
  339. pEnd = pBuff + dwScanLen;
  340. while(pBuff < pEnd)
  341. {
  342. while(pBuff < pEnd && 0x00 != *pBuff)
  343. {
  344. pBuff++;
  345. }
  346. dwlen = (DWORD)(pBuff - pTemp);
  347. if(dwlen)
  348. {
  349. pBuff2 += RLE1(pBuff2, pTemp, dwlen);
  350. pTemp = pBuff;
  351. }
  352. if(pBuff == pEnd) break;
  353. while(pBuff < pEnd && 0x00 == *pBuff)
  354. {
  355. pBuff++;
  356. }
  357. dwlen = (DWORD)(pBuff - pTemp);
  358. if(dwlen < 63)
  359. {
  360. *pBuff2++ = (BYTE)dwlen;
  361. goto T1;
  362. }
  363. *pBuff2++ = 0x3f;
  364. dwlen -= 63;
  365. while(dwlen >= 255)
  366. {
  367. *pBuff2++ = (BYTE)0xff;
  368. dwlen -= 255;
  369. }
  370. *pBuff2++ = (BYTE)dwlen;
  371. T1:
  372. pTemp = pBuff;
  373. }
  374. dwCounter--;
  375. *pBuff2++ = (BYTE)0x80;
  376. dwDatalen = (DWORD)(pBuff2 - pBuff2o);
  377. // If the compressed bitmap size is larger than nomal bitmap size,
  378. // we don't compress
  379. if(dwDatalen > dwInLen)
  380. {
  381. VERBOSE(("goto NO_COMP\r\n"));
  382. goto NO_COMP;
  383. }
  384. if(!dwCounter)
  385. return dwDatalen;
  386. /*
  387. * We compare the 1 previous line with the present line
  388. */
  389. do
  390. {
  391. pEnd = pBuff + dwScanLen;
  392. while(pBuff < pEnd)
  393. {
  394. while(pBuff < pEnd && *pLBuff != *pBuff)
  395. {
  396. pLBuff++;
  397. pBuff++;
  398. }
  399. dwlen = (DWORD)(pBuff - pTemp);
  400. if(dwlen)
  401. {
  402. pBuff2 += RLE1(pBuff2, pTemp, dwlen);
  403. pTemp = pBuff;
  404. }
  405. if(pBuff == pEnd) break;
  406. while(pBuff < pEnd && *pLBuff == *pBuff)
  407. {
  408. pLBuff++;
  409. pBuff++;
  410. }
  411. dwlen = (DWORD)(pBuff - pTemp);
  412. if(dwlen < 63)
  413. {
  414. *pBuff2++ = (BYTE)dwlen;
  415. goto T2;
  416. }
  417. *pBuff2++ = 0x3f;
  418. dwlen -= 63;
  419. while(dwlen >= 255)
  420. {
  421. *pBuff2++ = (BYTE)0xff;
  422. dwlen -= 255;
  423. }
  424. *pBuff2++ = (BYTE)dwlen;
  425. T2:
  426. pTemp = pBuff;
  427. }
  428. *pBuff2++ = (BYTE)0x80;
  429. dwDatalen = (DWORD)(pBuff2 - pBuff2o);
  430. // If the compressed bitmap size is larger than nomal bitmap size,
  431. // we don't compress
  432. if(dwDatalen > dwInLen) // full buffer
  433. {
  434. VERBOSE(("goto NO_COMP\r\n"));
  435. goto NO_COMP;
  436. }
  437. }
  438. while(--dwCounter);
  439. VERBOSE(("RLC2Comp() COMP Out---\r\n\r\n"));
  440. return dwDatalen;
  441. NO_COMP:
  442. VERBOSE(("RLC2Comp() NO_COMP Out---\r\n\r\n"));
  443. return 0;
  444. }
  445. //-------------------------------------------------------------------
  446. // OEMFilterGraphics
  447. // Action : Compress Bitmap Data
  448. //-------------------------------------------------------------------
  449. BOOL
  450. APIENTRY
  451. OEMFilterGraphics(
  452. PDEVOBJ pdevobj,
  453. PBYTE pBuf,
  454. DWORD dwLen
  455. )
  456. {
  457. POEMUD_EXTRADATA pOEM;
  458. INT i;
  459. BYTE Cmd[128];
  460. PBYTE pOutBuf;
  461. DWORD dwOutLen;
  462. BYTE jCompMethod;
  463. VERBOSE(("OEMFilterGraphics() In +++++++++++++++++++++++++++++\r\n"));
  464. // NTRAID#NTBUG9-580353-2002/03/18-v-sueyas-: Check for illegal parameters
  465. if (NULL == pdevobj || 0 == dwLen)
  466. {
  467. ERR(("OEMFilterGraphics: Invalid parameter(s).\n"));
  468. return FALSE;
  469. }
  470. //
  471. // verify pdevobj okay
  472. //
  473. ASSERT(VALID_PDEVOBJ(pdevobj));
  474. //
  475. // fill in printer commands
  476. //
  477. pOEM = (POEMUD_EXTRADATA)(pdevobj->pOEMDM);
  478. // NTRAID#NTBUG9-580353-2002/03/18-v-sueyas-: Check for illegal parameters
  479. if (NULL == pOEM)
  480. {
  481. ERR(("OEMFilterGraphics: Invalid parameter(s).\n"));
  482. return FALSE;
  483. }
  484. // Sanity check.
  485. if (!pBuf || pOEM->dwScanLen == 0) {
  486. ERR(("Invalid parameter.\r\n"));
  487. return FALSE;
  488. }
  489. // Prepare temp. buffer for compression.
  490. #ifdef BYPASS
  491. if ((!pOEM->pCompBuf || pOEM->dwCompBufLen < dwLen) &&
  492. !(pOEM->fGeneral & FG_NO_COMP)){
  493. #else
  494. if (!pOEM->pCompBuf || pOEM->dwCompBufLen < dwLen) {
  495. #endif // BYPASS
  496. if (pOEM->pCompBuf) {
  497. FREEMEM(pOEM->pCompBuf);
  498. }
  499. // NTRAID#NTBUG9-580363-2002/03/18-v-sueyas-: Check for deviding by zero
  500. if (0 == pOEM->dwScanLen)
  501. {
  502. ERR(("OEMFilterGraphics: pOEM->dwScanLen = 0.\n"));
  503. return FALSE;
  504. }
  505. pOEM->pCompBuf = ALLOCMEM(0,
  506. (dwLen << 1) + (dwLen / pOEM->dwScanLen),
  507. (ULONG)'NCDL');
  508. pOEM->dwCompBufLen = dwLen;
  509. }
  510. // Try compression methods.
  511. dwOutLen = 0;
  512. if (pOEM->pCompBuf != NULL) {
  513. pOutBuf = pOEM->pCompBuf;
  514. // Try RLC2 method;
  515. if (dwOutLen == 0) {
  516. if ((dwOutLen = RLC2Comp(pOutBuf, pBuf,
  517. dwLen, pOEM->dwScanLen)) > 0)
  518. jCompMethod = '5';
  519. }
  520. }
  521. if (dwOutLen == 0) {
  522. // Any of the Compression menthod faild.
  523. // We will send data to the printer withtout
  524. // compression.
  525. pOutBuf = pBuf;
  526. dwOutLen = dwLen;
  527. jCompMethod = '0'; // Without compression.
  528. }
  529. /* Send a draw coordinate command to the printer. */
  530. i = 0;
  531. i += memcopy(&Cmd[i], "\034e", 2);
  532. i += iDwtoA(&Cmd[i], pOEM->dwDeviceDestX);
  533. Cmd[i++] = ',';
  534. i += iDwtoA(&Cmd[i], pOEM->dwDeviceDestY);
  535. Cmd[i++] = '.';
  536. /* Save the present coordinate. */
  537. pOEM->dwDevicePrevX = pOEM->dwDeviceDestX;
  538. pOEM->dwDevicePrevY = pOEM->dwDeviceDestY;
  539. /* Send an image data draw command. */
  540. i += memcopy(&Cmd[i], "\034i", 2);
  541. i += iDwtoA(&Cmd[i], (pOEM->dwScanLen << 3));
  542. Cmd[i++] = ',';
  543. i += iDwtoA(&Cmd[i], (dwLen / pOEM->dwScanLen));
  544. Cmd[i++] = ',';
  545. Cmd[i++] = jCompMethod;
  546. i += memcopy(&Cmd[i], ",1/1,1/1,", 9);
  547. i += iDwtoA(&Cmd[i], dwOutLen);
  548. Cmd[i++] = ',';
  549. i += iDwtoA(&Cmd[i], (MASTER_UNIT / pOEM->wRes));
  550. Cmd[i++] = '.';
  551. WRITESPOOLBUF(pdevobj, Cmd, i);
  552. /* Send an image data */
  553. WRITESPOOLBUF(pdevobj, pOutBuf, dwOutLen);
  554. VERBOSE(("OEMFilterGraphics() Out-------------------------------\r\n\r\n"));
  555. return TRUE;
  556. }
  557. //-----------------------------------------------------------------------------
  558. //
  559. // Function: OEMCommandCallback
  560. //
  561. //-----------------------------------------------------------------------------
  562. INT
  563. APIENTRY
  564. OEMCommandCallback(
  565. PDEVOBJ pdevobj,
  566. DWORD dwCmdCbID,
  567. DWORD dwCount,
  568. PDWORD pdwParams
  569. )
  570. {
  571. INT i;
  572. BYTE *bp;
  573. BYTE Cmd[128];
  574. POEMUD_EXTRADATA pOEM;
  575. INT iRet;
  576. DWORD dwDeviceDestX, dwDeviceDestY;
  577. UINT gray;
  578. // NTRAID#NTBUG9-580353-2002/03/18-v-sueyas-: Check for illegal parameters
  579. if (NULL == pdevobj)
  580. {
  581. ERR(("OEMCommandCallback: Invalid parameter(s).\n"));
  582. return 0;
  583. }
  584. //
  585. // verify pdevobj okay
  586. //
  587. ASSERT(VALID_PDEVOBJ(pdevobj));
  588. //
  589. // fill in printer commands
  590. //
  591. i = 0;
  592. pOEM = (POEMUD_EXTRADATA)(pdevobj->pOEMDM);
  593. iRet = 0;
  594. // NTRAID#NTBUG9-580353-2002/03/18-v-sueyas-: Check for illegal parameters
  595. if (NULL == pOEM)
  596. {
  597. ERR(("OEMCommandCallback: pdevobj->pOEMDM = 0.\n"));
  598. return 0;
  599. }
  600. /*
  601. * There are four kinds of draw modes of this driver.When entering a
  602. * new draw mode, it send the commands which ends the previous draw mode
  603. * at the same time.
  604. * 1.FLAG_RASTER - raster image mode.The condition not to enter
  605. * a vector mode and a text mode.
  606. * Default condition is RASTER in this driver
  607. * 2.FLAG_SBCS - single byte text mode. IN: FSa, OUT:FSR
  608. * 3.FLAG_DBCS - double byte text mode. IN: FSa, OUT:FSR
  609. * 4.FLAG_VECTOR - vector mode. IN: FSY, OUT:FSZ
  610. */
  611. switch (dwCmdCbID) {
  612. case CMD_CR:
  613. pOEM->dwDeviceDestX = 0;
  614. WRITESPOOLBUF(pdevobj, "\015", 1);
  615. break;
  616. case CMD_MOVE_X:
  617. case CMD_MOVE_Y:
  618. // NTRAID#NTBUG9-580353-2002/03/18-v-sueyas-: Check for illegal parameters
  619. if (dwCount < 4 || !pdwParams)
  620. return 0; // cannot do anything
  621. pOEM->dwDeviceDestX = PARAM(pdwParams, 0) /
  622. (MASTER_UNIT / PARAM(pdwParams, 2));
  623. pOEM->dwDeviceDestY = PARAM(pdwParams, 1) /
  624. (MASTER_UNIT / PARAM(pdwParams, 3));
  625. // Set return value
  626. switch (dwCmdCbID) {
  627. case CMD_MOVE_X:
  628. iRet = (INT)pOEM->dwDeviceDestX;
  629. break;
  630. case CMD_MOVE_Y:
  631. iRet = (INT)pOEM->dwDeviceDestY;
  632. break;
  633. }
  634. break;
  635. // MW2250H, MW2300
  636. case CMD_RES_1200:
  637. i = 0;
  638. i += memcopy(&Cmd[i], "\x1C<1/1200,i.\x1CYSC;SU1,1200,0;PM1,1;SG0;\x1CZ", 39);
  639. WRITESPOOLBUF(pdevobj, Cmd, i);
  640. pOEM->wRes = MASTER_UNIT / 1200;
  641. break;
  642. case CMD_RES_600:
  643. i = 0;
  644. i += memcopy(&Cmd[i], "\x1C<1/600,i.\x1CYSC;SU1,600,0;PM1,1;SG0;\x1CZ", 37);
  645. WRITESPOOLBUF(pdevobj, Cmd, i);
  646. pOEM->wRes = MASTER_UNIT / 600;
  647. break;
  648. case CMD_RES_400:
  649. i = 0;
  650. i += memcopy(&Cmd[i], "\x1C<1/400,i.\x1CYSC;SU1,400,0;PM1,1;SG0;\x1CZ", 37);
  651. WRITESPOOLBUF(pdevobj, Cmd, i);
  652. pOEM->wRes = MASTER_UNIT / 400;
  653. break;
  654. case CMD_RES_240:
  655. i = 0;
  656. i += memcopy(&Cmd[i], "\x1C<1/240,i.\x1CYSC;SU1,240,0;PM1,1;SG0;\x1CZ", 37);
  657. WRITESPOOLBUF(pdevobj, Cmd, i);
  658. pOEM->wRes = MASTER_UNIT / 240;
  659. break;
  660. case CMD_BEGIN_RASTER:
  661. if (pOEM->wCurrentAddMode == FLAG_VECTOR){
  662. i = 0;
  663. i += memcopy(&Cmd[i], "EP;FL;\034Z", 8);
  664. WRITESPOOLBUF(pdevobj, Cmd, i);
  665. pOEM->wCurrentAddMode = FLAG_RASTER;
  666. }
  667. else if (pOEM->wCurrentAddMode == FLAG_SBCS ||
  668. pOEM->wCurrentAddMode == FLAG_DBCS){
  669. i = 0;
  670. i += memcopy(&Cmd[i], "\034R", 2);
  671. WRITESPOOLBUF(pdevobj, Cmd, i);
  672. pOEM->wCurrentAddMode = FLAG_RASTER;
  673. }
  674. break;
  675. case CMD_SEND_BLOCK_DATA:
  676. // NTRAID#NTBUG9-580353-2002/03/18-v-sueyas-: Check for illegal parameters
  677. if (dwCount < 1 || !pdwParams)
  678. return 0;
  679. // Rememter length of the scan line.
  680. pOEM->dwScanLen = PARAM(pdwParams, 0);
  681. break;
  682. #ifdef BYPASS
  683. case CMD_BEGIN_RASTER_NO_COMP:
  684. if (pOEM->wCurrentAddMode == FLAG_VECTOR){
  685. i = 0;
  686. i += memcopy(&Cmd[i], "EP;FL;\034Z", 8);
  687. WRITESPOOLBUF(pdevobj, Cmd, i);
  688. pOEM->wCurrentAddMode = FLAG_RASTER;
  689. }
  690. else if (pOEM->wCurrentAddMode == FLAG_SBCS ||
  691. pOEM->wCurrentAddMode == FLAG_DBCS){
  692. i = 0;
  693. i += memcopy(&Cmd[i], "\034R", 2);
  694. WRITESPOOLBUF(pdevobj, Cmd, i);
  695. pOEM->wCurrentAddMode = FLAG_RASTER;
  696. }
  697. pOEM->fGeneral |= FG_NO_COMP;
  698. break;
  699. #endif // BYPASS
  700. case CMD_PC_PRN_DIRECTION:
  701. // 02/04/09 NES Niigata : Check for illegal parameters
  702. if (dwCount < 1 || !pdwParams)
  703. return 0;
  704. {
  705. LONG lEsc90;
  706. LONG ESin[] = {0, 1, 0, -1};
  707. LONG ECos[] = {1, 0, -1, 0};
  708. lEsc90 = (PARAM(pdwParams, 0) % 360) / 90;
  709. pOEM->lSBCSXMove = pOEM->dwSBCSX * ECos[lEsc90];
  710. pOEM->lSBCSYMove = -(LONG)pOEM->dwSBCSX * ESin[lEsc90];
  711. pOEM->lDBCSXMove = pOEM->dwDBCSX * ECos[lEsc90];
  712. pOEM->lDBCSYMove = -(LONG)pOEM->dwDBCSX * ESin[lEsc90];
  713. }
  714. break;
  715. case CMD_FF:
  716. i = 0;
  717. if (pOEM->wCurrentAddMode == FLAG_VECTOR){
  718. i += memcopy(&Cmd[i], "EP;FL;\x1CZ\x0D\x0C", 10);
  719. WRITESPOOLBUF(pdevobj, Cmd, i);
  720. pOEM->wCurrentAddMode = FLAG_RASTER;
  721. }
  722. else if (pOEM->wCurrentAddMode == FLAG_SBCS ||
  723. pOEM->wCurrentAddMode == FLAG_DBCS){
  724. i += memcopy(&Cmd[i], "\x1CR\x0D\x0C", 4);
  725. WRITESPOOLBUF(pdevobj, Cmd, i);
  726. pOEM->wCurrentAddMode = FLAG_RASTER;
  727. }
  728. else{
  729. i += memcopy(&Cmd[i], "\x0D\x0C", 2);
  730. WRITESPOOLBUF(pdevobj, Cmd, i);
  731. pOEM->wCurrentAddMode = FLAG_RASTER;
  732. }
  733. break;
  734. case CMD_INIT_COORDINATE:
  735. pOEM->dwDeviceDestX = 0;
  736. pOEM->dwDeviceDestY = 0;
  737. pOEM->wCurrentAddMode = FLAG_RASTER;
  738. pOEM->cSubPath = 0;
  739. break;
  740. case CMD_WHITE_ON:
  741. if (pOEM->wCurrentAddMode == FLAG_VECTOR){
  742. i = 0;
  743. i += memcopy(&Cmd[i], "EP;FL;\034Z", 8);
  744. pOEM->wCurrentAddMode = FLAG_RASTER;
  745. }
  746. i += memcopy(&Cmd[i], "\034\"R.\034$100.", 10);
  747. WRITESPOOLBUF(pdevobj, Cmd, i);
  748. break;
  749. case CMD_WHITE_OFF:
  750. if (pOEM->wCurrentAddMode == FLAG_VECTOR){
  751. i = 0;
  752. i += memcopy(&Cmd[i], "EP;FL;\034Z", 8);
  753. pOEM->wCurrentAddMode = FLAG_RASTER;
  754. }
  755. i += memcopy(&Cmd[i], "\034\"O.\034$0.", 8);
  756. WRITESPOOLBUF(pdevobj, Cmd, i);
  757. break;
  758. case CMD_BOLD_ON:
  759. if (pOEM->wCurrentAddMode == FLAG_VECTOR){
  760. i = 0;
  761. i += memcopy(&Cmd[i], "EP;FL;\034Z", 8);
  762. pOEM->wCurrentAddMode = FLAG_RASTER;
  763. }
  764. i += memcopy(&Cmd[i], "\034c,,1.", 6);
  765. WRITESPOOLBUF(pdevobj, Cmd, i);
  766. break;
  767. case CMD_ITALIC_ON:
  768. if (pOEM->wCurrentAddMode == FLAG_VECTOR){
  769. i = 0;
  770. i += memcopy(&Cmd[i], "EP;FL;\034Z", 8);
  771. pOEM->wCurrentAddMode = FLAG_RASTER;
  772. }
  773. i += memcopy(&Cmd[i], "\034c,,2.", 6);
  774. WRITESPOOLBUF(pdevobj, Cmd, i);
  775. break;
  776. case CMD_CLEAR_ATTRIB:
  777. if (pOEM->wCurrentAddMode == FLAG_VECTOR){
  778. i = 0;
  779. i += memcopy(&Cmd[i], "EP;FL;\034Z", 8);
  780. pOEM->wCurrentAddMode = FLAG_RASTER;
  781. }
  782. i += memcopy(&Cmd[i], "\034c,,0.", 6);
  783. WRITESPOOLBUF(pdevobj, Cmd, i);
  784. break;
  785. case CMD_CLEAR_ATTRIB_P:
  786. if (pOEM->wCurrentAddMode == FLAG_VECTOR){
  787. i = 0;
  788. i += memcopy(&Cmd[i], "EP;FL;\034Z", 8);
  789. pOEM->wCurrentAddMode = FLAG_RASTER;
  790. }
  791. i += memcopy(&Cmd[i], "\034c,,0,80.", 9);
  792. WRITESPOOLBUF(pdevobj, Cmd, i);
  793. break;
  794. case CMD_RECTWIDTH:
  795. // NTRAID#NTBUG9-580353-2002/03/18-v-sueyas-: Check for illegal parameters
  796. if (dwCount < 1 || !pdwParams)
  797. return 0;
  798. // NTRAID#NTBUG9-580363-2002/03/18-v-sueyas-: Check for deviding by zero
  799. if (0 == pOEM->wRes)
  800. return 0;
  801. pOEM->dwRectWidth = PARAM(pdwParams, 0) / pOEM->wRes;
  802. break;
  803. case CMD_RECTHEIGHT:
  804. // NTRAID#NTBUG9-580353-2002/03/18-v-sueyas-: Check for illegal parameters
  805. if (dwCount < 1 || !pdwParams)
  806. return 0;
  807. // NTRAID#NTBUG9-580363-2002/03/18-v-sueyas-: Check for deviding by zero
  808. if (0 == pOEM->wRes)
  809. return 0;
  810. pOEM->dwRectHeight = PARAM(pdwParams, 0) / pOEM->wRes;
  811. break;
  812. case CMD_RECTWHITE:
  813. gray = 100;
  814. goto fill;
  815. case CMD_RECTBLACK:
  816. gray = 0;
  817. goto fill;
  818. case CMD_RECTGRAY:
  819. // NTRAID#NTBUG9-580353-2002/03/18-v-sueyas-: Check for illegal parameters
  820. if (dwCount < 1 || !pdwParams)
  821. return 0;
  822. gray = 100 - PARAM(pdwParams, 0);
  823. goto fill;
  824. fill:
  825. {
  826. // if rectangle size is zeor,we do not draw.
  827. if(pOEM->dwRectWidth - 1 < 1 && pOEM->dwRectHeight - 1 < 1)
  828. break;
  829. i = 0;
  830. /* Raster mode -> Vector mode in */
  831. if (pOEM->wCurrentAddMode == FLAG_RASTER){
  832. i += memcopy(&Cmd[i], "\x1CY", 2);
  833. pOEM->wCurrentAddMode = FLAG_VECTOR;
  834. if(pOEM->iGray != gray){
  835. i += memcopy(&Cmd[i], "SG", 2); // Send Gray Scale
  836. i += iDwtoA(&Cmd[i], gray);
  837. Cmd[i++] = ';';
  838. pOEM->iGray = gray;
  839. }
  840. i += memcopy(&Cmd[i], "NP;", 3);
  841. pOEM->cSubPath = 0;
  842. }
  843. /* Text mode -> Vector mode in */
  844. else if (pOEM->wCurrentAddMode == FLAG_SBCS ||
  845. pOEM->wCurrentAddMode == FLAG_DBCS){
  846. i += memcopy(&Cmd[i], "\x1CR\x1CY", 4);
  847. pOEM->wCurrentAddMode = FLAG_VECTOR;
  848. if(pOEM->iGray != gray){
  849. i += memcopy(&Cmd[i], "SG", 2); // Send Gray Scale
  850. i += iDwtoA(&Cmd[i], gray);
  851. Cmd[i++] = ';';
  852. pOEM->iGray = gray;
  853. }
  854. i += memcopy(&Cmd[i], "NP;", 3);
  855. pOEM->cSubPath = 0;
  856. }
  857. /* Already Vector mode and gray scale changed or
  858. sub path count is over 500 */
  859. if(pOEM->iGray != gray){
  860. i += memcopy(&Cmd[i], "EP;FL;SG", 8);
  861. i += iDwtoA(&Cmd[i], gray);
  862. i += memcopy(&Cmd[i], ";NP;", 4);
  863. pOEM->iGray = gray;
  864. pOEM->cSubPath = 0;
  865. }
  866. else if(pOEM->cSubPath >= MAX_SUBPATH){
  867. i += memcopy(&Cmd[i], "EP;FL;", 6);
  868. i += memcopy(&Cmd[i], "NP;", 3);
  869. pOEM->cSubPath = 0;
  870. }
  871. i += memcopy(&Cmd[i], "MA", 2);
  872. i += iDwtoA(&Cmd[i], pOEM->dwDeviceDestX);
  873. Cmd[i++] = ',';
  874. i += iDwtoA(&Cmd[i], pOEM->dwDeviceDestY);
  875. i += memcopy(&Cmd[i], ";PR", 3);
  876. i += iDwtoA(&Cmd[i], pOEM->dwRectWidth - 1);
  877. i += memcopy(&Cmd[i], ",0,0,", 5);
  878. i += iDwtoA(&Cmd[i], pOEM->dwRectHeight - 1);
  879. i += memcopy(&Cmd[i], ",-", 2);
  880. i += iDwtoA(&Cmd[i], pOEM->dwRectWidth - 1);
  881. i += memcopy(&Cmd[i], ",0;CP;", 6);
  882. pOEM->cSubPath+=4; // rect is built by 4 line
  883. // some model have to close pass when rect width or height under 1
  884. pOEM->cSubPath = MAX_SUBPATH;
  885. /* send RectFill command */
  886. WRITESPOOLBUF(pdevobj, Cmd, i);
  887. }
  888. break;
  889. }
  890. return iRet;
  891. }
  892. //-----------------------------------------------------------------------------
  893. //
  894. // Function: OEMSendFontCmd
  895. //
  896. //-----------------------------------------------------------------------------
  897. // NTRAID#NTBUG9-580367-2002/03/18-v-sueyas-: Error handling
  898. BOOL
  899. APIENTRY
  900. bOEMSendFontCmd(
  901. PDEVOBJ pdevobj,
  902. PUNIFONTOBJ pUFObj,
  903. PFINVOCATION pFInv)
  904. {
  905. PGETINFO_STDVAR pSV;
  906. DWORD adwStdVariable[2+2*4]; // it means dwSize + dwNumOfVariable +
  907. // (dwStdVarID + lStdVariable) * n
  908. DWORD dwIn, dwOut;
  909. PBYTE pubCmd;
  910. BYTE aubCmd[128];
  911. POEMUD_EXTRADATA pOEM;
  912. DWORD tmpPointsx, tmpPointsy;
  913. PIFIMETRICS pIFI;
  914. DWORD dwNeeded;
  915. DWORD dwCount;
  916. BOOL bFound = FALSE;
  917. VERBOSE(("OEMSendFontCmd() entry.\r\n"));
  918. VERBOSE((("CMD size:%ld\r\n"), pFInv->dwCount));
  919. // NTRAID#NTBUG9-580353-2002/03/18-v-sueyas-: Check for illegal parameters
  920. if (NULL == pdevobj || NULL == pUFObj || NULL == pFInv)
  921. {
  922. ERR(("bOEMSendFontCmd: Invalid parameter(s).\n"));
  923. return FALSE;
  924. }
  925. if(!pFInv->dwCount){
  926. VERBOSE(("CMD size is Zero return\r\n"));
  927. return FALSE;
  928. }
  929. pubCmd = pFInv->pubCommand;
  930. dwCount = pFInv->dwCount;
  931. pOEM = (POEMUD_EXTRADATA)(pdevobj->pOEMDM);
  932. // NTRAID#NTBUG9-580353-2002/03/18-v-sueyas-: Check for illegal parameters
  933. if (NULL == pubCmd || NULL == pOEM)
  934. {
  935. ERR(("bOEMSendFontCmd: pFInv->pubCommand = 0 Or pdevobj->pOEMDM = 0.\n"));
  936. return FALSE;
  937. }
  938. //
  939. // Get standard variables.
  940. //
  941. pSV = (PGETINFO_STDVAR)adwStdVariable;
  942. // 02/04/09 NES Niigata : Check for illegal parameters
  943. if (NULL == pSV)
  944. {
  945. ERR(("OEMSendFontCmd: pSV = 0.\n"));
  946. return FALSE;
  947. }
  948. pSV->dwSize = sizeof(GETINFO_STDVAR) + 2 * sizeof(DWORD) * (4 - 1);
  949. pSV->dwNumOfVariable = 4;
  950. pSV->StdVar[0].dwStdVarID = FNT_INFO_FONTHEIGHT;
  951. pSV->StdVar[1].dwStdVarID = FNT_INFO_FONTWIDTH;
  952. pSV->StdVar[2].dwStdVarID = FNT_INFO_TEXTYRES;
  953. pSV->StdVar[3].dwStdVarID = FNT_INFO_TEXTXRES;
  954. if (!pUFObj->pfnGetInfo(pUFObj, UFO_GETINFO_STDVARIABLE, pSV,
  955. pSV->dwSize, &dwNeeded)) {
  956. ERR(("UFO_GETINFO_STDVARIABLE failed.\r\n"));
  957. return FALSE;
  958. }
  959. VERBOSE((("FONTHEIGHT=%d\r\n"), pSV->StdVar[0].lStdVariable));
  960. VERBOSE((("FONTWIDTH=%d\r\n"), pSV->StdVar[1].lStdVariable));
  961. tmpPointsy = pSV->StdVar[0].lStdVariable * 720 / pSV->StdVar[2].lStdVariable;
  962. dwIn = dwOut = 0;
  963. /* vector mode ends.*/
  964. if (pOEM->wCurrentAddMode == FLAG_VECTOR){
  965. dwOut += memcopy(&aubCmd[dwOut], "EP;FL;\034Z", 8);
  966. }
  967. /* make font select command */
  968. while(dwCount--)
  969. {
  970. if(pubCmd[dwIn] !='#'){
  971. aubCmd[dwOut] = pubCmd[dwIn];
  972. dwOut++;
  973. dwIn++;
  974. }
  975. else{
  976. bFound = TRUE;
  977. break;
  978. }
  979. }
  980. if(bFound == TRUE)
  981. dwIn++;
  982. else
  983. return FALSE; // mismatch font command
  984. pOEM->fGeneral &= ~(FG_VERT | FG_PLUS | FG_DBCS);
  985. switch(pubCmd[dwIn])
  986. {
  987. case 'O': // for OCR-B Font support
  988. pOEM->fGeneral |= FG_PLUS;
  989. tmpPointsy = tmpPointsx = 120 * pOEM->wRes; // Only 12pt
  990. break;
  991. case 'R': // NPDL2P SBCS
  992. pOEM->fGeneral |= FG_PLUS;
  993. tmpPointsx = pSV->StdVar[1].lStdVariable * 1200 /
  994. pSV->StdVar[2].lStdVariable;
  995. break;
  996. case 'P': // NPDL2 SBCS
  997. tmpPointsx = pSV->StdVar[1].lStdVariable * 1200 /
  998. pSV->StdVar[2].lStdVariable;
  999. break;
  1000. case 'W': // NPDL2 DBCS and FontCard
  1001. pOEM->fGeneral |= FG_VERT;
  1002. case 'Q':
  1003. pOEM->fGeneral |= FG_DBCS;
  1004. tmpPointsx = pSV->StdVar[1].lStdVariable * 1440 /
  1005. pSV->StdVar[2].lStdVariable;
  1006. break;
  1007. case 'Y': // NPDL2P DBCS and FontCard
  1008. pOEM->fGeneral |= FG_VERT;
  1009. case 'S':
  1010. pOEM->fGeneral |= (FG_PLUS | FG_DBCS);
  1011. tmpPointsx = pSV->StdVar[1].lStdVariable * 1440 /
  1012. pSV->StdVar[2].lStdVariable;
  1013. break;
  1014. }
  1015. // NTRAID#NTBUG9-580363-2002/03/18-v-sueyas-: Check for deviding by zero
  1016. if (0 == pOEM->wRes)
  1017. return FALSE;
  1018. if(pOEM->fGeneral & FG_PLUS)
  1019. {
  1020. if(tmpPointsy > 9999) tmpPointsy = 9999;
  1021. else if(tmpPointsy < 10) tmpPointsy = 10;
  1022. if(tmpPointsx > 9999) tmpPointsx = 9999;
  1023. else if(tmpPointsx < 10) tmpPointsx = 10;
  1024. pOEM->wScale = tmpPointsx == tmpPointsy;
  1025. pOEM->lPointsx = tmpPointsx;
  1026. pOEM->lPointsy = tmpPointsy;
  1027. if(pOEM->fGeneral & FG_VERT)
  1028. {
  1029. if(pOEM->wScale){
  1030. aubCmd[dwOut++] = '\034';
  1031. dwOut += memcopy(&aubCmd[dwOut], "12S2-", 5);
  1032. dwOut += iDwtoA_FillZero(&aubCmd[dwOut],
  1033. tmpPointsy / pOEM->wRes, 4);
  1034. aubCmd[dwOut++] = '-';
  1035. dwOut += iDwtoA_FillZero(&aubCmd[dwOut],
  1036. tmpPointsx / pOEM->wRes, 4);
  1037. }
  1038. }
  1039. else{
  1040. dwOut += iDwtoA_FillZero(&aubCmd[dwOut],
  1041. tmpPointsx / pOEM->wRes, 4);
  1042. aubCmd[dwOut++] = '-';
  1043. dwOut += iDwtoA_FillZero(&aubCmd[dwOut],
  1044. tmpPointsy / pOEM->wRes, 4);
  1045. }
  1046. goto SEND_COM;
  1047. }
  1048. pOEM->wScale = 1;
  1049. if(tmpPointsy > 9999)
  1050. {
  1051. tmpPointsy = 9999;
  1052. goto MAKE_COM;
  1053. }
  1054. if(tmpPointsy < 10)
  1055. {
  1056. tmpPointsy = 10;
  1057. goto MAKE_COM;
  1058. }
  1059. pOEM->wScale = (int)(((tmpPointsx * 10) / tmpPointsy + 5) / 10);
  1060. if(pOEM->wScale > 8) pOEM->wScale = 8;
  1061. MAKE_COM:
  1062. dwOut += iDwtoA_FillZero(&aubCmd[dwOut], tmpPointsy / pOEM->wRes, 4);
  1063. SEND_COM:
  1064. if(!(pOEM->fGeneral & FG_PLUS))
  1065. {
  1066. char *bcom[] = {"1/2", "1/1", "2/1", "3/1",
  1067. "4/1", "4/1", "6/1", "6/1", "8/1"};
  1068. if(pOEM->fGeneral & FG_VERT)
  1069. {
  1070. if(pOEM->wScale == 1)
  1071. {
  1072. dwOut += memcopy(&aubCmd[dwOut], "\034m1/1,1/1.", 10);
  1073. }
  1074. }
  1075. else
  1076. {
  1077. aubCmd[dwOut++] = '\034';
  1078. dwOut += memcopy(&aubCmd[dwOut], "m1/1,", 5);
  1079. dwOut += memcopy(&aubCmd[dwOut], (LPSTR)bcom[pOEM->wScale], 3);
  1080. aubCmd[dwOut++] = '.';
  1081. }
  1082. }
  1083. // write spool builded command
  1084. WRITESPOOLBUF(pdevobj, aubCmd, dwOut);
  1085. /*
  1086. * I expect the interval of the current letter and the next letter
  1087. * from the letter size.
  1088. */
  1089. if(pOEM->fGeneral & FG_DBCS){
  1090. pOEM->dwDBCSX =
  1091. pOEM->lDBCSXMove =
  1092. (LONG)((pSV->StdVar[1].lStdVariable * 2.04) / pOEM->wRes);
  1093. pOEM->dwSBCSX =
  1094. pOEM->lSBCSXMove =
  1095. (LONG)(pSV->StdVar[1].lStdVariable * 1.03 / pOEM->wRes);
  1096. }
  1097. else{
  1098. pOEM->dwSBCSX =
  1099. pOEM->lSBCSXMove =
  1100. pSV->StdVar[1].lStdVariable / pOEM->wRes;
  1101. }
  1102. pOEM->lDBCSYMove = pOEM->lSBCSYMove = 0;
  1103. pOEM->wCurrentAddMode = FLAG_RASTER;
  1104. VERBOSE(("OEMSendFontCmd() end.\r\n"));
  1105. return TRUE;
  1106. }
  1107. //-----------------------------------------------------------------------------
  1108. //
  1109. // Function: OEMOutputCharStr
  1110. //
  1111. //-----------------------------------------------------------------------------
  1112. // NTRAID#NTBUG9-580367-2002/03/18-v-sueyas-: Error handling
  1113. BOOL APIENTRY
  1114. bOEMOutputCharStr(
  1115. PDEVOBJ pdevobj,
  1116. PUNIFONTOBJ pUFObj,
  1117. DWORD dwType,
  1118. DWORD dwCount,
  1119. PVOID pGlyph)
  1120. {
  1121. WORD wlen;
  1122. WORD j;
  1123. PIFIMETRICS pIFI;
  1124. POEMUD_EXTRADATA pOEM;
  1125. GETINFO_GLYPHSTRING GStr;
  1126. PTRANSDATA pTrans;
  1127. // #333653: Change I/F for GETINFO_GLYPHSTRING
  1128. // BYTE aubBuff[256];
  1129. PBYTE aubBuff;
  1130. DWORD dwI;
  1131. DWORD dwNeeded;
  1132. // Adjust baseline if font substituted from TrueType font.
  1133. DWORD dwYAdj;
  1134. PGETINFO_STDVAR pSV;
  1135. DWORD adwStdVar[2+2*2];
  1136. BYTE Cmd[256];
  1137. int i;
  1138. VERBOSE(("OEMOutputCharStr() entry.\r\n"));
  1139. VERBOSE((("FONT Num=%d\r\n"), dwCount));
  1140. // NTRAID#NTBUG9-580353-2002/03/18-v-sueyas-: Check for illegal parameters
  1141. if(NULL == pdevobj || NULL == pUFObj)
  1142. {
  1143. ERR(("bOEMOutputCharStr: Invalid parameter(s).\n"));
  1144. return FALSE;
  1145. }
  1146. if(dwType != TYPE_GLYPHHANDLE){
  1147. VERBOSE((("NOT TYPE_GLYPHHANDLE\r\n")));
  1148. return FALSE;
  1149. }
  1150. pOEM = (POEMUD_EXTRADATA)(pdevobj->pOEMDM);
  1151. pIFI = pUFObj->pIFIMetrics;
  1152. // NTRAID#NTBUG9-580353-2002/03/18-v-sueyas-: Check for illegal parameters
  1153. if(NULL == pOEM || NULL == pIFI)
  1154. {
  1155. ERR(("bOEMOutputCharStr: pdevobj->pOEMDM = 0 Or pUFObj->pIFIMetrics = 0.\n"));
  1156. return FALSE;
  1157. }
  1158. // NTRAID#NTBUG9-580363-2002/03/18-v-sueyas-: Check for deviding by zero
  1159. if (0 == pOEM->wRes)
  1160. return FALSE;
  1161. //
  1162. // Call the Unidriver service routine to convert
  1163. // glyph-handles into the character code data.
  1164. //
  1165. // #333653: Change I/F for GETINFO_GLYPHSTRING
  1166. GStr.dwSize = sizeof (GETINFO_GLYPHSTRING);
  1167. GStr.dwCount = dwCount;
  1168. GStr.dwTypeIn = TYPE_GLYPHHANDLE;
  1169. GStr.pGlyphIn = pGlyph;
  1170. GStr.dwTypeOut = TYPE_TRANSDATA;
  1171. GStr.pGlyphOut = NULL;
  1172. GStr.dwGlyphOutSize = 0;
  1173. if (pUFObj->pfnGetInfo(pUFObj, UFO_GETINFO_GLYPHSTRING, &GStr,
  1174. GStr.dwSize, &dwNeeded) || !GStr.dwGlyphOutSize)
  1175. {
  1176. VERBOSE(("UNIFONTOBJ_GetInfo:UFO_GETINFO_GLYPHSTRING failed.\r\n"));
  1177. return FALSE;
  1178. }
  1179. if ((aubBuff = MemAlloc(GStr.dwGlyphOutSize)) == NULL)
  1180. {
  1181. VERBOSE(("UNIFONTOBJ_GetInfo:MemAlloc failed.\r\n"));
  1182. return FALSE;
  1183. }
  1184. GStr.pGlyphOut = aubBuff;
  1185. if (!pUFObj->pfnGetInfo(pUFObj, UFO_GETINFO_GLYPHSTRING, &GStr,
  1186. GStr.dwSize, &dwNeeded))
  1187. {
  1188. VERBOSE(("UNIFONTOBJ_GetInfo:UFO_GETINFO_GLYPHSTRING failed.\r\n"));
  1189. MemFree(aubBuff);
  1190. return FALSE;
  1191. }
  1192. // Adjust baseline if font substituted from TrueType font.
  1193. if (pUFObj->dwFlags & UFOFLAG_TTSUBSTITUTED) {
  1194. pSV = (PGETINFO_STDVAR)adwStdVar;
  1195. pSV->dwSize = sizeof(GETINFO_STDVAR) + 2 * sizeof(DWORD) * (2 - 1);
  1196. pSV->dwNumOfVariable = 2;
  1197. pSV->StdVar[0].dwStdVarID = FNT_INFO_FONTHEIGHT;
  1198. pSV->StdVar[1].dwStdVarID = FNT_INFO_TEXTYRES;
  1199. if (!pUFObj->pfnGetInfo(pUFObj, UFO_GETINFO_STDVARIABLE, pSV,
  1200. pSV->dwSize, &dwNeeded)) {
  1201. ERR(("UFO_GETINFO_STDVARIABLE failed.\r\n"));
  1202. MemFree(aubBuff);
  1203. return FALSE;
  1204. }
  1205. dwYAdj = (pSV->StdVar[0].lStdVariable * pIFI->fwdWinDescender /
  1206. pIFI->fwdUnitsPerEm) / pOEM->wRes;
  1207. } else
  1208. dwYAdj = 0;
  1209. /* Vector mode off */
  1210. if (pOEM->wCurrentAddMode == FLAG_VECTOR){
  1211. i = 0;
  1212. i += memcopy(&Cmd[i], "EP;FL;\034Z", 8);
  1213. WRITESPOOLBUF(pdevobj, Cmd, i);
  1214. pOEM->wCurrentAddMode = FLAG_RASTER;
  1215. }
  1216. /*
  1217. * Three kind of the character cords which is given by UNIDRV
  1218. * 1.SBCS
  1219. * 2.DBCS Kanji
  1220. * 3.DBCS ANK
  1221. */
  1222. pTrans = (PTRANSDATA)aubBuff;
  1223. // 02/04/09 NES Niigata : Check for illegal parameters
  1224. if(NULL == pTrans)
  1225. {
  1226. ERR(("OEMOutputCharStr: pTrans = 0.\n"));
  1227. return FALSE;
  1228. }
  1229. for (dwI = 0; dwI < dwCount; dwI ++, pTrans++)
  1230. {
  1231. switch (pTrans->ubType & MTYPE_FORMAT_MASK)
  1232. {
  1233. case MTYPE_DIRECT:
  1234. /*
  1235. Pattern 1: SBCS
  1236. */
  1237. if(pOEM->wCurrentAddMode != FLAG_SBCS ||
  1238. pOEM->dwDeviceDestX != pOEM->dwDevicePrevX + pOEM->lPrevXMove ||
  1239. pOEM->dwDeviceDestY != pOEM->dwDevicePrevY + pOEM->lPrevYMove)
  1240. {
  1241. i = 0;
  1242. i += memcopy(&Cmd[i], "\034e", 2);
  1243. i += iDwtoA(&Cmd[i], pOEM->dwDeviceDestX);
  1244. Cmd[i++] = ',';
  1245. // Adjust baseline if font substituted from TrueType font.
  1246. i += iDwtoA(&Cmd[i], pOEM->dwDeviceDestY + dwYAdj);
  1247. Cmd[i++] = '.';
  1248. i += memcopy(&Cmd[i], "\034a", 2);
  1249. i += iDwtoA(&Cmd[i], pOEM->lSBCSXMove);
  1250. Cmd[i++] = ',';
  1251. i += iDwtoA(&Cmd[i], pOEM->lSBCSYMove);
  1252. Cmd[i++] = '.';
  1253. WRITESPOOLBUF(pdevobj, Cmd, i);
  1254. pOEM->wCurrentAddMode = FLAG_SBCS;
  1255. pOEM->lPrevXMove = pOEM->lSBCSXMove;
  1256. pOEM->lPrevYMove = pOEM->lSBCSYMove;
  1257. }
  1258. WRITESPOOLBUF(pdevobj, &pTrans->uCode.ubCode, 1);
  1259. break;
  1260. case MTYPE_PAIRED:
  1261. /*
  1262. Pattern 2: kanji
  1263. */
  1264. if(*pTrans->uCode.ubPairs)
  1265. {
  1266. if(pOEM->wCurrentAddMode != FLAG_DBCS ||
  1267. pOEM->dwDeviceDestX != pOEM->dwDevicePrevX + pOEM->lPrevXMove ||
  1268. pOEM->dwDeviceDestY != pOEM->dwDevicePrevY + pOEM->lPrevYMove)
  1269. {
  1270. i = 0;
  1271. i += memcopy(&Cmd[i], "\034e", 2);
  1272. i += iDwtoA(&Cmd[i], pOEM->dwDeviceDestX);
  1273. Cmd[i++] = ',';
  1274. // Adjust baseline if font substituted from TrueType font.
  1275. i += iDwtoA(&Cmd[i], pOEM->dwDeviceDestY + dwYAdj);
  1276. Cmd[i++] = '.';
  1277. i += memcopy(&Cmd[i], "\034a", 2);
  1278. i += iDwtoA(&Cmd[i], pOEM->lDBCSXMove);
  1279. Cmd[i++] = ',';
  1280. i += iDwtoA(&Cmd[i], pOEM->lDBCSYMove);
  1281. Cmd[i++] = '.';
  1282. if(pOEM->fGeneral & FG_VERT)
  1283. {
  1284. i += memcopy(&Cmd[i], "\033t", 2);
  1285. if(pOEM->wScale != 1)
  1286. {
  1287. if(!(pOEM->fGeneral & FG_PLUS))
  1288. {
  1289. char *bcom[] = {"1/2", "1/1", "2/1", "3/1",
  1290. "4/1", "4/1", "6/1", "6/1",
  1291. "8/1"};
  1292. Cmd[i++] = '\034';
  1293. Cmd[i++] = 'm';
  1294. i += memcopy(&Cmd[i], (LPSTR)bcom[pOEM->wScale], 3);
  1295. i += memcopy(&Cmd[i], ",1/1.", 5);
  1296. }
  1297. else{
  1298. Cmd[i++] = '\034';
  1299. i += memcopy(&Cmd[i], "12S2-", 5);
  1300. i += iDwtoA_FillZero(&Cmd[i],
  1301. pOEM->lPointsy / pOEM->wRes, 4);
  1302. Cmd[i++] = '-';
  1303. i += iDwtoA_FillZero(&Cmd[i],
  1304. pOEM->lPointsx / pOEM->wRes, 4);
  1305. }
  1306. }
  1307. }
  1308. WRITESPOOLBUF(pdevobj, Cmd, i);
  1309. pOEM->wCurrentAddMode = FLAG_DBCS;
  1310. pOEM->lPrevXMove = pOEM->lDBCSXMove;
  1311. pOEM->lPrevYMove = pOEM->lDBCSYMove;
  1312. }
  1313. }
  1314. /*
  1315. Pattern 3: ANK
  1316. */
  1317. else
  1318. {
  1319. if(pOEM->wCurrentAddMode != FLAG_SBCS ||
  1320. pOEM->dwDeviceDestX != pOEM->dwDevicePrevX + pOEM->lPrevXMove ||
  1321. pOEM->dwDeviceDestY != pOEM->dwDevicePrevY + pOEM->lPrevYMove)
  1322. {
  1323. i = 0;
  1324. i += memcopy(&Cmd[i], "\034e", 2);
  1325. i += iDwtoA(&Cmd[i], pOEM->dwDeviceDestX);
  1326. Cmd[i++] = ',';
  1327. // Adjust baseline if font substituted from TrueType font.
  1328. i += iDwtoA(&Cmd[i], pOEM->dwDeviceDestY + dwYAdj);
  1329. Cmd[i++] = '.';
  1330. i += memcopy(&Cmd[i], "\034a", 2);
  1331. i += iDwtoA(&Cmd[i], pOEM->lSBCSXMove);
  1332. Cmd[i++] = ',';
  1333. i += iDwtoA(&Cmd[i], pOEM->lSBCSYMove);
  1334. Cmd[i++] = '.';
  1335. /*
  1336. * ANK can't do vertical writing. We have to do
  1337. * vertical writing for holizontal writing compulsorily
  1338. */
  1339. if(pOEM->fGeneral & FG_VERT)
  1340. {
  1341. i += memcopy(&Cmd[i], "\033K", 2);
  1342. if(pOEM->wScale != 1)
  1343. {
  1344. if(!(pOEM->fGeneral & FG_PLUS))
  1345. {
  1346. char *bcom[] = {"1/2", "1/1", "2/1", "3/1",
  1347. "4/1", "4/1", "6/1", "6/1", "8/1"}; Cmd[i++] = '\034';
  1348. i += memcopy(&Cmd[i], "m1/1,", 5);
  1349. i += memcopy(&Cmd[i], (LPSTR)bcom[pOEM->wScale], 3);
  1350. Cmd[i++] = '.';
  1351. }
  1352. else{
  1353. Cmd[i++] = '\034';
  1354. i += memcopy(&Cmd[i], "12S2-", 5);
  1355. i += iDwtoA_FillZero(&Cmd[i],
  1356. pOEM->lPointsx / pOEM->wRes, 4);
  1357. Cmd[i++] = '-';
  1358. i += iDwtoA_FillZero(&Cmd[i],
  1359. pOEM->lPointsy / pOEM->wRes, 4);
  1360. }
  1361. }
  1362. }
  1363. WRITESPOOLBUF(pdevobj, Cmd, i);
  1364. pOEM->wCurrentAddMode = FLAG_SBCS;
  1365. pOEM->lPrevXMove = pOEM->lSBCSXMove;
  1366. pOEM->lPrevYMove = pOEM->lSBCSYMove;
  1367. }
  1368. }
  1369. WRITESPOOLBUF(pdevobj, pTrans->uCode.ubPairs, 2);
  1370. break;
  1371. }
  1372. pOEM->dwDevicePrevX = pOEM->dwDeviceDestX;
  1373. pOEM->dwDevicePrevY = pOEM->dwDeviceDestY;
  1374. pOEM->dwDeviceDestX += pOEM->lPrevXMove;
  1375. pOEM->dwDeviceDestY += pOEM->lPrevYMove;
  1376. }
  1377. // #333653: Change I/F for GETINFO_GLYPHSTRING
  1378. MemFree(aubBuff);
  1379. VERBOSE(("OEMOutputCharStr() end.\r\n"));
  1380. return TRUE;
  1381. }
  1382. // NTRAID#NTBUG9-741174-2002/11/20-yasuho-: Memory leak happened.
  1383. PDEVOEM APIENTRY
  1384. OEMEnablePDEV(
  1385. PDEVOBJ pdevobj,
  1386. PWSTR pPrinterName,
  1387. ULONG cPatterns,
  1388. HSURF *phsurfPatterns,
  1389. ULONG cjGdiInfo,
  1390. GDIINFO *pGdiInfo,
  1391. ULONG cjDevInfo,
  1392. DEVINFO *pDevInfo,
  1393. DRVENABLEDATA *pded)
  1394. {
  1395. if (NULL == pdevobj)
  1396. {
  1397. ERR(("OEMEnablePDEV: Invalid parameter(s).\n"));
  1398. return NULL;
  1399. }
  1400. return pdevobj->pOEMDM;
  1401. }
  1402. VOID
  1403. APIENTRY
  1404. OEMDisablePDEV(
  1405. PDEVOBJ pdevobj
  1406. )
  1407. /*++
  1408. Routine Description:
  1409. Implementation of DDI entry point OEMDisablePDEV.
  1410. Please refer to DDK documentation for more details.
  1411. Arguments:
  1412. Return Value:
  1413. NONE
  1414. --*/
  1415. {
  1416. POEMUD_EXTRADATA pOEM;
  1417. VERBOSE(("Entering OEMDisablePDEV...\n"));
  1418. // NTRAID#NTBUG9-580353-2002/03/18-v-sueyas-: Check for illegal parameters
  1419. if (NULL == pdevobj)
  1420. {
  1421. ERR(("Invalid parameter(s).\n"));
  1422. return;
  1423. }
  1424. //
  1425. // verify pdevobj okay
  1426. //
  1427. ASSERT(VALID_PDEVOBJ(pdevobj));
  1428. //
  1429. // fill in printer commands
  1430. //
  1431. pOEM = (POEMUD_EXTRADATA)(pdevobj->pOEMDM);
  1432. // NTRAID#NTBUG9-580353-2002/03/18-v-sueyas-: Check for illegal parameters
  1433. if (NULL == pOEM)
  1434. {
  1435. ERR(("pdevobj->pOEMDM = NULL.\n"));
  1436. return;
  1437. }
  1438. //
  1439. // Free up memory allocated for the temp. buffer
  1440. //
  1441. if (pOEM->pCompBuf) {
  1442. FREEMEM(pOEM->pCompBuf);
  1443. pOEM->pCompBuf = NULL;
  1444. pOEM->dwCompBufLen = 0;
  1445. }
  1446. }