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.

939 lines
27 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. // NTRAID#NTBUG9-588519-2002/03/28-yasuho-: Possible divide by zero.
  8. // NTRAID#NTBUG9-588527-2002/03/28-yasuho-: Possible buffer overrun.
  9. #include "pdev.h"
  10. #include <strsafe.h>
  11. #define WRITESPOOLBUF(p, s, n) \
  12. ((p)->pDrvProcs->DrvWriteSpoolBuf(p, s, n))
  13. #define PARAM(p,n) \
  14. (*((p)+(n)))
  15. //
  16. // command callback ID's
  17. //
  18. #define CMD_MOVE_X 23
  19. #define CMD_MOVE_Y 24
  20. #define CMD_BEGIN_RASTER 26
  21. #define CMD_RES_240 29 //for PR601,602,602R
  22. #define CMD_SEND_BLOCK_DATA 30 //for PR1000,1000/2,2000
  23. #define CMD_RES_240NEW 31 //for PR1000,1000/2,2000
  24. #define CMD_SEND_BLOCK_DATA2 32 //for PR601,602,602R
  25. #define CMD_INIT_COORDINATE 33
  26. #define CMD_PC_PRN_DIRECTION 50
  27. #define CMD_CR 51
  28. // #define CMD_RECTWIDTH 60
  29. // #define CMD_RECTHEIGHT 61
  30. // #define CMD_RECTWHITE 62
  31. // #define CMD_RECTBLACK 63
  32. // #define CMD_RECTGRAY 64
  33. //////////////////////////////////////////////////////////////////////////
  34. // Function: BInitOEMExtraData
  35. //
  36. // Description: Initializes OEM Extra data.
  37. //
  38. //
  39. // Parameters:
  40. //
  41. // pOEMExtra Pointer to a OEM Extra data.
  42. //
  43. // dwSize Size of OEM extra data.
  44. //
  45. //
  46. // Returns: TRUE if successful; FALSE otherwise.
  47. //
  48. //
  49. // Comments:
  50. //
  51. //
  52. // History:
  53. // 02/11/97 APresley Created.
  54. //
  55. //////////////////////////////////////////////////////////////////////////
  56. BOOL BInitOEMExtraData(POEMUD_EXTRADATA pOEMExtra)
  57. {
  58. // Initialize OEM Extra data.
  59. pOEMExtra->dmExtraHdr.dwSize = sizeof(OEMUD_EXTRADATA);
  60. pOEMExtra->dmExtraHdr.dwSignature = OEM_SIGNATURE;
  61. pOEMExtra->dmExtraHdr.dwVersion = OEM_VERSION;
  62. pOEMExtra->wRes = 1;
  63. pOEMExtra->dwDeviceDestX = 0;
  64. pOEMExtra->dwDeviceDestY = 0;
  65. pOEMExtra->dwDevicePrevX = 0;
  66. pOEMExtra->dwDevicePrevY = 0;
  67. return TRUE;
  68. }
  69. //////////////////////////////////////////////////////////////////////////
  70. // Function: BMergeOEMExtraData
  71. //
  72. // Description: Validates and merges OEM Extra data.
  73. //
  74. //
  75. // Parameters:
  76. //
  77. // pdmIn pointer to an input OEM private devmode containing the settings
  78. // to be validated and merged. Its size is current.
  79. //
  80. // pdmOut pointer to the output OEM private devmode containing the
  81. // default settings.
  82. //
  83. //
  84. // Returns: TRUE if valid; FALSE otherwise.
  85. //
  86. //
  87. // Comments:
  88. //
  89. //
  90. // History:
  91. // 02/11/97 APresley Created.
  92. // 04/08/97 ZhanW Modified the interface
  93. //
  94. //////////////////////////////////////////////////////////////////////////
  95. BOOL BMergeOEMExtraData(
  96. POEMUD_EXTRADATA pdmIn,
  97. POEMUD_EXTRADATA pdmOut
  98. )
  99. {
  100. if(pdmIn) {
  101. //
  102. // copy over the private fields, if they are valid
  103. //
  104. pdmOut->wRes = pdmIn->wRes;
  105. pdmOut->dwSBCSX = pdmIn->dwSBCSX;
  106. pdmOut->dwDBCSX = pdmIn->dwDBCSX;
  107. pdmOut->lSBCSXMove = pdmIn->lSBCSXMove;
  108. pdmOut->lSBCSYMove = pdmIn->lSBCSYMove;
  109. pdmOut->lDBCSXMove = pdmIn->lDBCSXMove;
  110. pdmOut->lDBCSYMove = pdmIn->lDBCSYMove;
  111. pdmOut->lPrevXMove = pdmIn->lPrevXMove;
  112. pdmOut->lPrevYMove = pdmIn->lPrevYMove;
  113. pdmOut->fGeneral = pdmIn->fGeneral;
  114. pdmOut->wCurrentAddMode = pdmIn->wCurrentAddMode;
  115. pdmOut->dwDeviceDestX = pdmIn->dwDeviceDestX;
  116. pdmOut->dwDeviceDestY = pdmIn->dwDeviceDestY;
  117. pdmOut->dwDevicePrevX = pdmIn->dwDevicePrevX;
  118. pdmOut->dwDevicePrevY = pdmIn->dwDevicePrevY;
  119. }
  120. return TRUE;
  121. }
  122. BYTE ShiftJis[256] = {
  123. // +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F
  124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //00
  125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //10
  126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //20
  127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //30
  128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //40
  129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //50
  130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //60
  131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //70
  132. 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, //80
  133. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, //90
  134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //A0
  135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //B0
  136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //C0
  137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //D0
  138. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, //E0
  139. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 //F0
  140. };
  141. //-----------------------------------------------------------------------------
  142. //
  143. // Function: iDwtoA
  144. //
  145. // Description: Convert from numeral into a character
  146. //-----------------------------------------------------------------------------
  147. static int
  148. iDwtoA(LPSTR buf, DWORD n)
  149. {
  150. int i, j;
  151. for( i = 0; n; i++ ) {
  152. buf[i] = (char)(n % 10 + '0');
  153. n /= 10;
  154. }
  155. /* n was zero */
  156. if( i == 0 )
  157. buf[i++] = '0';
  158. for( j = 0; j < i / 2; j++ ) {
  159. int tmp;
  160. tmp = buf[j];
  161. buf[j] = buf[i - j - 1];
  162. buf[i - j - 1] = (char)tmp;
  163. }
  164. buf[i] = '\0';
  165. return i;
  166. }
  167. //-----------------------------------------------------------------------------
  168. //
  169. // Function: iDwtoA_FillZero
  170. //
  171. // Description: Convert from numeral into a character and
  172. // fill a field which was specified with 0
  173. //-----------------------------------------------------------------------------
  174. static int
  175. iDwtoA_FillZero(LPSTR buf, DWORD n, int fw)
  176. {
  177. int i , j, k, l;
  178. l = n; // for later
  179. for( i = 0; n; i++ ) {
  180. buf[i] = (char)(n % 10 + '0');
  181. n /= 10;
  182. }
  183. /* n was zero */
  184. if( i == 0 )
  185. buf[i++] = '0';
  186. for( j = 0; j < i / 2; j++ ) {
  187. int tmp;
  188. tmp = buf[j];
  189. buf[j] = buf[i - j - 1];
  190. buf[i - j - 1] = (char)tmp;
  191. }
  192. buf[i] = '\0';
  193. for( k = 0; l; k++ ) {
  194. l /= 10;
  195. }
  196. if( k < 1) k++;
  197. k = fw - k;
  198. if(k > 0){;
  199. for (j = i; 0 < j + 1; j--){
  200. buf[j + k] = buf[j];
  201. }
  202. for ( j = 0; j < k; j++){
  203. buf[j] = '0';
  204. }
  205. i = i + k;
  206. }
  207. return i;
  208. }
  209. //-----------------------------------------------------------------------------
  210. //
  211. // Function: memcopy
  212. //
  213. // Description: Copy the memory from Src to Dest
  214. //-----------------------------------------------------------------------------
  215. static int
  216. memcopy(LPSTR lpDst, LPSTR lpSrc, WORD wLen)
  217. {
  218. WORD rLen;
  219. rLen = wLen;
  220. while(wLen--) *lpDst++ = *lpSrc++;
  221. return rLen;
  222. }
  223. //-----------------------------------------------------------------------------
  224. //
  225. // Function: OEMCommandCallback
  226. //
  227. //-----------------------------------------------------------------------------
  228. INT APIENTRY OEMCommandCallback(
  229. PDEVOBJ pdevobj,
  230. DWORD dwCmdCbID,
  231. DWORD dwCount,
  232. PDWORD pdwParams
  233. )
  234. {
  235. INT i;
  236. BYTE *bp;
  237. BYTE Cmd[128];
  238. POEMUD_EXTRADATA pOEM;
  239. INT iRet;
  240. DWORD dwDeviceDestX, dwDeviceDestY;
  241. // 02/04/09 NES Niigata : Check for illegal parameters
  242. if (NULL == pdevobj)
  243. {
  244. ERR(("OEMCommandCallback: Invalid parameter(s).\n"));
  245. return 0;
  246. }
  247. //
  248. // verify pdevobj okay
  249. //
  250. ASSERT(VALID_PDEVOBJ(pdevobj));
  251. //
  252. // fill in printer commands
  253. //
  254. i = 0;
  255. pOEM = (POEMUD_EXTRADATA)(pdevobj->pOEMDM);
  256. iRet = 0;
  257. // 02/04/09 NES Niigata : Check for illegal parameters
  258. if (NULL == pOEM)
  259. {
  260. ERR(("OEMCommandCallback: pdevobj->pOEMDM = 0.\n"));
  261. return 0;
  262. }
  263. switch (dwCmdCbID) {
  264. case CMD_CR:
  265. pOEM->dwDeviceDestX = 0;
  266. WRITESPOOLBUF(pdevobj, "\015", 1);
  267. break;
  268. case CMD_MOVE_X:
  269. case CMD_MOVE_Y:
  270. if (dwCount < 4)
  271. return 0; // cannot do anything
  272. if (!PARAM(pdwParams, 2) || !PARAM(pdwParams, 3))
  273. return 0;
  274. pOEM->dwDeviceDestX = PARAM(pdwParams, 0) /
  275. (MASTER_UNIT / PARAM(pdwParams, 2));
  276. pOEM->dwDeviceDestY = PARAM(pdwParams, 1) /
  277. (MASTER_UNIT / PARAM(pdwParams, 3));
  278. // Set return value
  279. switch (dwCmdCbID) {
  280. case CMD_MOVE_X:
  281. iRet = (INT)pOEM->dwDeviceDestX;
  282. break;
  283. case CMD_MOVE_Y:
  284. iRet = (INT)pOEM->dwDeviceDestY;
  285. break;
  286. }
  287. break;
  288. case CMD_RES_240:
  289. pOEM->wRes = MASTER_UNIT / 240;
  290. break;
  291. case CMD_RES_240NEW:
  292. i = 0;
  293. i += memcopy(&Cmd[i], "\034<1/240,i.", 10);
  294. WRITESPOOLBUF(pdevobj, Cmd, i);
  295. pOEM->wRes = MASTER_UNIT / 240;
  296. break;
  297. case CMD_SEND_BLOCK_DATA:
  298. // 02/04/09 NES Niigata : Check for illegal parameters
  299. if (dwCount < 3 || !pdwParams)
  300. return 0;
  301. /* Send a draw coordinate command to the printer. */
  302. i = 0;
  303. i += memcopy(&Cmd[i], "\034e", 2);
  304. i += iDwtoA(&Cmd[i], pOEM->dwDeviceDestX);
  305. Cmd[i++] = ',';
  306. i += iDwtoA(&Cmd[i], pOEM->dwDeviceDestY);
  307. Cmd[i++] = '.';
  308. WRITESPOOLBUF(pdevobj, Cmd, i);
  309. /* Save the present coordinate. */
  310. pOEM->dwDevicePrevX = pOEM->dwDeviceDestX;
  311. pOEM->dwDevicePrevY = pOEM->dwDeviceDestY;
  312. /* Send an image data draw command. */
  313. i = 0;
  314. i += memcopy(&Cmd[i], "\034R", 2);
  315. i += memcopy(&Cmd[i], "\034i", 2);
  316. i += iDwtoA(&Cmd[i], (PARAM(pdwParams, 0) * 8 ));
  317. Cmd[i++] = ',';
  318. i += iDwtoA(&Cmd[i], PARAM(pdwParams, 1));
  319. Cmd[i++] = ',';
  320. i += memcopy(&Cmd[i], "0,1/1,1/1,", 10);
  321. i += iDwtoA(&Cmd[i], PARAM(pdwParams, 2));
  322. Cmd[i++] = ',';
  323. i += memcopy(&Cmd[i], "240", 3);
  324. Cmd[i++] = '.';
  325. WRITESPOOLBUF(pdevobj, Cmd, i);
  326. break;
  327. case CMD_SEND_BLOCK_DATA2:
  328. // 02/04/09 NES Niigata : Check for illegal parameters
  329. if (dwCount < 3 || !pdwParams)
  330. return 0;
  331. /* Send a draw coordinate command to the printer. */
  332. i = 0;
  333. i += memcopy(&Cmd[i], "\034e", 2);
  334. i += iDwtoA(&Cmd[i], pOEM->dwDeviceDestX);
  335. Cmd[i++] = ',';
  336. i += iDwtoA(&Cmd[i], pOEM->dwDeviceDestY);
  337. Cmd[i++] = '.';
  338. WRITESPOOLBUF(pdevobj, Cmd, i);
  339. /* Save the present coordinate. */
  340. pOEM->dwDevicePrevX = pOEM->dwDeviceDestX;
  341. pOEM->dwDevicePrevY = pOEM->dwDeviceDestY;
  342. /* Send an image data draw command. */
  343. i = 0;
  344. i += memcopy(&Cmd[i], "\034R", 2);
  345. i += memcopy(&Cmd[i], "\034i", 2);
  346. i += iDwtoA(&Cmd[i], (PARAM(pdwParams, 0) * 8 ));
  347. Cmd[i++] = ',';
  348. i += iDwtoA(&Cmd[i], PARAM(pdwParams, 1));
  349. Cmd[i++] = ',';
  350. i += memcopy(&Cmd[i], "0,1/1,1/1,", 10);
  351. i += iDwtoA(&Cmd[i], PARAM(pdwParams, 2));
  352. Cmd[i++] = '.';
  353. WRITESPOOLBUF(pdevobj, Cmd, i);
  354. break;
  355. case CMD_BEGIN_RASTER:
  356. if (pOEM->wCurrentAddMode){
  357. i = 0;
  358. i += memcopy(&Cmd[i], "\034R", 2);
  359. WRITESPOOLBUF(pdevobj, Cmd, i);
  360. pOEM->wCurrentAddMode = 0;
  361. }
  362. break;
  363. case CMD_PC_PRN_DIRECTION:
  364. // 02/04/09 NES Niigata : Check for illegal parameters
  365. if (dwCount < 1 || !pdwParams)
  366. return 0;
  367. {
  368. LONG lEsc90;
  369. LONG ESin[] = {0, 1, 0, -1};
  370. LONG ECos[] = {1, 0, -1, 0};
  371. lEsc90 = (PARAM(pdwParams, 0) % 360) / 90;
  372. pOEM->lSBCSXMove = pOEM->dwSBCSX * ECos[lEsc90];
  373. pOEM->lSBCSYMove = -(LONG)pOEM->dwSBCSX * ESin[lEsc90];
  374. pOEM->lDBCSXMove = pOEM->dwDBCSX * ECos[lEsc90];
  375. pOEM->lDBCSYMove = -(LONG)pOEM->dwDBCSX * ESin[lEsc90];
  376. }
  377. break;
  378. case CMD_INIT_COORDINATE:
  379. if (!pOEM->wRes)
  380. return 0;
  381. pOEM->dwDeviceDestX = 0;
  382. pOEM->dwDeviceDestY = 0;
  383. pOEM->wCurrentAddMode = 0;
  384. if (!(pOEM->fGeneral & FG_GMINIT)) {
  385. i = 0;
  386. i += memcopy(&Cmd[i], "\x1CYIN;SU1,", 9);
  387. i += iDwtoA(&Cmd[i], MASTER_UNIT / pOEM->wRes);
  388. i += memcopy(&Cmd[i], ",0;XX1;PM1;XX0;\x1CZ", 17);
  389. WRITESPOOLBUF(pdevobj, Cmd, i);
  390. pOEM->fGeneral |= FG_GMINIT;
  391. }
  392. break;
  393. }
  394. return iRet;
  395. }
  396. //-----------------------------------------------------------------------------
  397. //
  398. // Function: OEMSendFontCmd
  399. //
  400. //-----------------------------------------------------------------------------
  401. VOID
  402. APIENTRY
  403. OEMSendFontCmd(
  404. PDEVOBJ pdevobj,
  405. PUNIFONTOBJ pUFObj,
  406. PFINVOCATION pFInv)
  407. {
  408. PGETINFO_STDVAR pSV;
  409. DWORD adwStdVariable[2+2*4];
  410. DWORD dwIn, dwOut, dwTemp; // = i,ocmd = counter
  411. PBYTE pubCmd; // = lpcmd
  412. BYTE aubCmd[128]; // = rgcmd[]
  413. POEMUD_EXTRADATA pOEM; // = LPPR602DATASTRUCTURE like
  414. DWORD tmpPoints;
  415. PIFIMETRICS pIFI; // = LPFONTINFO
  416. DWORD dwNeeded;
  417. DWORD dwCount;
  418. BOOL bFound = FALSE;
  419. char pcom1[] = {'Q', 'E', 'H'};
  420. char *pcom2[] = {"070","105","120"};
  421. char *bcom[] = {"1/2,1/2,L.", "1/1,1/1,L.", "2/1,2/1,L.", "3/1,3/1,L.",
  422. "4/1,4/1,L.", "6/1,6/1,L.", "8/1,8/1,L."};
  423. short PTable1[] = { 0,1,2,0,0,1,1,1,2,2,0,0,0,0,1,1,1,
  424. 0,0,2,2,2,2,0,0,0,1,1,1,1,2,2,2,2,2,1,1,
  425. 1,0,0,0,0,2,2,2,2,2,2,2,0,0,0,0,0,0,1,1,
  426. 1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,1,1,1,1,
  427. 1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2};
  428. short BTable1[] = { 0,0,0,1,1,1,1,1,1,1,2,2,2,2,2,2,2,
  429. 3,3,2,2,2,2,4,4,4,3,3,3,3,3,3,3,3,3,4,4,
  430. 4,5,5,5,5,4,4,4,4,4,4,4,6,6,6,6,6,6,5,5,
  431. 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,
  432. 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6};
  433. short PTable2[] = { 0,1,2,0,0,0,1,1,2,2,0,0,0,0,0,1,1,
  434. 1,1,2,2,2,2,0,0,0,0,1,1,1,1,2,2,2,2,2,1,
  435. 1,1,1,1,1,2,2,2,2,2,2,2,0,0,0,0,0,0,0,0,
  436. 0,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,1,
  437. 1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2};
  438. short BTable2[] = { 0,0,0,1,1,1,1,1,1,1,2,2,2,2,2,2,2,
  439. 2,2,2,2,2,2,4,4,4,4,3,3,3,3,3,3,3,3,3,4,
  440. 4,4,4,4,4,4,4,4,4,4,4,4,6,6,6,6,6,6,6,6,
  441. 6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,
  442. 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6};
  443. VERBOSE(("OEMSendFontCmd() entry.\r\n"));
  444. VERBOSE((("CMD size:%ld\r\n"), pFInv->dwCount));
  445. // 02/04/09 NES Niigata : Check for illegal parameters
  446. if (NULL == pdevobj || NULL == pUFObj || NULL == pFInv)
  447. {
  448. ERR(("OEMSendFontCmd: Invalid parameter(s).\n"));
  449. return;
  450. }
  451. if(!pFInv->dwCount){
  452. VERBOSE(("CMD size is Zero return\r\n"));
  453. return;
  454. }
  455. pubCmd = pFInv->pubCommand; //Copy Font Selection Command
  456. dwCount = pFInv->dwCount;
  457. pOEM = (POEMUD_EXTRADATA)(pdevobj->pOEMDM); //Copy ExtraData
  458. pIFI = pUFObj->pIFIMetrics;
  459. // 02/04/09 NES Niigata : Check for illegal parameters
  460. if (NULL == pubCmd || NULL == pOEM || NULL == pIFI)
  461. {
  462. ERR(("OEMSendFontCmd: pFInv->pubCommand = 0 Or pdevobj->pOEMDM = 0 Or pUFObj->pIFIMetrics = 0.\n"));
  463. return;
  464. }
  465. //
  466. // Get standard variables.
  467. //
  468. pSV = (PGETINFO_STDVAR)adwStdVariable;
  469. // 02/04/09 NES Niigata : Check for illegal parameters
  470. if (NULL == pSV)
  471. {
  472. ERR(("OEMSendFontCmd: pSV = 0.\n"));
  473. return;
  474. }
  475. pSV->dwSize = sizeof(GETINFO_STDVAR) + 2 * sizeof(DWORD) * (4 - 1);
  476. pSV->dwNumOfVariable = 4;
  477. pSV->StdVar[0].dwStdVarID = FNT_INFO_FONTHEIGHT;
  478. pSV->StdVar[1].dwStdVarID = FNT_INFO_FONTWIDTH;
  479. pSV->StdVar[2].dwStdVarID = FNT_INFO_TEXTYRES;
  480. pSV->StdVar[3].dwStdVarID = FNT_INFO_TEXTXRES;
  481. if (!pUFObj->pfnGetInfo(pUFObj, UFO_GETINFO_STDVARIABLE, pSV,
  482. pSV->dwSize, &dwNeeded)) {
  483. ERR(("UFO_GETINFO_STDVARIABLE failed.\r\n"));
  484. return;
  485. }
  486. VERBOSE((("FONTHEIGHT=%d\r\n"), pSV->StdVar[0].lStdVariable));
  487. VERBOSE((("FONTWIDTH=%d\r\n"), pSV->StdVar[1].lStdVariable));
  488. if (!pOEM->wRes || !pSV->StdVar[2].lStdVariable)
  489. return;
  490. tmpPoints = ((pSV->StdVar[0].lStdVariable / pOEM->wRes) * 72)
  491. / pSV->StdVar[2].lStdVariable;
  492. if(tmpPoints > 96) tmpPoints = 96;
  493. else if(tmpPoints < 4) tmpPoints = 4;
  494. tmpPoints -= 4;
  495. dwIn = dwOut = dwTemp = 0;
  496. pOEM->fGeneral &= ~(FG_VERT | FG_DBCS);
  497. while(dwIn < pFInv->dwCount && dwOut < 128)
  498. {
  499. while(dwCount--)
  500. {
  501. if(pubCmd[dwIn] !='#'){
  502. aubCmd[dwOut] = pubCmd[dwIn];
  503. dwOut++;
  504. dwIn++;
  505. }
  506. else{
  507. bFound = TRUE;
  508. break;
  509. }
  510. }
  511. if(bFound == TRUE)
  512. dwIn++;
  513. else
  514. return; // mismatch font command
  515. switch(pubCmd[dwIn])
  516. {
  517. case 'T': // 602,602R 2Byte TATE Size
  518. pOEM->fGeneral |= FG_VERT;
  519. case 'Q': // 602,602R 2Byte YOKO Size
  520. pOEM->fGeneral |= FG_DBCS;
  521. if(tmpPoints < 3) tmpPoints = 3;
  522. dwOut +=
  523. memcopy(&aubCmd[dwOut], (LPSTR)pcom2[PTable2[tmpPoints]], 3);
  524. break;
  525. case 'S': // NPDL 2Byte TATE Size
  526. pOEM->fGeneral |= FG_VERT;
  527. case 'P': // NPDL 2Byte YOKO Size
  528. pOEM->fGeneral |= FG_DBCS;
  529. dwOut +=
  530. memcopy(&aubCmd[dwOut], (LPSTR)pcom2[PTable2[tmpPoints]], 3);
  531. break;
  532. case 'U': // 601 TATE SIZE
  533. pOEM->fGeneral |= FG_VERT;
  534. case 'R': // 601 2Byte YOKO Size
  535. pOEM->fGeneral |= FG_DBCS;
  536. if(tmpPoints < 3) tmpPoints = 3;
  537. dwTemp = BTable2[tmpPoints] > 2 ? 2 : PTable2[tmpPoints];
  538. dwOut += memcopy(&aubCmd[dwOut], (LPSTR)pcom2[dwTemp], 3);
  539. break;
  540. case 'X': // 602,602R,NPDL 2Byte Scale
  541. pOEM->fGeneral |= FG_DBCS;
  542. dwOut +=
  543. memcopy(&aubCmd[dwOut], (LPSTR)bcom[BTable2[tmpPoints]], 10);
  544. break;
  545. case 'Y': // 601 2Byte Scale
  546. pOEM->fGeneral |= FG_DBCS;
  547. dwTemp = BTable2[tmpPoints] > 1 ? 2 : 1;
  548. dwOut += memcopy(&aubCmd[dwOut], (LPSTR)bcom[dwTemp], 10);
  549. break;
  550. case 'L': // 1Byte Size
  551. aubCmd[dwOut] = pcom1[PTable1[tmpPoints]];
  552. dwOut++;
  553. break;
  554. case 'M': // 1Byte Scale
  555. dwOut +=
  556. memcopy(&aubCmd[dwOut], (LPSTR)bcom[BTable2[tmpPoints]], 10);
  557. }
  558. dwIn++;
  559. }
  560. WRITESPOOLBUF(pdevobj, aubCmd, dwOut);
  561. /*
  562. * I expect the interval of the current letter and the next letter
  563. * from the letter size.
  564. */
  565. if(pOEM->fGeneral & FG_DBCS)
  566. {
  567. pOEM->dwDBCSX =
  568. pOEM->lDBCSXMove =
  569. (LONG)((pSV->StdVar[1].lStdVariable * 2.04) / pOEM->wRes);
  570. pOEM->dwSBCSX =
  571. pOEM->lSBCSXMove =
  572. (LONG)(pSV->StdVar[1].lStdVariable * 1.03 / pOEM->wRes);
  573. }
  574. else{
  575. pOEM->dwSBCSX =
  576. pOEM->lSBCSXMove =
  577. pSV->StdVar[1].lStdVariable / pOEM->wRes;
  578. }
  579. pOEM->lDBCSYMove = pOEM->lSBCSYMove = 0;
  580. pOEM->wCurrentAddMode = 0;
  581. VERBOSE(("OEMSendFontCmd() end.\r\n"));
  582. }
  583. //-----------------------------------------------------------------------------
  584. //
  585. // Function: OEMOutputCharStr
  586. //
  587. //-----------------------------------------------------------------------------
  588. VOID APIENTRY
  589. OEMOutputCharStr(
  590. PDEVOBJ pdevobj,
  591. PUNIFONTOBJ pUFObj,
  592. DWORD dwType,
  593. DWORD dwCount,
  594. PVOID pGlyph)
  595. {
  596. WORD wlen;
  597. WORD j;
  598. PIFIMETRICS pIFI;
  599. POEMUD_EXTRADATA pOEM;
  600. GETINFO_GLYPHSTRING GStr;
  601. PTRANSDATA pTrans;
  602. PBYTE aubBuff;
  603. DWORD dwI;
  604. DWORD dwNeeded;
  605. VERBOSE(("OEMOutputCharStr() entry.\r\n"));
  606. VERBOSE((("FONT Num=%d\r\n"), dwCount));
  607. // 02/04/09 NES Niigata : Check for illegal parameters
  608. if(NULL == pdevobj || NULL == pUFObj)
  609. {
  610. ERR(("OEMOutputCharStr: Invalid parameter(s).\n"));
  611. return;
  612. }
  613. if(dwType != TYPE_GLYPHHANDLE){
  614. VERBOSE((("NOT TYPE_GLYPHHANDLE\r\n")));
  615. return;
  616. }
  617. pOEM = (POEMUD_EXTRADATA)(pdevobj->pOEMDM);
  618. pIFI = pUFObj->pIFIMetrics;
  619. // 02/04/09 NES Niigata : Check for illegal parameters
  620. if(NULL == pOEM || NULL == pIFI)
  621. {
  622. ERR(("OEMOutputCharStr: pdevobj->pOEMDM = 0 Or pUFObj->pIFIMetrics = 0.\n"));
  623. return;
  624. }
  625. //
  626. // Call the Unidriver service routine to convert
  627. // glyph-handles into the character code data.
  628. //
  629. GStr.dwSize = sizeof (GETINFO_GLYPHSTRING);
  630. GStr.dwCount = dwCount;
  631. GStr.dwTypeIn = TYPE_GLYPHHANDLE;
  632. GStr.pGlyphIn = pGlyph;
  633. GStr.dwTypeOut = TYPE_TRANSDATA;
  634. GStr.pGlyphOut = NULL;
  635. GStr.dwGlyphOutSize = 0;
  636. if (pUFObj->pfnGetInfo(pUFObj, UFO_GETINFO_GLYPHSTRING, &GStr,
  637. GStr.dwSize, &dwNeeded) || !GStr.dwGlyphOutSize)
  638. {
  639. VERBOSE(("UNIFONTOBJ_GetInfo:UFO_GETINFO_GLYPHSTRING failed.\r\n"));
  640. return;
  641. }
  642. if ((aubBuff = MemAlloc(GStr.dwGlyphOutSize)) == NULL)
  643. {
  644. VERBOSE(("UNIFONTOBJ_GetInfo:MemAlloc failed.\r\n"));
  645. return;
  646. }
  647. GStr.pGlyphOut = aubBuff;
  648. if (!pUFObj->pfnGetInfo(pUFObj, UFO_GETINFO_GLYPHSTRING, &GStr,
  649. GStr.dwSize, &dwNeeded))
  650. {
  651. VERBOSE(("UNIFONTOBJ_GetInfo:UFO_GETINFO_GLYPHSTRING failed.\r\n"));
  652. MemFree(aubBuff);
  653. return;
  654. }
  655. /*
  656. * Three kind of the character cords which is given by UNIDRV
  657. * 1.SBCS
  658. * 2.DBCS Kanji
  659. * 3.DBCS ANK
  660. */
  661. pTrans = (PTRANSDATA)aubBuff;
  662. // 02/04/09 NES Niigata : Check for illegal parameters
  663. if(NULL == pTrans)
  664. {
  665. ERR(("OEMOutputCharStr: pTrans = 0.\n"));
  666. return;
  667. }
  668. for (dwI = 0; dwI < dwCount; dwI ++, pTrans++)
  669. {
  670. switch (pTrans->ubType & MTYPE_FORMAT_MASK)
  671. {
  672. case MTYPE_DIRECT:
  673. /*
  674. Pattern 1: SBCS
  675. */
  676. if(pOEM->wCurrentAddMode != FLAG_SBCS ||
  677. pOEM->dwDeviceDestX != pOEM->dwDevicePrevX + pOEM->lPrevXMove ||
  678. pOEM->dwDeviceDestY != pOEM->dwDevicePrevY + pOEM->lPrevYMove)
  679. {
  680. int i = 0;
  681. BYTE Cmd[256];
  682. i += memcopy(&Cmd[i], "\034e", 2);
  683. i += iDwtoA(&Cmd[i], pOEM->dwDeviceDestX);
  684. Cmd[i++] = ',';
  685. i += iDwtoA(&Cmd[i], pOEM->dwDeviceDestY);
  686. Cmd[i++] = '.';
  687. i += memcopy(&Cmd[i], "\034a", 2);
  688. i += iDwtoA(&Cmd[i], pOEM->lSBCSXMove);
  689. Cmd[i++] = ',';
  690. i += iDwtoA(&Cmd[i], pOEM->lSBCSYMove);
  691. Cmd[i++] = ',';
  692. Cmd[i++] = '0';
  693. Cmd[i++] = '.';
  694. WRITESPOOLBUF(pdevobj, Cmd, i);
  695. pOEM->wCurrentAddMode = FLAG_SBCS;
  696. pOEM->lPrevXMove = pOEM->lSBCSXMove;
  697. pOEM->lPrevYMove = pOEM->lSBCSYMove;
  698. }
  699. WRITESPOOLBUF(pdevobj, &pTrans->uCode.ubCode, 1);
  700. break;
  701. case MTYPE_PAIRED:
  702. /*
  703. Pattern 2: kanji
  704. */
  705. if(*pTrans->uCode.ubPairs)
  706. {
  707. if(pOEM->wCurrentAddMode != FLAG_DBCS ||
  708. pOEM->dwDeviceDestX != pOEM->dwDevicePrevX + pOEM->lPrevXMove ||
  709. pOEM->dwDeviceDestY != pOEM->dwDevicePrevY + pOEM->lPrevYMove)
  710. {
  711. int i = 0;
  712. BYTE Cmd[256];
  713. i += memcopy(&Cmd[i], "\034e", 2);
  714. i += iDwtoA(&Cmd[i], pOEM->dwDeviceDestX);
  715. Cmd[i++] = ',';
  716. i += iDwtoA(&Cmd[i], pOEM->dwDeviceDestY);
  717. Cmd[i++] = '.';
  718. i += memcopy(&Cmd[i], "\034a", 2);
  719. i += iDwtoA(&Cmd[i], pOEM->lDBCSXMove);
  720. Cmd[i++] = ',';
  721. i += iDwtoA(&Cmd[i], pOEM->lDBCSYMove);
  722. Cmd[i++] = ',';
  723. Cmd[i++] = '0';
  724. Cmd[i++] = '.';
  725. if(pOEM->fGeneral & FG_VERT)
  726. {
  727. i += memcopy(&Cmd[i], "\033t", 2);
  728. }
  729. WRITESPOOLBUF(pdevobj, Cmd, i);
  730. pOEM->wCurrentAddMode = FLAG_DBCS;
  731. pOEM->lPrevXMove = pOEM->lDBCSXMove;
  732. pOEM->lPrevYMove = pOEM->lDBCSYMove;
  733. }
  734. }
  735. /*
  736. Pattern 3: ANK
  737. */
  738. else
  739. {
  740. if(pOEM->wCurrentAddMode != FLAG_SBCS ||
  741. pOEM->dwDeviceDestX != pOEM->dwDevicePrevX + pOEM->lPrevXMove ||
  742. pOEM->dwDeviceDestY != pOEM->dwDevicePrevY + pOEM->lPrevYMove)
  743. {
  744. int i = 0;
  745. BYTE Cmd[256];
  746. i += memcopy(&Cmd[i], "\034e", 2);
  747. i += iDwtoA(&Cmd[i], pOEM->dwDeviceDestX);
  748. Cmd[i++] = ',';
  749. i += iDwtoA(&Cmd[i], pOEM->dwDeviceDestY);
  750. Cmd[i++] = '.';
  751. i += memcopy(&Cmd[i], "\034a", 2);
  752. i += iDwtoA(&Cmd[i], pOEM->lSBCSXMove);
  753. Cmd[i++] = ',';
  754. i += iDwtoA(&Cmd[i], pOEM->lSBCSYMove);
  755. Cmd[i++] = ',';
  756. Cmd[i++] = '0';
  757. Cmd[i++] = '.';
  758. /*
  759. * ANK can't do vertical writing. We have to do
  760. * vertical writing for holizontal writing compulsorily
  761. */
  762. if(pOEM->fGeneral & FG_VERT)
  763. {
  764. i += memcopy(&Cmd[i], "\033K", 2);
  765. }
  766. WRITESPOOLBUF(pdevobj, Cmd, i);
  767. pOEM->wCurrentAddMode = FLAG_SBCS;
  768. pOEM->lPrevXMove = pOEM->lSBCSXMove;
  769. pOEM->lPrevYMove = pOEM->lSBCSYMove;
  770. }
  771. }
  772. WRITESPOOLBUF(pdevobj, pTrans->uCode.ubPairs, 2);
  773. break;
  774. }
  775. pOEM->dwDevicePrevX = pOEM->dwDeviceDestX;
  776. pOEM->dwDevicePrevY = pOEM->dwDeviceDestY;
  777. pOEM->dwDeviceDestX += pOEM->lPrevXMove;
  778. pOEM->dwDeviceDestY += pOEM->lPrevYMove;
  779. }
  780. MemFree(aubBuff);
  781. VERBOSE(("OEMOutputCharStr() end.\r\n"));
  782. }