home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / pascal-p / plotter.lbr / PLOTTER.DZC / PLOTTER.DOC
Encoding:
Text File  |  1987-02-07  |  8.0 KB  |  193 lines

  1.              PLOTTER subsystem - by C.B. Falconer
  2.  
  3. The file PLOTTER.INC may be included in a PascalP source program with
  4. "(*$i'plotter.inc'*), and provides:
  5.  
  6.        A 900 (wide) by 640 (deep) bit field, which will appear
  7.        as a 7 1/2 inch by 8 inch field on an Epson printer.
  8.  
  9.        The ability to set any dot in the field, to write lines
  10.        from the "current" position to any other position;  to
  11.        reposition the "pen" at any position (by writing a line
  12.        with no ink); and to write graphics characters, described
  13.        by a Hershey font file, at any location and at any angle,
  14.        and with any scale factor.
  15.  
  16. The field size may be modified by altering the constant HDOTS (for the
  17. width), and MAXSTRIPS (for the height).  The height is always MAXSTRIPS
  18. times 8 dots, and this value is available in VDOTS : integer (but ONLY
  19. after plotopen is called.
  20.  
  21. The constants VDPI and HDPI (vertical/horizontal dots per inch) are
  22. used to modify the Hershey fonts for the proper form factors.  These are
  23. set for the Epson printers.  ONLY after plotopen is called, the ratio is
  24. available in ASPECT : real.
  25.  
  26. The values in XNOW, YNOW, VDOTS, ASPECT may be used, but should NOT be
  27. altered by the application program.
  28.  
  29. The file TESTPLOT.PAS is a demonstrator, and allows the user to specify
  30. lines and character strings to write.  It automatically creates an outline
  31. border.  Use this as a usage example.
  32.  
  33. In general, before using the system the procedure PLOTOPEN must be called
  34.  
  35.               plotopen
  36.  
  37. to initialize.  If graphics characters are to be written the font must be
  38. loaded by:
  39.               loadfont(VAR f : text)
  40.  
  41. where f is the text file holding the font.  Note that the font may be
  42. changed on the fly by reloading a new font.  The font may be loaded before
  43. or after calling plotopen.  Loadfont reads the file from the beginning.
  44.  
  45. All plotting (except PLOTDOT) is done in terms of an imaginary pen position.
  46. Lines are drawn from the present position to a specified new position, with
  47. or without marking the "paper".  The call is:
  48.  
  49.               plotline(ink : boolean; x, y : integer)
  50.  
  51. where ink false causes no paper marking.  x and y are the final absolute
  52. pen location.  At least one dot will be made when ink is true.
  53.  
  54. The variables XNOW and YNOW (: integer) always hold the current pen position.
  55.  
  56. The primitive
  57.  
  58.               plotdot(x, y : integer)
  59.  
  60. allows other subsystems to interface, such as arc generators.
  61.  
  62. To plot a character (which is in the loaded font), the call is:
  63.  
  64.               plotchar(ch : char; x, y : integer;
  65.                        height, compress, angle : real);
  66.  
  67. where x,y is the starting location, height is the relative height (usually
  68. in the range 0.5 to 2.0), compress (usually 1) specifies horizontal 
  69. compression/expansion (values less than 1 specify compression), and angle
  70. (in radians) specifies counter-clockwise rotation of the x axis for the
  71. character.  At completion xnow/ynow will be a suitable location for the
  72. next character at the same angle.  A space uses the horizontal size of the
  73. first character in the font (usually 'A') and simply moves.
  74.  
  75. Plotchar uses the 'aspect' value to correct distortions in the font caused
  76. by different vertical and horizontal dot densities.
  77.  
  78. At completion of the drawing, to write the output to either a disk file or
  79. the listing device (an Epson printer), do
  80.  
  81.               plotclose(VAR f : text);
  82.  
  83. where f is the already opened file to write to.  This allows multiple
  84. drawings to be emitted to the same file.
  85.  
  86. WARNING: If a disk file is created that file will contain many non-printing
  87. characters whose interpretation is not the usual.  To print it must be
  88. copied totally unchanged to the printer.  Program LIST can do this.
  89.  
  90. NOTE: Both the virtual memory (temporary) file, and the output file, will
  91. contain about 71 K bytes.  The virtual file is created on the default drive,
  92. but the output file may be controlled at run time.  The application may
  93. remove the virtual file with "purge(stripfile)" at completion, if desired.
  94.  
  95.  
  96. Fonts
  97. =====
  98.  
  99. The font files consist of a series of entries, consisting of:
  100.  
  101. * The character 'C'
  102.   The character to be plotted
  103.  
  104. and the remainder of the entry is a series of integers, separated by
  105. spaces or <eolns>
  106.  
  107. * The standard Hershey identification number for the graphic.
  108.   the height of the character (2 digits)
  109.   the width  of the character (2 digits)
  110. * the width for non-proportional writing (2 digits)
  111.   <eoln>
  112.  
  113. followed by a series of 4 or 5 char. integers, max 10 per line,
  114. specifying RELATIVE pen positions (offset by 10 for x, by 35 for y).
  115. If the integer is negative it specifies that no marks are to be
  116. made in moving to this position, otherwise "ink" is used.  The rest
  117. of the integer is interpreted as its absolute value (i.e. after
  118. discarding any - sign).  If the value is >= 10000 it is the last 
  119. for the character (and eoln follows).  The right two digits are a
  120. "y" position, and the left two (ignoring any 10000) are the "x"
  121. position.  These are alway relative to the starting position for
  122. the character, after subtracting the above offsets.
  123.  
  124. The fields marked with "*" are not used by this software, and thus
  125. may be anything.  However they must be present in the file or the
  126. load process will fail.
  127.  
  128. This allows custom fonts to be generated and used as desired.
  129. The three fonts supplied (font1, font2, and font3) require successively
  130. more processing, and are successively elegant.  They contain the
  131. characters 'A' thru 'Z', 'a' thru 'z', '0' thru '9'.
  132.  
  133.  
  134. PascalP PCD vs COM files
  135. ========================
  136.  
  137. Since most of the time is spent in system procedures (file i/o, real
  138. arithmetic, and trigonometric functions) minimum speed improvements
  139. result from the use of .COM files rather than the machine independant
  140. .PCD files.  Time ratios will be in the order of 2:1 to 3:2.
  141.  
  142.  
  143. Other systems
  144. =============
  145. Most of the code is in ISO standard Pascal, and thus should port with
  146. no difficulty.  The declarations may have to be inserted in the appropriate
  147. portion of the application for systems other than PascalP (which allows
  148. complete modularizaation).  Other points are discussed below, and potential
  149. problem areas are marked with '{}' in the first column of the source.
  150.  
  151.  
  152. Other printers
  153. ==============
  154.  
  155. The output interface is entirely specified in PLOTCLOSE, and thus can
  156. be modified without affecting any other portion of the code.  A simple
  157. FOR loop can be used for character by character output, but will be
  158. much slower.  If the output rate is limited by a printer, this will not
  159. matter, but for diskfile output will be a nuisance.  Printers with other
  160. formats (interleaved, etc) may require some local data manipulation 
  161. and/or combination of adjacent strips.
  162.  
  163.  
  164. Virtual Memory
  165. ==============
  166.  
  167. The system uses a virtual memory scheme for the bit map, thus allowing
  168. execution on systems with limited data segments (CPM, HP3000, most
  169. 8086/MsDos compilers).  This uses the random file access procedures
  170. of PascalP ('update', 'reposition') and the non-aborting 'allocate' (which
  171. is identical to 'new', except returns NIL in place of aborting when memory
  172. is not available).  To use 'new', adjust the constant 'maxloaded' downwards
  173. until the program stops aborting.   Any adjustments to other systems
  174. should be confined to 'getstrip', 'keepstrip', 'plotopen', (and possibly
  175. 'plotclose').
  176.  
  177. On any system, if the pagesize or resolution is increased, sooner or later
  178. the virtual memory will be required, since internal memory is always finite.
  179.  
  180.  
  181. References
  182. ==========
  183.  
  184. Much code was adapted from DOTGRAM (1986) (of the PHYLIP suite), by
  185. Felsenstein and Meacham, and ELLIPSE (1985) by C. B. Falconer.  The
  186. methods are expounded in Decision Variables, by Tom Hogan, Dr Dobbs
  187. Journal, May 1985, and Algorithm for Computer Control of Digital
  188. Plotter, IBM Sys. J. 4(1):25-30, 1965.  The fundamental algorithm is
  189. known as Bresenhams algorithm.
  190.  
  191.  
  192. C.B. Falconer 87/02/02
  193. n