home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / DATABASE / PRN_LIB.ZIP / PRN_LIB.PRG < prev    next >
Encoding:
Text File  |  1988-08-04  |  8.5 KB  |  334 lines

  1. *=============================================================================*
  2. *
  3. *  PRN_LIB:  Printer Control Function Library
  4. *
  5. *  These functions are part of a tutorial on printer control
  6. *  for the Twin Cities dBASE Compiler User Group.
  7. *
  8. *  Placed in the public domain by Craig Yellick, August 4, 1988,
  9. *  with no restictions on their use but no warranties on their
  10. *  performance.  You can incorporate them freely in your
  11. *  applications as long as you take responsibility for everything.
  12. *  I'd appreciate an ego-stroking credit if you lift these functions
  13. *  verbatim and sell products that use them, but who'd know for sure?
  14. *
  15. *  Author   Craig Yellick
  16. *           Yellick Computing
  17. *           509 Maple Square
  18. *           Wayazata, MN 55391-1036
  19. *           (612) 473-1805
  20. *
  21. *=============================================================================*
  22. *
  23. *  Contents (Alphabetically):
  24. *
  25. *  NextLine()    Print 1..N lines down, with left margin
  26. *  PageHead()    Print a page heading if conditions are right
  27. *  PgHd_Init()   Initialize the page header variables
  28. *  PrintOff()    Turn printer off, send exit string if needed
  29. *  PrintOn()     Turn printer on, send init string if needed
  30. *  Prn_Init()    Initialize printer control variables
  31. *  SameLine()    Print on current line, 0..N columns over
  32. *
  33. *  Various printer control functions:
  34. *
  35. *  Norm()     Bold()     Cond()     Large()     Italic()     UndScr()
  36. *  Norm_On()  Bold_On()  Cond_On()  Large_On()  Italic_On()  UndScr_On()
  37. *  Norm_Off() Bold_Off() Cond_Off() Large_Off() Italic_Off() UndScr_Off()
  38. *  PrnEject()
  39. *
  40. *=============================================================================*
  41. *
  42. *  See tutorial text for usage and implementation notes.
  43. *  See associated programs for sample code, README file has details.
  44. *
  45. *  Functions were written with Clipper, S'87 in mind but should work with
  46. *  any dBASE-syntax compiler that supports user-defined functions and
  47. *  at least one-dimensional arrays.  You could probably write around the
  48. *  use of arrays with some macro substitution if arrays bother you.
  49. *
  50. *=============================================================================*
  51.  
  52. function NextLine         && Print something 1..N lines down, with left margin
  53.  
  54. parameters how_many, what
  55.  
  56. ***  Clean up the parameters
  57. *
  58. do case
  59. case pcount() = 0
  60.   how_many= 1
  61.   what= []
  62. case pcount() = 1
  63.   what= []
  64. endcase
  65.  
  66. @ prow() +how_many, 00     say Norm(space(prn_lmar))    && Left margin
  67.  
  68. @ prow(), pcol() say what     && Whatever you sent to be printed (optional)
  69.  
  70. prn_line= prn_line +how_many  && Increment the line counter
  71.  
  72. return prow()
  73.  
  74. * end func NextLine
  75. *-----------------------------------------------------------------------------*
  76.  
  77. function PageHead              && Print a page heading if conditions are right
  78.  
  79. private did_eject
  80. did_eject= .f.    && Flag whether or not we actually eject
  81.  
  82. ***  It's time to eject if current_line +bottom_margin
  83. *    is beyond the page_length.
  84. *
  85. if (prn_line +prn_bmar) > prn_plen
  86.   did_eject= .t.
  87.   prn_page= prn_page +1
  88.   prn_line= 0
  89.   setprc(0,0)  && Force internal row/col counters to zero
  90.  
  91.   ***  Don't need to eject if it's the first page
  92.   *
  93.   if prn_first
  94.     prn_first= .f.
  95.     PrintOn()
  96.   else
  97.     PrnEject()
  98.   endif
  99.  
  100.   ***  Move down beyond the top margin
  101.   *
  102.   NextLine(prn_tmar)
  103.  
  104.   ***  Loop through the HEADER_ array and print each line
  105.   *
  106.   private i
  107.   for i= 1 to len(header_)
  108.     NextLine(1, header_[i])
  109.   next
  110.   
  111.   ***  New current line is the top_margin plus the length of the header.
  112.   *
  113.   prn_line= prn_tmar +i
  114.  
  115. endif
  116.  
  117. return did_eject
  118.  
  119. * end func PageHead
  120. *-----------------------------------------------------------------------------*
  121.  
  122. function PgHd_Init                     && Initialize the page header variables
  123.  
  124. ***  Make sure every proc hears about this
  125. *
  126. public prn_first, prn_line, prn_page
  127.  
  128. ***  Init PageHead() variables to default values
  129. *
  130. prn_first= .t.    && We starting are on the first page
  131. prn_page=  0      && Page will be incremented by one in PageHead()
  132. prn_line=  99999  && Force initial page header
  133.  
  134. return []
  135.  
  136. * end func PgHd_Init
  137. *-----------------------------------------------------------------------------*
  138.  
  139. function PrintOff              && Turn printer off, send exit string if needed
  140.  
  141. SameLine(0, prn_exit)
  142. set device to screen
  143.  
  144. return []
  145.  
  146. * end func PrintOff
  147. *-----------------------------------------------------------------------------*
  148.  
  149. function PrintOn                && Turn printer on, send init string if needed
  150.  
  151. set device to print
  152. SameLine(0, prn_init)
  153.  
  154. return []
  155.  
  156. * end func PrintOn
  157. *-----------------------------------------------------------------------------*
  158.  
  159. function Prn_Init                      && Initialize printer control variables
  160. parameters  model
  161.  
  162. ***  All procs need to know about these
  163. *
  164. public prn_norm1, prn_cond1, prn_bold1, prn_larg1, prn_ital1, prn_und1
  165. public prn_norm0, prn_cond0, prn_bold0, prn_larg0, prn_ital0, prn_und0
  166. public prn_model, prn_init,  prn_exit,  prn_eject
  167. public prn_lmar,  prn_rmar,  prn_xmar,  prn_tmar
  168. public prn_bmar,  prn_hmar,  prn_fmar,  prn_plen, prn_line, prn_page
  169.  
  170. ***  Store null string to all controls
  171. *
  172. store [] to prn_model, prn_init,  prn_exit,  prn_eject
  173. store [] to prn_norm1, prn_cond1, prn_bold1, prn_larg1, prn_ital1, prn_und1
  174. store [] to prn_norm0, prn_cond0, prn_bold0, prn_larg0, prn_ital0, prn_und0
  175.  
  176. ***  Establish reasonable defaults for important variables
  177. *
  178. prn_model= "MONO-FONT ASCII"
  179. *
  180. prn_eject= chr(12) +chr(13)  && ^L FormFeed + ^M Carriage Return (flush buffer)
  181. prn_cond1= chr(15)           && ^O Condensed-On for most printers
  182. prn_cond0= chr(18)           && ^R Condensed-Off
  183. *
  184. prn_lmar= 0
  185. prn_rmar= 80
  186. prn_xmar= 132
  187. prn_tmar= 3
  188. prn_bmar= 5
  189. prn_hmar= 0
  190. prn_fmar= 0
  191. prn_plen= 66
  192. prn_line= 0
  193. prn_page= 0
  194.  
  195. ***  Load custom values if any are found.
  196. *    Set flag depending on successful load.
  197. *
  198. private is_custom
  199. is_custom= .f.
  200. if pcount() > 0
  201.   if file("&MODEL..MEM")              && Yes, you need TWO periods.
  202.     restore from &MODEL. additive     && The first terminates the macro.
  203.     is_custom= .t.
  204.   endif
  205. else
  206.   if file("PRINTER.MEM")
  207.     restore from PRINTER additive
  208.     is_custom= .t.
  209.   endif
  210. endif
  211.  
  212. ***  Return YES if we loaded a custom set
  213. *    or NO if we are using the defaults.
  214. *
  215. return is_custom
  216.  
  217. * end func Prn_Init
  218. *-----------------------------------------------------------------------------*
  219.  
  220. function SameLine                  && Print on current line, 0..N columns over
  221.  
  222. parameters cols_over, what, with_pict
  223.  
  224. ***  Nothing to print, just move the print head
  225. *
  226. if pcount() < 2
  227.   @ prow(), pcol() +cols_over say []
  228.   what= []
  229.  
  230. else
  231.   ***  Unformatted data, just print it
  232.   *
  233.   if pcount() < 3
  234.     @ prow(), pcol() +cols_over say what
  235.  
  236.   ***  Formatted data, print using the template
  237.   *
  238.   else
  239.     @ prow(), pcol() +cols_over say what pict "&with_pict."
  240.   endif
  241. endif
  242.  
  243. return pcol()
  244.  
  245. * end func SameLine
  246. *-----------------------------------------------------------------------------*
  247. *
  248. *  Various Printer Control Functions
  249. *
  250. *  Norm()     Bold()     Cond()     Large()     Italic()     UndScr()
  251. *  Norm_On()  Bold_On()  Cond_On()  Large_On()  Italic_On()  UndScr_On()
  252. *  Norm_Off() Bold_Off() Cond_Off() Large_Off() Italic_Off() UndScr_Off()
  253. *  PrnEject()
  254.  
  255. function  Norm
  256. parameter s
  257. return prn_norm1 +s +prn_norm0
  258.  
  259. function  Bold
  260. parameter s
  261. return prn_bold1 +s +prn_bold0
  262.  
  263. function  Cond
  264. parameter s
  265. return prn_cond1 +s +prn_cond0
  266.  
  267. function  Large
  268. parameter s
  269. return prn_larg1 +s +prn_larg0
  270.  
  271. function  Italic
  272. parameter s
  273. return prn_ital1 +s +prn_ital0
  274.  
  275. function  UndScr
  276. parameter s
  277. return prn_und1 +s +prn_und0
  278.  
  279. function Norm_ON
  280. SameLine(0, prn_norm1)
  281. return []
  282.  
  283. function Norm_OFF
  284. SameLine(0, prn_norm0)
  285. return []
  286.  
  287. function Bold_ON
  288. SameLine(0, prn_bold1)
  289. return []
  290.  
  291. function Bold_OFF
  292. SameLine(0, prn_bold0)
  293. return []
  294.  
  295. function Cond_ON
  296. SameLine(0, prn_cond1)
  297. return []
  298.  
  299. function Cond_OFF
  300. SameLine(0, prn_cond0)
  301. return []
  302.  
  303. function Large_ON
  304. SameLine(0, prn_larg1)
  305. return []
  306.  
  307. function Large_OFF
  308. SameLine(0, prn_larg0)
  309. return []
  310.  
  311. function Italic_ON
  312. SameLine(0, prn_ital1)
  313. return []
  314.  
  315. function Italic_OFF
  316. SameLine(0, prn_ital0)
  317. return []
  318.  
  319. function UndScr_ON
  320. SameLine(0, prn_und1)
  321. return []
  322.  
  323. function UndScr_OFF
  324. SameLine(0, prn_und0)
  325. return []
  326.  
  327. function PrnEject
  328. SameLine(0, prn_eject)
  329. return []
  330.  
  331. * end of various printer control functions
  332. *-----------------------------------------------------------------------------*
  333. * eof Prn_Lib.Prg
  334.