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.

857 lines
42 KiB

  1. /*****************************************************************************/
  2. /* CODE.C */
  3. /* */
  4. /* The FE minidriver with Win95 style callbacks negotiates with the */
  5. /* Unidriver using a data block MINIDRVENABLEDATA. Minidriver exports a */
  6. /* callback function MiniDrvEnableDriver() to be recognized by the Unidriver */
  7. /* (so that it can know the minidriver has Win95 style callbacks in it). */
  8. /* */
  9. /* Following files are used by only NT4.0 FE minidriver when driver use */
  10. /* callback function. */
  11. /* */
  12. /* gdidefs.inc mdevice.h print.h mindrvrc.h */
  13. /* minidriv.h unidrv.h udmdi.h version.h */
  14. /* uniutil.c */
  15. /* */
  16. /* Copyright (C) 1997- Advanced Peripherals Technologies, Inc. */
  17. /* */
  18. /* <HISTORY> */
  19. /* */
  20. /*****************************************************************************/
  21. //+---------------------------------------------------------------------------+
  22. //| I N C L U D E F I L E |
  23. //+---------------------------------------------------------------------------+
  24. char *rgchModuleName = "APTiE840";
  25. #include <print.h>
  26. #include "mdevice.h"
  27. #include "gdidefs.inc"
  28. #include "mindrvrc.h"
  29. #include "minidriv.h"
  30. #include "unidrv.h"
  31. #include "code.h"
  32. #include <windows.h>
  33. #include <windowsx.h>
  34. /*****************************************************************************/
  35. /* */
  36. /* Module: MiniDrvEnableDriver */
  37. /* */
  38. /* Function: */
  39. /* */
  40. /* Syntax: BOOL MiniDrvEnableDriver(MINIDRVENABLEDATA) */
  41. /* */
  42. /* Input: *pEnableData */
  43. /* */
  44. /* Output: BOOL */
  45. /* */
  46. /* Notice: This callback routine is "for NT4.0 FE minidriver only". */
  47. /* */
  48. /* History: 1997. 06.03 initial */
  49. /* */
  50. /*****************************************************************************/
  51. BOOL MiniDrvEnableDriver(MINIDRVENABLEDATA *pEnableData)
  52. {
  53. if (pEnableData == NULL)
  54. return FALSE;
  55. if (pEnableData->cbSize == 0) {
  56. pEnableData->cbSize = sizeof(MINIDRVENABLEDATA);
  57. return TRUE;
  58. }
  59. if ((pEnableData->cbSize < sizeof(MINIDRVENABLEDATA))
  60. || (HIBYTE(pEnableData->DriverVersion) < HIBYTE(MDI_DRIVER_VERSION)))
  61. return FALSE; // Wrong size and/or version mismatch.
  62. // Load address of Unidriver provided function
  63. if (!bLoadUniDrvCallBack(pEnableData,INDEX_UniDrvWriteSpoolBuf,(PFN *)&WriteSpoolBuf)
  64. ||!bLoadUniDrvCallBack(pEnableData,INDEX_UniDrvAllocMem,(PFN *)&AllocMem)
  65. ||!bLoadUniDrvCallBack(pEnableData,INDEX_UniDrvFreeMem,(PFN *)&FreeMem))
  66. {
  67. // Failed to get Unidriver callback function address.
  68. return FALSE;
  69. }
  70. // Set minidriver's function table to MINIDRVENABLEDATA
  71. pEnableData->cMiniDrvFn = sizeof(MiniDrvFnTab)/sizeof(MiniDrvFnTab[0]);
  72. pEnableData->pMinDrvFn = MiniDrvFnTab;
  73. return TRUE; // Now we are done.
  74. }
  75. /*****************************************************************************/
  76. /* */
  77. /* Module: MiniDrvEnablePDEV */
  78. /* */
  79. /* Function: */
  80. /* */
  81. /* Syntax: BOOL PASCAL MiniDrvEnablePDEV(LPDV, PGDIINFO) */
  82. /* */
  83. /* Input: lpdv */
  84. /* pdevcaps */
  85. /* */
  86. /* Output: BOOL */
  87. /* */
  88. /* Notice: This callback routine is "for NT4.0 FE minidriver only". */
  89. /* */
  90. /* History: 1997. 06.03 initial */
  91. /* */
  92. /*****************************************************************************/
  93. BOOL PASCAL MiniDrvEnablePDEV(LPDV lpdv, PGDIINFO pdevcaps)
  94. {
  95. LPAPDL lpApdl;
  96. lpdv->fMdv = FALSE;
  97. /* allocate memory for A/PDL structure */
  98. if (!(lpApdl = lpdv->lpMdv = AllocMem(sizeof(APDL))))
  99. return FALSE;
  100. /* allocate buffer for image compression */
  101. if (!(lpApdl->lpCompBuf = AllocMem(MAXIMGSIZE)))
  102. return FALSE;
  103. /* allocate buffer for image compression */
  104. if (!(lpApdl->lpTempBuf = AllocMem(MAXIMGSIZE)))
  105. return FALSE;
  106. /* save current resolution */
  107. lpApdl->ulHorzRes = pdevcaps->ulAspectX;
  108. lpApdl->ulVertRes = pdevcaps->ulAspectY;
  109. /* save physical offset of the unwriteable margin */
  110. lpApdl->ptlPhysOffset.x = pdevcaps->ptlPhysOffset.x;
  111. lpApdl->ptlPhysOffset.y = pdevcaps->ptlPhysOffset.y;
  112. /* save physical Size of the entire surface, including unwriteable margin */
  113. lpApdl->szlPhysSize.cx = pdevcaps->szlPhysSize.cx;
  114. lpApdl->szlPhysSize.cy = pdevcaps->szlPhysSize.cy;
  115. lpdv->fMdv = TRUE;
  116. return TRUE;
  117. }
  118. /*****************************************************************************/
  119. /* */
  120. /* Module: MiniDrvDisablePDEV */
  121. /* */
  122. /* Function: */
  123. /* */
  124. /* Syntax: BOOL PASCAL MiniDrvDisablePDEV(LPDV) */
  125. /* */
  126. /* Input: lpdv */
  127. /* */
  128. /* Output: BOOL */
  129. /* */
  130. /* Notice: This callback routine is "for NT4.0 FE minidriver only". */
  131. /* */
  132. /* History: 1997. 06.03 initial */
  133. /* */
  134. /*****************************************************************************/
  135. BOOL PASCAL MiniDrvDisablePDEV(LPDV lpdv)
  136. {
  137. if (lpdv->fMdv){
  138. FreeMem(((LPAPDL)(lpdv->lpMdv))->lpCompBuf);
  139. FreeMem(((LPAPDL)(lpdv->lpMdv))->lpTempBuf);
  140. FreeMem(lpdv->lpMdv);
  141. lpdv->fMdv = FALSE;
  142. }
  143. return TRUE;
  144. }
  145. /*****************************************************************************/
  146. /* */
  147. /* Module: CBFilterGraphics */
  148. /* */
  149. /* Function: */
  150. /* */
  151. /* Syntax: WORD PASCAL CBFilterGraphics(LPDV, LPSTR, WORD) */
  152. /* */
  153. /* Input: lpdv address of PDEVICE structure */
  154. /* lpBuf points to buffer of graphics data */
  155. /* wLen length of buffer in bytes */
  156. /* */
  157. /* Output: WORD */
  158. /* */
  159. /* Notice: nFunction and Escape numbers are the same */
  160. /* */
  161. /*****************************************************************************/
  162. WORD PASCAL CBFilterGraphics (LPDV lpdv, LPSTR lpBuf, WORD wLen)
  163. {
  164. LPAPDL lpApdl = lpdv->lpMdv;
  165. ULONG ulHorzPixel;
  166. WORD wCompLen;
  167. LPSTR lpSrcImage;
  168. LPSTR lpCompImage;
  169. LPSTR lpTempImage;
  170. /*_ LPDV�ɕۊǂ����Ұ���ޯ̧���߲������� */
  171. lpSrcImage = lpBuf;
  172. lpCompImage = lpApdl->lpCompBuf;
  173. lpTempImage = lpApdl->lpTempBuf;
  174. wCompLen = BRL_ECmd((LPBYTE)lpSrcImage,
  175. (LPBYTE)lpCompImage,
  176. (LPBYTE)lpTempImage,
  177. wLen);
  178. // Set the LEN of the DrawBlockImage command
  179. CmdDrawImgCurrent[4] = (BYTE)((wCompLen + 9) >>8 & 0x00ff);
  180. CmdDrawImgCurrent[5] = (BYTE)((wCompLen + 9) & 0x00ff);
  181. // Set the WIDTH parameter of the DrawBlockImage command
  182. ulHorzPixel = (ULONG)((wLen / LINE_PER_BAND) * 8); // in bits
  183. CmdDrawImgCurrent[7] = (BYTE)(ulHorzPixel >> 8 & 0x000000ffL);
  184. CmdDrawImgCurrent[8] = (BYTE)(ulHorzPixel & 0x000000ffL);
  185. // Set the LEN of uncompressed data
  186. CmdDrawImgCurrent[13] = (BYTE)(wLen >> 8 & 0x000000ff);
  187. CmdDrawImgCurrent[14] = (BYTE)(wLen & 0x000000ff);
  188. // Draw Block Image at Current Position
  189. WriteSpoolBuf((LPDV)lpdv, (LPSTR)CmdDrawImgCurrent, sizeof(CmdDrawImgCurrent));
  190. WriteSpoolBuf((LPDV)lpdv, lpCompImage, wCompLen);
  191. return wLen;
  192. }
  193. /*****************************************************************************/
  194. /* */
  195. /* Module: OEMOutputCmd */
  196. /* */
  197. /* Function: */
  198. /* */
  199. /* Syntax: VOID PASCAL OEMOutputCmd(LPDV, WORD, LPDWORD) */
  200. /* */
  201. /* Input: lpdv */
  202. /* wCmdCbId */
  203. /* lpdwParams */
  204. /* */
  205. /* Output: VOID */
  206. /* */
  207. /* Notice: */
  208. /* */
  209. /*****************************************************************************/
  210. // @Aug/31/98 ->
  211. #define MAX_COPIES_VALUE 255
  212. // @Aug/31/98 <-
  213. VOID PASCAL OEMOutputCmd(LPDV lpdv, WORD wCmdCbId, LPDWORD lpdwParams)
  214. {
  215. LPAPDL lpApdl = lpdv->lpMdv;
  216. WORD wTemp;
  217. WORD wPhysWidth;
  218. WORD wPhysHeight;
  219. DWORD dwXval;
  220. DWORD dwYval;
  221. switch(wCmdCbId)
  222. {
  223. /*------------------------------------------------------*/
  224. /* A/PDL start now */
  225. /*------------------------------------------------------*/
  226. case PAGECONTROL_BEGIN_DOC:
  227. /* reset flag of sent Set Physical Paper command */
  228. lpApdl->fSendSetPhysPaper = FALSE;
  229. /* initialize flag */
  230. lpApdl->fBold = FALSE;
  231. lpApdl->fItalic = FALSE;
  232. lpApdl->fDuplex = FALSE;
  233. CmdSetPhysPage[10] = 0x00;
  234. /* Send Change Data Stream Command for Enter A/PDL mode */
  235. WriteSpoolBuf((LPDV)lpdv, (LPSTR)CmdInAPDLMode, 6);
  236. /* Send A/PLDL start Command */
  237. WriteSpoolBuf((LPDV)lpdv, (LPSTR)CmdAPDLStart, 2);
  238. break;
  239. /*------------------------------------------------------*/
  240. /* send Page Description command */
  241. /*------------------------------------------------------*/
  242. case PAGECONTROL_BEGIN_PAGE:
  243. if(!lpApdl->fSendSetPhysPaper){ // if command has not sent yet
  244. /* reset duplex mode if fDuplex is FALSE */
  245. if(!lpApdl->fDuplex)
  246. CmdSetPhysPaper[8] = 0x00; // Duplex OFF
  247. /* send Set Physical Paper command */
  248. WriteSpoolBuf((LPDV)lpdv,
  249. (LPSTR)CmdSetPhysPaper, sizeof(CmdSetPhysPaper));
  250. if(lpApdl->ulHorzRes == 600) { // set unit base
  251. CmdSetPhysPage[6] = 0x17;
  252. CmdSetPhysPage[7] = 0x70;
  253. } else {
  254. CmdSetPhysPage[6] = 0x0B;
  255. CmdSetPhysPage[7] = 0xB8;
  256. }
  257. lpApdl->fSendSetPhysPaper = TRUE; // already sent
  258. }
  259. // send Set Physical Page command
  260. WriteSpoolBuf((LPDV)lpdv,
  261. (LPSTR)CmdSetPhysPage, sizeof(CmdSetPhysPage));
  262. // send Begin Physical Page command
  263. WriteSpoolBuf((LPDV)lpdv,
  264. (LPSTR)CmdBeginPhysPage, sizeof(CmdBeginPhysPage));
  265. // send Begin Logical Page command
  266. WriteSpoolBuf((LPDV)lpdv,
  267. (LPSTR)CmdBeginLogPage, sizeof(CmdBeginLogPage));
  268. // send Define Drawing Area command
  269. WriteSpoolBuf((LPDV)lpdv,
  270. (LPSTR)CmdDefDrawArea, sizeof(CmdDefDrawArea));
  271. break;
  272. case PAGECONTROL_END_PAGE:
  273. // send End Logical Page command
  274. WriteSpoolBuf ((LPDV)lpdv,(LPSTR)CmdEndLogPage, sizeof(CmdEndLogPage));
  275. // send End Physical Page command
  276. WriteSpoolBuf ((LPDV)lpdv,(LPSTR)CmdEndPhysPage, sizeof(CmdEndPhysPage));
  277. break;
  278. case PAGECONTROL_ABORT_DOC:
  279. case PAGECONTROL_END_DOC:
  280. // send A/PDL End command
  281. WriteSpoolBuf((LPDV)lpdv, (LPSTR)CmdAPDLEnd, sizeof(CmdAPDLEnd));
  282. break;
  283. /*------------------------------------------------------*/
  284. /* save print direction */
  285. /*------------------------------------------------------*/
  286. case PAGECONTROL_POTRAIT: // 36
  287. lpApdl->fOrientation = TRUE;
  288. break;
  289. case PAGECONTROL_LANDSCAPE: // 37
  290. lpApdl->fOrientation = FALSE;
  291. break;
  292. /*------------------------------------------------------*/
  293. /* set Drawing Area into SetPhysPaperDesc command */
  294. /*------------------------------------------------------*/
  295. case PHYS_PAPER_A3: // 50
  296. case PHYS_PAPER_A4: // 51
  297. case PHYS_PAPER_B4: // 54
  298. case PHYS_PAPER_LETTER: // 57
  299. case PHYS_PAPER_LEGAL: // 58
  300. CmdSetPhysPaper[5] = SetDrawArea(lpdv, wCmdCbId);
  301. break;
  302. case PHYS_PAPER_B5: // 55
  303. case PHYS_PAPER_A5: // 52
  304. CmdSetPhysPaper[5] = SetDrawArea(lpdv, wCmdCbId);
  305. /* even if Duplex is selected, it cancel */
  306. lpApdl->fDuplex = FALSE;
  307. CmdSetPhysPaper[8] = 0x00; // Duplex is off
  308. break;
  309. case PHYS_PAPER_POSTCARD: // 59
  310. CmdSetPhysPaper[5] = SetDrawArea(lpdv, wCmdCbId);
  311. /* if paper is Postcard, papersource is always Front Tray */
  312. CmdSetPhysPaper[6] = 0x00; // select Front Tray
  313. CmdSetPhysPaper[7] = 0x00; // Auto Tray Select is OFF
  314. /* even if Duplex is selected, it cancel */
  315. lpApdl->fDuplex = FALSE;
  316. CmdSetPhysPaper[8] = 0x00; // Duplex is off
  317. break;
  318. case PHYS_PAPER_UNFIXED: // 60
  319. /* if paper is Unfixed, papersource is always Front Tray */
  320. CmdSetPhysPaper[6] = 0x00; // Select Front Tray
  321. CmdSetPhysPaper[7] = 0x00; // Auto Tray Select is OFF
  322. /* even if Duplex is selected, it cancel */
  323. lpApdl->fDuplex = FALSE;
  324. CmdSetPhysPaper[8] = 0x00; // Duplex is off
  325. CmdSetPhysPaper[5] = SetDrawArea(lpdv, wCmdCbId);
  326. CmdSetPhysPaper[12] = 0x00; // UnitBase : 10 inch
  327. if(lpApdl->ulHorzRes == 600) { // set logical unit
  328. CmdSetPhysPaper[13] = 0x17;
  329. CmdSetPhysPaper[14] = 0x70;
  330. } else {
  331. CmdSetPhysPaper[13] = 0x0B;
  332. CmdSetPhysPaper[14] = 0xB8;
  333. }
  334. if(lpApdl->fOrientation){ // portrait
  335. wPhysWidth = (WORD)lpApdl->szlPhysSize.cx;
  336. wPhysHeight = (WORD)lpApdl->szlPhysSize.cy;
  337. } else { // landscape
  338. wPhysWidth = (WORD)lpApdl->szlPhysSize.cy;
  339. wPhysHeight = (WORD)lpApdl->szlPhysSize.cx;
  340. }
  341. CmdSetPhysPaper[15] = (BYTE)(wPhysWidth >> 8 & 0x00ff);
  342. CmdSetPhysPaper[16] = (BYTE)(wPhysWidth & 0x00ff);
  343. CmdSetPhysPaper[17] = (BYTE)(wPhysHeight >> 8 & 0x00ff);
  344. CmdSetPhysPaper[18] = (BYTE)(wPhysHeight & 0x00ff);
  345. break;
  346. /*------------------------------------------------------*/
  347. /* set Paper Tray into SetPhysPaperDesc command */
  348. /*------------------------------------------------------*/
  349. case PAPER_SRC_FTRAY:
  350. CmdSetPhysPaper[6] = 0x00; // Select Front Tray
  351. CmdSetPhysPaper[7] = 0x00; // Auto Tray Select is OFF
  352. break;
  353. case PAPER_SRC_CAS1:
  354. CmdSetPhysPaper[6] = 0x01; // Select Cassette 1
  355. CmdSetPhysPaper[7] = 0x00; // Auto Tray Select is OFF
  356. break;
  357. case PAPER_SRC_CAS2:
  358. CmdSetPhysPaper[6] = 0x02; // Select Cassette 2
  359. CmdSetPhysPaper[7] = 0x00; // Auto Tray Select is OFF
  360. break;
  361. case PAPER_SRC_CAS3:
  362. CmdSetPhysPaper[6] = 0x03; // Select Cassette 3
  363. CmdSetPhysPaper[7] = 0x00; // Auto Tray Select is OFF
  364. break;
  365. /*------------------------------------------------------*/
  366. /* set Auto Tray Mode into SetPhysPaperDesc command */
  367. /*------------------------------------------------------*/
  368. case PAPER_DEST_SCALETOFIT_ON: // 25
  369. lpApdl->fScaleToFit = TRUE;
  370. CmdSetPhysPaper[7] = 0x02;
  371. break;
  372. case PAPER_DEST_SCALETOFIT_OFF: // 26
  373. lpApdl->fScaleToFit = FALSE;
  374. CmdSetPhysPaper[7] = 0x00;
  375. break;
  376. /*------------------------------------------------------*/
  377. /* set Duplex Mode into SetPhysPaperDesc command */
  378. /*------------------------------------------------------*/
  379. case PAGECONTROL_DUPLEX_UPDOWN:
  380. lpApdl->fDuplex = TRUE;
  381. CmdSetPhysPaper[8] = 0x01; // Up Side Down
  382. break;
  383. case PAGECONTROL_DUPLEX_RIGHTUP:
  384. lpApdl->fDuplex = TRUE;
  385. CmdSetPhysPaper[8] = 0x02; // Right Side Up
  386. break;
  387. case PAGECONTROL_DUPLEX_OFF:
  388. lpApdl->fDuplex = FALSE;
  389. break;
  390. /*------------------------------------------------------*/
  391. /* set Toner Save into SetPhysPage command */
  392. /*------------------------------------------------------*/
  393. case TONER_SAVE_OFF: // 100
  394. CmdSetPhysPage[10] = 0x00; // off
  395. break;
  396. case TONER_SAVE_DARK: // 101
  397. CmdSetPhysPage[10] = 0x02; // dark
  398. break;
  399. case TONER_SAVE_LIGHT: // 102
  400. CmdSetPhysPage[10] = 0x01; // right
  401. break;
  402. /*------------------------------------------------------*/
  403. /* set Copy Count to SetPhysPaperDesc command */
  404. /*------------------------------------------------------*/
  405. case PAGECONTROL_MULTI_COPIES:
  406. // @Aug/31/98 ->
  407. if(MAX_COPIES_VALUE < *lpdwParams)
  408. CmdSetPhysPaper[9] = MAX_COPIES_VALUE;
  409. else if(1 > *lpdwParams)
  410. CmdSetPhysPaper[9] = 1;
  411. else
  412. CmdSetPhysPaper[9] = (BYTE)*lpdwParams;
  413. // @Aug/31/98 <-
  414. break;
  415. /*------------------------------------------------------*/
  416. /* send Set Character Attribute with ornament */
  417. /*------------------------------------------------------*/
  418. case BOLD_ON:
  419. if (!lpApdl->fItalic) // bold only
  420. WriteSpoolBuf(lpdv, CmdBoldOn, sizeof(CmdBoldOn));
  421. else // bold and italic
  422. WriteSpoolBuf(lpdv, CmdBoldItalicOn, sizeof(CmdBoldItalicOn));
  423. lpApdl->fBold = TRUE;
  424. break;
  425. case ITALIC_ON:
  426. if (!lpApdl->fBold) // italic only
  427. WriteSpoolBuf(lpdv, CmdItalicOn, sizeof(CmdItalicOn));
  428. else // italic and bold
  429. WriteSpoolBuf(lpdv, CmdBoldItalicOn, sizeof(CmdBoldItalicOn));
  430. lpApdl->fItalic = TRUE;
  431. break;
  432. case BOLD_OFF:
  433. case ITALIC_OFF:
  434. lpApdl->fItalic = lpApdl->fBold = FALSE;
  435. WriteSpoolBuf(lpdv, CmdBoldItalicOff, sizeof(CmdBoldItalicOff));
  436. break;
  437. /*------------------------------------------------------*/
  438. /* */
  439. /*------------------------------------------------------*/
  440. case X_ABS_MOVE:
  441. wTemp = (WORD)*lpdwParams / (MASTER_UNIT / (WORD)lpApdl->ulHorzRes);
  442. CmdGivenHoriPos[2] = (BYTE) (wTemp >> 8 & 0x00ff);
  443. CmdGivenHoriPos[3] = (BYTE) (wTemp & 0x00ff);
  444. /* Send SetGivenHorizontalPosition Command */
  445. WriteSpoolBuf(lpdv, CmdGivenHoriPos, sizeof(CmdGivenHoriPos));
  446. break;
  447. case Y_ABS_MOVE:
  448. wTemp = (WORD)*lpdwParams;
  449. CmdGivenVerPos[2] = (BYTE) (wTemp >> 8 & 0x00ff);
  450. CmdGivenVerPos[3] = (BYTE) (wTemp & 0x00ff);
  451. /* Send SetGivenVerticalPosition Command */
  452. WriteSpoolBuf(lpdv, CmdGivenVerPos, sizeof(CmdGivenVerPos));
  453. break;
  454. case CR_EMULATION:
  455. CmdGivenVerPos[2] = 0x00;
  456. CmdGivenVerPos[3] = 0x00;
  457. /* Send SetGivenVerticalPosition Command */
  458. WriteSpoolBuf(lpdv, CmdGivenVerPos, sizeof(CmdGivenVerPos));
  459. break;
  460. case XY_ABS_MOVE:
  461. if(lpApdl->ulHorzRes == 300) {
  462. dwXval = (DWORD) lpdwParams[0] / 2;
  463. dwYval = (DWORD) lpdwParams[1] / 2;
  464. } else {
  465. dwXval = (DWORD) lpdwParams[0];
  466. dwYval = (DWORD) lpdwParams[1];
  467. } /* endif */
  468. CmdSetGivenPos[2] = (BYTE)(dwXval >> 8 & 0x00ff);
  469. CmdSetGivenPos[3] = (BYTE)(dwXval & 0x00ff);
  470. CmdSetGivenPos[4] = (BYTE)(dwYval >> 8 & 0x00ff);
  471. CmdSetGivenPos[5] = (BYTE)(dwYval & 0x00ff);
  472. WriteSpoolBuf(lpdv, CmdSetGivenPos, sizeof(CmdSetGivenPos));
  473. break;
  474. }
  475. }
  476. /*****************************************************************************/
  477. /* */
  478. /* Module: OEMOutputChar */
  479. /* */
  480. /* Function: */
  481. /* */
  482. /* Syntax: VOID PASCAL OEMOutputChar(LPDV, LPSTR, WORD, SHORT) */
  483. /* */
  484. /* Input: lpdv address of PDEVICE structure */
  485. /* lpstr */
  486. /* len */
  487. /* rcID */
  488. /* */
  489. /* Output: short */
  490. /* */
  491. /* Notice: */
  492. /* */
  493. /*****************************************************************************/
  494. VOID PASCAL OEMOutputChar(LPDV lpdv, LPSTR lpstr, WORD len, SHORT rcID)
  495. {
  496. LPAPDL lpApdl = lpdv->lpMdv;
  497. if (rcID){ // "rc != 0" means font is device font.
  498. CmdPrnStrCurrent[2] = (BYTE)((len+1) >> 8 & 0x00ff);
  499. CmdPrnStrCurrent[3] = (BYTE)((len+1) & 0x00ff);
  500. /* send Print Character String at Current Position command */
  501. WriteSpoolBuf(lpdv, (LPSTR)CmdPrnStrCurrent, sizeof(CmdPrnStrCurrent));
  502. WriteSpoolBuf(lpdv, lpstr, len);
  503. if(len <= 2) {
  504. /* send Move Position Horizontally command */
  505. CmdMoveHoriPos[2] = (BYTE)((lpApdl->wWidths * len) >> 8 & 0x00ff);
  506. CmdMoveHoriPos[3] = (BYTE)((lpApdl->wWidths * len) & 0x00ff);
  507. WriteSpoolBuf(lpdv, (LPSTR)CmdMoveHoriPos, sizeof(CmdMoveHoriPos));
  508. }
  509. }
  510. }
  511. /*****************************************************************************/
  512. /* */
  513. /* Module: OEMSendScalableFontCmd */
  514. /* */
  515. /* Function: send A/PDL-style font selection command. */
  516. /* */
  517. /* Syntax: VOID PASCAL OEMSendScalableFontCmd(LPDV, LPCD, LPFONTINFO) */
  518. /* */
  519. /* Input: lpdv address of PDEVICE structure */
  520. /* lpcd offset to the command heap */
  521. /* lpFont deveice font information */
  522. /* */
  523. /* Output: VOID */
  524. /* */
  525. /* Notice: */
  526. /* */
  527. /*****************************************************************************/
  528. VOID PASCAL OEMSendScalableFontCmd(LPDV lpdv, LPCD lpcd, LPFONTINFO lpFont)
  529. {
  530. LPSTR lpcmd;
  531. short ocmd;
  532. WORD wCount;
  533. BYTE rgcmd[CCHMAXCMDLEN]; // build command here
  534. LPAPDL lpApdl = lpdv->lpMdv;
  535. WORD wHeight;
  536. WORD wWidth;
  537. if (!lpcd || !lpFont)
  538. return;
  539. // be careful about integer overflow.
  540. lpcmd = (LPSTR)(lpcd+1);
  541. ocmd = 0;
  542. for (wCount = 0; wCount < lpcd->wLength && ocmd < CCHMAXCMDLEN; )
  543. if (lpcmd[wCount] == '#' && lpcmd[wCount + 1] == 'H'){ // height
  544. wHeight = (lpFont->dfPixHeight - lpFont->dfInternalLeading);
  545. rgcmd[ocmd++] = HIBYTE(wHeight);
  546. rgcmd[ocmd++] = LOBYTE(wHeight);
  547. wCount += 2;
  548. }
  549. else {
  550. if (lpcmd[wCount] == '#' && lpcmd[wCount + 1] == 'W'){ // width
  551. if (lpFont->dfPixWidth > 0){
  552. wWidth = lpFont->dfMaxWidth;
  553. rgcmd[ocmd++] = HIBYTE(wWidth);
  554. rgcmd[ocmd++] = LOBYTE(wWidth);
  555. // move current position for device font in OEMOutputCHar
  556. lpApdl->wWidths = lpFont->dfAvgWidth;
  557. }
  558. wCount += 2;
  559. }
  560. else
  561. rgcmd[ocmd++] = lpcmd[wCount++];
  562. }
  563. WriteSpoolBuf(lpdv, (LPSTR) rgcmd, ocmd);
  564. }
  565. /*****************************************************************************/
  566. /* */
  567. /* Module: OEMScaleWidth */
  568. /* */
  569. /* Function: return the scaled width which is calcualted based on the */
  570. /* assumption that APDL assumes 72 points in one 1 inch. */
  571. /* */
  572. /* Syntax: SHORT PASCAL OEMScaleWidth(SHORT, SHORT, SHORT, SHORT, SHORT) */
  573. /* */
  574. /* Input: width in units specified by 'masterUnits' */
  575. /* masterUnits */
  576. /* newHeight in units specified by 'vRes' */
  577. /* vRes height device units */
  578. /* hRes width device units */
  579. /* */
  580. /* Output: short */
  581. /* */
  582. /* Notice: <extent> : <font units> = <base Width> : <hRes> */
  583. /* <base width> : <etmMasterHeight> = <newWidth> : <newHeight> */
  584. /* <etmMasterUnits> : <etmMasterHeight> = <font units> : <vRes> */
  585. /* <newWidth> = (<extent> * <hRes> * <newHeight>) / */
  586. /* (<etmMasterUnits> * <vRes>) */
  587. /* */
  588. /*****************************************************************************/
  589. SHORT PASCAL OEMScaleWidth(SHORT width,
  590. SHORT masterUnits, SHORT newHeight, SHORT vRes, SHORT hRes)
  591. {
  592. DWORD newWidth10;
  593. short newWidth;
  594. // assert that hRes == vRes to avoid overflow problem.
  595. if (vRes != hRes)
  596. return 0;
  597. newWidth10 = (DWORD)width * (DWORD)newHeight * 10;
  598. newWidth10 /= (DWORD)masterUnits;
  599. // we multiplied 10 first in order to maintain the precision of
  600. // the width calcution. Now convert it back and round to the
  601. // nearest integer.
  602. newWidth = (short)((newWidth10 + 5) / 10);
  603. return newWidth;
  604. }
  605. /*****************************************************************************/
  606. /* */
  607. /* Module: SetDrawArea */
  608. /* */
  609. /* Function: */
  610. /* */
  611. /* Syntax: BYTE PASCAL SetDrawArea(LPDV, WORD) */
  612. /* */
  613. /* Input: lpdv */
  614. /* wCmdCbId */
  615. /* */
  616. /* Output: BYTE */
  617. /* */
  618. /* Notice: */
  619. /* */
  620. /*****************************************************************************/
  621. BYTE PASCAL SetDrawArea(LPDV lpdv, WORD wCmdCbId)
  622. {
  623. LPAPDL lpApdl = lpdv->lpMdv;
  624. WORD wWidth;
  625. WORD wHeight;
  626. BYTE bIndex;
  627. if(wCmdCbId != PHYS_PAPER_UNFIXED){
  628. bIndex = (BYTE)(wCmdCbId - PAPERSIZE_MAGIC);
  629. wWidth = phySize[bIndex].wWidth / (MASTER_UNIT / (WORD)lpApdl->ulHorzRes);
  630. wHeight= phySize[bIndex].wHeight / (MASTER_UNIT / (WORD)lpApdl->ulHorzRes);
  631. } else {
  632. bIndex = 0x7f;
  633. if(lpApdl->ulHorzRes == 600){
  634. if(lpApdl->fOrientation){ // portrait
  635. wWidth = (WORD)lpApdl->szlPhysSize.cx - (0x5e * 2);
  636. wHeight= (WORD)lpApdl->szlPhysSize.cy - (0x5e * 2);
  637. } else { // landscape
  638. wWidth = (WORD)lpApdl->szlPhysSize.cy - (0x5e * 2);
  639. wHeight= (WORD)lpApdl->szlPhysSize.cx - (0x5e * 2);
  640. }
  641. } else {
  642. if(lpApdl->fOrientation){ // portrait
  643. wWidth = (WORD)lpApdl->szlPhysSize.cx - (0x2f * 2);
  644. wHeight= (WORD)lpApdl->szlPhysSize.cy - (0x2f * 2);
  645. } else { // landscape
  646. wWidth = (WORD)lpApdl->szlPhysSize.cy - (0x2f * 2);
  647. wHeight= (WORD)lpApdl->szlPhysSize.cx - (0x2f * 2);
  648. }
  649. }
  650. }
  651. /* set value of width, height into DefineDrawingArea command */
  652. CmdDefDrawArea[9] = (BYTE)(wWidth >> 8 & 0x00ff);
  653. CmdDefDrawArea[10] = (BYTE)(wWidth & 0x00ff);
  654. CmdDefDrawArea[11] = (BYTE)(wHeight >> 8 & 0x00ff);
  655. CmdDefDrawArea[12] = (BYTE)(wHeight & 0x00ff);
  656. /* set value of Origin-X, Y into DefineDrawingArea command */
  657. if(lpApdl->ulHorzRes == 600){
  658. CmdDefDrawArea[5] = CmdDefDrawArea[7] = 0x00;
  659. CmdDefDrawArea[6] = CmdDefDrawArea[8] = 0x5e;
  660. } else {
  661. CmdDefDrawArea[5] = CmdDefDrawArea[7] = 0x00;
  662. CmdDefDrawArea[6] = CmdDefDrawArea[8] = 0x2f;
  663. }
  664. /* set Media Origin into DefineDrawingArea command */
  665. if(lpApdl->fOrientation) // portrait
  666. CmdDefDrawArea[15] = 0x00;
  667. else { // landscape
  668. if( wCmdCbId==50 || wCmdCbId==54 || wCmdCbId==61)
  669. CmdDefDrawArea[15] = 0x01; // A3 or B4 or Unfixed
  670. else
  671. CmdDefDrawArea[15] = 0x03;
  672. }
  673. return bIndex;
  674. }
  675. /*****************************************************************************/
  676. /* */
  677. /* Module: BRL_Ecmd */
  678. /* */
  679. /* Function: ByteRunLength(HBP) Compression Routine */
  680. /* */
  681. /* Syntax: WORD PASCAL BRL_Ecmd(LPBYTE, LPBYTE, LPBYTE, WORD) */
  682. /* */
  683. /* Input: lpbSrc */
  684. /* lpbTgt */
  685. /* lpbTmp */
  686. /* len */
  687. /* */
  688. /* Output: WORD */
  689. /* */
  690. /* Notice: */
  691. /* */
  692. /*****************************************************************************/
  693. WORD PASCAL BRL_ECmd(LPBYTE lpbSrc, LPBYTE lpbTgt, LPBYTE lpbTmp, WORD len)
  694. {
  695. BYTE bRCnt = 1; // repeating byte counter
  696. BYTE bNRCnt = 0; // non-repeating byte counter
  697. BYTE bSaveRCnt;
  698. WORD i = 0, j = 0, k = 0, l = 0; // movement trackers
  699. char Go4LastByte = TRUE; // flag to get last byte
  700. /* initialize data */
  701. _fmemcpy(lpbTmp,(LPBYTE)lpbSrc,len);
  702. /* start compression routine - ByteRunLength Encoding */
  703. do {
  704. if(lpbSrc[i] != (lpbSrc[i+1])) { // non-repeating data?
  705. while(((lpbTmp[i] != (lpbTmp[i+1]))
  706. && ((i+1) < len)) && (bNRCnt < NRPEAK)) {
  707. bNRCnt++; // if so, how many?
  708. i++;
  709. }
  710. /* if at last element but less than NRPEAK value */
  711. if(((i+1)==len) && (bNRCnt<NRPEAK)) {
  712. bNRCnt++; // inc count for last element
  713. Go4LastByte = FALSE; // no need to go back
  714. } else
  715. /* if at last BYTE, but before that, NRPEAK value has been reached */
  716. if(((i+1)==len) && ((bNRCnt)==NRPEAK))
  717. Go4LastByte = TRUE; // get the last BYTE
  718. /* assign the value for Number of Non-repeating bytes */
  719. lpbTgt[j] = bNRCnt-1; // subtract one for WinP's case
  720. j++; // update tracker
  721. /* afterwards...write the Raw Data */
  722. for (l=0; l<bNRCnt;l++) {
  723. lpbTgt[j] = lpbSrc[k];
  724. k++;
  725. j++;
  726. }
  727. /* reset counter */
  728. bNRCnt = 0;
  729. } else { // end of Non-repeating data
  730. // data is repeating
  731. while(((lpbTmp[i]==(lpbTmp[i+1])) && ((i+1)<len)) && (bRCnt<RPEAK)) {
  732. bRCnt++;
  733. i++;
  734. }
  735. /* Convert to Two's Complement */
  736. bSaveRCnt = bRCnt; // save original value
  737. bRCnt = (BYTE) 0 - bRCnt;
  738. /* Write the Number of Repeating Data */
  739. lpbTgt[j] = bRCnt + 1; // add one for WinP's case
  740. j++; // go to next element
  741. /* afterwards...write the Repeating data */
  742. lpbTgt[j] = lpbSrc[k];
  743. j++;
  744. /* update counters */
  745. k += bSaveRCnt;
  746. bRCnt = 1;
  747. i += 1;
  748. /* check if last element has been reached */
  749. if (i==len)
  750. Go4LastByte=FALSE; // if so, no need to go back
  751. } // end of Repeating data
  752. } while (Go4LastByte); // end of Compression
  753. return ( j );
  754. }
  755. /*****************************************************************************/
  756. /* */
  757. /* Module: fnOEMGetFontCmd */
  758. /* */
  759. /* Function: */
  760. /* */
  761. /* Syntax: BOOL fnOEMGetFontCmd(LPDV, WORD, PVOID, BOOL, PBYTE, PWORD) */
  762. /* */
  763. /* Input�F lpdv */
  764. /* wCmdCbId */
  765. /* lpFont */
  766. /* fSelect */
  767. /* lpBuf */
  768. /* lpwSize */
  769. /* */
  770. /* Output�F */
  771. /* */
  772. /* Notice�F */
  773. /* */
  774. /* History�F 1996.05.20 Ver 1.00 */
  775. /* */
  776. /*****************************************************************************/
  777. BOOL PASCAL OEMGetFontCmd(LPDV lpdv, WORD wCmdCbId, PVOID lpFont,
  778. BOOL fSelect, PBYTE lpBuf, PWORD lpwSize)
  779. {
  780. return (TRUE);
  781. }