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.

2045 lines
81 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-1999 Microsoft Corporation
  9. Module Name:
  10. cmdcb.c
  11. Abstract:
  12. Implementation of GPD command callback for "test.gpd":
  13. bCommandCallback
  14. Environment:
  15. Windows NT Unidrv driver
  16. Revision History:
  17. // NOTICE-2002/3/14-takashim
  18. // 04/07/97 -zhanw-
  19. // Created it.
  20. --*/
  21. #include "pdev.h"
  22. #include <stdio.h>
  23. #include <strsafe.h>
  24. /*--------------------------------------------------------------------------*/
  25. /* G L O B A L V A L U E */
  26. /*--------------------------------------------------------------------------*/
  27. /*======================= P A P E R S I Z E T A B L E =====================*/
  28. const PHYSIZE phySize[12] = {
  29. // Width Height Physical paper size for 600dpi
  30. (0x1AAC),(0x2604), // A3 1B66 x 26C4
  31. (0x12A5),(0x1AAC), // A4 1362 x 1B66
  32. (0x0CEC),(0x12A4), // A5
  33. (0x0000),(0x0000), // A6 (Reserved)
  34. (0x16FA),(0x20DA), // B4 17B8 x 2196
  35. (0x100F),(0x16FA), // B5 10CE x 17B8
  36. (0x0000),(0x0000), // B6 (Reserved)
  37. (0x087E),(0x0CEC), // Post Card 93C x DAA (Origin is EE)
  38. (0x1330),(0x190C), // Letter 13CE x 19C8
  39. (0x1330),(0x2014), // Legal
  40. (0x0000),(0x0000), // Executive (Reserved)
  41. (0x0000),(0x0000) // Unfixed
  42. };
  43. /*==================== A / P D L C O M M A N D S T R I N G ===============*/
  44. const BYTE CmdInAPDLMode[] = {0x1B,0x7E,0x12,0x00,0x01,0x07};
  45. const BYTE CmdOutAPDLMode[] = {0x1B,0x7E,0x12,0x00,0x01,0x00};
  46. const BYTE CmdAPDLStart[] = {0x1C,0x01}; // A/PDL start
  47. const BYTE CmdAPDLEnd[] = {0x1C,0x02}; // A/PDL end
  48. const BYTE CmdBeginPhysPage[] = {0x1C,0x03}; // Begin Physical Page
  49. const BYTE CmdEndPhysPage[] = {0x1C,0x04}; // End Physical Page
  50. const BYTE CmdBeginLogPage[] = {0x1C,0x05}; // Begin Logical page
  51. const BYTE CmdEndLogPage[] = {0x1C,0x06}; // End Logical Page
  52. const BYTE CmdEjectPhysPaper[] = {0x1C,0x0F}; // Print&Eject Phys Paper
  53. //BYTE CmdMoveHoriPos[] = {0x1C,0x21,0x00,0x00}; // Horizontal Relative
  54. //BYTE CmdMoveVertPos[] = {0x1C,0x22,0x00,0x00}; // Vertical Relative
  55. const BYTE CmdGivenHoriPos[] = {0x1C,0x23,0x00,0x00}; // Horizontal Absolute
  56. const BYTE CmdGivenVertPos[] = {0x1C,0x24,0x00,0x00}; // Vertical Absolute
  57. const BYTE CmdSetGivenPos[] = {0x1C,0x40,0x00,0x00,0x00,0x00};
  58. //BYTE CmdPrnStrCurrent[] = {0x1C,0xC3,0x00,0x00,0x03}; // Print String
  59. const BYTE CmdBoldItalicOn[] = {
  60. 0x1C,0xA5,0x08,0x04,0x06,0x02,0x30,0x00,0x00,0x00,0x00};
  61. const BYTE CmdBoldOn[] = {
  62. 0x1C,0xA5,0x04,0x04,0x02,0x02,0x20};
  63. const BYTE CmdItalicOn[] = {
  64. 0x1c,0xa5,0x08,0x04,0x06,0x02,0x10,0x00,0x00,0x00,0x00};
  65. const BYTE CmdBoldItalicOff[] = {
  66. 0x1c,0xa5,0x04,0x04,0x02,0x02,0x00};
  67. //#287122
  68. const BYTE CmdDelTTFont[] = {0x1C,0x20,0xFF,0xFF};
  69. const BYTE CmdDelDLCharID[] = { 0x1c, 0x20, 0xff, 0xff };
  70. // for vertical font x adjustment
  71. const BYTE CmdSelectSingleByteMincho[] = {0x1C,0xA5,0x03,0x02,0x01,0x01};
  72. //980212 #284407
  73. //const BYTE CmdSelectDoubleByteMincho[] = {0x1C,0xA5,0x03,0x02,0x00,0x00};
  74. const BYTE CmdSelectDoubleByteMincho[] = {0x1C,0xA5,0x03,0x02,0x01,0x00};
  75. const BYTE CmdSelectSingleByteGothic[] = {0x1C,0xA5,0x03,0x02,0x03,0x03};
  76. //980212 #284407
  77. //const BYTE CmdSelectDoubleByteGothic[] = {0x1C,0xA5,0x03,0x02,0x02,0x02};
  78. const BYTE CmdSelectDoubleByteGothic[] = {0x1C,0xA5,0x03,0x02,0x03,0x02};
  79. #define CmdSetPhysPaper pOEM->ajCmdSetPhysPaper
  80. #define CmdSetPhysPage pOEM->ajCmdSetPhysPage
  81. #define CmdDefDrawArea pOEM->ajCmdDefDrawArea
  82. #define CMD_SET_PHYS_PAPER_PAPER_SIZE 5
  83. #define CMD_SET_PHYS_PAPER_PAPER_TRAY 6
  84. #define CMD_SET_PHYS_PAPER_AUTO_TRAY_MODE 7
  85. #define CMD_SET_PHYS_PAPER_DUPLEX 8
  86. #define CMD_SET_PHYS_PAPER_COPY_COUNT 9
  87. #define CMD_SET_PHYS_PAPER_UNIT_BASE 12
  88. #define CMD_SET_PHYS_PAPER_LOGICAL_UNIT 13 // 2 bytes
  89. #define CMD_SET_PHYS_PAPER_WIDTH 15 // 2 bytes
  90. #define CMD_SET_PHYS_PAPER_HEIGHT 17 // 2 bytes
  91. const BYTE XXXCmdSetPhysPaper[] = {0x1C,0xA0, // Set Physical Paper
  92. 0x10, // length
  93. 0x01, // SubCmd Basic Characteristics
  94. 0x05, // SubCmdLength
  95. 0x01, // Paper Size
  96. 0x01, // PaperTray
  97. 0x00, // AutoTrayMode
  98. 00, // Duplex Mode
  99. 0x01, // Copy Count
  100. 0x02, // SubCmd Set Unfixed Paper Size
  101. 0x07, // SubCmdLength
  102. 00, // UnitBase
  103. 00,00, // Logical Unit
  104. 00,00, // Width
  105. 00,00}; // Height
  106. #define CMD_SET_PHYS_PAGE_RES 6 // 2 bytes
  107. #define CMD_SET_PHYS_PAGE_TONER_SAVE 10
  108. const BYTE XXXCmdSetPhysPage[] = {0x1C,0xA1, // Set Physical Page
  109. 0x0D, // Length
  110. 0x01, // SubCmd Resolution
  111. 0x03, // SubCmdLength
  112. 00, // Unit Base of 10
  113. 0x0B,0xB8, // and Logical Unit Res of 3000
  114. 0x02, // SubCmd Toner Save
  115. 0x01, // SubCmdLength
  116. 00, // Toner Save OFF
  117. 0x03, // SubCmd N-Up
  118. 0x03, // SubCmdLength
  119. 00,00,00}; // N-Up off
  120. #define CMD_DEF_DRAW_AREA_ORIGIN_X 5 // 2 bytes
  121. #define CMD_DEF_DRAW_AREA_ORIGIN_Y 7 // 2 bytes
  122. #define CMD_DEF_DRAW_AREA_WIDTH 9 // 2 bytes
  123. #define CMD_DEF_DRAW_AREA_HEIGHT 11 // 2 bytes
  124. #define CMD_DEF_DRAW_AREA_ORIENT 15 // 2 bytes
  125. const BYTE XXXCmdDefDrawArea[] = {0x1C,0xA2, // Define Drawing Area
  126. 0x0D, // length
  127. 0x01, // SubCmd origin width,height
  128. 0x08, // SubCmdLength
  129. 0x00,0x77, // origin X
  130. 0x00,0x77, // origin Y
  131. 00,00, // width
  132. 00,00, // height
  133. 0x02, // SubCmd Media Origin
  134. 0x01, // SubCmdLength
  135. 00}; // Portrait
  136. /*****************************************************************************/
  137. /* */
  138. /* Module: APDLRES.DLL */
  139. /* */
  140. /* Function: OEMEnablePDEV */
  141. /* */
  142. /* Syntax: PDEVOEM APIENTRY OEMEnablePDEV( */
  143. /* PDEVOBJ pdevobj, */
  144. /* PWSTR pPrinterName, */
  145. /* ULONG cPatterns, */
  146. /* HSURF *phsurfPatterns, */
  147. /* ULONG cjGdiInfo, */
  148. /* GDIINFO *pGdiInfo, */
  149. /* ULONG cjDevInfo, */
  150. /* DEVINFO *pDevInfo, */
  151. /* DRVENABLEDATA *pded) */
  152. /* */
  153. /* Description: Allocate buffer of private data to pdevobj */
  154. /* */
  155. /*****************************************************************************/
  156. PDEVOEM APIENTRY
  157. OEMEnablePDEV(
  158. PDEVOBJ pdevobj,
  159. PWSTR pPrinterName,
  160. ULONG cPatterns,
  161. HSURF *phsurfPatterns,
  162. ULONG cjGdiInfo,
  163. GDIINFO *pGdiInfo,
  164. ULONG cjDevInfo,
  165. DEVINFO *pDevInfo,
  166. DRVENABLEDATA *pded)
  167. {
  168. PAPDLPDEV pOEM;
  169. if (NULL == pdevobj)
  170. {
  171. // Invalid parameter.
  172. return NULL;
  173. }
  174. if(!pdevobj->pdevOEM)
  175. {
  176. if(!(pdevobj->pdevOEM = MemAllocZ(sizeof(APDLPDEV))))
  177. {
  178. ERR(("Faild to allocate memory. (%d)\n",
  179. GetLastError()));
  180. return NULL;
  181. }
  182. }
  183. pOEM = (PAPDLPDEV)pdevobj->pdevOEM;
  184. if (sizeof(CmdSetPhysPaper) < sizeof(XXXCmdSetPhysPaper)
  185. || sizeof(CmdSetPhysPage) < sizeof(XXXCmdSetPhysPage)
  186. || sizeof(CmdDefDrawArea) < sizeof(XXXCmdDefDrawArea))
  187. {
  188. ERR(("Dest buffer too small.\n"));
  189. return NULL;
  190. }
  191. CopyMemory(CmdSetPhysPaper, XXXCmdSetPhysPaper,
  192. sizeof(XXXCmdSetPhysPaper));
  193. CopyMemory(CmdSetPhysPage, XXXCmdSetPhysPage,
  194. sizeof(XXXCmdSetPhysPage));
  195. CopyMemory(CmdDefDrawArea, XXXCmdDefDrawArea,
  196. sizeof(XXXCmdDefDrawArea));
  197. return pdevobj->pdevOEM;
  198. }
  199. /*****************************************************************************/
  200. /* */
  201. /* Module: APDLRES.DLL */
  202. /* */
  203. /* Function: OEMDisablePDEV */
  204. /* */
  205. /* Syntax: VOID APIENTRY OEMDisablePDEV( */
  206. /* PDEVOBJ pdevobj) */
  207. /* */
  208. /* Description: Free buffer of private data */
  209. /* */
  210. /*****************************************************************************/
  211. VOID APIENTRY
  212. OEMDisablePDEV(
  213. PDEVOBJ pdevobj)
  214. {
  215. PAPDLPDEV pOEM;
  216. if (NULL == pdevobj)
  217. {
  218. // Invalid parameter.
  219. return;
  220. }
  221. pOEM = (PAPDLPDEV)pdevobj->pdevOEM;
  222. if (pOEM)
  223. {
  224. if (NULL != pOEM->pjTempBuf) {
  225. MemFree(pOEM->pjTempBuf);
  226. pOEM->pjTempBuf = NULL;
  227. pOEM->dwTempBufLen = 0;
  228. }
  229. MemFree(pdevobj->pdevOEM);
  230. pdevobj->pdevOEM = NULL;
  231. }
  232. return;
  233. }
  234. BOOL APIENTRY OEMResetPDEV(
  235. PDEVOBJ pdevobjOld,
  236. PDEVOBJ pdevobjNew)
  237. {
  238. PAPDLPDEV pOEMOld, pOEMNew;
  239. PBYTE pTemp;
  240. DWORD dwTemp;
  241. if (NULL == pdevobjOld || NULL == pdevobjNew)
  242. {
  243. // Invalid parameter.
  244. return FALSE;
  245. }
  246. pOEMOld = (PAPDLPDEV)pdevobjOld->pdevOEM;
  247. pOEMNew = (PAPDLPDEV)pdevobjNew->pdevOEM;
  248. if (pOEMOld != NULL && pOEMNew != NULL) {
  249. // Save pointer and length
  250. pTemp = pOEMNew->pjTempBuf;
  251. dwTemp = pOEMNew->dwTempBufLen;
  252. *pOEMNew = *pOEMOld;
  253. // Restore..
  254. pOEMNew->pjTempBuf = pTemp;
  255. pOEMNew->dwTempBufLen = dwTemp;
  256. }
  257. return TRUE;
  258. }
  259. /*****************************************************************************/
  260. /* */
  261. /* Module: OEMFilterGraphics */
  262. /* */
  263. /* Function: */
  264. /* */
  265. /* Syntax: BOOL APIENTRY OEMFilterGraphics(PDEVOBJ, PBYTE, DWORD) */
  266. /* */
  267. /* Input: pdevobj address of PDEVICE structure */
  268. /* pBuf points to buffer of graphics data */
  269. /* dwLen length of buffer in bytes */
  270. /* */
  271. /* Output: BOOL */
  272. /* */
  273. /* Notice: nFunction and Escape numbers are the same */
  274. /* */
  275. /*****************************************************************************/
  276. BOOL
  277. APIENTRY
  278. OEMFilterGraphics(
  279. PDEVOBJ pdevobj,
  280. PBYTE pBuf,
  281. DWORD dwLen)
  282. {
  283. PAPDLPDEV pOEM;
  284. ULONG ulHorzPixel;
  285. BOOL bComp = TRUE;
  286. BYTE jTemp[15];
  287. DWORD dwOutLen;
  288. DWORD dwTemp;
  289. INT iTemp;
  290. DWORD dwPaddingCount; /* #441427 */
  291. WORD wTmpHeight ;
  292. DWORD dwNewBufLen = 0 ;
  293. if (NULL == pdevobj || NULL == pBuf || 0 == dwLen)
  294. {
  295. // Invalid parameter.
  296. return FALSE;
  297. }
  298. pOEM = (PAPDLPDEV)pdevobj->pdevOEM;
  299. //We have to make image hight multiple of 8
  300. if ( pOEM->wImgHeight % 8 != 0){
  301. VERBOSE(("Pad zeros to make multiple of 8\n"));
  302. wTmpHeight = ((pOEM->wImgHeight + 7) / 8) * 8;
  303. dwNewBufLen = (DWORD)(wTmpHeight * pOEM->wImgWidth) / 8;
  304. }
  305. else{
  306. wTmpHeight = pOEM->wImgHeight;
  307. dwNewBufLen = dwLen;
  308. }
  309. if (NULL == pOEM->pjTempBuf ||
  310. dwNewBufLen > pOEM->dwTempBufLen) {
  311. if (NULL != pOEM->pjTempBuf) {
  312. MemFree(pOEM->pjTempBuf);
  313. }
  314. pOEM->pjTempBuf = (PBYTE)MemAlloc(dwNewBufLen);
  315. if (NULL == pOEM->pjTempBuf) {
  316. ERR(("Faild to allocate memory. (%d)\n",
  317. GetLastError()));
  318. pOEM->dwTempBufLen = 0;
  319. // Still try to ouptut with no compression.
  320. bComp = FALSE;
  321. }
  322. pOEM->dwTempBufLen = dwNewBufLen;
  323. }
  324. dwOutLen = dwNewBufLen;
  325. if (bComp) {
  326. // try compression
  327. dwOutLen = BRL_ECmd(
  328. (PBYTE)pBuf,
  329. (PBYTE)pOEM->pjTempBuf,
  330. dwLen,
  331. dwNewBufLen);
  332. // Does not fit into the destination buffer.
  333. if (dwOutLen >= dwNewBufLen) {
  334. // No compression.
  335. bComp = FALSE;
  336. dwOutLen = dwNewBufLen;
  337. }
  338. }
  339. /* #441427: if bComp==FALSE, pjTempBuf == NULL */
  340. // if (!bComp) {
  341. // // Construct padding zeros.
  342. // ZeroMemory(pOEM->pjTempBuf, (dwOutLen - dwLen));
  343. // }
  344. iTemp = 0;
  345. jTemp[iTemp++] = 0x1c;
  346. jTemp[iTemp++] = 0xe1;
  347. // Set the LEN of the DrawBlockImage command
  348. dwTemp = dwOutLen + (bComp ? 9 : 5);
  349. jTemp[iTemp++] = (BYTE)((dwTemp >> 24) & 0xff);
  350. jTemp[iTemp++] = (BYTE)((dwTemp >> 16) & 0xff);
  351. jTemp[iTemp++] = (BYTE)((dwTemp >> 8) & 0xff);
  352. jTemp[iTemp++] = (BYTE)((dwTemp >> 0) & 0xff);
  353. jTemp[iTemp++] = (bComp ? 1 : 0);
  354. // Set the WIDTH parameter of the DrawBlockImage command
  355. jTemp[iTemp++] = HIBYTE(pOEM->wImgWidth);
  356. jTemp[iTemp++] = LOBYTE(pOEM->wImgWidth);
  357. // Set height parameters (9,10 byte)
  358. jTemp[iTemp++] = HIBYTE(wTmpHeight);
  359. jTemp[iTemp++] = LOBYTE(wTmpHeight);
  360. if (bComp) {
  361. // length of uncompressed data
  362. jTemp[iTemp++] = (BYTE)((dwNewBufLen >> 24) & 0xff);
  363. jTemp[iTemp++] = (BYTE)((dwNewBufLen >> 16) & 0xff);
  364. jTemp[iTemp++] = (BYTE)((dwNewBufLen >> 8) & 0xff);
  365. jTemp[iTemp++] = (BYTE)((dwNewBufLen >> 0) & 0xff);
  366. }
  367. // Draw Block Image at Current Position
  368. WRITESPOOLBUF(pdevobj, jTemp, iTemp);
  369. if (bComp) {
  370. // Output compressed data, which also contains
  371. // padding zeros.
  372. WRITESPOOLBUF(pdevobj, pOEM->pjTempBuf, dwOutLen);
  373. }
  374. else {
  375. // Output uncompressed data, with padding zeros.
  376. WRITESPOOLBUF(pdevobj, pBuf, dwLen);
  377. /* #441427: if bComp==FALSE, pjTempBuf == NULL */
  378. if ( (dwOutLen - dwLen) > 0 )
  379. {
  380. for ( dwPaddingCount = 0 ; dwPaddingCount < dwOutLen - dwLen ; dwPaddingCount++ )
  381. {
  382. WRITESPOOLBUF(pdevobj, "\x00", 1 );
  383. }
  384. }
  385. //WRITESPOOLBUF(pdevobj, pOEM->pjTempBuf,
  386. // (dwOutLen - dwLen));
  387. }
  388. return TRUE;
  389. }
  390. /*****************************************************************************/
  391. /* */
  392. /* Module: bCommandCallback */
  393. /* */
  394. /* Function: */
  395. /* */
  396. /* Syntax: BOOL bCommandCallback(PDEVOBJ,DWORD,DWORD,PDWORD) */
  397. /* */
  398. /* Input: pdevobj */
  399. /* dwCmdCbID */
  400. /* dwCount */
  401. /* pdwParams */
  402. /* */
  403. /* Output: INT */
  404. /* */
  405. /* Notice: */
  406. /* */
  407. /*****************************************************************************/
  408. INT APIENTRY
  409. bCommandCallback(
  410. PDEVOBJ pdevobj, // Points to private data required by the Unidriver.dll
  411. DWORD dwCmdCbID, // Callback ID
  412. DWORD dwCount, // Counts of command parameter
  413. PDWORD pdwParams, // points to values of command params
  414. INT *piResult ) // result code
  415. {
  416. PAPDLPDEV pOEM;
  417. WORD wTemp;
  418. WORD wPhysWidth;
  419. WORD wPhysHeight;
  420. WORD wXval;
  421. WORD wYval;
  422. // #278517: RectFill
  423. BYTE CmdDrawLine[] =
  424. { 0x1C,0x81,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
  425. // Load default return code.
  426. if (NULL == pdevobj || NULL == piResult)
  427. {
  428. ERR(("Invalid parameter(s).\n"));
  429. return FALSE;
  430. }
  431. pOEM = (PAPDLPDEV)pdevobj->pdevOEM;
  432. *piResult = 0;
  433. switch(dwCmdCbID)
  434. {
  435. case PAGECONTROL_BEGIN_JOB:
  436. //Move these command from PAGECONTROL_BEGIN_DOC
  437. /* Send Change Data Stream Command for Enter A/PDL mode */
  438. WRITESPOOLBUF(pdevobj, CmdInAPDLMode, sizeof(CmdInAPDLMode));
  439. /* Send A/PLDL start Command */
  440. WRITESPOOLBUF(pdevobj, CmdAPDLStart, sizeof(CmdAPDLStart));
  441. /* Delete downloaded font */
  442. //#287122
  443. //To clean up downloaded font in the printer.
  444. //#304858
  445. //This command makes printer do FF, cause error of duplex.
  446. //and #287122 does not replo with this chenge.
  447. WRITESPOOLBUF(pdevobj, CmdDelTTFont, sizeof(CmdDelTTFont));
  448. break ;
  449. /*------------------------------------------------------*/
  450. /* A/PDL start now */
  451. /*------------------------------------------------------*/
  452. case PAGECONTROL_BEGIN_DOC:
  453. /* reset flag of sent Set Physical Paper command */
  454. pOEM->fSendSetPhysPaper = FALSE;
  455. /* initialize flag */
  456. pOEM->fDuplex = FALSE;
  457. CmdSetPhysPage[CMD_SET_PHYS_PAGE_TONER_SAVE] = 0x00;
  458. break;
  459. /*------------------------------------------------------*/
  460. /* send Page Description command */
  461. /*------------------------------------------------------*/
  462. case PAGECONTROL_BEGIN_PAGE:
  463. pOEM->fGeneral |= (BIT_FONTSIM_RESET
  464. | BIT_XMOVE_ABS
  465. | BIT_YMOVE_ABS);
  466. pOEM->wXPosition = 0;
  467. pOEM->wYPosition = 0;
  468. pOEM->bCurByteMode = BYTE_BYTEMODE_RESET;
  469. /* reset duplex mode if fDuplex is FALSE */
  470. if(!pOEM->fDuplex)
  471. CmdSetPhysPaper[CMD_SET_PHYS_PAPER_DUPLEX] = 0x00; // Duplex OFF
  472. /* send Set Physical Paper command */
  473. WRITESPOOLBUF(pdevobj,
  474. CmdSetPhysPaper, sizeof(CmdSetPhysPaper));
  475. if(pOEM->ulHorzRes == 600) // set unit base
  476. {
  477. CmdSetPhysPage[CMD_SET_PHYS_PAGE_RES] = 0x17;
  478. CmdSetPhysPage[CMD_SET_PHYS_PAGE_RES + 1] = 0x70;
  479. } else {
  480. CmdSetPhysPage[CMD_SET_PHYS_PAGE_RES] = 0x0B;
  481. CmdSetPhysPage[CMD_SET_PHYS_PAGE_RES + 1] = 0xB8;
  482. }
  483. // send Set Physical Page command
  484. WRITESPOOLBUF(pdevobj, CmdSetPhysPage, sizeof(CmdSetPhysPage));
  485. // send Begin Physical Page command
  486. WRITESPOOLBUF(pdevobj,
  487. CmdBeginPhysPage, sizeof(CmdBeginPhysPage));
  488. // send Begin Logical Page command
  489. WRITESPOOLBUF(pdevobj, CmdBeginLogPage, sizeof(CmdBeginLogPage));
  490. // send Define Drawing Area command
  491. WRITESPOOLBUF(pdevobj, CmdDefDrawArea, sizeof(CmdDefDrawArea));
  492. break;
  493. case PAGECONTROL_END_PAGE:
  494. if(pOEM->wCachedBytes)
  495. VOutputText(pdevobj);
  496. // send End Logical Page command
  497. WRITESPOOLBUF(pdevobj, CmdEndLogPage, sizeof(CmdEndLogPage));
  498. // send End Physical Page command
  499. WRITESPOOLBUF(pdevobj, CmdEndPhysPage, sizeof(CmdEndPhysPage));
  500. break;
  501. case PAGECONTROL_ABORT_DOC:
  502. case PAGECONTROL_END_DOC:
  503. if(pOEM->wCachedBytes)
  504. VOutputText(pdevobj);
  505. // Send delete DL char ID command
  506. if(pOEM->wNumDLChar)
  507. {
  508. WRITESPOOLBUF(pdevobj, CmdDelDLCharID, sizeof(CmdDelDLCharID));
  509. pOEM->wNumDLChar = 0;
  510. }
  511. /* Delete downloaded font
  512. WRITESPOOLBUF(pdevobj, CmdDelTTFont, sizeof(CmdDelTTFont));
  513. // send A/PDL End command
  514. WRITESPOOLBUF(pdevobj, CmdAPDLEnd, sizeof(CmdAPDLEnd));
  515. // Send A/PDL Mode out command
  516. WRITESPOOLBUF(pdevobj, CmdOutAPDLMode, sizeof(CmdOutAPDLMode));
  517. break;
  518. /*------------------------------------------------------*/
  519. /* save print direction */
  520. /*------------------------------------------------------*/
  521. case PAGECONTROL_POTRAIT: // 36
  522. pOEM->fOrientation = TRUE;
  523. break;
  524. case PAGECONTROL_LANDSCAPE: // 37
  525. pOEM->fOrientation = FALSE;
  526. break;
  527. /*------------------------------------------------------*/
  528. /* save resolution */
  529. /*------------------------------------------------------*/
  530. case RESOLUTION_300:
  531. pOEM->ulHorzRes = 300;
  532. pOEM->ulVertRes = 300;
  533. break;
  534. case RESOLUTION_600:
  535. pOEM->ulHorzRes = 600;
  536. pOEM->ulVertRes = 600;
  537. break;
  538. case SEND_BLOCK_DATA:
  539. // for graphics printing, send cursor move command at here
  540. bSendCursorMoveCommand( pdevobj, FALSE );
  541. pOEM->wImgWidth = (WORD)(PARAM(pdwParams, 1) * 8);
  542. pOEM->wImgHeight = (WORD)PARAM(pdwParams, 2);
  543. break;
  544. /*------------------------------------------------------*/
  545. /* set Drawing Area into SetPhysPaperDesc command */
  546. /*------------------------------------------------------*/
  547. case PHYS_PAPER_A3: // 50
  548. case PHYS_PAPER_A4: // 51
  549. case PHYS_PAPER_B4: // 54
  550. case PHYS_PAPER_LETTER: // 57
  551. case PHYS_PAPER_LEGAL: // 58
  552. pOEM->szlPhysSize.cx = PARAM(pdwParams, 0);
  553. pOEM->szlPhysSize.cy = PARAM(pdwParams, 1);
  554. CmdSetPhysPaper[CMD_SET_PHYS_PAPER_PAPER_SIZE] = SetDrawArea(pdevobj, dwCmdCbID);
  555. break;
  556. case PHYS_PAPER_B5: // 55
  557. case PHYS_PAPER_A5: // 52
  558. pOEM->szlPhysSize.cx = PARAM(pdwParams, 0);
  559. pOEM->szlPhysSize.cy = PARAM(pdwParams, 1);
  560. CmdSetPhysPaper[CMD_SET_PHYS_PAPER_PAPER_SIZE] = SetDrawArea(pdevobj, dwCmdCbID);
  561. /* even if Duplex is selected, it cancel */
  562. pOEM->fDuplex = FALSE;
  563. CmdSetPhysPaper[CMD_SET_PHYS_PAPER_DUPLEX] = 0x00; // Duplex is off
  564. break;
  565. case PHYS_PAPER_POSTCARD: // 59
  566. pOEM->szlPhysSize.cx = PARAM(pdwParams, 0);
  567. pOEM->szlPhysSize.cy = PARAM(pdwParams, 1);
  568. CmdSetPhysPaper[CMD_SET_PHYS_PAPER_PAPER_SIZE] = SetDrawArea(pdevobj, dwCmdCbID);
  569. /* if paper is Postcard, papersource is always Front Tray */
  570. CmdSetPhysPaper[CMD_SET_PHYS_PAPER_PAPER_TRAY] = 0x00; // select Front Tray
  571. CmdSetPhysPaper[CMD_SET_PHYS_PAPER_AUTO_TRAY_MODE] = 0x00; // Auto Tray Select is OFF
  572. /* even if Duplex is selected, it cancel */
  573. pOEM->fDuplex = FALSE;
  574. CmdSetPhysPaper[CMD_SET_PHYS_PAPER_DUPLEX] = 0x00; // Duplex is off
  575. break;
  576. case PHYS_PAPER_UNFIXED: // 60
  577. pOEM->szlPhysSize.cx = PARAM(pdwParams, 0);
  578. pOEM->szlPhysSize.cy = PARAM(pdwParams, 1);
  579. /* if paper is Unfixed, papersource is always Front Tray */
  580. CmdSetPhysPaper[CMD_SET_PHYS_PAPER_PAPER_TRAY] = 0x00; // Select Front Tray
  581. CmdSetPhysPaper[CMD_SET_PHYS_PAPER_AUTO_TRAY_MODE] = 0x00; // Auto Tray Select is OFF
  582. /* even if Duplex is selected, it cancel */
  583. pOEM->fDuplex = FALSE;
  584. CmdSetPhysPaper[CMD_SET_PHYS_PAPER_DUPLEX] = 0x00; // Duplex is off
  585. CmdSetPhysPaper[CMD_SET_PHYS_PAPER_PAPER_SIZE] = SetDrawArea(pdevobj, dwCmdCbID);
  586. CmdSetPhysPaper[CMD_SET_PHYS_PAPER_UNIT_BASE] = 0x00; // UnitBase : 10 inch
  587. switch(pOEM->ulHorzRes) // set logical unit
  588. {
  589. case 600:
  590. CmdSetPhysPaper[CMD_SET_PHYS_PAPER_LOGICAL_UNIT] = 0x17;
  591. CmdSetPhysPaper[CMD_SET_PHYS_PAPER_LOGICAL_UNIT + 1] = 0x70;
  592. break;
  593. case 300:
  594. default:
  595. CmdSetPhysPaper[CMD_SET_PHYS_PAPER_LOGICAL_UNIT] = 0x0B;
  596. CmdSetPhysPaper[CMD_SET_PHYS_PAPER_LOGICAL_UNIT + 1] = 0xB8;
  597. // Make sure it is meaningful value
  598. if (300 != pOEM->ulHorzRes)
  599. pOEM->ulHorzRes = HORZ_RES_DEFAULT;
  600. }
  601. wPhysWidth = (WORD)pOEM->szlPhysSize.cx / (MASTER_UNIT / (WORD)pOEM->ulHorzRes);
  602. wPhysHeight = (WORD)pOEM->szlPhysSize.cy / (MASTER_UNIT / (WORD)pOEM->ulHorzRes);
  603. CmdSetPhysPaper[CMD_SET_PHYS_PAPER_WIDTH] = HIBYTE(wPhysWidth);
  604. CmdSetPhysPaper[CMD_SET_PHYS_PAPER_WIDTH + 1] = LOBYTE(wPhysWidth);
  605. CmdSetPhysPaper[CMD_SET_PHYS_PAPER_HEIGHT] = HIBYTE(wPhysHeight);
  606. CmdSetPhysPaper[CMD_SET_PHYS_PAPER_HEIGHT + 1] = LOBYTE(wPhysHeight);
  607. break;
  608. /*------------------------------------------------------*/
  609. /* set Paper Tray into SetPhysPaperDesc command */
  610. /*------------------------------------------------------*/
  611. case PAPER_SRC_FTRAY:
  612. CmdSetPhysPaper[CMD_SET_PHYS_PAPER_PAPER_TRAY] = 0x00; // Select Front Tray
  613. CmdSetPhysPaper[CMD_SET_PHYS_PAPER_AUTO_TRAY_MODE] = 0x00; // Auto Tray Select is OFF
  614. break;
  615. case PAPER_SRC_CAS1:
  616. CmdSetPhysPaper[CMD_SET_PHYS_PAPER_PAPER_TRAY] = 0x01; // Select Cassette 1
  617. CmdSetPhysPaper[CMD_SET_PHYS_PAPER_AUTO_TRAY_MODE] = 0x00; // Auto Tray Select is OFF
  618. break;
  619. case PAPER_SRC_CAS2:
  620. CmdSetPhysPaper[CMD_SET_PHYS_PAPER_PAPER_TRAY] = 0x02; // Select Cassette 2
  621. CmdSetPhysPaper[CMD_SET_PHYS_PAPER_AUTO_TRAY_MODE] = 0x00; // Auto Tray Select is OFF
  622. break;
  623. case PAPER_SRC_CAS3:
  624. CmdSetPhysPaper[CMD_SET_PHYS_PAPER_PAPER_TRAY] = 0x03; // Select Cassette 3
  625. CmdSetPhysPaper[CMD_SET_PHYS_PAPER_AUTO_TRAY_MODE] = 0x00; // Auto Tray Select is OFF
  626. break;
  627. case PAPER_SRC_AUTO_SELECT: //Auto Tray Select ON
  628. if(pOEM->fScaleToFit == TRUE){ //Select PAPER_DEST_SCALETOFIT_ON
  629. CmdSetPhysPaper[CMD_SET_PHYS_PAPER_PAPER_TRAY] = 0x01;
  630. CmdSetPhysPaper[CMD_SET_PHYS_PAPER_AUTO_TRAY_MODE] = 0x03;
  631. }
  632. else if(pOEM->fScaleToFit == FALSE){
  633. CmdSetPhysPaper[CMD_SET_PHYS_PAPER_PAPER_TRAY] = 0x01;
  634. CmdSetPhysPaper[CMD_SET_PHYS_PAPER_AUTO_TRAY_MODE] = 0x01;
  635. }
  636. break;
  637. /*------------------------------------------------------*/
  638. /* set Auto Tray Mode into SetPhysPaperDesc command */
  639. /*------------------------------------------------------*/
  640. case PAPER_DEST_SCALETOFIT_ON: // 25
  641. pOEM->fScaleToFit = TRUE;
  642. CmdSetPhysPaper[CMD_SET_PHYS_PAPER_AUTO_TRAY_MODE] = 0x02;
  643. break;
  644. case PAPER_DEST_SCALETOFIT_OFF: // 26
  645. pOEM->fScaleToFit = FALSE;
  646. CmdSetPhysPaper[CMD_SET_PHYS_PAPER_AUTO_TRAY_MODE] = 0x00;
  647. break;
  648. /*------------------------------------------------------*/
  649. /* set Duplex Mode into SetPhysPaperDesc command */
  650. /*------------------------------------------------------*/
  651. case PAGECONTROL_DUPLEX_UPDOWN:
  652. pOEM->fDuplex = TRUE;
  653. CmdSetPhysPaper[CMD_SET_PHYS_PAPER_DUPLEX] = 0x01; // Up Side Down
  654. break;
  655. case PAGECONTROL_DUPLEX_RIGHTUP:
  656. pOEM->fDuplex = TRUE;
  657. CmdSetPhysPaper[CMD_SET_PHYS_PAPER_DUPLEX] = 0x02; // Right Side Up
  658. break;
  659. case PAGECONTROL_DUPLEX_OFF:
  660. pOEM->fDuplex = FALSE;
  661. break;
  662. /*------------------------------------------------------*/
  663. /* set Toner Save into SetPhysPage command */
  664. /*------------------------------------------------------*/
  665. case TONER_SAVE_OFF: // 100
  666. CmdSetPhysPage[CMD_SET_PHYS_PAGE_TONER_SAVE] = 0x00; // off
  667. break;
  668. case TONER_SAVE_DARK: // 101
  669. CmdSetPhysPage[CMD_SET_PHYS_PAGE_TONER_SAVE] = 0x02; // dark
  670. break;
  671. case TONER_SAVE_LIGHT: // 102
  672. CmdSetPhysPage[CMD_SET_PHYS_PAGE_TONER_SAVE] = 0x01; // right
  673. break;
  674. /*------------------------------------------------------*/
  675. /* set Copy Count to SetPhysPaperDesc command */
  676. /*------------------------------------------------------*/
  677. case PAGECONTROL_MULTI_COPIES:
  678. // @Aug/31/98 ->
  679. if(MAX_COPIES_VALUE < PARAM(pdwParams,0)) {
  680. CmdSetPhysPaper[CMD_SET_PHYS_PAPER_COPY_COUNT] = MAX_COPIES_VALUE;
  681. }
  682. else if (1 > PARAM(pdwParams,0)) {
  683. CmdSetPhysPaper[CMD_SET_PHYS_PAPER_COPY_COUNT] = 1;
  684. }
  685. else {
  686. CmdSetPhysPaper[CMD_SET_PHYS_PAPER_COPY_COUNT] = (BYTE)PARAM(pdwParams,0);
  687. }
  688. // @Aug/31/98 <-
  689. break;
  690. /*------------------------------------------------------*/
  691. /* send Set Character Attribute with ornament */
  692. /*------------------------------------------------------*/
  693. case BOLD_ON:
  694. if(!(pOEM->fGeneral & BIT_FONTSIM_BOLD))
  695. {
  696. if(pOEM->wCachedBytes)
  697. VOutputText(pdevobj);
  698. pOEM->fGeneral |= BIT_FONTSIM_BOLD;
  699. }
  700. break;
  701. case ITALIC_ON:
  702. if(!(pOEM->fGeneral & BIT_FONTSIM_ITALIC))
  703. {
  704. if(pOEM->wCachedBytes)
  705. VOutputText(pdevobj);
  706. pOEM->fGeneral |= BIT_FONTSIM_ITALIC;
  707. }
  708. break;
  709. case BOLD_OFF:
  710. if(pOEM->fGeneral & BIT_FONTSIM_BOLD)
  711. {
  712. if(pOEM->wCachedBytes)
  713. VOutputText(pdevobj);
  714. pOEM->fGeneral &= ~BIT_FONTSIM_BOLD;
  715. }
  716. break;
  717. case ITALIC_OFF:
  718. if(pOEM->fGeneral & BIT_FONTSIM_ITALIC)
  719. {
  720. if(pOEM->wCachedBytes)
  721. VOutputText(pdevobj);
  722. pOEM->fGeneral &= ~BIT_FONTSIM_ITALIC;
  723. }
  724. break;
  725. case SELECT_SINGLE_BYTE:
  726. if(ISVERTICALFONT(pOEM->bFontID))
  727. {
  728. if(pOEM->bCurByteMode == BYTE_DOUBLE_BYTE)
  729. {
  730. if(pOEM->wCachedBytes)
  731. VOutputText(pdevobj);
  732. if(pOEM->bFontID == MINCHO_VERT)
  733. WRITESPOOLBUF(pdevobj, CmdSelectSingleByteMincho,
  734. sizeof(CmdSelectSingleByteMincho));
  735. else if(pOEM->bFontID == GOTHIC_VERT)
  736. WRITESPOOLBUF(pdevobj, CmdSelectSingleByteGothic,
  737. sizeof(CmdSelectSingleByteGothic));
  738. }
  739. pOEM->bCurByteMode = BYTE_SINGLE_BYTE;
  740. }
  741. break;
  742. case SELECT_DOUBLE_BYTE:
  743. if(ISVERTICALFONT(pOEM->bFontID))
  744. {
  745. if(pOEM->bCurByteMode == BYTE_SINGLE_BYTE)
  746. {
  747. if(pOEM->wCachedBytes)
  748. VOutputText(pdevobj);
  749. if(pOEM->bFontID == MINCHO_VERT)
  750. WRITESPOOLBUF(pdevobj, CmdSelectDoubleByteMincho,
  751. sizeof(CmdSelectDoubleByteMincho));
  752. else if(pOEM->bFontID == GOTHIC_VERT)
  753. WRITESPOOLBUF(pdevobj, CmdSelectDoubleByteGothic,
  754. sizeof(CmdSelectDoubleByteGothic));
  755. }
  756. pOEM->bCurByteMode = BYTE_DOUBLE_BYTE;
  757. }
  758. break;
  759. /*------------------------------------------------------*/
  760. /* Send
  761. /*------------------------------------------------------*/
  762. case X_ABS_MOVE:
  763. if(pOEM->wCachedBytes)
  764. VOutputText(pdevobj);
  765. pOEM->wUpdateXPos = 0;
  766. if (0 == pOEM->ulHorzRes)
  767. pOEM->ulHorzRes = HORZ_RES_DEFAULT;
  768. wTemp = (WORD)PARAM(pdwParams,0) / (MASTER_UNIT / (WORD)pOEM->ulHorzRes);
  769. pOEM->wXPosition = wTemp;
  770. pOEM->fGeneral |= BIT_XMOVE_ABS;
  771. *piResult = (INT)wTemp;
  772. return TRUE;
  773. case Y_ABS_MOVE:
  774. if(pOEM->wCachedBytes)
  775. VOutputText(pdevobj);
  776. //#332101 prob.4: wUpdateXPos is cleared only when X_ABS_MOVE and CR.
  777. //pOEM->wUpdateXPos = 0;
  778. if (0 == pOEM->ulVertRes)
  779. pOEM->ulVertRes = VERT_RES_DEFAULT;
  780. wTemp = (WORD)PARAM(pdwParams,0) / (MASTER_UNIT / (WORD)pOEM->ulVertRes);
  781. pOEM->wYPosition = wTemp;
  782. pOEM->fGeneral |= BIT_YMOVE_ABS;
  783. *piResult = (INT)wTemp;
  784. return TRUE;
  785. case CR_EMULATION:
  786. pOEM->wXPosition = 0;
  787. pOEM->wUpdateXPos = 0;
  788. pOEM->fGeneral |= BIT_XMOVE_ABS;
  789. break;
  790. case SET_CUR_GLYPHID:
  791. if(!pdwParams || dwCount != 1)
  792. {
  793. ERR(("bCommandCallback: parameter is invalid.\n"));
  794. return FALSE;
  795. }
  796. if(PARAM(pdwParams,0) < MIN_GLYPH_ID || PARAM(pdwParams,0) > MAX_GLYPH_ID)
  797. {
  798. ERR(("bCommandCallback: glyph id is out of range.\n"));
  799. return FALSE;
  800. }
  801. pOEM->wGlyphID = (WORD)PARAM(pdwParams,0);
  802. break;
  803. // #278517: RectFill
  804. case RECT_SET_WIDTH:
  805. if (0 == pOEM->ulHorzRes)
  806. pOEM->ulHorzRes = HORZ_RES_DEFAULT;
  807. wTemp = (WORD)PARAM(pdwParams,0) / (MASTER_UNIT / (WORD)pOEM->ulHorzRes);
  808. pOEM->wRectWidth = wTemp;
  809. break;
  810. case RECT_SET_HEIGHT:
  811. if (0 == pOEM->ulVertRes)
  812. pOEM->ulVertRes = VERT_RES_DEFAULT;
  813. wTemp = (WORD)PARAM(pdwParams,0) / (MASTER_UNIT / (WORD)pOEM->ulVertRes);
  814. pOEM->wRectHeight = wTemp;
  815. break;
  816. case RECT_FILL_BLACK:
  817. wTemp = pOEM->wXPosition;
  818. CmdDrawLine[2] = HIBYTE(wTemp);
  819. CmdDrawLine[3] = LOBYTE(wTemp);
  820. wTemp = pOEM->wYPosition;
  821. CmdDrawLine[4] = HIBYTE(wTemp);
  822. CmdDrawLine[5] = LOBYTE(wTemp);
  823. wTemp = pOEM->wRectWidth;
  824. CmdDrawLine[6] = HIBYTE(wTemp);
  825. CmdDrawLine[7] = LOBYTE(wTemp);
  826. wTemp = pOEM->wRectHeight;
  827. CmdDrawLine[8] = HIBYTE(wTemp);
  828. CmdDrawLine[9] = LOBYTE(wTemp);
  829. WRITESPOOLBUF(pdevobj, CmdDrawLine, sizeof(CmdDrawLine));
  830. break;
  831. default:
  832. break;
  833. }
  834. return TRUE;
  835. }
  836. /*****************************************************************************/
  837. /* */
  838. /* Module: bOutputCharStr */
  839. /* */
  840. /* Function: */
  841. /* */
  842. /* Syntax: BOOL bOutputCharStr(PDEVOBJ, PUNIFONTOBJ, DWORD, */
  843. /* DWORD, PVOID) */
  844. /* */
  845. /* Input: pdevobj address of PDEVICE structure */
  846. /* pUFObj */
  847. /* dwType */
  848. /* dwCount */
  849. /* pGlyph */
  850. /* */
  851. /* Output: BOOL */
  852. /* */
  853. /* Notice: */
  854. /* */
  855. /*****************************************************************************/
  856. BOOL
  857. bOutputCharStr(
  858. PDEVOBJ pdevobj,
  859. PUNIFONTOBJ pUFObj,
  860. DWORD dwType,
  861. DWORD dwCount,
  862. PVOID pGlyph )
  863. {
  864. GETINFO_GLYPHSTRING GStr;
  865. PAPDLPDEV pOEM = (PAPDLPDEV)pdevobj->pdevOEM;
  866. PTRANSDATA pTrans;
  867. DWORD dwI;
  868. WORD wLen = (WORD)dwCount;
  869. PBYTE pbCommand;
  870. PDWORD pdwGlyphID;
  871. WORD wFontID;
  872. WORD wCmdLen;
  873. if(NULL == pdevobj || NULL == pUFObj)
  874. {
  875. ERR(("bOutputCharStr: Invalid parameter(s).\n"));
  876. return FALSE;
  877. }
  878. if (0 == dwCount || NULL == pGlyph)
  879. return TRUE;
  880. switch(dwType)
  881. {
  882. case TYPE_GLYPHHANDLE:
  883. // Send appropriate cursor move command
  884. bSendCursorMoveCommand( pdevobj, TRUE );
  885. // Set font simulation if needed
  886. VSetFontSimulation( pdevobj );
  887. // #333653: Change I/F for GETINFO_GLYPHSTRING begin
  888. // Translate character code
  889. GStr.dwSize = sizeof (GETINFO_GLYPHSTRING);
  890. GStr.dwCount = dwCount;
  891. GStr.dwTypeIn = TYPE_GLYPHHANDLE;
  892. GStr.pGlyphIn = pGlyph;
  893. GStr.dwTypeOut = TYPE_TRANSDATA;
  894. GStr.pGlyphOut = NULL;
  895. GStr.dwGlyphOutSize = 0; /* new member of GETINFO_GLYPHSTRING */
  896. /* Get TRANSDATA buffer size */
  897. if(pUFObj->pfnGetInfo(pUFObj, UFO_GETINFO_GLYPHSTRING, &GStr, 0, NULL)
  898. || !GStr.dwGlyphOutSize )
  899. {
  900. ERR(("Get Glyph String error\n"));
  901. return FALSE;
  902. }
  903. // Alloc translation buffer
  904. if (NULL == pOEM->pjTempBuf ||
  905. pOEM->dwTempBufLen < GStr.dwGlyphOutSize)
  906. {
  907. if (NULL != pOEM->pjTempBuf) {
  908. MemFree(pOEM->pjTempBuf);
  909. }
  910. pOEM->pjTempBuf = MemAllocZ(GStr.dwGlyphOutSize);
  911. if (NULL == pOEM->pjTempBuf)
  912. {
  913. ERR(("Faild to allocate memory. (%d)\n",
  914. GetLastError()));
  915. pOEM->dwTempBufLen = 0;
  916. return FALSE;
  917. }
  918. pOEM->dwTempBufLen = GStr.dwGlyphOutSize;
  919. }
  920. pTrans = (PTRANSDATA)pOEM->pjTempBuf;
  921. /* Get actual TRANSDATA */
  922. GStr.pGlyphOut = pTrans;
  923. if (!pUFObj->pfnGetInfo(pUFObj, UFO_GETINFO_GLYPHSTRING, &GStr, 0, NULL))
  924. {
  925. ERR(("GetInfo failed.\n"));
  926. return FALSE;
  927. }
  928. // #333653: Change I/F for GETINFO_GLYPHSTRING end
  929. // Spooled device font characters
  930. for(dwI = 0; dwI < dwCount; dwI++, pTrans++)
  931. {
  932. // ISSUE-2002/3/14-takashim - Condtion is not correct?
  933. // Not sure what below wCachedBytes + dwCount * 2 > sizeof(pOEM->bCharData)
  934. // means. Is it counting the worst case, where all the characters are
  935. // double-byte characters?
  936. // Why this is within the "for" loop (dwCount never changes in it)?
  937. // Make sure there is no overflow
  938. if(pOEM->wCachedBytes + dwCount * 2 > sizeof(pOEM->bCharData))
  939. VOutputText(pdevobj);
  940. switch(pTrans->ubType & MTYPE_FORMAT_MASK)
  941. {
  942. case MTYPE_DIRECT:
  943. pOEM->bCharData[pOEM->wCachedBytes++] =
  944. pTrans->uCode.ubCode;
  945. break;
  946. case MTYPE_PAIRED:
  947. pOEM->bCharData[pOEM->wCachedBytes++] =
  948. pTrans->uCode.ubPairs[0];
  949. pOEM->bCharData[pOEM->wCachedBytes++] =
  950. pTrans->uCode.ubPairs[1];
  951. break;
  952. }
  953. }
  954. break; //switch(dwType)
  955. case TYPE_GLYPHID:
  956. if(!pOEM->wNumDLChar || pOEM->wNumDLChar > MAX_DOWNLOAD_CHAR)
  957. {
  958. ERR(("Illegal number of DL glyphs. wNumDLChar = %d\n",
  959. pOEM->wNumDLChar));
  960. return FALSE;
  961. }
  962. // ISSUE-2002/3/14-takashim - Not sure what "16" here stands for.
  963. // The byte size of the CmdPrintDLChar[] below is 8 bytes,
  964. // so this can be dwCount * 8?
  965. if (NULL == pOEM->pjTempBuf ||
  966. pOEM->dwTempBufLen < dwCount * 16) {
  967. if (NULL != pOEM->pjTempBuf) {
  968. MemFree(pOEM->pjTempBuf);
  969. }
  970. pOEM->pjTempBuf = MemAllocZ((dwCount * 16));
  971. if(NULL == pOEM->pjTempBuf) {
  972. ERR(("Faild to allocate memory. (%d)\n",
  973. GetLastError()));
  974. pOEM->dwTempBufLen = 0;
  975. return FALSE;
  976. }
  977. pOEM->dwTempBufLen = dwCount * 16;
  978. }
  979. pbCommand = pOEM->pjTempBuf;
  980. wCmdLen = 0;
  981. wFontID = (WORD)(pUFObj->ulFontID - FONT_ID_DIFF);
  982. bSendCursorMoveCommand( pdevobj, FALSE );
  983. for (dwI = 0, pdwGlyphID = (PDWORD)pGlyph;
  984. dwI < dwCount; dwI++, pdwGlyphID++)
  985. {
  986. BYTE CmdPrintDLChar[] = "\x1C\xC1\x00\x04\x00\x00\x00\x00";
  987. WORD wGlyphID = *(PWORD)pdwGlyphID;
  988. WORD wDownloadedCharID;
  989. WORD wXInc;
  990. WORD wXAdjust;
  991. WORD wYAdjust;
  992. if(wGlyphID > MAX_GLYPH_ID || wGlyphID < MIN_GLYPH_ID)
  993. {
  994. ERR(("bOutputCharStr: GlyphID is invalid. GlyphID = %ld\n", wGlyphID));
  995. return FALSE;
  996. }
  997. // set parameters each a character
  998. wDownloadedCharID =
  999. pOEM->DLCharID[wFontID][wGlyphID].wCharID;
  1000. wXInc = pOEM->DLCharID[wFontID][wGlyphID].wXIncrement;
  1001. wYAdjust= pOEM->DLCharID[wFontID][wGlyphID].wYAdjust;
  1002. wXAdjust = pOEM->DLCharID[wFontID][wGlyphID].wXAdjust;
  1003. // Position adjusting based on UPPERLEFT of font box
  1004. pbCommand[wCmdLen++] = CmdGivenVertPos[0];
  1005. pbCommand[wCmdLen++] = CmdGivenVertPos[1];
  1006. pbCommand[wCmdLen++] = HIBYTE(pOEM->wYPosition - wYAdjust);
  1007. pbCommand[wCmdLen++] = LOBYTE(pOEM->wYPosition - wYAdjust);
  1008. if(wXAdjust)
  1009. {
  1010. pbCommand[wCmdLen++] = CmdGivenHoriPos[0];
  1011. pbCommand[wCmdLen++] = CmdGivenHoriPos[1];
  1012. pbCommand[wCmdLen++] = HIBYTE(pOEM->wXPosition - wXAdjust);
  1013. pbCommand[wCmdLen++] = LOBYTE(pOEM->wXPosition - wXAdjust);
  1014. pOEM->wXPosition -= wXAdjust;
  1015. }
  1016. CmdPrintDLChar[4] = HIBYTE(wDownloadedCharID);
  1017. CmdPrintDLChar[5] = LOBYTE(wDownloadedCharID);
  1018. CmdPrintDLChar[6] = HIBYTE(wXInc);
  1019. CmdPrintDLChar[7] = LOBYTE(wXInc);
  1020. pOEM->wXPosition += wXInc;
  1021. if (pOEM->dwTempBufLen
  1022. < (DWORD)(wCmdLen + sizeof(CmdPrintDLChar)))
  1023. {
  1024. ERR(("Destination buffer too small.\n"));
  1025. return FALSE;
  1026. }
  1027. else
  1028. {
  1029. memcpy(pbCommand + wCmdLen,
  1030. CmdPrintDLChar, sizeof(CmdPrintDLChar));
  1031. wCmdLen += sizeof(CmdPrintDLChar);
  1032. }
  1033. }
  1034. WRITESPOOLBUF(pdevobj, pbCommand, wCmdLen);
  1035. break;
  1036. }
  1037. return TRUE;
  1038. }
  1039. /*****************************************************************************/
  1040. /* */
  1041. /* Module: OEMSendFontCmd */
  1042. /* */
  1043. /* Function: send A/PDL-style font selection command. */
  1044. /* */
  1045. /* Syntax: VOID APIENTRY OEMSendFontCmd( */
  1046. /* PDEVOBJ, PUNIFONTOBJ, PFINVOCATION) */
  1047. /* */
  1048. /* Input: pdevobj address of PDEVICE structure */
  1049. /* pUFObj address of UNIFONTOBJ structure */
  1050. /* pFInv address of FINVOCATION */
  1051. /* */
  1052. /* Output: VOID */
  1053. /* */
  1054. /* Notice: */
  1055. /* */
  1056. /*****************************************************************************/
  1057. VOID APIENTRY
  1058. OEMSendFontCmd(
  1059. PDEVOBJ pdevobj,
  1060. PUNIFONTOBJ pUFObj,
  1061. PFINVOCATION pFInv )
  1062. {
  1063. PAPDLPDEV pOEM;
  1064. BYTE rgcmd[CCHMAXCMDLEN];
  1065. PGETINFO_STDVAR pSV;
  1066. DWORD dwStdVariable[STDVAR_BUFSIZE(2) / sizeof(DWORD)];
  1067. DWORD i, ocmd = 0;
  1068. WORD wHeight, wWidth;
  1069. //#305000
  1070. WORD wDescend, wAscend ;
  1071. if (NULL == pdevobj || NULL == pUFObj || NULL == pFInv)
  1072. {
  1073. // Invalid parameter(s).
  1074. return;
  1075. }
  1076. pOEM = (PAPDLPDEV)pdevobj->pdevOEM;
  1077. if(pOEM->wCachedBytes)
  1078. VOutputText(pdevobj);
  1079. pSV = (PGETINFO_STDVAR)dwStdVariable;
  1080. pSV->dwSize = STDVAR_BUFSIZE(2);
  1081. pSV->dwNumOfVariable = 2;
  1082. pSV->StdVar[0].dwStdVarID = FNT_INFO_FONTHEIGHT;
  1083. pSV->StdVar[1].dwStdVarID = FNT_INFO_FONTMAXWIDTH;
  1084. if (!pUFObj->pfnGetInfo(pUFObj, UFO_GETINFO_STDVARIABLE, pSV,
  1085. pSV->dwSize, NULL))
  1086. {
  1087. ERR(("UFO_GETINFO_STDVARIABLE failed.\n"));
  1088. return;
  1089. }
  1090. wHeight = (WORD)pSV->StdVar[0].lStdVariable;
  1091. wWidth = (WORD)pSV->StdVar[1].lStdVariable;
  1092. if(pOEM->ulHorzRes == 300)
  1093. {
  1094. wHeight = (wHeight + 1) / 2;
  1095. wWidth = (wWidth + 1) / 2;
  1096. }
  1097. pOEM->bFontID = (BYTE)pUFObj->ulFontID;
  1098. if(pUFObj->ulFontID == 1 || pUFObj->ulFontID == 2)
  1099. {
  1100. // This font is vertical
  1101. pOEM->wFontHeight = wWidth;
  1102. pOEM->wWidths = wHeight;
  1103. } else {
  1104. // This font is horizontal.
  1105. pOEM->wFontHeight = wHeight;
  1106. pOEM->wWidths = wWidth;
  1107. }
  1108. //#305000: set to base line as a TT fonts.
  1109. wAscend = pUFObj->pIFIMetrics->fwdWinAscender ;
  1110. wDescend = pUFObj->pIFIMetrics->fwdWinDescender ;
  1111. wDescend = pOEM->wFontHeight * wDescend / (wAscend + wDescend) ;
  1112. pOEM->wFontHeight -= wDescend ;
  1113. for (i = 0; i < pFInv->dwCount && ocmd < CCHMAXCMDLEN; )
  1114. {
  1115. if (pFInv->pubCommand[i] == '#'
  1116. && i + 1 < pFInv->dwCount)
  1117. {
  1118. if (pFInv->pubCommand[i+1] == 'H')
  1119. {
  1120. rgcmd[ocmd++] = HIBYTE(wHeight);
  1121. rgcmd[ocmd++] = LOBYTE(wHeight);
  1122. i += 2;
  1123. continue;
  1124. }
  1125. else if (pFInv->pubCommand[i+1] == 'W')
  1126. {
  1127. rgcmd[ocmd++] = HIBYTE(wWidth);
  1128. rgcmd[ocmd++] = LOBYTE(wWidth);
  1129. i += 2;
  1130. continue;
  1131. }
  1132. }
  1133. // Default case.
  1134. rgcmd[ocmd++] = pFInv->pubCommand[i++];
  1135. }
  1136. WRITESPOOLBUF(pdevobj, rgcmd, ocmd);
  1137. return;
  1138. }
  1139. /*****************************************************************************/
  1140. /* */
  1141. /* Module: OEMTTDownloadMethod */
  1142. /* */
  1143. /* Function: Choose how to print TrueType font */
  1144. /* */
  1145. /* Syntax: DWORD APIENTRY OEMTTDownloadMethod( */
  1146. /* PDEVOBJ, PUNIFONTOBJ) */
  1147. /* */
  1148. /* Input: pdevobj address of PDEVICE structure */
  1149. /* pUFObj address of UNIFONTOBJ structure */
  1150. /* */
  1151. /* Output: DWORD */
  1152. /* */
  1153. /* Notice: */
  1154. /* */
  1155. /*****************************************************************************/
  1156. DWORD APIENTRY
  1157. OEMTTDownloadMethod(
  1158. PDEVOBJ pdevobj,
  1159. PUNIFONTOBJ pUFObj)
  1160. {
  1161. PAPDLPDEV pOEM;
  1162. DWORD dwReturn;
  1163. dwReturn = TTDOWNLOAD_GRAPHICS;
  1164. if (NULL == pdevobj || NULL == pUFObj)
  1165. return dwReturn;
  1166. pOEM = (PAPDLPDEV)pdevobj->pdevOEM;
  1167. if(pOEM->wNumDLChar <= MAX_DOWNLOAD_CHAR)
  1168. dwReturn = TTDOWNLOAD_BITMAP;
  1169. VERBOSE(("TTDownloadMethod: dwReturn=%ld\n", dwReturn));
  1170. return dwReturn;
  1171. }
  1172. /*****************************************************************************/
  1173. /* */
  1174. /* Module: OEMDownloadFontHeader */
  1175. /* */
  1176. /* Function: Download font header */
  1177. /* */
  1178. /* Syntax: DWORD APIENTRY OEMDownloadFontHeader( */
  1179. /* PDEVOBJ, PUNIFONTOBJ) */
  1180. /* */
  1181. /* Input: pdevobj address of PDEVICE structure */
  1182. /* pUFObj address of UNIFONTOBJ structure */
  1183. /* */
  1184. /* Output: DWORD */
  1185. /* */
  1186. /* Notice: */
  1187. /* */
  1188. /*****************************************************************************/
  1189. DWORD APIENTRY
  1190. OEMDownloadFontHeader(
  1191. PDEVOBJ pdevobj,
  1192. PUNIFONTOBJ pUFObj)
  1193. {
  1194. // dummy support
  1195. return (DWORD)100;
  1196. }
  1197. /*****************************************************************************/
  1198. /* */
  1199. /* Module: OEMDownloadCharGlyph */
  1200. /* */
  1201. /* Function: send char glyph */
  1202. /* */
  1203. /* Syntax: DWORD APIENTRY OEMDownloadFontHeader( */
  1204. /* PDEVOBJ, PUNIFONTOBJ, HGLYPH, PDWORD) */
  1205. /* */
  1206. /* Input: pdevobj address of PDEVICE structure */
  1207. /* pUFObj address of UNIFONTOBJ structure */
  1208. /* hGlyph handle of glyph */
  1209. /* pdwWidth address of glyph width */
  1210. /* */
  1211. /* Output: DWORD */
  1212. /* */
  1213. /* Notice: */
  1214. /* */
  1215. /*****************************************************************************/
  1216. DWORD APIENTRY
  1217. OEMDownloadCharGlyph(
  1218. PDEVOBJ pdevobj,
  1219. PUNIFONTOBJ pUFObj,
  1220. HGLYPH hGlyph,
  1221. PDWORD pdwWidth)
  1222. {
  1223. PAPDLPDEV pOEM;
  1224. GETINFO_GLYPHBITMAP GD;
  1225. GLYPHBITS *pgb;
  1226. WORD wSrcGlyphWidth;
  1227. WORD wSrcGlyphHeight;
  1228. WORD wDstGlyphWidthBytes;
  1229. WORD wDstGlyphHeight;
  1230. WORD wDstGlyphBytes;
  1231. WORD wLeftMarginBytes;
  1232. WORD wShiftBits;
  1233. PBYTE pSrcGlyph;
  1234. PBYTE pDstGlyphSave;
  1235. PBYTE pDstGlyph;
  1236. WORD i, j;
  1237. BYTE CmdDownloadChar[] =
  1238. "\x1c\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00";
  1239. WORD wGlyphID;
  1240. WORD wFontID;
  1241. WORD wXCharInc;
  1242. if (NULL == pdevobj || NULL == pUFObj || NULL == pdwWidth)
  1243. {
  1244. ERR(("OEMDownloadCharGlyph: Invalid parameter(s).\n"));
  1245. return 0;
  1246. }
  1247. pOEM = (PAPDLPDEV)pdevobj->pdevOEM;
  1248. wGlyphID = pOEM->wGlyphID;
  1249. wFontID = (WORD)(pUFObj->ulFontID - FONT_ID_DIFF);
  1250. if(wGlyphID > MAX_GLYPH_ID || wFontID > MAX_FONT_ID)
  1251. {
  1252. ERR(("Parameter is invalid.\n"));
  1253. return 0;
  1254. }
  1255. // Get glyph bitmap
  1256. GD.dwSize = sizeof(GETINFO_GLYPHBITMAP);
  1257. GD.hGlyph = hGlyph;
  1258. GD.pGlyphData = NULL;
  1259. if(!pUFObj->pfnGetInfo(pUFObj, UFO_GETINFO_GLYPHBITMAP, &GD,
  1260. GD.dwSize, NULL))
  1261. {
  1262. ERR(("UFO_GETINFO_GLYPHBITMAP failed.\n"));
  1263. return 0;
  1264. }
  1265. // set parameters
  1266. pgb = GD.pGlyphData->gdf.pgb;
  1267. // set source glyph bitmap size
  1268. wSrcGlyphWidth = (WORD)((pgb->sizlBitmap.cx + 7) / 8);
  1269. wSrcGlyphHeight = (WORD)pgb->sizlBitmap.cy;
  1270. // set dest. glyph bitmap size
  1271. if(pgb->ptlOrigin.x >= 0)
  1272. {
  1273. wDstGlyphWidthBytes = (WORD)(((pgb->sizlBitmap.cx
  1274. + pgb->ptlOrigin.x) + 7) / 8);
  1275. wLeftMarginBytes = (WORD)(pgb->ptlOrigin.x / 8);
  1276. pOEM->DLCharID[wFontID][wGlyphID].wXAdjust = 0;
  1277. wShiftBits = (WORD)(pgb->ptlOrigin.x % 8);
  1278. } else {
  1279. wDstGlyphWidthBytes = (WORD)((pgb->sizlBitmap.cx + 7) / 8);
  1280. wLeftMarginBytes = 0;
  1281. pOEM->DLCharID[wFontID][wGlyphID].wXAdjust
  1282. = (WORD)ABS(pgb->ptlOrigin.x);
  1283. wShiftBits = 0;
  1284. }
  1285. wDstGlyphHeight = wSrcGlyphHeight;
  1286. wDstGlyphBytes = wDstGlyphWidthBytes * wDstGlyphHeight;
  1287. if (wDstGlyphWidthBytes * 8 > MAXGLYPHWIDTH
  1288. || wDstGlyphHeight > MAXGLYPHHEIGHT
  1289. || wDstGlyphBytes > MAXGLYPHSIZE)
  1290. {
  1291. ERR(("No more glyph can be downloaded.\n"));
  1292. return 0;
  1293. }
  1294. // set pointer of bitmap area
  1295. if (NULL == pOEM->pjTempBuf ||
  1296. pOEM->dwTempBufLen < wDstGlyphBytes) {
  1297. if (NULL != pOEM->pjTempBuf) {
  1298. MemFree(pOEM->pjTempBuf);
  1299. }
  1300. pOEM->pjTempBuf = MemAllocZ(wDstGlyphBytes);
  1301. if (NULL == pOEM->pjTempBuf)
  1302. {
  1303. ERR(("Memory alloc failed.\n"));
  1304. return 0;
  1305. }
  1306. pOEM->dwTempBufLen = wDstGlyphBytes;
  1307. }
  1308. pDstGlyph = pOEM->pjTempBuf;
  1309. pSrcGlyph = pgb->aj;
  1310. // create Dst Glyph
  1311. for(i = 0; i < wSrcGlyphHeight && pSrcGlyph && pDstGlyph; i++)
  1312. {
  1313. if(wLeftMarginBytes)
  1314. {
  1315. if (pOEM->dwTempBufLen - (pDstGlyph - pOEM->pjTempBuf)
  1316. < wLeftMarginBytes)
  1317. {
  1318. ERR(("Dest buffer too small.\n"));
  1319. return 0;
  1320. }
  1321. memset(pDstGlyph, 0, wLeftMarginBytes);
  1322. pDstGlyph += wLeftMarginBytes;
  1323. }
  1324. if(wShiftBits)
  1325. {
  1326. // First byte
  1327. *pDstGlyph++ = (BYTE)((*pSrcGlyph++) >> wShiftBits);
  1328. for(j = 0; j < wSrcGlyphWidth - 1; j++, pSrcGlyph++, pDstGlyph++)
  1329. {
  1330. WORD wTemp1 = (WORD)*(pSrcGlyph - 1);
  1331. WORD wTemp2 = (WORD)*pSrcGlyph;
  1332. wTemp1 <<= (8 - wShiftBits);
  1333. wTemp2 >>= wShiftBits;
  1334. *pDstGlyph = LOBYTE(wTemp1);
  1335. *pDstGlyph |= LOBYTE(wTemp2);
  1336. }
  1337. // bounded last byte of src glyph
  1338. if(((pgb->sizlBitmap.cx + wShiftBits + 7) >> 3) != wSrcGlyphWidth)
  1339. {
  1340. *pDstGlyph = *(pSrcGlyph - 1) << (8 - wShiftBits);
  1341. pDstGlyph++;
  1342. }
  1343. } else {
  1344. for(j = 0; j < wSrcGlyphWidth; j++, pSrcGlyph++, pDstGlyph++)
  1345. *pDstGlyph = *pSrcGlyph;
  1346. }
  1347. }
  1348. // set parameter at Download char table
  1349. wXCharInc = wDstGlyphWidthBytes * 8;
  1350. pOEM->wNumDLChar++;
  1351. pOEM->DLCharID[wFontID][wGlyphID].wCharID = pOEM->wNumDLChar;
  1352. pOEM->DLCharID[wFontID][wGlyphID].wXIncrement =
  1353. (WORD)((GD.pGlyphData->ptqD.x.HighPart + 15) >> 4);
  1354. pOEM->DLCharID[wFontID][wGlyphID].wYAdjust = (WORD)-pgb->ptlOrigin.y;
  1355. //#305000 : Need to add 1 that was rounded off.
  1356. if(pOEM->ulHorzRes == 300)
  1357. {
  1358. pOEM->DLCharID[wFontID][wGlyphID].wYAdjust += 1;
  1359. }
  1360. // send command
  1361. // set LEN parameter
  1362. CmdDownloadChar[2] = HIBYTE(7 + wDstGlyphBytes);
  1363. CmdDownloadChar[3] = LOBYTE(7 + wDstGlyphBytes);
  1364. // set ID parameter
  1365. CmdDownloadChar[4] = HIBYTE(pOEM->wNumDLChar);
  1366. CmdDownloadChar[5] = LOBYTE(pOEM->wNumDLChar);
  1367. // set CW CH IW IH
  1368. CmdDownloadChar[7] = CmdDownloadChar[9] = (BYTE)wXCharInc;
  1369. CmdDownloadChar[8] = CmdDownloadChar[10] = (BYTE)wDstGlyphHeight;
  1370. // send download char command and image
  1371. WRITESPOOLBUF(pdevobj, (PBYTE)CmdDownloadChar, 11);
  1372. WRITESPOOLBUF(pdevobj, (PBYTE)pOEM->pjTempBuf, wDstGlyphBytes);
  1373. *pdwWidth = (DWORD)wXCharInc;
  1374. return (DWORD)wDstGlyphBytes;
  1375. }
  1376. /*****************************************************************************/
  1377. /* */
  1378. /* Module: SetDrawArea */
  1379. /* */
  1380. /* Function: */
  1381. /* */
  1382. /* Syntax: BYTE SetDrawArea(PDEVOBJ, DWORD) */
  1383. /* */
  1384. /* Input: pdevobj */
  1385. /* dwCmdCbId */
  1386. /* */
  1387. /* Output: BYTE */
  1388. /* */
  1389. /* Notice: */
  1390. /* */
  1391. /*****************************************************************************/
  1392. BYTE SetDrawArea(
  1393. PDEVOBJ pdevobj,
  1394. DWORD dwCmdCbId)
  1395. {
  1396. PAPDLPDEV pOEM;
  1397. WORD wWidth;
  1398. WORD wHeight;
  1399. BYTE bIndex;
  1400. BYTE bMargin;
  1401. pOEM = (PAPDLPDEV)pdevobj->pdevOEM;
  1402. if(dwCmdCbId != PHYS_PAPER_UNFIXED)
  1403. {
  1404. bIndex = (BYTE)(dwCmdCbId - PAPERSIZE_MAGIC);
  1405. bMargin = 0x76;
  1406. wWidth = (WORD)pOEM->szlPhysSize.cx - (0x76 * 2);
  1407. wHeight = (WORD)pOEM->szlPhysSize.cy - (0x76 * 2);
  1408. if(pOEM->ulHorzRes == 300)
  1409. {
  1410. wWidth /= 2;
  1411. wHeight /= 2;
  1412. }
  1413. } else {
  1414. bIndex = 0x7f;
  1415. bMargin = 0x00;
  1416. wWidth = (WORD)pOEM->szlPhysSize.cx - (0x25 * 2);
  1417. wHeight= (WORD)pOEM->szlPhysSize.cy - (0x25 * 2);
  1418. if(pOEM->ulHorzRes == 300)
  1419. {
  1420. wWidth /= 2;
  1421. wHeight /= 2;
  1422. }
  1423. }
  1424. /* set value of width, height into DefineDrawingArea command */
  1425. CmdDefDrawArea[CMD_DEF_DRAW_AREA_WIDTH] = HIBYTE(wWidth);
  1426. CmdDefDrawArea[CMD_DEF_DRAW_AREA_WIDTH + 1] = LOBYTE(wWidth);
  1427. CmdDefDrawArea[CMD_DEF_DRAW_AREA_HEIGHT] = HIBYTE(wHeight);
  1428. CmdDefDrawArea[CMD_DEF_DRAW_AREA_HEIGHT + 1] = LOBYTE(wHeight);
  1429. /* set value of Origin-X, Y into DefineDrawingArea command */
  1430. if(pOEM->ulHorzRes == 600)
  1431. {
  1432. CmdDefDrawArea[CMD_DEF_DRAW_AREA_ORIGIN_X]
  1433. = CmdDefDrawArea[CMD_DEF_DRAW_AREA_ORIGIN_Y] = 0x00;
  1434. CmdDefDrawArea[CMD_DEF_DRAW_AREA_ORIGIN_X + 1]
  1435. = CmdDefDrawArea[CMD_DEF_DRAW_AREA_ORIGIN_Y + 1] = bMargin;
  1436. } else {
  1437. CmdDefDrawArea[CMD_DEF_DRAW_AREA_ORIGIN_X]
  1438. = CmdDefDrawArea[CMD_DEF_DRAW_AREA_ORIGIN_Y] = 0x00;
  1439. CmdDefDrawArea[CMD_DEF_DRAW_AREA_ORIGIN_X + 1]
  1440. = CmdDefDrawArea[CMD_DEF_DRAW_AREA_ORIGIN_Y + 1] = bMargin / 2;
  1441. }
  1442. /* set Media Origin into DefineDrawingArea command */
  1443. if(pOEM->fOrientation) // portrait
  1444. CmdDefDrawArea[CMD_DEF_DRAW_AREA_ORIENT] = 0x00;
  1445. else { // landscape
  1446. CmdDefDrawArea[CMD_DEF_DRAW_AREA_ORIENT] = 0x03;
  1447. }
  1448. return bIndex;
  1449. }
  1450. /*****************************************************************************/
  1451. /* */
  1452. /* Module: BRL_Ecmd */
  1453. /* */
  1454. /* Function: ByteRunLength(HBP) Compression Routine */
  1455. /* */
  1456. /* Syntax: WORD BRL_Ecmd(PBYTE, PBYTE, PBYTE, DWORD) */
  1457. /* */
  1458. /* Input: lpbSrc */
  1459. /* lpbTgt */
  1460. /* lpbTmp */
  1461. /* len */
  1462. /* */
  1463. /* Output: WORD */
  1464. /* */
  1465. /* Notice: */
  1466. /* */
  1467. /*****************************************************************************/
  1468. DWORD
  1469. BRL_ECmd(
  1470. PBYTE lpbSrc,
  1471. PBYTE lpbTgt,
  1472. DWORD lenNoPad,
  1473. DWORD len)
  1474. {
  1475. BYTE bRCnt = 1; // repeating byte counter
  1476. BYTE bNRCnt = 0; // non-repeating byte counter
  1477. BYTE bSaveRCnt;
  1478. DWORD i = 0, j = 0, k = 0, l = 0; // movement trackers
  1479. char Go4LastByte = TRUE; // flag to get last byte
  1480. #define jSrcByte(i) \
  1481. ((i < lenNoPad) ? lpbSrc[(i)] : 0)
  1482. /* start compression routine - ByteRunLength Encoding */
  1483. do {
  1484. if(jSrcByte(i) != jSrcByte(i+1)) // non-repeating data?
  1485. {
  1486. while(((jSrcByte(i) != jSrcByte(i+1))
  1487. && (((DWORD)(i+1)) < len)) && (bNRCnt < NRPEAK))
  1488. {
  1489. bNRCnt++; // if so, how many?
  1490. i++;
  1491. }
  1492. /* if at last element but less than NRPEAK value */
  1493. if( (((DWORD)(i+1))==len) && (bNRCnt<NRPEAK) )
  1494. {
  1495. bNRCnt++; // inc count for last element
  1496. Go4LastByte = FALSE; // no need to go back
  1497. } else
  1498. /* if at last BYTE, but before that,
  1499. NRPEAK value has been reached */
  1500. if((((DWORD)(i+1))==len) && ((bNRCnt)==NRPEAK))
  1501. Go4LastByte = TRUE; // get the last BYTE
  1502. // ISSUE-2002/3/14-takashim - Condition is not correct?
  1503. // The below can be (j + bNRCnt + 1) > len, since here we are only loading
  1504. // 1 + bNRCnd bytes to the dest buffer?
  1505. /* Check Target's room to set data */
  1506. if ( (j + bNRCnt + 2) > len ) /* 2 means [Counter] and what bNRCnt starts form 0 */
  1507. {
  1508. /* no room to set data, so return ASAP with the buffer size */
  1509. /* not to use temporary buffer to output. */
  1510. return (len);
  1511. }
  1512. /* assign the value for Number of Non-repeating bytes */
  1513. lpbTgt[j] = bNRCnt-1; // subtract one for WinP's case
  1514. j++; // update tracker
  1515. /* afterwards...write the Raw Data */
  1516. for (l=0; l<bNRCnt;l++)
  1517. {
  1518. lpbTgt[j] = jSrcByte(k);
  1519. k++;
  1520. j++;
  1521. }
  1522. /* reset counter */
  1523. bNRCnt = 0;
  1524. } else { // end of Non-repeating data
  1525. // data is repeating
  1526. while(((jSrcByte(i)==jSrcByte(i+1))
  1527. && ( ((DWORD)(i+1)) < len))
  1528. && (bRCnt<RPEAK))
  1529. {
  1530. bRCnt++;
  1531. i++;
  1532. }
  1533. /* Convert to Two's Complement */
  1534. bSaveRCnt = bRCnt; // save original value
  1535. bRCnt = (BYTE) 0 - bRCnt;
  1536. /* Check Target's room to set data */
  1537. if ( j + 2 > len ) /* 2 means [Counter][Datum] */
  1538. {
  1539. /* no room to set data, so return ASAP with the buffer size */
  1540. /* not to use temporary buffer to output. */
  1541. return (len);
  1542. }
  1543. /* Write the Number of Repeating Data */
  1544. lpbTgt[j] = bRCnt + 1; // add one for WinP's case
  1545. j++; // go to next element
  1546. /* afterwards...write the Repeating data */
  1547. lpbTgt[j] = jSrcByte(k);
  1548. j++;
  1549. /* update counters */
  1550. k += bSaveRCnt;
  1551. bRCnt = 1;
  1552. i += 1;
  1553. /* check if last element has been reached */
  1554. if (i==len)
  1555. Go4LastByte=FALSE; // if so, no need to go back
  1556. } // end of Repeating data
  1557. } while (Go4LastByte); // end of Compression
  1558. return ( j );
  1559. }
  1560. /*****************************************************************************/
  1561. /* */
  1562. /* Module: VOutputText */
  1563. /* */
  1564. /* Function: Send device font characters spooled from bOutputCharStr */
  1565. /* */
  1566. /* Syntax: VOID VOutputText( PDEVOBJ ) */
  1567. /* */
  1568. /* Input: PDEVOBJ pdevobj pointer to the PDEVOBJ structure */
  1569. /* */
  1570. /* Output: VOID */
  1571. /* */
  1572. /* Notice: */
  1573. /* */
  1574. /*****************************************************************************/
  1575. VOID
  1576. VOutputText(
  1577. PDEVOBJ pdevobj)
  1578. {
  1579. PBYTE pCmd;
  1580. WORD wCmdLen = 0;
  1581. PAPDLPDEV pOEM = (PAPDLPDEV)pdevobj->pdevOEM;
  1582. #define CMD_PRN_STR_CUR_VAL 2 // 2 bytes
  1583. BYTE CmdPrnStrCurrent[] = {0x1C,0xC3,0x00,0x00,0x03}; // Print String
  1584. #define CMD_MOVE_HOR_POS_VAL 2 // 2 bytes
  1585. BYTE CmdMoveHoriPos[] = {0x1C,0x21,0x00,0x00}; // Horizontal Relative
  1586. BYTE fGeneralSave;
  1587. // ensure Y position
  1588. fGeneralSave = pOEM->fGeneral;
  1589. pOEM->fGeneral |= BIT_YMOVE_ABS;
  1590. pOEM->fGeneral &= ~BIT_XMOVE_ABS;
  1591. bSendCursorMoveCommand( pdevobj, TRUE );
  1592. pOEM->fGeneral = fGeneralSave;
  1593. if(pOEM->wUpdateXPos)
  1594. {
  1595. CmdMoveHoriPos[CMD_MOVE_HOR_POS_VAL] = HIBYTE(pOEM->wUpdateXPos);
  1596. CmdMoveHoriPos[CMD_MOVE_HOR_POS_VAL + 1] = LOBYTE(pOEM->wUpdateXPos);
  1597. WRITESPOOLBUF(pdevobj, CmdMoveHoriPos, sizeof(CmdMoveHoriPos));
  1598. }
  1599. CmdPrnStrCurrent[CMD_PRN_STR_CUR_VAL] = HIBYTE((pOEM->wCachedBytes + 1));
  1600. CmdPrnStrCurrent[CMD_PRN_STR_CUR_VAL + 1] = LOBYTE((pOEM->wCachedBytes + 1));
  1601. WRITESPOOLBUF(pdevobj, CmdPrnStrCurrent, sizeof(CmdPrnStrCurrent));
  1602. WRITESPOOLBUF(pdevobj, pOEM->bCharData, pOEM->wCachedBytes);
  1603. //#332101 prob.4: Keep wUpdateXPos to accumulate
  1604. pOEM->wUpdateXPos += pOEM->wWidths * (pOEM->wCachedBytes / 2);
  1605. if(pOEM->wCachedBytes % 2)
  1606. pOEM->wUpdateXPos += pOEM->wWidths / 2;
  1607. ZeroMemory(pOEM->bCharData, sizeof(pOEM->bCharData));
  1608. pOEM->wCachedBytes = 0;
  1609. }
  1610. /*****************************************************************************/
  1611. /* */
  1612. /* Module: VSetFontSimulation */
  1613. /* */
  1614. /* Function: Set attribute of device font characters if needed */
  1615. /* */
  1616. /* Syntax: VOID VSetFontSimulation( PDEVOBJ ) */
  1617. /* */
  1618. /* Input: PDEVOBJ pdevobj pointer to the PDEVOBJ structure */
  1619. /* */
  1620. /* Output: VOID */
  1621. /* */
  1622. /* Notice: */
  1623. /* */
  1624. /*****************************************************************************/
  1625. VOID
  1626. VSetFontSimulation(
  1627. PDEVOBJ pdevobj)
  1628. {
  1629. PAPDLPDEV pOEM = (PAPDLPDEV)pdevobj->pdevOEM;
  1630. BYTE CmdFontSim[] = {0x1C,0xA5,0x4,0x04,0x02,0x02,0x00,0x00,0x00,0x00,0x00};
  1631. WORD wCmdLen = 0;
  1632. if((pOEM->fGeneral & FONTSIM_MASK) != pOEM->fCurFontSim ||
  1633. (pOEM->fGeneral & BIT_FONTSIM_RESET) )
  1634. {
  1635. // Send Font simulation command
  1636. if((pOEM->fGeneral & BIT_FONTSIM_RESET) &&
  1637. (!(pOEM->fGeneral & BIT_FONTSIM_BOLD)) &&
  1638. (!(pOEM->fGeneral & BIT_FONTSIM_ITALIC)) )
  1639. {
  1640. // Send Bold and Italic off
  1641. CmdFontSim[6] = 0x00; // Bold and Italic off
  1642. wCmdLen = BYTE_WITHOUT_ITALIC; // 7 bytes
  1643. pOEM->fGeneral &= ~BIT_FONTSIM_RESET;
  1644. } else {
  1645. if(pOEM->fGeneral & BIT_FONTSIM_RESET)
  1646. pOEM->fGeneral &= ~BIT_FONTSIM_RESET;
  1647. CmdFontSim[6] = (pOEM->fGeneral & FONTSIM_MASK);
  1648. wCmdLen = BYTE_WITHOUT_ITALIC; // 7 bytes
  1649. if(pOEM->fGeneral & BIT_FONTSIM_ITALIC)
  1650. {
  1651. CmdFontSim[2] = 0x08; // Total length
  1652. CmdFontSim[4] = 0x06; // Ornament lengh
  1653. wCmdLen = BYTE_WITH_ITALIC; // 11bytes
  1654. }
  1655. // update current font sim infomation
  1656. pOEM->fCurFontSim = pOEM->fGeneral;
  1657. }
  1658. if(wCmdLen)
  1659. WRITESPOOLBUF(pdevobj, CmdFontSim, wCmdLen);
  1660. }
  1661. }
  1662. /*****************************************************************************/
  1663. /* */
  1664. /* Module: bSendCursorMoveCommand */
  1665. /* */
  1666. /* Function: Send appropriate cursor move command */
  1667. /* */
  1668. /* Syntax: BOOL bSendCursorMoveCommand( PDEVOBJ, BOOL ) */
  1669. /* */
  1670. /* Input: PDEVOBJ pdevobj pointer to the PDEVOBJ structure */
  1671. /* BOOL bAdjust adjusting y position flag */
  1672. /* */
  1673. /* Output: BOOL */
  1674. /* */
  1675. /* Notice: */
  1676. /* */
  1677. /*****************************************************************************/
  1678. BOOL
  1679. bSendCursorMoveCommand(
  1680. PDEVOBJ pdevobj, // pointer to the PDEVOBJ structure
  1681. BOOL bYAdjust) // adjusting y position if device font
  1682. {
  1683. PAPDLPDEV pOEM = (PAPDLPDEV)pdevobj->pdevOEM;
  1684. BYTE bCursorMoveCmd[6];
  1685. WORD wCmdLen = 0;
  1686. WORD wY = pOEM->wYPosition;
  1687. WORD wI;
  1688. if(bYAdjust)
  1689. wY -= pOEM->wFontHeight;
  1690. // Set appropriate cursor move command
  1691. if( (pOEM->fGeneral & BIT_XMOVE_ABS) && (pOEM->fGeneral & BIT_YMOVE_ABS) )
  1692. {
  1693. if (sizeof(bCursorMoveCmd) < BYTE_XY_ABS
  1694. || sizeof(CmdSetGivenPos) < BYTE_XY_ABS)
  1695. {
  1696. ERR(("Dest buffer too small.\n"));
  1697. return FALSE;
  1698. }
  1699. memcpy(bCursorMoveCmd, CmdSetGivenPos, BYTE_XY_ABS);
  1700. wCmdLen = BYTE_XY_ABS;
  1701. pOEM->fGeneral &= ~BIT_XMOVE_ABS;
  1702. pOEM->fGeneral &= ~BIT_YMOVE_ABS;
  1703. // Set parameters
  1704. bCursorMoveCmd[2] = HIBYTE(pOEM->wXPosition);
  1705. bCursorMoveCmd[3] = LOBYTE(pOEM->wXPosition);
  1706. bCursorMoveCmd[4] = HIBYTE(wY);
  1707. bCursorMoveCmd[5] = LOBYTE(wY);
  1708. } else if((pOEM->fGeneral & BIT_XMOVE_ABS)
  1709. && (!(pOEM->fGeneral & BIT_YMOVE_ABS)) ) {
  1710. if (sizeof(bCursorMoveCmd) < BYTE_SIMPLE_ABS
  1711. || sizeof(CmdGivenHoriPos) < BYTE_SIMPLE_ABS)
  1712. {
  1713. ERR(("Dest buffer too small.\n"));
  1714. return FALSE;
  1715. }
  1716. memcpy(bCursorMoveCmd, CmdGivenHoriPos, BYTE_SIMPLE_ABS);
  1717. wCmdLen = BYTE_SIMPLE_ABS;
  1718. pOEM->fGeneral &= ~BIT_XMOVE_ABS;
  1719. // set parameter
  1720. bCursorMoveCmd[2] = HIBYTE(pOEM->wXPosition);
  1721. bCursorMoveCmd[3] = LOBYTE(pOEM->wXPosition);
  1722. } else if((pOEM->fGeneral & BIT_YMOVE_ABS)
  1723. && (!(pOEM->fGeneral & BIT_XMOVE_ABS)) ) {
  1724. if (sizeof(bCursorMoveCmd) < BYTE_SIMPLE_ABS
  1725. || sizeof(CmdGivenVertPos) < BYTE_SIMPLE_ABS)
  1726. {
  1727. ERR(("Dest buffer too small.\n"));
  1728. return FALSE;
  1729. }
  1730. memcpy(bCursorMoveCmd, CmdGivenVertPos, BYTE_SIMPLE_ABS);
  1731. wCmdLen = BYTE_SIMPLE_ABS;
  1732. pOEM->fGeneral &= ~BIT_YMOVE_ABS;
  1733. // set parameter
  1734. bCursorMoveCmd[2] = HIBYTE(wY);
  1735. bCursorMoveCmd[3] = LOBYTE(wY);
  1736. }
  1737. if(wCmdLen)
  1738. WRITESPOOLBUF(pdevobj, bCursorMoveCmd, wCmdLen);
  1739. return TRUE;
  1740. }