home *** CD-ROM | disk | FTP | other *** search
/ Sound Sensations! / sound_sensations.iso / cmf / laser / laser.prg < prev    next >
Encoding:
Text File  |  1989-12-03  |  14.5 KB  |  329 lines

  1. ********* 
  2. *
  3. *  laser.prg
  4. *
  5. *  HP LaserJet Routines to draw lines and boxes.
  6. *
  7. *  Written 12/89 by 
  8. *        Kevin Talbot
  9. *        KJT enterprises
  10. *        7632 SE 37th Place
  11. *        Mercer Island, WA 98040
  12. *        (206) 236-1060
  13. *        Compuserve ID: 75706,316 
  14. * These are "public domain" and are free for anyone to use or modify.
  15. * Acknowledgement of the author would be appreciated.
  16.  
  17.  
  18. * Notes:
  19. *
  20. *   All coordinates, lengths, widths, etc., for functions assume INCHES.
  21. *
  22. *   All "drawing" functions start with the current cursor position, so be 
  23. *   sure to "lj_gotoxy()" before calling a "draw" function.
  24. *
  25. *   All functions assume that "set print on" has been set previously as they
  26. *   all use the "??" command to send data to the printer. You may also want to
  27. *   "set console off" so the screen is not filled with lots of funny escape 
  28. *   codes.
  29. *
  30. *   All functions save and restore the current prow() and pcol() values so
  31. *   accuracy of "@ r,c" commands directed to the printer is maintained. These
  32. *   functions all send tons of escape codes to the printer which really fouls
  33. *   up the interal printer cursor positon pointer in Clipper! I have found
  34. *   it MUCH easier to dispense with '@ r,c' when using a laser printer and
  35. *   use the 'lj_say()' function instead. Since the LaserJet is a page printer,
  36. *   you can move the printer cursor anywhere you want without triggering a
  37. *   form feed from Clipper just because you moved the printe cursor 'back' or
  38. *   'up' from the present position.
  39. *
  40. *   The LaserJet fill patterns are specified as strings just as they
  41. *   are defined in the LaserJet technical manual. The fill pattern can be
  42. *   one of 7 shades of gray plus white and black or one of six regular line
  43. *   patterns. These routines differentiate between "gray" and "pattern" by
  44. *   having a pattern number prefix with a "#".
  45. *   Gray shades are specified as follows:
  46. *              "0" = 0% gray (white, only supported on the new LaserJet IIP!)
  47. *         "1".."2" = 2% gray 
  48. *        "3".."10" = 10% gray 
  49. *       "11".."20" = 20% gray 
  50. *       "21".."35" = 30% gray 
  51. *       "36".."55" = 45% gray 
  52. *       "56".."80" = 70% gray 
  53. *       "81".."99" = 90% gray
  54. *            "100" = 100% gray (black) 
  55. *
  56. *   Patterns are specified as follows:
  57. *       "#1" = horizontal lines
  58. *       "#2" = vertical lines
  59. *       "#3" = diagonal lines running from lower left to upper right
  60. *       "#4" = diagonal lines running from upper left to lower right 
  61. *       "#5" = orthogonal crosshatch (like #1 and #2 combined)
  62. *       "#6" = diagonal crosshatch (like #3 and #4 combined)
  63. *
  64. ******************************************************************************
  65. ******************************************************************************
  66.  
  67.  
  68. * Function summary:
  69.  
  70. *    lj_inch2dots(inches)                        Convert inches to printer dots
  71. *    lj_gotoxy(x,y)                              Absolute position in inches
  72. *    lj_gotorc(r,c)                              Absolute position in columns
  73. *    lj_move(delta_x,delta_y)                    Relative move 
  74. *    lj_fill(width,height,fill)                  Fills rectangular area
  75. *    lj_line(length,thickness,orientation,fill)  Draws lines
  76. *    lj_box(width,height,thickness,fill)         Draws boxes
  77. *    lj_say(row,col,string)                      Just like "@ R,C say..."
  78.  
  79. * These arguments are real numbers (inches:
  80. *    width, length, thickness, height, x, y, delta_x, delta_y, inches
  81.  
  82. * These arguments are character strings:
  83. *    fill, orientation, string
  84.  
  85. * These arguments are integers:
  86. *    row, col
  87.  
  88.  
  89.  
  90. *────────────────────────────────────────────────────────────────────────────┐
  91. * FUNCTION NAME: lj_inch2dots                                                │
  92. *    PARAMETERS: inches                                                      │
  93. *       RETURNS: Character string of the integer equivalent printer dots     │
  94. *                at 300 DPI.                                                 │
  95. *   DESCRIPTION: Obvious. Mainly intended for internal use.                  │
  96. *       EXAMPLE: foo = lj_inch2dots(3.56) [returns the string "1068"]        │
  97. *────────────────────────────────────────────────────────────────────────────┘
  98.  
  99. function lj_inch2dots
  100.   parameters inches
  101. return alltrim(str(300.0 * inches,10))
  102.  
  103.  
  104.  
  105.  
  106. *────────────────────────────────────────────────────────────────────────────┐
  107. * FUNCTION NAME: lj_gotoxy                      ∙──> +x                      │
  108. *    PARAMETERS: x & y location in inches       │                            │
  109. *       RETURNS: Nothing.                       V +y                         │
  110. *   DESCRIPTION: Moves LJ cursor to the absolute x and y values passed.      │
  111. *       EXAMPLE: lj_gotoxy(4.25,5.5)  [about the middle of the page]         │
  112. *────────────────────────────────────────────────────────────────────────────┘
  113.  
  114. function lj_gotoxy                                                           
  115.   parameters x, y      && real numbers in inches
  116.   private null, row
  117.   null = ""
  118.   ** save Clipper printer position pointer 
  119.   row = prow()           
  120.   col = pcol()
  121.   ?? chr(27) + "*p" + lj_inch2dots(x) + "x" + lj_inch2dots(y) + "Y"
  122.   ** restore Clipper printer position pointer 
  123.   setprc(row,col)         && restore printer row and col
  124. return null
  125.  
  126.  
  127.  
  128.  
  129. *────────────────────────────────────────────────────────────────────────────┐
  130. * FUNCTION NAME: lj_move                                ∙──> +x              │
  131. *    PARAMETERS: deltax, deltay (in inches)             │                    │
  132. *       RETURNS: Nothing.                               V +y                 │
  133. *   DESCRIPTION: Moves LJ "cursor" a relative amount.                        │
  134. *       EXAMPLE: lj_move(1.0,-2.5)  moves the cursor right 1.0" and up 2.5"  │
  135. *          NOTE: Positive amounts move the cursor right or down, negative    │
  136. *                move the cursor left or up.                                 │
  137. *────────────────────────────────────────────────────────────────────────────┘
  138.  
  139. function lj_move 
  140.   parameters dx, dy      && real numbers in inches
  141.   private null, row, col
  142.   null = ""
  143.   ** save Clipper printer position pointer 
  144.   row = prow()           
  145.   col = pcol()
  146.   ?? chr(27) + "*p" + if(dx >= 0.0,"+","") + lj_inch2dots(dx) + "x" + ;
  147.                       if(dy >= 0.0,"+","") + lj_inch2dots(dy) + "Y"
  148.   ** restore Clipper printer position pointer 
  149.   setprc(row,col)         
  150. return null
  151.  
  152.  
  153.  
  154.  
  155.  
  156. *─────────────────────────────────────────────────────────────────────────────┐
  157. * FUNCTION NAME: lj_fill                                                      │
  158. *    PARAMETERS: width, height, fill                                          │
  159. *       RETURNS: Nothing.                                                     │
  160. *   DESCRIPTION: Fills a rectangular area with the specified pattern at the   │
  161. *                current cursor positon. Specify a gray pattern by passing    │
  162. *                a string between "0" and "100" (0=white, 100=black, 1..99    │
  163. *                are levels of gray) or specify a fill pattern with "#1"      │
  164. *                "#6".                                                        │
  165. *       EXAMPLE: lj_fill(1.5, 2.5,"#6") will create a 1.5" wide by 2.5"       │
  166. *                high rectangle filled with HP pattern 6 (crosshatching).     │
  167. *─────────────────────────────────────────────────────────────────────────────┘
  168.  
  169. function lj_fill
  170.   parameters width, height, fill
  171.   private null, row, col, s
  172.   null = ""
  173.   * cleanup parameters
  174.   fill = alltrim(fill)
  175.   ** save Clipper printer position pointer 
  176.   row = prow()           
  177.   col = pcol()
  178.   s = chr(27) + "*c"                       && PCL prefix for area fill
  179.   s = s + lj_inch2dots(width) + "a"        && spec horizontal size....
  180.   s = s + lj_inch2dots(height) + "b"       && spec vertical size....
  181.   if left(fill,1) == "#"                   && fixed pattern is desired 
  182.     s = s + right(fill,1) + 'g3P'          && so strip the "#" character
  183.   else                                     && some shade of gray requested
  184.     if val(fill) = 0                       && "white" is spec'd differently
  185.       s = s + 'g1P'                        && white fill is LJ IIP specific! 
  186.     else                                   && gray or black fill
  187.       s = s + fill + 'g2P'  
  188.     endif
  189.   endif
  190.   ?? s                             && now send the entire string
  191.   setprc(row,col)                  && restore Clipper printer position pointer 
  192. return null
  193.  
  194.  
  195.  
  196. *─────────────────────────────────────────────────────────────────────────────┐
  197. * FUNCTION NAME: lj_line                                                      │
  198. *    PARAMETERS: length, thickness, orientation, fill                         │
  199. *       RETURNS: Nothing.                                                     │
  200. *   DESCRIPTION: Draws lines as specified either horizontal or vertical       │
  201. *                at the current cursor position with the specified fill       │
  202. *                pattern.                                                     │
  203. *          NOTE: A negative length will draw a line to the left               │
  204. *                or up from the current cursor position.                      │
  205. *       EXAMPLE: lj_line(2.5, .01, "H", "20")                                 │
  206. *                                                                             │
  207. *     ∙───────┐┬                         ∙┐┬                                  │
  208. *     └───────┘┼   "H" orientation       │││                                  │
  209. *     ├── L ──┤│                         ││L      "V" orientation             │
  210. *              └ T                       │││                                  │
  211. *                                        └┘┴                                  │
  212. *                                        ├┼─── T                              │
  213. *   ["∙" is the current cursor position]                                      │
  214. *─────────────────────────────────────────────────────────────────────────────┘
  215.  
  216. function lj_line
  217.   parameters length, thickness, orientation, fill
  218.   private null 
  219.   null = ""
  220.   * clean up parameters
  221.   thickness = abs(thickness)
  222.   orientation = upper(left(alltrim(orientation),1))           
  223.   fill = alltrim(fill)
  224.   * figure out how far (relative) we have to move first
  225.   * then use the lj_fill() function to do most of the work
  226.   do case
  227.     case orientation = "H"      
  228.        if length >= 0.0      
  229.          lj_fill(length, thickness, fill)       && draw to the right
  230.        else 
  231.          lj_move(length, 0.0)                   && move left first 
  232.          lj_fill(abs(length), thickness, fill)
  233.        endif
  234.     case orientation = "V" 
  235.        if length >= 0.0      
  236.          lj_fill(thickness, length, fill)       && draw downward 
  237.        else 
  238.          lj_move(0.0, length)                   && move up first 
  239.          lj_fill(thickness, abs(length), fill)
  240.        endif
  241.   endcase
  242. return null
  243.  
  244.  
  245.  
  246.  
  247. *────────────────────────────────────────────────────────────────────────────┐
  248. * FUNCTION NAME: lj_box                                                      │
  249. *    PARAMETERS: width, height, thickness, pattern                           │
  250. *       RETURNS: Nothing.                                                    │
  251. *   DESCRIPTION: Draws a rectangular box at the current cursor postion.      │
  252. *                The current cursor position is the uppe left hand corner.   │
  253. *       EXAMPLE: lj_box(4.0,1.0,.02,"20") will draw a box 4" wide, 1" high   │
  254. *                with .02" wide lines of 20% gray                            │
  255. *          NOTE: Using a gray pattern with thin lines (2 or 3 printer dots)  │
  256. *                sometimes results in invisible lines if you happen to be    │
  257. *                filling with the "white" part of the gray pattern!          │
  258. *────────────────────────────────────────────────────────────────────────────┘
  259.  
  260. function lj_box
  261.   parameters width, height, thickness, pattern
  262.   private null
  263.   null = ""
  264.   * cleanup parameters
  265.   width = abs(width)
  266.   height = abs(height)
  267.   thickness = abs(thickness)
  268.   pattern = upper(alltrim(pattern))           
  269.   lj_line(width,thickness,"H",pattern)     && draw top line first
  270.   lj_line(height,thickness,"V",pattern)    && left side line
  271.   lj_move(width-thickness,0.0)             && move to the right side
  272.   lj_line(height,thickness,"V", pattern)   && right side line
  273.   lj_move(thickness,height-thickness)      && move over and down
  274.   lj_line(-width,thickness,"H",pattern)    && finally, the bottom line
  275. return null
  276.  
  277.  
  278.  
  279. *────────────────────────────────────────────────────────────────────────────┐
  280. * FUNCTION NAME: lj_gotorc                                                   │
  281. *    PARAMETERS: row and comlumn location (in characters)                    │
  282. *       RETURNS: Nothing.                                                    │
  283. *   DESCRIPTION: Moves LJ cursor to the absolute r and c values (0,0 = upper │
  284. *                left corner of logical page                                 │
  285. *       EXAMPLE: lj_gotoxy(40,30)  [about the middle of the page]            │
  286. *────────────────────────────────────────────────────────────────────────────┘
  287.  
  288. function lj_gotorc
  289.   parameters r, c                && assume these are integers        
  290.   private null, row, rs, cs
  291.   null = ""
  292.   ** save Clipper printer position pointer 
  293.   row = prow()           
  294.   col = pcol()
  295.   rs = ltrim(str(r,4))
  296.   cs = ltrim(str(c,4))
  297.   ?? chr(27) + "&a" + rs + "r" + cs + "C"
  298.   setprc(row,col)         && restore printer row and col
  299. return null
  300.  
  301.  
  302.  
  303. *────────────────────────────────────────────────────────────────────────────┐
  304. * FUNCTION NAME: lj_say               (as in "@ r,c say...")                 │
  305. *    PARAMETERS: row, column, string      (in characters)                    │
  306. *       RETURNS: Nothing.                                                    │
  307. *                                                                            │
  308. *   DESCRIPTION: Moves LJ cursor to the absolute r and c values (0,0 = upper │
  309. *                left corner of logical page and prints the string.          │
  310. *       EXAMPLE: lj_gotoxy(40,30,"Hello")  [about the middle of the page]    │
  311. *────────────────────────────────────────────────────────────────────────────┘
  312.  
  313. function lj_say
  314.   parameters r, c, string      && integer columns        
  315.   private null
  316.   null = ""
  317.   ** save Clipper printer position pointer 
  318.   row = prow()           
  319.   col = pcol()
  320.   lj_gotorc(r,c)
  321.   ?? string
  322.   ** restore Clipper printer position pointer 
  323.   setprc(row,col)     
  324. return null
  325.  
  326.  
  327.