home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_PAS / AJCPRT.ZIP / AJCPRNTW.DOC next >
Text File  |  1994-01-16  |  8KB  |  263 lines

  1. AJCPrntW - Printer Unit for Windows
  2.  
  3.  
  4.  
  5. This unit was written using Borland International's Borland
  6. Pascal v7.0, and the Object Windows Library (OWL) provided with
  7. that product.
  8.  
  9.  
  10.  
  11. I have not copyrighted this program, and donate it to the public
  12. domain.  All portions of this program may be used, modified,
  13. and/or distributed, in whole or in part.
  14.  
  15.  
  16.  
  17. I wrote this unit to provide myself with some reusible functions
  18. that would help me out in preparing printed hard copy from an
  19. OWL program.  I am just a "hobby" programmer, having written
  20. nothing for anyone but myself.  Therefore, this unit may not be
  21. comprehensive, or even particularly robust.  However, it has met
  22. my own needs, and it may actually be usefull to someone
  23. else--besides, it's free!  I am open to suggestions, comments,
  24. or enhancements (although, I can't promise quick turn around
  25. because I have a real job, plus I teach, plus I have a
  26. family--then I code for fun--in that order <grin>).
  27.  
  28.  
  29.  
  30. This unit provides two objects that are descended from the
  31. printing objects provided by OWL.
  32.  
  33.  
  34.  
  35. TAJCPrinter
  36.  
  37.  
  38.  
  39. TAJCPrinter is descended from TPrinter.  It provides a single
  40. additional method, SetPageOrientation.
  41.  
  42.  
  43.  
  44. SetPageOrientation
  45.  
  46.  
  47.  
  48. SetPageOrientation takes a single parameter, Orientation. 
  49. Orientation is an Integer parameter that indicates whether the
  50. orientation should be portrait or landscape.  You can use the
  51. constants dmOrient_Portrait and dmOrient_Landscape, which are
  52. provided by WinTypes.
  53.  
  54.  
  55.  
  56. SetPageOrientation returns an integer value which indicates the
  57. success or failure of the call.  -1 indicates failure, while 0
  58. indicates success.
  59.  
  60.  
  61.  
  62. As far as I have determined, SetPageOrientation can be called
  63. anytime after the object has been initialized with the inherited
  64. Init method.
  65.  
  66.  
  67.  
  68. As currently coded, it only works with printer drivers that
  69. support ExtDeviceMode, and it doesn't bother to check for the
  70. device's capabilities first.
  71.  
  72.  
  73.  
  74. TAJCPrinOut
  75.  
  76.  
  77.  
  78. TAJCPrintOut is descended from TPrintOut.  It provides five
  79. additional data attributes, overrides three methods, and
  80. provides ten new methodes.
  81.  
  82. VUnitsPerInch:  Integer
  83.  
  84. VUnitsPerInch contains the number of Logical Device Units per
  85. Logical Inch in the vertical direction on the device.
  86.  
  87. HUnitsPerInch:  Integer
  88.  
  89. HUnitsPerInch contains the number of Logical Device Units per
  90. Logical Inch in the horizontal direction on the device.
  91.  
  92. LMarginUnits:  Integer
  93.  
  94. The number of Logical Device Units in the unprintable left
  95. margin of the physical device.  (This value can also be assumed
  96. to represent the size of the unprintable right margin.
  97.  
  98. RMarginUnits:  Integer
  99.  
  100. The number of Logical Device Units in the unprintable top margin
  101. of the physical device.  (This value can also be assumed to
  102. represent the size of the unprintable bottom margin.
  103.  
  104. OriginalAlignmentOptions:  Word
  105.  
  106. This word variable is a holder for the original text alignment
  107. options for the Device Context.  It is used to clean up the use
  108. of the Device Context by putting it back the way it was.  It is
  109. set by JustifyLeft, JustifyCenter, and JustifyRight.  If its
  110. value is zero, then none of the three Justify... methods have
  111. been called yet.
  112.  
  113. Init(ATitle: PChar);
  114.  
  115. Init calls the inherited Init, and initializes
  116. OriginalAlignmentOptions to zero.
  117.  
  118. Done
  119.  
  120. If OriginalAlignmentOptions is non-zero, then SetTextAlign is
  121. called to return the Text Alignment settings to their original
  122. state.
  123.  
  124.  
  125.  
  126. Next, the inherited Done is called.
  127.  
  128. SetPrintParams(ADC: HDC; ASize: TPoint);
  129.  
  130. After calling the inherited SetPrintParams, this SetPrintParams
  131. initializes the five data attributes described above with their
  132. working values.
  133.  
  134. VLogPos(Pos: Integer): Integer;
  135.  
  136. VLogPos takes an integer value that represents an X coordinate
  137. relative to the physical edge of the paper.  VLogPos returns an
  138. X coordinate that takes into account (that is, adjusts for) the
  139. unprintable part of the paper.
  140.  
  141.  
  142.  
  143. If Pos is negative, then it is considered to be relative to the
  144. right edge of the paper, otherwise it is assumed to be relative
  145. to the left edge of the paper.
  146.  
  147.  
  148.  
  149. For example, if Size.X is 40, and the size of the unprintable
  150. side margins are 3, then VLogPos(10) returns 7, and VLogPos(-10)
  151. returns 33.
  152.  
  153. HLogPos(Pos: Integer): Integer;
  154.  
  155. HLogPos takes an integer value that represents a Y coordinate
  156. relative to the physical edge of the paper.  HLogPos returns a Y
  157. coordinate that takes into account (that is, adjusts for) the
  158. unprintable part of the paper.
  159.  
  160.  
  161.  
  162. If Pos is negative, then it is considered to be relative to the
  163. bottom edge of the paper, otherwise itis assumed to be relative
  164. to the top edge of the paper.
  165.  
  166.  
  167.  
  168. For example, if Size.Y is 40, and the size of the unprintable
  169. top/bottom margins are 3, then HLogPos(10) returns 6, and
  170. HLogPos(-10) returns 33.
  171.  
  172. VInches(Inches: Real): Integer;
  173.  
  174. VInches takes a Real value that represents a number of inches
  175. (such as 1.5) and returns an integer value that represents the
  176. number of Logical Units in the virtical direction that would
  177. correspond to that number of inches.
  178.  
  179. HInches(Inches: Real): Integer;
  180.  
  181. HInches takes a Real value that represents a number of inches
  182. (such as 1.5) and returns an integer value that represents the
  183. number of Logical Units in the horizontal direction that would
  184. correspond to that number of inches.
  185.  
  186. (Notes on the usage of VLogPos, HLogPos, VInches, and HInches)
  187.  
  188. Here's an example of how I've been using these methods:
  189.  
  190.  
  191.  
  192. TextOut(DC, VLogPos(VInches(1.0)), HLogPos(HInches(1.0)), ....)
  193.  
  194.  
  195.  
  196. That will print text starting 1 inch down from the top edge of
  197. the paper, and 1 inch to the right of the left edge of the paper.
  198.  
  199. Points(APoints: Integer): Integer;
  200.  
  201. Points a text height, APoints, expressed in Points, and returns
  202. an integer value representing the number of Logical Units, in
  203. the vertical direction, that correspond to that number of points.
  204.  
  205. PrintHeader(Mode, Page: Word): Integer;
  206.  
  207. This is an abstract unit that should be overridden.  Mode should
  208. be passed one of the constant values pm_Size or pm_Print.  Page
  209. should represent the page number being printed.  PrintHeader
  210. should return an Integer value that represents the virtical size
  211. of the header in Logical Units.
  212.  
  213.  
  214.  
  215. If Mode is pm_Size, then PrintHeader should return the header
  216. size and nothing else.  If Mode is pm_Print, then PrintHeader
  217. should print the header AND return the size of the header.
  218.  
  219. PrintFooter(Mode, Page: Word): Integer;
  220.  
  221. This is an abstract unit that should be overridden.  Mode should
  222. be passed one of the constant values pm_Size of pm_Print.  Page
  223. should represent the page number being printed.  PrintFooter
  224. should return an Integer value that represents the virtical size
  225. of the footer in Logical Units.
  226.  
  227.  
  228.  
  229. If Mode is pm_Size, then PrintFooter should return the footer
  230. size and nothing else.  If Mode is pm_Print, then PrintFooter
  231. should print the footer AND return the size of the footer.
  232.  
  233. JustifyLeft;
  234.  
  235. JustifyLeft changes the text alignment options for the Device
  236. Context so that text printed with TextOut and ExtTextOut Left
  237. Justified.  This option remains in effect until JustifyCenter or
  238. JustifyRight are called.  If this is the first call to one of
  239. the Justify... methods, then the original alignment options are
  240. stored in OriginalAlignmentOptions so that they can be reset by
  241. the Done method.
  242.  
  243. JustifyCenter;
  244.  
  245. JustifyCenter changes the text alignment options for the Device
  246. Context so that text printed with TextOut and ExtTextOut
  247. Centered.  This option remains in effect until JustifyLeft or
  248. JustifyRight are called.  If this is the first call to one of
  249. the Justify... methods, then the original alignment options are
  250. stored in OriginalAlignmentOptions so that they can be reset by
  251. the Done method.
  252.  
  253. JustifyRight;
  254.  
  255. JustifyRight changes the text alignment options for the Device
  256. Context so that text printed with TextOut and ExtTextOut Right
  257. Justified.  This option remains in effect until Justify Left or
  258. JustifyCenter are called.  If this is the first call to one of
  259. the Justify... methods, then the original alignment options are
  260. stored in OriginalAlignmentOptions so that they can be reset by
  261. the Done method.
  262.  
  263.