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.

222 lines
7.3 KiB

  1. //----------------------------------------------------------------------------//
  2. // Filename: yjlbp.c //
  3. // //
  4. // This file contains code for using Scalable Fonts on Yangjae Page printers //
  5. // //
  6. // Copyright (c) 1992-1994 Microsoft Corporation //
  7. //----------------------------------------------------------------------------//
  8. //-----------------------------------------------------------------------------
  9. // This files contains the module name for this mini driver. Each mini driver
  10. // must have a unique module name. The module name is used to obtain the
  11. // module handle of this Mini Driver. The module handle is used by the
  12. // generic library to load in tables from the Mini Driver.
  13. //-----------------------------------------------------------------------------
  14. // Added code in OEMSendScalableFontCmd to check for English or
  15. // Hangeul Font Width command - Garydo 1/20/95
  16. char *rgchModuleName = "YJLBP";
  17. #define PRINTDRIVER
  18. #include <print.h>
  19. #include "mdevice.h"
  20. #include "gdidefs.inc"
  21. #include "unidrv.h"
  22. #include <memory.h>
  23. #ifndef _INC_WINDOWSX
  24. #include <windowsx.h>
  25. #endif
  26. #define CCHMAXCMDLEN 128
  27. typedef struct
  28. {
  29. BYTE fGeneral; // General purpose bitfield
  30. BYTE bCmdCbId; // Callback ID; 0 iff no callback
  31. WORD wCount; // # of EXTCD structures following
  32. WORD wLength; // length of the command
  33. } CD, *PCD, FAR * LPCD;
  34. #ifdef WINNT
  35. LPWRITESPOOLBUF WriteSpoolBuf;
  36. LPALLOCMEM UniDrvAllocMem;
  37. LPFREEMEM UniDrvFreeMem;
  38. #include <stdio.h>
  39. #ifdef wsprintf
  40. #undef wsprintf
  41. #endif // wsprint
  42. #define wsprintf sprintf
  43. #define GlobalAllocPtr(a,b) UniDrvAllocMem(b)
  44. #define GlobalFreePtr UniDrvFreeMem
  45. #endif //WINNT
  46. //----------------------------*OEMScaleWidth*--------------------------------
  47. // Action: return the scaled width which is calcualted based on the
  48. // assumption that Yangjae printers assume 72 points in one 1 inch.
  49. //
  50. // Formulas:
  51. // <extent> : <font units> = <base Width> : <hRes>
  52. // <base width> : <etmMasterHeight> = <newWidth> : <newHeight>
  53. // <etmMasterUnits> : <etmMasterHeight> = <font units> : <vRes>
  54. // therefore,
  55. // <newWidth> = (<extent> * <hRes> * <newHeight>) /
  56. // (<etmMasterUnits> * <vRes>)
  57. //---------------------------------------------------------------------------
  58. short FAR PASCAL OEMScaleWidth(width, masterUnits, newHeight, vRes, hRes)
  59. short width; // in units specified by 'masterUnits'.
  60. short masterUnits;
  61. short newHeight; // in units specified by 'vRes'.
  62. short vRes, hRes; // height and width device units.
  63. {
  64. DWORD newWidth10;
  65. short newWidth;
  66. // assert that hRes == vRes to avoid overflow problem.
  67. if (vRes != hRes)
  68. return 0;
  69. newWidth10 = (DWORD)width * (DWORD)newHeight * 10;
  70. newWidth10 /= (DWORD)masterUnits;
  71. // we multiplied 10 first in order to maintain the precision of
  72. // the width calcution. Now convert it back and round to the
  73. // nearest integer.
  74. newWidth = (short)((newWidth10 + 5) / 10);
  75. return newWidth;
  76. }
  77. //---------------------------*OEMSendScalableFontCmd*--------------------------
  78. // Action: send Qnix-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. if (!lpcd || !lpFont)
  90. return;
  91. // be careful about integer overflow.
  92. lpcmd = (LPSTR)(lpcd+1);
  93. ocmd = 0;
  94. for (i = 0; i < lpcd->wLength && ocmd < CCHMAXCMDLEN; )
  95. if (lpcmd[i] == '#' && lpcmd[i+1] == 'Y') // height
  96. {
  97. long height;
  98. // use 1/300 inch unit, which should have already been set.
  99. // convert font height to 1/300 inch units
  100. height = ((long)(lpFont->dfPixHeight - lpFont->dfInternalLeading)
  101. * 300) / lpFont->dfVertRes ;
  102. ocmd += wsprintf(&rgcmd[ocmd], "%ld", height);
  103. i += 2;
  104. }
  105. else if (lpcmd[i] == '#' && lpcmd[i+1] == 'X') // pitch
  106. {
  107. if (lpFont->dfPixWidth > 0)
  108. {
  109. long width;
  110. // Check if we are going to print an English Font, if so
  111. // then we use PixWidth, Else use MaxWidth which is
  112. // twice as wide in DBCS fonts.
  113. // Note: Command Format = '\x1B+#X;#Y;1C' or '\x1B+#X;#Y;2C'
  114. // Or, in text: ESC+<Width>;<Height>;<Font type>C
  115. // English Font type = 1, Korean Font = 2.
  116. if (lpcmd[i+6] == '1')
  117. width = ((long)(lpFont->dfPixWidth) * 300) / (lpFont->dfHorizRes);
  118. else
  119. width = ((long)(lpFont->dfMaxWidth) * 300) / (lpFont->dfHorizRes);
  120. ocmd += wsprintf(&rgcmd[ocmd], "%ld", width);
  121. }
  122. i += 2;
  123. }
  124. else
  125. rgcmd[ocmd++] = lpcmd[i++];
  126. WriteSpoolBuf(lpdv, (LPSTR) rgcmd, ocmd);
  127. }
  128. #ifdef WINNT
  129. DRVFN MiniDrvFnTab[] =
  130. {
  131. { INDEX_OEMScaleWidth1, (PFN)OEMScaleWidth },
  132. { INDEX_OEMSendScalableFontCmd, (PFN)OEMSendScalableFontCmd },
  133. };
  134. /*************************** Function Header *******************************
  135. * MiniDrvEnableDriver
  136. * Requests the driver to fill in a structure containing recognized
  137. * functions and other control information.
  138. * One time initialization, such as semaphore allocation may be
  139. * performed, but no device activity should happen. That is done
  140. * when dhpdevEnable is called.
  141. * This function is the only way the rasdd can determine what
  142. * functions we supply to it.
  143. *
  144. * HISTORY:
  145. * June 19, 1996 -by- Weibing Zhan [Weibz]
  146. * Created it, following KK Codes.
  147. *
  148. ***************************************************************************/
  149. BOOL
  150. MiniDrvEnableDriver(
  151. MINIDRVENABLEDATA *pEnableData
  152. )
  153. {
  154. if (pEnableData == NULL)
  155. return FALSE;
  156. if (pEnableData->cbSize == 0)
  157. {
  158. pEnableData->cbSize = sizeof (MINIDRVENABLEDATA);
  159. return TRUE;
  160. }
  161. if (pEnableData->cbSize < sizeof (MINIDRVENABLEDATA)
  162. || HIBYTE(pEnableData->DriverVersion)
  163. < HIBYTE(MDI_DRIVER_VERSION))
  164. {
  165. // Wrong size and/or mismatched version
  166. return FALSE;
  167. }
  168. // Load callbacks provided by the Unidriver
  169. if (!bLoadUniDrvCallBack(pEnableData,
  170. INDEX_UniDrvWriteSpoolBuf, (PFN *) &WriteSpoolBuf)
  171. || !bLoadUniDrvCallBack(pEnableData,
  172. INDEX_UniDrvAllocMem, (PFN *) &UniDrvAllocMem)
  173. || !bLoadUniDrvCallBack(pEnableData,
  174. INDEX_UniDrvFreeMem, (PFN *) &UniDrvFreeMem))
  175. {
  176. return FALSE;
  177. }
  178. pEnableData->cMiniDrvFn
  179. = sizeof (MiniDrvFnTab) / sizeof(MiniDrvFnTab[0]);
  180. pEnableData->pMiniDrvFn = MiniDrvFnTab;
  181. return TRUE;
  182. }
  183. #endif //WINNT