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.

564 lines
19 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. // Copyright (C) 1994-1995 Microsoft Corporation
  8. // Copyright (C) 1995 Advanced Peripherals Technologies, Inc.
  9. //-----------------------------------------------------------------------------
  10. char *rgchModuleName = "PAGESMS";
  11. #define PRINTDRIVER
  12. #include <print.h>
  13. #include "mdevice.h"
  14. #include "gdidefs.inc"
  15. #include "unidrv.h"
  16. #include <memory.h>
  17. #ifndef _INC_WINDOWSX
  18. #include <windowsx.h>
  19. #endif
  20. #define CCHMAXCMDLEN 128
  21. #define MAXIMGSIZE 0x7FED /* GDI����CBFilterGraphics�ɑ������Ă��� */
  22. /* �ް���1ײݕ������A�Ƃ肠����ESX86�ő��M */
  23. /* �”\�ȍő�IMAGE���ނ��p�ӂ��Ă����B */
  24. /* 0x7FFF - 18 = 7FED byte */
  25. /*_ �޲����ݸ޽ ���kٰ�� */
  26. extern WORD FAR PASCAL RL_ECmd(LPBYTE, LPBYTE, WORD);
  27. /*_ ���ݸ޽4 ���kٰ�� */
  28. extern WORD FAR PASCAL RL4_ECmd (LPBYTE, LPBYTE, WORD, WORD, WORD);
  29. typedef struct
  30. {
  31. BYTE fGeneral; // General purpose bitfield
  32. BYTE bCmdCbId; // Callback ID; 0 iff no callback
  33. WORD wCount; // # of EXTCD structures following
  34. WORD wLength; // length of the command
  35. } CD, *PCD, FAR * LPCD;
  36. typedef struct tagPAGES {
  37. short sHorzRes;
  38. short sVertRes;
  39. LPSTR lpCompBuf; // ���k�ް���ޯ̧
  40. } PAGES, FAR * LPPAGES;
  41. static BYTE ShiftJisPAGES[256] = {
  42. // +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F
  43. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //00
  44. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //10
  45. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //20
  46. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //30
  47. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //40
  48. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //50
  49. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //60
  50. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //70
  51. 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, //80
  52. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, //90
  53. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //A0
  54. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //B0
  55. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //C0
  56. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //D0
  57. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, //E0
  58. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 //F0
  59. };
  60. static BYTE ESC_VERT_ON[] = "\x1B\x7E\x0E\x00\x01\x0B";
  61. static BYTE ESC_VERT_OFF[] = "\x1B\x7E\x0E\x00\x01\x0C";
  62. short usHorzRes;
  63. short usVertRes;
  64. #ifndef WINNT
  65. BYTE NEAR __loadds IsDBCSLeadBytePAGES(BYTE Ch)
  66. #else
  67. BYTE NEAR IsDBCSLeadBytePAGES(BYTE Ch)
  68. #endif
  69. {
  70. return ShiftJisPAGES[Ch];
  71. }
  72. #ifdef WINNT
  73. LPWRITESPOOLBUF WriteSpoolBuf;
  74. LPALLOCMEM UniDrvAllocMem;
  75. LPFREEMEM UniDrvFreeMem;
  76. #endif // WINNT
  77. //---------------------------*OEMSendScalableFontCmd*--------------------------
  78. // Action: send Pages-style font selection command.
  79. //-----------------------------------------------------------------------------
  80. VOID FAR PASCAL OEMSendScalableFontCmd(lpdv, lpcd, lpFont)
  81. LPDV lpdv;
  82. LPCD lpcd; // offset to the command heap
  83. LPFONTINFO lpFont;
  84. {
  85. LPSTR lpcmd;
  86. short ocmd;
  87. WORD i;
  88. BYTE rgcmd[CCHMAXCMDLEN]; // build command here
  89. LPPAGES lpPages = lpdv->lpMdv;
  90. if (!lpcd || !lpFont)
  91. return;
  92. // be careful about integer overflow.
  93. lpcmd = (LPSTR)(lpcd+1);
  94. ocmd = 0;
  95. for (i = 0; i < lpcd->wLength && ocmd < CCHMAXCMDLEN; )
  96. if (lpcmd[i] == '#' && lpcmd[i+1] == 'V') // height
  97. {
  98. WORD height;
  99. height = (lpFont->dfPixHeight - lpFont->dfInternalLeading)
  100. * (1440 / lpFont->dfVertRes);
  101. rgcmd[ocmd++] = HIBYTE(height);
  102. rgcmd[ocmd++] = LOBYTE(height);
  103. i += 2;
  104. }
  105. else if (lpcmd[i] == '#' && lpcmd[i+1] == 'L') // pitch
  106. {
  107. WORD height;
  108. height = lpFont->dfPixHeight * (1440 / lpFont->dfVertRes);
  109. rgcmd[ocmd++] = HIBYTE(height);
  110. rgcmd[ocmd++] = LOBYTE(height);
  111. i += 2;
  112. }
  113. else if (lpcmd[i] == '#' && lpcmd[i+1] == 'H') // width
  114. {
  115. if (lpFont->dfPixWidth > 0)
  116. {
  117. short tmpWidth;
  118. tmpWidth = lpFont->dfMaxWidth * (1440 / lpFont->dfVertRes);
  119. rgcmd[ocmd++] = HIBYTE(tmpWidth);
  120. rgcmd[ocmd++] = LOBYTE(tmpWidth);
  121. }
  122. i += 2;
  123. }
  124. else if (lpcmd[i] == '#' && lpcmd[i+1] == 'P') // pitch
  125. {
  126. if (lpFont->dfPixWidth > 0)
  127. {
  128. short sWidth = (lpFont->dfMaxWidth * (1440/lpPages->sHorzRes));
  129. rgcmd[ocmd++] = HIBYTE(sWidth);
  130. rgcmd[ocmd++] = LOBYTE(sWidth);
  131. }
  132. i += 2;
  133. }
  134. else
  135. rgcmd[ocmd++] = lpcmd[i++];
  136. WriteSpoolBuf(lpdv, (LPSTR) rgcmd, ocmd);
  137. }
  138. //----------------------------*OEMScaleWidth*--------------------------------
  139. // Action: return the scaled width which is calcualted based on the
  140. // assumption that ESC\Page assumes 72 points in one 1 inch.
  141. //
  142. // Formulas:
  143. // <extent> : <font units> = <base Width> : <hRes>
  144. // <base width> : <etmMasterHeight> = <newWidth> : <newHeight>
  145. // <etmMasterUnits> : <etmMasterHeight> = <font units> : <vRes>
  146. // therefore,
  147. // <newWidth> = (<extent> * <hRes> * <newHeight>) /
  148. // (<etmMasterUnits> * <vRes>)
  149. //---------------------------------------------------------------------------
  150. short FAR PASCAL OEMScaleWidth(width, masterUnits, newHeight, vRes, hRes)
  151. short width; // in units specified by 'masterUnits'.
  152. short masterUnits;
  153. short newHeight; // in units specified by 'vRes'.
  154. short vRes, hRes; // height and width device units.
  155. {
  156. DWORD newWidth10;
  157. short newWidth;
  158. // assert that hRes == vRes to avoid overflow problem.
  159. if (vRes != hRes)
  160. return 0;
  161. newWidth10 = (DWORD)width * (DWORD)newHeight * 10;
  162. newWidth10 /= (DWORD)masterUnits;
  163. // we multiplied 10 first in order to maintain the precision of
  164. // the width calcution. Now convert it back and round to the
  165. // nearest integer.
  166. newWidth = (short)((newWidth10 + 5) / 10);
  167. return newWidth;
  168. }
  169. #ifndef WINNT
  170. short FAR PASCAL __loadds OEMOutputChar( lpdv, lpstr, len, rcID)
  171. #else
  172. short FAR PASCAL OEMOutputChar( lpdv, lpstr, len, rcID)
  173. #endif
  174. LPDV lpdv;
  175. LPSTR lpstr;
  176. short len;
  177. short rcID;
  178. {
  179. short rSize = 0;
  180. if (rcID == 6 || rcID == 8)
  181. {
  182. LPSTR lpChar = lpstr,
  183. lpStrTmp = lpstr;
  184. WORD fLeadByteFlag = TRUE;
  185. int i, j;
  186. for (i = 0,j = 0; i < len; j ++, i++, lpChar++)
  187. {
  188. if (!IsDBCSLeadBytePAGES((BYTE)*lpChar)) // SBCS
  189. {
  190. if (fLeadByteFlag)
  191. {
  192. WriteSpoolBuf(lpdv, lpStrTmp, j);
  193. WriteSpoolBuf(lpdv, ESC_VERT_OFF, sizeof(ESC_VERT_OFF));
  194. lpStrTmp += j;
  195. j = 0;
  196. fLeadByteFlag = FALSE;
  197. rSize += sizeof(ESC_VERT_OFF);
  198. }
  199. }
  200. else // DBCS
  201. {
  202. if (!fLeadByteFlag)
  203. {
  204. WriteSpoolBuf(lpdv, lpStrTmp, j);
  205. WriteSpoolBuf(lpdv, ESC_VERT_ON, sizeof(ESC_VERT_ON));
  206. lpStrTmp += j;
  207. j = 0;
  208. fLeadByteFlag = TRUE;
  209. rSize += sizeof(ESC_VERT_ON);
  210. }
  211. j ++; i++; lpChar++;
  212. }
  213. }
  214. WriteSpoolBuf(lpdv, lpStrTmp, j);
  215. }
  216. else
  217. WriteSpoolBuf(lpdv, lpstr, len);
  218. return len+rSize;
  219. }
  220. #ifndef WINNT
  221. short FAR PASCAL Enable( lpdv, style, lpModel, lpPort, lpStuff)
  222. LPDV lpdv;
  223. WORD style;
  224. LPSTR lpModel;
  225. LPSTR lpPort;
  226. LPDM lpStuff;
  227. {
  228. CUSTOMDATA cd;
  229. short sRet;
  230. LPPAGES lpPages;
  231. cd.cbSize = sizeof( CUSTOMDATA );
  232. cd.hMd = GetModuleHandle( (LPSTR)rgchModuleName );
  233. cd.fnOEMDump = NULL;
  234. cd.fnOEMOutputChar = (LPFNOEMOUTPUTCHAR)OEMOutputChar;
  235. // In order to the Style vlalue, following process is performed.
  236. // 0x0000 Initialize device block.
  237. // 0x0001 Inquire Device GDIINFO.
  238. // 0x8000 Initialize device block without output. CreateIC()
  239. // 0x8001 Inquire Device GDIINFO without output. CreateIC()
  240. sRet = UniEnable( lpdv, style, lpModel, lpPort, lpStuff, &cd );
  241. if (style == 0x0000)
  242. {
  243. lpdv->fMdv = FALSE;
  244. if (!(lpPages = lpdv->lpMdv = GlobalAllocPtr(GHND,sizeof(PAGES))))
  245. {
  246. UniDisable( lpdv );
  247. return FALSE;
  248. }
  249. lpdv->fMdv = TRUE;
  250. lpPages->sHorzRes = usHorzRes;
  251. lpPages->sVertRes = usVertRes;
  252. } else
  253. if( style == 0x0001)
  254. {
  255. //INQUIREINFO
  256. usHorzRes = ((LPGDIINFO)lpdv)->dpAspectX;
  257. usVertRes = ((LPGDIINFO)lpdv)->dpAspectY;
  258. }
  259. return sRet;
  260. }
  261. //-------------------------------------------------------------------
  262. // Function: Disable()
  263. // Action : free Mdv and call Mdv
  264. //-------------------------------------------------------------------
  265. void FAR PASCAL Disable(lpdv)
  266. LPDV lpdv;
  267. {
  268. if (lpdv->fMdv)
  269. {
  270. GlobalFreePtr (lpdv->lpMdv);
  271. lpdv->fMdv = FALSE;
  272. }
  273. UniDisable(lpdv);
  274. }
  275. #else //WINNT
  276. /*************************** Function Header *******************************
  277. * MiniDrvEnablePDEV
  278. *
  279. * HISTORY:
  280. * 30 Apl 1996 -by- Sueya Sugihara [sueyas]
  281. * Created it, from NT/DDI spec.
  282. *
  283. ***************************************************************************/
  284. BOOL
  285. MiniDrvEnablePDEV(
  286. LPDV lpdv,
  287. ULONG *pdevcaps)
  288. {
  289. LPPAGES lpPages;
  290. usHorzRes = (short)((PGDIINFO)pdevcaps)->ulAspectX;
  291. usVertRes = (short)((PGDIINFO)pdevcaps)->ulAspectY;
  292. lpdv->fMdv = FALSE;
  293. if (!(lpPages = lpdv->lpMdv = UniDrvAllocMem(sizeof(PAGES))))
  294. {
  295. return FALSE;
  296. }
  297. if (!(lpPages->lpCompBuf = UniDrvAllocMem(MAXIMGSIZE)))
  298. {
  299. return FALSE;
  300. }
  301. lpdv->fMdv = TRUE;
  302. lpPages->sHorzRes = usHorzRes;
  303. lpPages->sVertRes = usVertRes;
  304. return TRUE;
  305. }
  306. /*************************** Function Header *******************************
  307. * MiniDrvDisablePDEV
  308. *
  309. * HISTORY:
  310. * 30 Apl 1996 -by- Sueya Sugihara [sueyas]
  311. * Created it, from NT/DDI spec.
  312. *
  313. ***************************************************************************/
  314. VOID
  315. MiniDrvDisablePDEV(
  316. LPDV lpdv)
  317. {
  318. if (lpdv->fMdv)
  319. {
  320. UniDrvFreeMem(((LPPAGES)(lpdv->lpMdv))->lpCompBuf);
  321. UniDrvFreeMem(lpdv->lpMdv);
  322. lpdv->fMdv = FALSE;
  323. }
  324. }
  325. #endif //WINNT
  326. /*f***************************************************************************/
  327. /* PAGES PRINTER DRIVER for MS-Windows95 */
  328. /* */
  329. /* ���́F CBFilterGraphics */
  330. /* */
  331. /* �@�\�F �Ұ���ް���ESX86����ނ��g�p���ďo�͂����B */
  332. /* */
  333. /* �����F WORD FAR PASCAL CBFilterGraphics(lpdv, lpBuf, wLen) */
  334. /* */
  335. /* ���́F LPDV lpdv UNIDRV.DLL���g�p����PDEVICE�\���� */
  336. /* LPSTR lpBuf ׽�����̨����ް����ޯ̧���߲�� */
  337. /* WORD wLen lpBuf�̻���(�޲Đ�) */
  338. /* */
  339. /* */
  340. /* �o�́F return �o�͂����޲Đ� �@ */
  341. /* */
  342. /* ���L�F */
  343. /* */
  344. /* �����F 1995.11.xx Ver 1.00 */
  345. /*****************************************************************************/
  346. WORD FAR PASCAL CBFilterGraphics (lpdv, lpBuf, wLen)
  347. LPDV lpdv; // Points to private data required by the Unidriver.dll
  348. LPSTR lpBuf; // points to buffer of graphics data
  349. WORD wLen; // length of buffer in bytes
  350. {
  351. LPSTR lpCompImage;
  352. WORD wCompLen;
  353. LONG lHorzPixel;
  354. WORD wLength; // Let's use a temporary LEN
  355. LPPAGES lpPages = lpdv->lpMdv;
  356. //#define MAXIMGSIZE 0x7FED // 32K-18 bytes
  357. static BYTE params[] = {(0x1B), (0x7E), (0x86), 00,00, 01, 00, 00,00,00,00, 00,00,00,00, 00,00,00,00, 00,00,00,01};
  358. /*_ LPDV�ɕۊǂ����Ұ���ޯ̧���߲������� */
  359. lpCompImage = lpPages->lpCompBuf;
  360. /*_ �Ұ�ނ�i�������̻���ISIZ���v�Z�����B */
  361. lHorzPixel = (LONG)(wLen * 8);
  362. /*_ �C���[�W�f�[�^��Btye Run Length Algorithm�ň��k�B */
  363. wCompLen = RL_ECmd((LPBYTE)lpBuf, (LPBYTE)lpCompImage, wLen);
  364. /*_ ���k�����ް��̻��ނ�ESX86��LEN�ȊO�����Ұ����̻��ނ��������B */
  365. wLength = wCompLen + 18;
  366. /*_ ESX86�R�}���h��LEN���Z�b�g�B */
  367. params[3] = (BYTE) (wLength >>8 & 0x00ff); // get higher byte
  368. params[4] = (BYTE) (wLength & 0x00ff); // get lower byte
  369. /*_ ���k���@�̃p�����[�^��Byte Run Length�ɃZ�b�g�B */
  370. params[6] = 0x02;
  371. /*_ ESX86�R�}���h��ISIZ���Z�b�g�B */
  372. params[17] = (BYTE) (lHorzPixel >> 8 & 0x000000ffL); // get ISZ higher byte
  373. params[18] = (BYTE) (lHorzPixel & 0x000000ffL); // get ISZ lower byte
  374. /*_ ESX86�R�}���h���X�v�[���o�͂����B */
  375. WriteSpoolBuf((LPDV)lpdv, (LPSTR)params, 23);
  376. /*_ ���k���ꂽ�f�[�^���X�v�[���o�͂����B */
  377. WriteSpoolBuf((LPDV)lpdv, lpCompImage, wCompLen);
  378. return wLen;
  379. }
  380. // The following is implemented in MiniDrvEnablePDEV/DisablePDEV
  381. // on NT-J. We do not simulate Control DDI call, and it is not
  382. // guranteed that STARTOC, etc. always corresponds to minidriver
  383. // enable/disable.
  384. #ifndef WINNT
  385. /*f***************************************************************************/
  386. /* PAGES PRINTER DRIVER for MS-Windows95 */
  387. /* */
  388. /* ���́F Control */
  389. /* */
  390. /* �@�\�F Calls Escape function from applications */
  391. /* */
  392. /* �����F short FAR PASCAL Control(lpdv, nFunction, */
  393. /* lpInData, lpOutData) */
  394. /* */
  395. /* ���́F LPDV lpdv PDEVICE structure */
  396. /* WORD function Subfunction ID */
  397. /* LPSTR lpInData Input data */
  398. /* LPSTR lpOutData Output data */
  399. /* */
  400. /* �o�́F short ret Positive : Normal exit */
  401. /* Negative : Error exit */
  402. /* FALSE : No escape subfunction */
  403. /* */
  404. /* ���L�F nFunction and Escape numbers are the same */
  405. /* */
  406. /* �����F 1995.12.xx Ver 1.00 */
  407. /* */
  408. /*****************************************************************************/
  409. short FAR PASCAL Control(LPDV lpdv,
  410. WORD function,
  411. LPSTR lpInData,
  412. LPSTR lpOutData)
  413. {
  414. LPPAGES lpPages = lpdv->lpMdv;
  415. switch (function)
  416. {
  417. /*_ STARTDOC�̂Ƃ��́A���k�ް��p���ޯ̧���m�ۂ����B */
  418. case STARTDOC :
  419. lpPages->lpCompBuf = GlobalAllocPtr(GHND,MAXIMGSIZE);
  420. break;
  421. /*_ ABORTDOC,ENDDOC�̂Ƃ��́A���k�ް��p���ޯ̧�����������B */
  422. case ABORTDOC :
  423. case ENDDOC :
  424. GlobalFreePtr (lpPages->lpCompBuf);
  425. break;
  426. }
  427. /*_ UNIDRV��Control DDI����� */
  428. return UniControl(lpdv, function, lpInData, lpOutData);
  429. }
  430. #endif //!WINNT
  431. #ifdef WINNT
  432. DRVFN MiniDrvFnTab[] =
  433. {
  434. { INDEX_MiniDrvEnablePDEV, (PFN)MiniDrvEnablePDEV },
  435. { INDEX_MiniDrvDisablePDEV, (PFN)MiniDrvDisablePDEV },
  436. { INDEX_OEMWriteSpoolBuf, (PFN)CBFilterGraphics },
  437. { INDEX_OEMSendScalableFontCmd, (PFN)OEMSendScalableFontCmd },
  438. { INDEX_OEMScaleWidth1, (PFN)OEMScaleWidth },
  439. { INDEX_OEMOutputChar, (PFN)OEMOutputChar }
  440. };
  441. BOOL
  442. MiniDrvEnableDriver(
  443. MINIDRVENABLEDATA *pEnableData
  444. )
  445. {
  446. if (pEnableData == NULL)
  447. return FALSE;
  448. if (pEnableData->cbSize == 0)
  449. {
  450. pEnableData->cbSize = sizeof (MINIDRVENABLEDATA);
  451. return TRUE;
  452. }
  453. if (pEnableData->cbSize < sizeof (MINIDRVENABLEDATA)
  454. || HIBYTE(pEnableData->DriverVersion)
  455. < HIBYTE(MDI_DRIVER_VERSION))
  456. {
  457. // Wrong size and/or mismatched version
  458. return FALSE;
  459. }
  460. // Load callbacks provided by the Unidriver
  461. if (!bLoadUniDrvCallBack(pEnableData,
  462. INDEX_UniDrvWriteSpoolBuf, (PFN *) &WriteSpoolBuf)
  463. ||!bLoadUniDrvCallBack(pEnableData,
  464. INDEX_UniDrvAllocMem, (PFN *) &UniDrvAllocMem)
  465. ||!bLoadUniDrvCallBack(pEnableData,
  466. INDEX_UniDrvFreeMem, (PFN *) &UniDrvFreeMem))
  467. {
  468. return FALSE;
  469. }
  470. pEnableData->cMiniDrvFn
  471. = sizeof (MiniDrvFnTab) / sizeof(MiniDrvFnTab[0]);
  472. pEnableData->pMiniDrvFn = MiniDrvFnTab;
  473. return TRUE;
  474. }
  475. #endif //WINNT