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.

1195 lines
28 KiB

  1. #define PRINTDRIVER
  2. #include <print.h>
  3. #include "mdevice.h"
  4. #include "gdidefs.inc"
  5. #include "unidrv.h"
  6. #include <memory.h>
  7. #ifndef _INC_WINDOWSX
  8. #include <windowsx.h>
  9. #endif
  10. #ifdef WINNT
  11. #define CODESEG /* not used */
  12. #else // WINNT
  13. #define _CODESEG "_CODESEG"
  14. #define CODESEG __based(__segname(_CODESEG))
  15. #endif // WINNT
  16. //-----------------------------------------------------------------------------
  17. // This files contains the module name for this mini driver. Each mini driver
  18. // must have a unique module name. The module name is used to obtain the
  19. // module handle of this Mini Driver. The module handle is used by the
  20. // generic library to load in tables from the Mini Driver.
  21. //-----------------------------------------------------------------------------
  22. char *rgchModuleName = "FXART4";
  23. #define DEVICE_MASTER_UNIT 7200
  24. #define DRIVER_MASTER_UNIT 1200
  25. typedef struct
  26. {
  27. BYTE fGeneral; // General purpose bitfield
  28. BYTE bCmdCbId; // Callback ID; 0 iff no callback
  29. WORD wCount; // # of EXTCD structures following
  30. WORD wLength; // length of the command
  31. } CD, *PCD, FAR * LPCD;
  32. typedef struct tagMYMDV {
  33. POINTL ptlOrg;
  34. POINTL ptlCur;
  35. SIZEL sizlRes;
  36. WORD iCopies;
  37. CHAR *chOrient;
  38. CHAR *chSize;
  39. BOOL bString;
  40. WORD cFontId;
  41. WORD iFontId;
  42. WORD iFontHeight;
  43. LONG aFontId[20];
  44. POINTL ptlTextCur;
  45. WORD iTextFontId;
  46. WORD iTextFontHeight;
  47. WORD cTextBuf;
  48. BYTE ajTextBuf[1024];
  49. WORD fFontSim;
  50. } MYMDV, *LPMYMDV;
  51. #define FONT_SIM_ITALIC 1
  52. #define FONT_SIM_BOLD 2
  53. // to get physical paper sizes.
  54. typedef struct tagMYFORMS {
  55. CHAR *id;
  56. LONG x;
  57. LONG y;
  58. } MYFORMS, *LPMYFORMS;
  59. // font name to font id mappnig
  60. typedef struct tagMYFONTS {
  61. LONG id;
  62. CHAR *fid1;
  63. CHAR *fid2;
  64. CHAR *pface;
  65. } MYFONTS, *LPMYFONTS;
  66. //
  67. // Load necessary information for specified paper size.
  68. // Make sure PC_OCD_LANDSCAPE and PC_OCD_PORTRAIT are
  69. // called.
  70. //
  71. MYFORMS gForms[] = {
  72. "a3", 13608, 19422,
  73. "a4", 9498, 13608,
  74. "a5", 6570, 9498,
  75. "b4", 11718, 16776,
  76. "b5", 8178, 11718,
  77. "pc", 4302, 6570, // Postcard
  78. "dl", 12780, 19980, // Tabloid
  79. "lt", 9780, 12780, // Letter
  80. "gg", 9780, 15180, // German Legal Fanfold
  81. "lg", 9780, 16380, // Legal
  82. "s1", 4530, 10962, // (Env) Comm 10
  83. "s2", 4224, 8580, // (Env) Monarch
  84. "s3", 4776, 9972, // (Env) DL
  85. "s4", 7230, 10398, // (Env) C5
  86. NULL, 0, 0
  87. };
  88. MYFONTS gFonts[] = {
  89. 150, "fid 150 1 0 0 960 480\n", "fid 151 2 4 0 960 960\n",
  90. "\x96\xbe\x92\xa9", // Mincho
  91. 152, "fid 152 1 0 1 960 480\n", "fid 153 2 4 1 960 960\n",
  92. "\xba\xde\xbc\xaf\xb8", // Gothic
  93. 154, "fid 154 1 0 2 960 480\n", "fid 155 2 4 2 960 960\n",
  94. "\x8a\xdb\xba\xde\xbc\xaf\xb8", // Maru-Gothic
  95. 156, "fid 156 1 0 0 960 480\n", "fid 157 2 5 0 960 960\n",
  96. "\x40\x96\xbe\x92\xa9", // @Mincho
  97. 158, "fid 158 1 0 1 960 480\n", "fid 159 2 5 1 960 960\n",
  98. "\x40\xba\xde\xbc\xaf\xb8", // @Gothic
  99. 160, "fid 160 1 0 2 960 480\n", "fid 161 2 5 2 960 960\n",
  100. "\x40\x8a\xdb\xba\xde\xbc\xaf\xb8", // @Maru-Gothic
  101. 180, "fid 180 1 130 100 0 0\n", NULL, "CS TIMES",
  102. 181, "fid 181 1 130 101 0 0\n", NULL, "CS TIMES Italic",
  103. 182, "fid 182 1 130 102 0 0\n", NULL, "CS TIMES Bold",
  104. 183, "fid 183 1 130 103 0 0\n", NULL, "CS TIMES Italic Bold",
  105. 184, "fid 184 1 130 104 0 0\n", NULL, "CS Triumvirate",
  106. 185, "fid 185 1 130 105 0 0\n", NULL, "CS Triumvirate Italic",
  107. 186, "fid 186 1 130 106 0 0\n", NULL, "CS Triumvirate Bold",
  108. 187, "fid 187 1 130 107 0 0\n", NULL, "CS Triumvirate Italic Bold",
  109. 188, "fid 188 1 130 108 0 0\n", NULL, "CS Courier",
  110. 189, "fid 189 1 130 109 0 0\n", NULL, "CS Courier Italic",
  111. 190, "fid 190 1 130 110 0 0\n", NULL, "CS Courier Bold",
  112. 191, "fid 191 1 130 111 0 0\n", NULL, "CS Courier Italic Bold",
  113. 192, "fid 192 1 130 112 0 0\n", NULL, "CS Symbol",
  114. 0, NULL, NULL, NULL
  115. };
  116. #define ISDBCSFONT(i) ((i) < 180)
  117. #define ISVERTFONT(i) ((i) >= 156 && (i) < 180)
  118. #ifdef WINNT
  119. #include <stdio.h>
  120. #ifdef wsprintf
  121. #undef wsprintf
  122. #endif // wsprintf
  123. #define wsprintf sprintf
  124. LPWRITESPOOLBUF WriteSpoolBuf;
  125. LPALLOCMEM UniDrvAllocMem;
  126. LPFREEMEM UniDrvFreeMem;
  127. BOOL
  128. MyIsDBCSLeadByte(
  129. BYTE bByte);
  130. #define IsDBCSLeadByte MyIsDBCSLeadByte
  131. #endif //WINNT
  132. BOOL
  133. LoadPaperInfo(
  134. LPMYMDV lpMdv,
  135. CHAR *id ) {
  136. LPMYFORMS ptmp;
  137. for ( ptmp = gForms; ptmp->id; ptmp++ ) {
  138. if ( strcmp( id, ptmp->id) == 0 )
  139. break;
  140. }
  141. if ( ptmp->id == NULL )
  142. return FALSE;
  143. lpMdv->chSize = ptmp->id;
  144. lpMdv->ptlOrg.x = 0;
  145. if ( strcmp( lpMdv->chOrient, "l") == 0 ){
  146. lpMdv->ptlOrg.y = ptmp->x;
  147. }
  148. else {
  149. lpMdv->ptlOrg.y = ptmp->y;
  150. }
  151. lpMdv->ptlOrg.x += 210;
  152. //v-jiroya (3/19/1997)
  153. // lpMdv->ptlOrg.y -= 210;
  154. lpMdv->ptlOrg.y += 210;
  155. return TRUE;
  156. }
  157. VOID
  158. SjisToJis(
  159. BYTE *pDst, BYTE *pSrc
  160. )
  161. {
  162. INT c1, c2;
  163. c1 = *pSrc;
  164. c2 = *(pSrc + 1);
  165. // Replace code values which cannot be mapped into 0x2121 - 0x7e7e
  166. // (94 x 94 cahracter plane) with Japanese defult character, which
  167. // is KATAKANA MIDDLE DOT.
  168. if (c1 >= 0xf0) {
  169. c1 = 0x81;
  170. c2 = 0x45;
  171. }
  172. c1 -= ( c1 > 0x9f ) ? 0xb1 : 0x71;
  173. c1 = c1 * 2 + 1;
  174. if ( c2 > 0x9e ) {
  175. c2 = c2 - 0x7e;
  176. c1++;
  177. }
  178. else {
  179. if ( c2 > 0x7e )
  180. c2--;
  181. c2 -= 0x1f;
  182. }
  183. *pDst = c1;
  184. *(pDst + 1) = c2;
  185. }
  186. #define TOHEX(j) ((j) < 10 ? ((j) + '0') : ((j) - 10 + 'a'))
  187. LONG
  188. HexOutput(
  189. LPDV lpDv,
  190. BYTE *lpBuf,
  191. WORD wLen )
  192. {
  193. BYTE Buf[1024];
  194. BYTE *pSrc, *pSrcMax;
  195. LONG iRet, j;
  196. pSrc = (BYTE *)lpBuf;
  197. pSrcMax = pSrc + wLen;
  198. iRet = 0;
  199. while ( pSrc < pSrcMax ) {
  200. for ( j = 0; j < sizeof (Buf) && pSrc < pSrcMax; pSrc++ ) {
  201. BYTE c1, c2;
  202. c1 = (((*pSrc) >> 4) & 0x0f);
  203. c2 = (*pSrc & 0x0f);
  204. Buf[ j++ ] = TOHEX( c1 );
  205. Buf[ j++ ] = TOHEX( c2 );
  206. }
  207. if (WriteSpoolBuf( lpDv, Buf, j ) < 0)
  208. break;
  209. iRet += j;
  210. }
  211. return (WORD) iRet;
  212. }
  213. VOID
  214. BeginString(
  215. LPDV lpdv,
  216. BOOL bReset )
  217. {
  218. LONG ilen;
  219. BYTE buf[512];
  220. LPMYMDV lpMdv;
  221. BYTE *pbuf;
  222. lpMdv = lpdv->lpMdv;
  223. if (lpMdv->bString)
  224. return;
  225. pbuf = buf;
  226. if ( bReset ) {
  227. ilen = wsprintf( pbuf,
  228. "scp %d %d\n",
  229. ( lpMdv->ptlOrg.x + lpMdv->ptlTextCur.x ),
  230. ( lpMdv->ptlOrg.y - lpMdv->ptlTextCur.y ));
  231. pbuf += ilen;
  232. }
  233. ilen = wsprintf( pbuf,
  234. "sh <" );
  235. pbuf += ilen;
  236. if ( (pbuf - buf) > 0 ) {
  237. WriteSpoolBuf( lpdv, buf, (pbuf - buf) );
  238. }
  239. lpMdv->bString = TRUE;
  240. }
  241. VOID
  242. EndString(
  243. LPDV lpdv )
  244. {
  245. LONG ilen;
  246. BYTE buf[512];
  247. LPMYMDV lpMdv;
  248. lpMdv = lpdv->lpMdv;
  249. if (!lpMdv->bString)
  250. return;
  251. ilen = wsprintf( buf,
  252. ">\n" );
  253. if ( ilen > 0 ) {
  254. WriteSpoolBuf( lpdv, buf, ilen );
  255. }
  256. lpMdv->bString = FALSE;
  257. }
  258. VOID
  259. BeginVertWrite(
  260. LPDV lpdv )
  261. {
  262. BYTE buf[512];
  263. LPMYMDV lpMdv;
  264. INT ilen;
  265. BYTE *pbuf;
  266. lpMdv = lpdv->lpMdv;
  267. pbuf = buf;
  268. ilen = wsprintf( pbuf,
  269. "fo 90\nsrcp %d 0\n", lpMdv->iFontHeight );
  270. pbuf += ilen;
  271. if (lpMdv->fFontSim & FONT_SIM_ITALIC) {
  272. ilen = wsprintf( pbuf,
  273. "trf -18 y\n" );
  274. pbuf += ilen;
  275. }
  276. if ( pbuf > buf ) {
  277. WriteSpoolBuf( lpdv, buf, (pbuf - buf) );
  278. }
  279. }
  280. VOID
  281. EndVertWrite(
  282. LPDV lpdv )
  283. {
  284. BYTE buf[512];
  285. LPMYMDV lpMdv;
  286. INT ilen;
  287. BYTE *pbuf;
  288. lpMdv = lpdv->lpMdv;
  289. pbuf = buf;
  290. ilen = wsprintf( pbuf,
  291. "fo 0\nsrcp %d 0\n", -(lpMdv->iFontHeight) );
  292. pbuf += ilen;
  293. if (lpMdv->fFontSim & FONT_SIM_ITALIC) {
  294. ilen = wsprintf( pbuf,
  295. "trf x -18\n" );
  296. pbuf += ilen;
  297. }
  298. if ( pbuf > buf ) {
  299. WriteSpoolBuf( lpdv, buf, (pbuf - buf) );
  300. }
  301. }
  302. //
  303. // Save the current poistion as the begining position of text output.
  304. // We will cache string output so that we need to remember this.
  305. //
  306. VOID
  307. SaveTextCur(
  308. LPDV lpdv )
  309. {
  310. LPMYMDV lpMdv;
  311. lpMdv = lpdv->lpMdv;
  312. lpMdv->ptlTextCur.x = lpMdv->ptlCur.x;
  313. lpMdv->ptlTextCur.y = lpMdv->ptlCur.y;
  314. lpMdv->iTextFontId = lpMdv->iFontId;
  315. lpMdv->iTextFontHeight = lpMdv->iFontHeight;
  316. }
  317. //
  318. // Flush out the cached text. We switch between single byte font and
  319. // double byte font if necesary.
  320. //
  321. VOID
  322. FlushText(
  323. LPDV lpdv )
  324. {
  325. LPMYMDV lpMdv;
  326. INT i;
  327. INT ilen;
  328. BYTE *pStr, *pStrSav, *pStrMax;
  329. BYTE buf[512];
  330. BOOL bReset;
  331. bReset = TRUE;
  332. lpMdv = lpdv->lpMdv;
  333. pStr = lpMdv->ajTextBuf;
  334. pStrMax = pStr + lpMdv->cTextBuf;
  335. pStrSav = pStr;
  336. for ( ; pStr < pStrMax; ) {
  337. if (ISDBCSFONT( lpMdv->iTextFontId )) {
  338. for ( pStrSav = pStr; pStr < pStrMax; pStr += 2 ) {
  339. if (!IsDBCSLeadByte(*pStr))
  340. break;
  341. SjisToJis(pStr, pStr);
  342. }
  343. if ((pStr - pStrSav) > 0) {
  344. // switch font to output double byte characters
  345. // we have assigned fontid + 1 as the font ids for
  346. // double byte fonts, so just add 1 to get double
  347. // byte font id.
  348. ilen = wsprintf( buf,
  349. "sfi %d\nfs %d 0\n",
  350. (lpMdv->iTextFontId + 1),
  351. lpMdv->iFontHeight );
  352. WriteSpoolBuf( lpdv, buf, ilen );
  353. if (ISVERTFONT(lpMdv->iTextFontId))
  354. BeginVertWrite( lpdv );
  355. BeginString( lpdv, bReset );
  356. HexOutput(lpdv, pStrSav, (WORD)(pStr - pStrSav));
  357. EndString( lpdv );
  358. if (ISVERTFONT(lpMdv->iTextFontId))
  359. EndVertWrite( lpdv );
  360. bReset = FALSE;
  361. }
  362. if ( pStr >= pStrMax )
  363. break;
  364. // switch font to output single byte characters
  365. for ( pStrSav = pStr; pStr < pStrMax; pStr++ ) {
  366. if (IsDBCSLeadByte(*pStr))
  367. break;
  368. }
  369. }
  370. else {
  371. pStr = pStrMax;
  372. }
  373. if ((pStr - pStrSav) > 0) {
  374. // switch font to output single byte characters
  375. ilen = wsprintf( buf,
  376. "sfi %d\nfs %d 0\n",
  377. (lpMdv->iTextFontId),
  378. lpMdv->iFontHeight );
  379. WriteSpoolBuf( lpdv, buf, ilen );
  380. BeginString( lpdv, bReset );
  381. HexOutput(lpdv, pStrSav, (WORD)(pStr - pStrSav));
  382. EndString( lpdv );
  383. bReset = FALSE;
  384. }
  385. if ( pStr >= pStrMax )
  386. break;
  387. pStrSav = pStr;
  388. }
  389. lpMdv->cTextBuf = 0;
  390. }
  391. //-------------------------------------------------------------------
  392. // CBFilerGraphics
  393. // Action : Convert binary byte stream into ASCII hexadecimal
  394. // representation. This is required for ART1, where no binary
  395. // transmission of image data is allowed.
  396. //-------------------------------------------------------------------
  397. WORD PASCAL CBFilterGraphics(
  398. LPDV lpdv, LPSTR lpBuf, WORD wLen )
  399. {
  400. return (WORD)HexOutput(lpdv, lpBuf, wLen );
  401. }
  402. //-------------------------------------------------------------------
  403. // OEMOutputCmd
  404. // Action :
  405. //-------------------------------------------------------------------
  406. // #define CBID_CM_OCD_XM_ABS 1
  407. // #define CBID_CM_OCD_XM_REL 2
  408. // #define CBID_CM_OCD_YM_ABS 3
  409. // #define CBID_CM_OCD_YM_REL 4
  410. #define CBID_CM_OCD_XY_ABS 5
  411. #define CBID_CM_OCD_XY_REL 6
  412. #define CBID_RES_OCD_SELECTRES_240DPI 21
  413. #define CBID_RES_OCD_SELECTRES_300DPI 22
  414. #define CBID_RES_OCD_SELECTRES_400DPI 23
  415. #define CBID_RES_OCD_SELECTRES_600DPI 24
  416. #define CBID_RES_OCD_SENDBLOCK_ASCII 25
  417. #define CBID_RES_OCD_SENDBLOCK 26
  418. #define CBID_PC_OCD_BEGINDOC_ART 11
  419. #define CBID_PC_OCD_BEGINDOC_ART3 12
  420. #define CBID_PC_OCD_BEGINDOC_ART4 13
  421. #define CBID_PC_OCD_BEGINPAGE 14
  422. #define CBID_PC_OCD_ENDPAGE 15
  423. #define CBID_PC_OCD_MULT_COPIES 16
  424. #define CBID_PC_OCD_PORTRAIT 17
  425. #define CBID_PC_OCD_LANDSCAPE 18
  426. #define CBID_PSZ_OCD_SELECT_A3 30
  427. #define CBID_PSZ_OCD_SELECT_A4 31
  428. #define CBID_PSZ_OCD_SELECT_A5 32
  429. #define CBID_PSZ_OCD_SELECT_B4 33
  430. #define CBID_PSZ_OCD_SELECT_B5 34
  431. #define CBID_PSZ_OCD_SELECT_PC 35
  432. #define CBID_PSZ_OCD_SELECT_DL 36
  433. #define CBID_PSZ_OCD_SELECT_LT 37
  434. #define CBID_PSZ_OCD_SELECT_GG 38
  435. #define CBID_PSZ_OCD_SELECT_LG 39
  436. #define CBID_PSZ_OCD_SELECT_S1 40
  437. #define CBID_PSZ_OCD_SELECT_S2 41
  438. #define CBID_PSZ_OCD_SELECT_S3 42
  439. #define CBID_PSZ_OCD_SELECT_S4 43
  440. #define CBID_FS_OCD_BOLD_ON 51
  441. #define CBID_FS_OCD_BOLD_OFF 52
  442. #define CBID_FS_OCD_ITALIC_ON 53
  443. #define CBID_FS_OCD_ITALIC_OFF 54
  444. #define CBID_FS_OCD_SINGLE_BYTE 55
  445. #define CBID_FS_OCD_DOUBLE_BYTE 56
  446. #define CBID_FS_OCD_WHITE_TEXT_ON 57
  447. #define CBID_FS_OCD_WHITE_TEXT_OFF 58
  448. #define CBID_FONT_SELECT_OUTLINE 101
  449. // @Aug/31/98 ->
  450. #define MAX_COPIES_VALUE 99
  451. // @Aug/31/98 <-
  452. VOID FAR CODESEG PASCAL
  453. OEMOutputCmd(
  454. LPDV lpdv,
  455. WORD wCmdCbId,
  456. LPDWORD lpdwParams )
  457. {
  458. BYTE buf[512];
  459. INT ilen;
  460. LPMYMDV lpMdv;
  461. LONG x, y;
  462. BOOL bAscii;
  463. CHAR *pStr;
  464. lpMdv = lpdv->lpMdv;
  465. bAscii = FALSE;
  466. ilen = 0;
  467. switch( wCmdCbId ) {
  468. // PAPERSIZE
  469. case CBID_PSZ_OCD_SELECT_A3:
  470. LoadPaperInfo( lpMdv, "a3" );
  471. break;
  472. case CBID_PSZ_OCD_SELECT_A4:
  473. LoadPaperInfo( lpMdv, "a4" );
  474. break;
  475. case CBID_PSZ_OCD_SELECT_A5:
  476. LoadPaperInfo( lpMdv, "a5" );
  477. break;
  478. case CBID_PSZ_OCD_SELECT_B4:
  479. LoadPaperInfo( lpMdv, "b4" );
  480. break;
  481. case CBID_PSZ_OCD_SELECT_B5:
  482. LoadPaperInfo( lpMdv, "b5" );
  483. break;
  484. case CBID_PSZ_OCD_SELECT_PC:
  485. LoadPaperInfo( lpMdv, "pc" );
  486. break;
  487. case CBID_PSZ_OCD_SELECT_DL:
  488. LoadPaperInfo( lpMdv, "dl" );
  489. break;
  490. case CBID_PSZ_OCD_SELECT_LT:
  491. LoadPaperInfo( lpMdv, "lt" );
  492. break;
  493. case CBID_PSZ_OCD_SELECT_GG:
  494. LoadPaperInfo( lpMdv, "gg" );
  495. break;
  496. case CBID_PSZ_OCD_SELECT_LG:
  497. LoadPaperInfo( lpMdv, "lg" );
  498. break;
  499. case CBID_PSZ_OCD_SELECT_S1:
  500. LoadPaperInfo( lpMdv, "s1" );
  501. break;
  502. case CBID_PSZ_OCD_SELECT_S2:
  503. LoadPaperInfo( lpMdv, "s2" );
  504. break;
  505. case CBID_PSZ_OCD_SELECT_S3:
  506. LoadPaperInfo( lpMdv, "s3" );
  507. break;
  508. case CBID_PSZ_OCD_SELECT_S4:
  509. LoadPaperInfo( lpMdv, "s4" );
  510. break;
  511. case CBID_PC_OCD_PORTRAIT:
  512. lpMdv->chOrient = "p";
  513. break;
  514. case CBID_PC_OCD_LANDSCAPE:
  515. lpMdv->chOrient = "l";
  516. break;
  517. // PAGECONTROL
  518. case CBID_PC_OCD_BEGINDOC_ART:
  519. ilen = wsprintf( buf,
  520. "stj c\n" );
  521. break;
  522. case CBID_PC_OCD_BEGINDOC_ART3:
  523. ilen = wsprintf( buf,
  524. "srl %d %d\nstj c\n",
  525. lpMdv->sizlRes.cx,
  526. lpMdv->sizlRes.cy );
  527. break;
  528. case CBID_PC_OCD_BEGINDOC_ART4:
  529. ilen = wsprintf( buf,
  530. "\x1b%%-12345X@PL > ART \x0d\x0asrl %d %d\nccode j\nstj c\n",
  531. lpMdv->sizlRes.cx,
  532. lpMdv->sizlRes.cy );
  533. break;
  534. case CBID_PC_OCD_BEGINPAGE:
  535. // bold-simulation width: res / 50
  536. ilen = wsprintf( buf,
  537. "stp %s %s\nud i\nscl %d %d\nsb %d\n",
  538. lpMdv->chOrient,
  539. lpMdv->chSize,
  540. (DEVICE_MASTER_UNIT / DRIVER_MASTER_UNIT),
  541. (DEVICE_MASTER_UNIT / DRIVER_MASTER_UNIT),
  542. (lpMdv->sizlRes.cy * 2 / 100));
  543. lpMdv->ptlCur.x = 0;
  544. lpMdv->ptlCur.y = 0;
  545. break;
  546. case CBID_PC_OCD_ENDPAGE:
  547. FlushText( lpdv );
  548. ilen = wsprintf( buf,
  549. "ep %d\n",
  550. lpMdv->iCopies );
  551. lpMdv->cFontId = 0;
  552. break;
  553. case CBID_PC_OCD_MULT_COPIES:
  554. // @Aug/31/98 ->
  555. if(MAX_COPIES_VALUE < *lpdwParams)
  556. lpMdv->iCopies = MAX_COPIES_VALUE;
  557. else if(1 > *lpdwParams)
  558. lpMdv->iCopies = 1;
  559. else
  560. lpMdv->iCopies = (WORD)*lpdwParams;
  561. // @Aug/31/98 <-
  562. break;\
  563. case CBID_CM_OCD_XY_ABS:
  564. /////
  565. if (0) {
  566. char buf[128];
  567. wsprintf(buf, "\\%% xy_abs %d %d %%\\\n",
  568. *(LONG *)(lpdwParams),
  569. *(LONG *)(lpdwParams + 1)
  570. );
  571. WriteSpoolBuf( lpdv, buf, strlen(buf));
  572. }
  573. /////
  574. lpMdv->ptlCur.x = *(LONG *)(lpdwParams);
  575. lpMdv->ptlCur.y = *(LONG *)(lpdwParams + 1);
  576. FlushText( lpdv );
  577. SaveTextCur( lpdv );
  578. break;
  579. case CBID_CM_OCD_XY_REL:
  580. /////
  581. if (0) {
  582. char buf[128];
  583. wsprintf(buf, "\\%% xy_rel %d %d %%\\\n",
  584. *(LONG *)(lpdwParams),
  585. *(LONG *)(lpdwParams + 1)
  586. );
  587. WriteSpoolBuf( lpdv, buf, strlen(buf));
  588. }
  589. /////
  590. lpMdv->ptlCur.x += *(LONG *)(lpdwParams);
  591. lpMdv->ptlCur.y += *(LONG *)(lpdwParams + 1);
  592. FlushText( lpdv );
  593. SaveTextCur( lpdv );
  594. break;
  595. // RESOLUTION
  596. case CBID_RES_OCD_SELECTRES_240DPI:
  597. lpMdv->sizlRes.cx = 240;
  598. lpMdv->sizlRes.cy = 240;
  599. break;
  600. case CBID_RES_OCD_SELECTRES_300DPI:
  601. lpMdv->sizlRes.cx = 300;
  602. lpMdv->sizlRes.cy = 300;
  603. break;
  604. case CBID_RES_OCD_SELECTRES_400DPI:
  605. lpMdv->sizlRes.cx = 400;
  606. lpMdv->sizlRes.cy = 400;
  607. break;
  608. case CBID_RES_OCD_SELECTRES_600DPI:
  609. lpMdv->sizlRes.cx = 600;
  610. lpMdv->sizlRes.cy = 600;
  611. break;
  612. case CBID_RES_OCD_SENDBLOCK_ASCII:
  613. bAscii = TRUE;
  614. /* FALLTHROUGH */
  615. case CBID_RES_OCD_SENDBLOCK:
  616. //
  617. // image x y psx psy pcy pcy [string]
  618. //
  619. {
  620. LONG iPsx, iPsy, iPcx, iPcy;
  621. iPsx = DRIVER_MASTER_UNIT / lpMdv->sizlRes.cx;
  622. iPsy = DRIVER_MASTER_UNIT / lpMdv->sizlRes.cy;
  623. iPcx = lpdwParams[2] * 8;
  624. iPcy = lpdwParams[1];
  625. ilen = wsprintf( buf,
  626. "im %d %d %d %d %d %d %s",
  627. ( lpMdv->ptlOrg.x + lpMdv->ptlCur.x ),
  628. ( lpMdv->ptlOrg.y - lpMdv->ptlCur.y ),
  629. iPsx,
  630. iPsy,
  631. iPcx,
  632. (- iPcy),
  633. (bAscii ? "<" : "[")
  634. );
  635. }
  636. break;
  637. case CBID_FS_OCD_BOLD_ON:
  638. case CBID_FS_OCD_BOLD_OFF:
  639. case CBID_FS_OCD_ITALIC_ON:
  640. case CBID_FS_OCD_ITALIC_OFF:
  641. case CBID_FS_OCD_SINGLE_BYTE:
  642. case CBID_FS_OCD_DOUBLE_BYTE:
  643. case CBID_FS_OCD_WHITE_TEXT_ON:
  644. case CBID_FS_OCD_WHITE_TEXT_OFF:
  645. FlushText( lpdv );
  646. pStr = NULL;
  647. switch ( wCmdCbId ) {
  648. case CBID_FS_OCD_WHITE_TEXT_ON:
  649. pStr = "pm i c\n";
  650. break;
  651. case CBID_FS_OCD_WHITE_TEXT_OFF:
  652. pStr = "pm n o\n";
  653. break;
  654. case CBID_FS_OCD_BOLD_ON:
  655. pStr = "bb\n";
  656. lpMdv->fFontSim |= FONT_SIM_BOLD;
  657. break;
  658. case CBID_FS_OCD_BOLD_OFF:
  659. // pStr = "eb\n";
  660. pStr = "eb\net\n"; // DCR: Do we need "et\n"(Transform off)?
  661. lpMdv->fFontSim &= ~FONT_SIM_BOLD;
  662. lpMdv->fFontSim &= ~FONT_SIM_ITALIC; // DCR: Do we need "et\n"(Transform off)?
  663. break;
  664. case CBID_FS_OCD_ITALIC_ON:
  665. pStr = "trf x -18\nbt\n";
  666. lpMdv->fFontSim |= FONT_SIM_ITALIC;
  667. break;
  668. case CBID_FS_OCD_ITALIC_OFF:
  669. // pStr = "et\n";
  670. pStr = "eb\net\n"; // DCR: Do we need "et\n"(Transform off)?
  671. lpMdv->fFontSim &= ~FONT_SIM_ITALIC;
  672. lpMdv->fFontSim &= ~FONT_SIM_BOLD; // DCR: Do we need "et\n"(Transform off)?
  673. break;
  674. }
  675. if ( pStr ) {
  676. ilen = strlen( pStr );
  677. WriteSpoolBuf( lpdv, pStr, ilen );
  678. }
  679. ilen = 0;
  680. break;
  681. default:
  682. break;
  683. }
  684. if ( ilen > 0 ) {
  685. WriteSpoolBuf( lpdv, buf, ilen );
  686. }
  687. }
  688. BOOL FAR PASCAL
  689. OEMGetFontCmd(
  690. LPDV lpdv, // Pointer to PDEVICE structure
  691. WORD wCmdCbId, // Command callback id#, defined by minidriver
  692. LPFONTINFO lpfont, // Pointer to PFM data
  693. BOOL fSelect, // TRUE for selection
  694. LPBYTE lpBuf, // Buffer to put command into
  695. LPWORD lpwSize ) // Ptr to actual size of buffer
  696. {
  697. INT iFontId;
  698. CHAR *pface;
  699. INT j;
  700. LPMYMDV lpMdv;
  701. BOOL bRet;
  702. lpMdv = lpdv->lpMdv;
  703. if ( !fSelect ) {
  704. return TRUE;
  705. }
  706. iFontId = 0;
  707. pface = (CHAR *)((BYTE *)lpfont + lpfont->dfFace);
  708. for ( j = 0; gFonts[ j ].pface; j++ ) {
  709. if ( !strcmp(pface, gFonts[ j ].pface ) ) {
  710. iFontId = gFonts[ j ].id;
  711. break;
  712. }
  713. }
  714. if ( !gFonts[ j ].pface )
  715. j = 0;
  716. if ( *lpwSize > 0 ) {
  717. *lpBuf = j;
  718. bRet = TRUE;
  719. }
  720. else {
  721. bRet = FALSE;
  722. }
  723. *lpwSize = 1;
  724. return bRet;
  725. }
  726. VOID FAR
  727. OEMSendScalableFontCmd(
  728. LPDV lpdv,
  729. LPCD lpcd,
  730. LPFONTINFO lpFont )
  731. {
  732. LPMYMDV lpMdv;
  733. BYTE *lpCmd;
  734. BYTE buf[512], *pbuf;
  735. INT ilen;
  736. LONG iFontHeight;
  737. LONG i, j;
  738. LONG iFontId;
  739. if (!lpcd || !lpFont)
  740. return;
  741. lpMdv = lpdv->lpMdv;
  742. lpCmd = (BYTE *)lpcd + sizeof (CD);
  743. pbuf = buf;
  744. j = *lpCmd;
  745. iFontId = gFonts[ j ].id;
  746. for ( i = 0; i < lpMdv->cFontId; i++ ) {
  747. if ( iFontId == lpMdv->aFontId[ i ] )
  748. break;
  749. }
  750. if ( i >= lpMdv->cFontId ) {
  751. // not declared yet within this page, so let us declare
  752. // it here.
  753. lpMdv->aFontId[ lpMdv->cFontId++ ] = (BYTE)iFontId;
  754. if ( gFonts[ j ].fid2 ) {
  755. ilen = wsprintf( pbuf,
  756. "std\n%s%sed\n",
  757. gFonts[ j ].fid1,
  758. gFonts[ j ].fid2 );
  759. pbuf += ilen;
  760. }
  761. else {
  762. ilen = wsprintf( pbuf,
  763. "std\n%sed\n",
  764. gFonts[ j ].fid1 );
  765. pbuf += ilen;
  766. }
  767. }
  768. lpMdv->iFontId = (WORD)iFontId;
  769. lpMdv->iFontHeight = (WORD)(lpFont->dfPixHeight
  770. * DRIVER_MASTER_UNIT / lpMdv->sizlRes.cy);
  771. if ( pbuf > buf ) {
  772. WriteSpoolBuf( lpdv, buf, (INT)(pbuf - buf) );
  773. }
  774. // Need set iFontId to iTextFontId
  775. SaveTextCur( lpdv );
  776. }
  777. /***************************************************************************
  778. Function Name : OEMOutputChar
  779. Parameters : LPDV lpdv Private Device Structure
  780. LPSTR lpstr Print String
  781. WORD len Length
  782. WORD rcID Font ID
  783. Note :
  784. ***************************************************************************/
  785. VOID FAR
  786. OEMOutputChar(
  787. LPDV lpdv,
  788. LPSTR lpStr,
  789. WORD wLen,
  790. WORD rcID )
  791. {
  792. LPMYMDV lpMdv;
  793. INT i;
  794. BYTE *pStr;
  795. lpMdv = lpdv->lpMdv;
  796. pStr = (BYTE *)lpStr;
  797. for ( i = 0; i < wLen; i++ ) {
  798. if ( lpMdv->cTextBuf >= sizeof ( lpMdv->ajTextBuf ))
  799. FlushText( lpdv );
  800. lpMdv->ajTextBuf[ lpMdv->cTextBuf++ ] = *pStr++;
  801. }
  802. }
  803. #ifndef WINNT
  804. //-------------------------------------------------------------------
  805. // Function: Enable()
  806. // Action : call UniEnable and setup Mdv
  807. //-------------------------------------------------------------------
  808. SHORT CALLBACK Enable(
  809. LPDV lpdv,
  810. WORD style,
  811. PSTR lpModel,
  812. LPSTR lpPort,
  813. LPDM lpStuff )
  814. {
  815. LPMYMDV lpMdv;
  816. INT iRet;
  817. CUSTOMDATA cd;
  818. cd.cbSize = sizeof(CUSTOMDATA);
  819. cd.hMd = GetModuleHandle((LPSTR)rgchModuleName);
  820. cd.fnOEMDump = NULL;
  821. cd.fnOEMOutputChar = OEMOutputChar;
  822. iRet = UniEnable( lpdv, style, lpModel, lpPort, lpStuff, &cd );
  823. if (style == 0x0000 && iRet != 0) {
  824. if (!(lpMdv = GlobalAllocPtr(GHND, sizeof(MYMDV)))) {
  825. lpdv->fMdv = FALSE;
  826. UniDisable( lpdv );
  827. return FALSE;
  828. }
  829. lpdv->lpMdv = lpMdv;
  830. // default values
  831. memset( lpMdv, 0, sizeof (MYMDV) );
  832. lpMdv->iCopies = 1;
  833. // mark we have initialized it
  834. lpdv->fMdv = TRUE;
  835. }
  836. return iRet;
  837. }
  838. //-------------------------------------------------------------------
  839. // Function: Disable()
  840. // Action : free Mdv and call Mdv
  841. //-------------------------------------------------------------------
  842. void FAR PASCAL Disable(lpdv)
  843. LPDV lpdv;
  844. {
  845. if ( lpdv->fMdv ) {
  846. GlobalFreePtr ( lpdv->lpMdv );
  847. lpdv->fMdv = FALSE;
  848. }
  849. UniDisable( lpdv );
  850. }
  851. #endif // WINNT
  852. #ifdef WINNT
  853. /*************************** Function Header *******************************
  854. * MiniDrvEnablePDEV
  855. *
  856. * HISTORY:
  857. * 30 Apl 1996 -by- Sueya Sugihara [sueyas]
  858. * Created it, from NT/DDI spec.
  859. *
  860. ***************************************************************************/
  861. BOOL
  862. MiniDrvEnablePDEV(
  863. LPDV lpdv,
  864. ULONG *pdevcaps)
  865. {
  866. LPMYMDV lpMdv;
  867. if (!(lpMdv = UniDrvAllocMem(sizeof(MYMDV)))) {
  868. lpdv->fMdv = FALSE;
  869. return FALSE;
  870. }
  871. lpdv->lpMdv = lpMdv;
  872. // default values
  873. memset( lpMdv, 0, sizeof (MYMDV) );
  874. lpMdv->iCopies = 1;
  875. // mark we have initialized it
  876. lpdv->fMdv = TRUE;
  877. return TRUE;
  878. }
  879. /*************************** Function Header *******************************
  880. * MiniDrvDisablePDEV
  881. *
  882. * HISTORY:
  883. * 30 Apl 1996 -by- Sueya Sugihara [sueyas]
  884. * Created it, from NT/DDI spec.
  885. *
  886. ***************************************************************************/
  887. VOID
  888. MiniDrvDisablePDEV(
  889. LPDV lpdv)
  890. {
  891. if ( lpdv->fMdv ) {
  892. UniDrvFreeMem( lpdv->lpMdv );
  893. lpdv->fMdv = FALSE;
  894. }
  895. }
  896. BOOL
  897. MyIsDBCSLeadByte(
  898. BYTE bByte)
  899. {
  900. if( ((bByte >= 0x81) && (bByte <= 0x9F)) ||
  901. ((bByte >= 0xE0) && (bByte <= 0xFC)) )
  902. return TRUE;
  903. return FALSE;
  904. }
  905. DRVFN
  906. MiniDrvFnTab[] =
  907. {
  908. { INDEX_MiniDrvEnablePDEV, (PFN)MiniDrvEnablePDEV },
  909. { INDEX_MiniDrvDisablePDEV, (PFN)MiniDrvDisablePDEV },
  910. { INDEX_OEMGetFontCmd, (PFN)OEMGetFontCmd },
  911. { INDEX_OEMOutputCmd, (PFN)OEMOutputCmd },
  912. { INDEX_OEMWriteSpoolBuf, (PFN)CBFilterGraphics },
  913. { INDEX_OEMSendScalableFontCmd, (PFN)OEMSendScalableFontCmd },
  914. { INDEX_OEMOutputChar, (PFN)OEMOutputChar }
  915. };
  916. BOOL
  917. MiniDrvEnableDriver(
  918. MINIDRVENABLEDATA *pEnableData
  919. )
  920. {
  921. if (pEnableData == NULL)
  922. return FALSE;
  923. if (pEnableData->cbSize == 0)
  924. {
  925. pEnableData->cbSize = sizeof (MINIDRVENABLEDATA);
  926. return TRUE;
  927. }
  928. if (pEnableData->cbSize < sizeof (MINIDRVENABLEDATA)
  929. || HIBYTE(pEnableData->DriverVersion)
  930. < HIBYTE(MDI_DRIVER_VERSION))
  931. {
  932. // Wrong size and/or mismatched version
  933. return FALSE;
  934. }
  935. // Load callbacks provided by the Unidriver
  936. if (!bLoadUniDrvCallBack(pEnableData,
  937. INDEX_UniDrvWriteSpoolBuf, (PFN *) &WriteSpoolBuf)
  938. || !bLoadUniDrvCallBack(pEnableData,
  939. INDEX_UniDrvAllocMem, (PFN *) &UniDrvAllocMem)
  940. || !bLoadUniDrvCallBack(pEnableData,
  941. INDEX_UniDrvFreeMem, (PFN *) &UniDrvFreeMem))
  942. {
  943. return FALSE;
  944. }
  945. pEnableData->cMiniDrvFn
  946. = sizeof (MiniDrvFnTab) / sizeof(MiniDrvFnTab[0]);
  947. pEnableData->pMiniDrvFn = MiniDrvFnTab;
  948. return TRUE;
  949. }
  950. #endif //WINNT