home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / LASER / SHADE.ZIP / SHADE.TXT
Encoding:
Text File  |  1989-02-14  |  8.1 KB  |  266 lines

  1.                    "Green-bar" paper on a LaserJet II
  2.                    ----------------------------------
  3.  
  4. This document explains how to shade every other line of a LaserJet
  5. II-printed report so that the result is similar to that produced on
  6. "green bar" paper stock.  This makes it easier to read reports such as
  7. data file listings, etc., where each line is a record.
  8.  
  9.  
  10. Printer functions required
  11. --------------------------
  12. The technique involves two basic LJ functions: cursor positioning and
  13. rectangular area filling.  These are documented in the "LaserJet Series
  14. II Printer Technical Reference Manual", available at extra cost from
  15. Hewlett-Packard (Part No. 33440-90905).
  16.  
  17. The area filling functions allow you to define a rectangular box and
  18. fill it with the pattern or shading level of your choice.  We will use a
  19. box that is 8.5" wide and 1/6" high--the full width of the paper by one
  20. line high.  It is then "filled" by shading.
  21.  
  22. The cursor positioning functions move the "cursor", which is the active
  23. printing location--where the next character will print.  It is analagous
  24. to a screen cursor.  In essence, we will start at the upper left corner
  25. of the page and shade every other line by moving the cursor down two
  26. lines after each fill.
  27.  
  28.  
  29. Algorithm
  30. ---------
  31. The basic algorithm is:
  32.  
  33.     Save the "cursor" position
  34.     Move the cursor to the upper left corner of the page
  35.     Define the box characteristics
  36.     Do 30 times
  37.         Shade the box
  38.         Move the cursor down two lines
  39.     End do
  40.     Restore the initial cursor position
  41.  
  42. At the end of this process, every other line has been shaded.  The
  43. character data is then sent to the printer as usual for printing.
  44.  
  45.  
  46. Specific functions used
  47. -----------------------
  48. "Ec" is an ASCII ESC character (decimal code 27, hex 1B).  "#" is a
  49. variable value that is replaced by a numeric parameter (in ASCII: for
  50. example, "50" is transmitted by sending the ASCII characters "5" and
  51. "0").
  52.  
  53. Note: the LJ-II commands show below have been simplified somewhat, i.e.,
  54. the definitions shown don't necessarily convey all possible formats of
  55. the commands given.
  56.  
  57. 1. Cursor positioning
  58.  
  59.     a. Save/restore cursor position
  60.  
  61.             Ec&f0S
  62.  
  63.        This saves the current cursor position by pushing it onto a LIFO
  64.        stack.  It can be restored (popped) by the control string
  65.  
  66.             Ec&f1S
  67.  
  68.         The stack is large enough to save 20 cursor positions.
  69.  
  70.     b. Set cursor position (horizontal absolute, by dots)
  71.  
  72.             Ec*p#X
  73.  
  74.        The variable value # is the horizontal dot number.  The
  75.        leftmost dot on a row is dot 0, so the control string
  76.  
  77.             Ec*p0X
  78.  
  79.        moves the cursor to the left side of the page.
  80.  
  81.     c. Set cursor position (vertical absolute, by dots)
  82.  
  83.             Ec*p#Y
  84.  
  85.        The variable value # is the vertical dot number.  The topmost
  86.        dot row on the page is row 0.  To put the cursor at the top of
  87.        the page:
  88.  
  89.             Ec*p0Y
  90.  
  91.     d. Set cursor position (vertical relative, by rows)
  92.  
  93.             Ec&a#R
  94.  
  95.        The variable value is preceded by a plus or minus sign to
  96.        indicate whether the cursor is to be moved up (-) or down (+) the
  97.        specified number of rows.  This moves the cursor down two rows:
  98.  
  99.             Ec&a+2R
  100.  
  101.  
  102. 2. Area filling
  103.  
  104.     a. Define box width (in dots)
  105.  
  106.             Ec*c#A
  107.  
  108.        To define a box 8.5" wide (8.5 x 300 = 2550 dots):
  109.  
  110.             Ec*c2550A
  111.  
  112.         Note that the printer will clip the box at the left and right
  113.         margins.
  114.  
  115.     b. Define box height (in dots)
  116.  
  117.             Ec*c#B
  118.  
  119.        To define a box 1/6" (one line) high:
  120.  
  121.             Ec*c50B
  122.  
  123.         1/6" at 300 dots per inch is 50 dots.
  124.  
  125.     c. Define shading level
  126.  
  127.             Ec*c#G
  128.  
  129.         The variable value # represents a shading level from 2% to 100%.
  130.         The printer can actually print eight different levels, and there
  131.         are some discrepancies in the HP manual regarding these levels.
  132.         However, 2, 10, 15, 30, 45, 70, 90, and 100% would seem to
  133.         represent the real levels.  To set 15% shading:
  134.  
  135.             Ec*c15G
  136.  
  137.         I suggest 10% or 15% shading for the "green bar" paper.
  138.  
  139.     d. Print box as currently defined
  140.  
  141.             Ec*c2P
  142.  
  143.        This control string performs the gray scale fill using the area
  144.        dimensions and fill level currently defined.  The box is printed
  145.        at the current cursor position; the cursor position is not
  146.        changed.  As always, no physical printing occurs until the page
  147.        is filled with text data or a formfeed is received.
  148.  
  149.  
  150. Combining functions
  151. -------------------
  152. The LJ-II allows some concatenation of control strings.  Strings may be
  153. concatenated if the first two characters following the ESC are the same:
  154.  
  155.         Ec*p#X
  156.         Ec*p#Y
  157.  
  158. If strings are combined, the trailing character for all control
  159. strings except the last one is lowercase, and the first three characters
  160. are omitted after the first string.  For example, the three strings
  161.  
  162.         Ec*c2550A
  163.         Ec*c50B
  164.         Ec*c15G
  165.  
  166. can be combined into one string as follows:
  167.  
  168.         Ec*c2550a50b15G
  169.  
  170.  
  171. Margins etc.
  172. ------------
  173. This document assumes that you're using 8.5 x 11 paper at 60 lines per
  174. page (i.e., with the default top and bottom margins), six lines per
  175. inch, in portrait mode.  If you use anything else, you'll need to adjust
  176. some of the parameters.
  177.  
  178. The left/right margins have no effect on the printing of the shaded
  179. rectangles, but the top margin and text length do.  In other words, dot
  180. column 0 is an absolute position on the page, but dot row 0 is relative
  181. to the top margin.  If you print shaded boxes beyond the bottom of the
  182. text area, a page eject will occur (and you'll have a shaded page
  183. with no text).
  184.  
  185.  
  186. Sample code
  187. -----------
  188. Each of the following code samples sends the following control sequences
  189. to the printer:
  190.  
  191.     Ec&f0S                  ; Save curpos
  192.     Ec*p0x0Y                ; Cursor to (0,0)
  193.     Ec*c2550a50b10G         ; Define box: 8.5" x 1/6", 10% shading
  194.     (30 times:)
  195.         Ec*c2P              ; Print box
  196.         Ec&a+2R             ; Move down two lines
  197.     Ec&f1S                  ; Restore curpos
  198.  
  199. Some of these have been combined for greater efficiency.
  200.  
  201. This code must be executed for each page printed, of course.  If you are
  202. going to be printing many pages, it may be faster (especially in dBASE!)
  203. to contatenate 30 instances of Ec*c2PEc&a+2R into one string (and print
  204. it once per page) than to send the string to the printer thirty times
  205. for each page.
  206.  
  207.  
  208. BASIC:
  209.     100 EC$ = CHR$(27)
  210.     110 LPRINT EC$ + "&f0S" + EC$ + "*p0x0Y" + EC$ + "*c2550a50b10G";
  211.     120 FOR I = 1 TO 30: LPRINT EC$ + "*c2P" + EC$ + "&a+2R";: NEXT
  212.     130 LPRINT EC$ + "&f1S";
  213.  
  214. C:
  215.     int i;
  216.     fprintf (stdprn, "\033&f0S\033*p0x0Y\033*c2550a50b10G");
  217.     for (i=1; i <= 30; i++)
  218.         fprintf (stdprn, "\033*c2P\033&a+2R");
  219.     fprintf (stdprn, "\033&f1S");
  220.  
  221. dBASE III+:
  222.     set print on
  223.     set console off
  224.     Ec = chr(27)
  225.     ?? Ec + "&f0S" + Ec + "*p0x0Y" + Ec + "*c2550a50b10G"
  226.     i = 1
  227.     do while i <= 30
  228.         ?? Ec + "*c2P" + Ec + "&a+2R"
  229.         i = i+1
  230.     enddo
  231.     ?? Ec + "&f1S"
  232.     set print off
  233.     set console on
  234.  
  235. dBASE IV:
  236.     ??? "{ESC}&f0S{ESC}*p0x0Y{ESC}*c2550a50b10G"
  237.     i = 1
  238.     do while i <= 30
  239.         ??? "{ESC}*c2P{ESC}&a+2R"
  240.         i = i+1
  241.     enddo
  242.     ??? "{ESC}&f1S"
  243.  
  244. REXX:
  245.     Ec = '1B'x
  246.     call charout 'prn',Ec'&f0S'Ec'*p0x0Y'Ec'*c2550a50b10G'
  247.     do 30
  248.         call charout 'prn',Ec'*c2P'Ec'&a+2R'
  249.     end
  250.     call charout 'prn',Ec'&f1S'
  251.  
  252.  
  253.             ===============================================
  254.  
  255.                               Document by:
  256.                              Chris Dunford
  257.                         The Cove Software Group
  258.                               PO Box 1072
  259.                            Columbia, MD 21044
  260.                               301/992-9371
  261.                          CompuServe 76703,2002
  262.  
  263.                              Prepared for:
  264.                            CompuServe IBMNET
  265.                                 02/01/89
  266.