home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / lout2.lzh / LOUT2 / DOC / TR.LOUT / ch3.23 < prev    next >
Text File  |  1994-01-25  |  7KB  |  230 lines

  1. @Section
  2.    @Title { "@Graphic" }
  3.    @Tag { graphic }
  4. @Begin
  5. @PP
  6. graphic.sym @Index { @@Graphic symbol }
  7. diagrams @Index { Diagrams }
  8. Lout does not provide the vast repertoire of graphical objects (lines,
  9. circles, boxes, etc.) required by diagrams.  Instead, it provides an
  10. escape route to some other language that does have these features, via
  11. its @@Graphic symbol:
  12. postscript.graphic @SubIndex { used by @@Graphic }
  13. @ID @Code {
  14. "{ 0 0 moveto"
  15. "  0 ysize lineto"
  16. "  xsize ysize lineto"
  17. "  xsize 0 lineto"
  18. "  closepath"
  19. "  stroke"
  20. "}"
  21. "@Graphic"
  22. "{ //0.2c"
  23. "  ||0.2c hello, world ||0.2c"
  24. "  //0.2c"
  25. "}"
  26. }
  27. The result of the above invocation of the symbol @@Graphic is
  28. @ID {
  29. { 0     0     moveto
  30.   0     ysize lineto
  31.   xsize ysize lineto
  32.   xsize 0     lineto
  33.   closepath
  34.   stroke
  35. }
  36. @Graphic
  37. { //0.2c
  38.   ||0.2c hello, world ||0.2c
  39.   //0.2c
  40. }
  41. }
  42. @PP
  43. The right parameter always appears as part of the result, and indeed the
  44. result is always an object whose size is identical to the size of the
  45. right parameter with @@OneCol and @@OneRow applied to
  46. it.  From now on we refer to this part of the result as the {@I base}.
  47. @PP
  48. The left parameter is implementation-dependent: that is, its
  49. meaning is not defined by Lout, and different implementations could
  50. require different values for it.  The following description applies to
  51. Basser Lout, which uses the PostScript page description language
  52. [{@Ref adobe90}].
  53. @PP
  54. The left parameter refers to a coordinate system whose origin 
  55. is the bottom left-hand corner of the base.  It may use the symbols
  56. @Code xsize and @Code ysize to denote the horizontal and vertical size
  57. of the base; similarly, @Code xmark and @Code ymark denote the positions
  58. of the base's column and row marks:
  59. @ID 9p @Font @Fig {
  60.    { &1rt @I ysize /0ik &1rt @I ymark /0ik &1rt 0 } |0.4c
  61.    {  /
  62.       |0ik @ShowMarks { 1c @High 1.5c @Wide ^| 3c @Wide ^/ 2c @High }
  63.       |0ik /
  64.    }
  65.    /0.2c
  66.    | 0 | @I xmark | @I xsize
  67. }
  68. In addition to these four symbols and 0, lengths may be denoted in
  69. centimetres, inches, points, ems, f's, v's and s's using the notation
  70. @ID @Tab
  71.     vmargin { 0.5vx }
  72.     hmargin { 1m }
  73.     @Fmta { @Col {@I l  @Code A} ! @Col {instead of Lout's} ! @Col {{@I l}B} }
  74. {
  75. @Rowa A { cm } B { c }
  76. @Rowa A { in } B { i }
  77. @Rowa A { pt } B { p }
  78. @Rowa A { em } B { m }
  79. @Rowa A { ft } B { f }
  80. @Rowa A { vs } B { v }
  81. @Rowa A { sp } B { s }
  82. }
  83. Note that there must be a space between the number and its unit,
  84. unlike Lout proper.
  85. @PP
  86. A point within the base (and, with care, a point outside it) may
  87. be denoted by a pair of lengths.  For example,
  88. @ID @Code {
  89. "xmark  ymark"
  90. }
  91. is the point where the marks cross, and
  92. @ID @Code {
  93. "0   2 cm"
  94. }
  95. is a point on the left edge, two centimetres above the bottom left-hand
  96. corner.  These two numbers are called the @I {x coordinate} and the
  97. @I {y coordinate} of the point.
  98. @PP
  99. The first step in specifying a graphic object is to define a
  100. {@I path}.  A path can be thought of as the track of a pen moving over
  101. the page.  The pen may be up (not drawing) or down (drawing a line or
  102. curve) as it moves.  The entire path is a sequence of the following
  103. items:
  104. @LP
  105. 2i @Wide { |1rt @I {x y} @Code moveto }
  106. |2m Lift the pen and move it to the indicated point.
  107. @JP
  108. 2i @Wide { |1rt @I {x y} @Code lineto }
  109. |2m Put the pen down and draw a straight line to the indicated point.
  110. @JP
  111. 2i @Wide { |1rt @I {x y r angle1 angle2} @Code arc }
  112. |2m Put the pen down and draw a circular arc whose centre has
  113. coordinates @I x and @I y and whose radius is {@I r}.  The arc begins
  114. at the angle @I angle1 measuring counterclockwise from the point
  115. directly to the right of the centre, and proceeds counterclockwise to
  116. {@I angle2}.  If the arc is not the first thing on the path, a straight
  117. line will be drawn connecting the current point to the start of the arc.
  118. @JP
  119. 2i @Wide { |1rt @I {x y r angle1 angle2} @Code arcn }
  120. |2m As for arc, but the arc goes clockwise from @I angle1 to
  121. {@I angle2 }.
  122. @JP
  123. 2i @Wide @Code { |1rt closepath }
  124. |2m Draw a straight line back to the point most recently moved to.
  125. @LP
  126. The first item should always be a {@Code moveto}, {@Code arc}, or
  127. {@Code arcn}.  It should be clear from this that the path given earlier:
  128. @ID @Code {
  129. "0 0 moveto"
  130. "0 ysize lineto"
  131. "xsize ysize lineto"
  132. "xsize 0 lineto"
  133. "closepath"
  134. }
  135. traces around the boundary of the base with the pen down.
  136. @PP
  137. Once a path is set up, we are ready to @I paint it onto the page.  There 
  138. are two choices: we can either @I stroke it, which means to display it
  139. as described; or we can @I fill it, which means to paint everything
  140. inside it grey or black.  For stroking the two main options are
  141. @IL
  142. @LI {
  143. 2i @Wide { |1rt @I length @Code setlinewidth }
  144. |2m The pen will draw lines of the given width.
  145. }
  146. @LI {
  147. 2i @Wide { |1rt @Code "[" @I length @Code {"]" 0 setdash} }
  148. |2m The pen will draw dashed lines when it is down, with the dashes each
  149. of the given length.
  150. }
  151. @EL
  152. These options are followed by the word {@Code "stroke"}.  So, for example,
  153. @ID @Code {
  154. "{ 0 0 moveto xsize 0 lineto"
  155. "  2 pt setlinewidth [ 5 pt ] 0 setdash stroke"
  156. "}"
  157. "@Graphic { 3i @Wide }"
  158. }
  159. has result
  160. @ID {
  161. { 0 0 moveto xsize 0 lineto
  162.   2 pt setlinewidth [ 5 pt ] 0 setdash stroke
  163. }
  164. @Graphic { 3i @Wide }
  165. }
  166. @PP
  167. When filling in the region enclosed by a path, the main option is
  168. {@Code setgray}, which determines the shade of grey to use, on a scale
  169. from 0 (black) to 1 (white).  So, for example,
  170. @ID @Code {
  171. "{ 0 0 moveto xsize 0 lineto 0 ysize lineto closepath"
  172. "  0.8 setgray fill"
  173. "}"
  174. "@Graphic"
  175. "{ 2c @Wide  2c @High }"
  176. }
  177. has result
  178. @ID {
  179. { 0 0 moveto xsize 0 lineto 0 ysize lineto closepath
  180.   0.8 setgray fill
  181. }
  182. @Graphic
  183. { 2c @Wide  2c @High }
  184. }
  185. @PP
  186. There are many other options.  The value of the left parameter of
  187. @@Graphic may be any fragment of the PostScript page description language
  188. [{@Ref adobe90}].  Here are two other examples:
  189. @ID @Code {
  190. xsize 2 div
  191. }
  192. denoting a length equal to half the horizontal size of the base, and
  193. @ID @Code {
  194. gsave fill grestore stroke
  195. }
  196. which both fills and strokes the path.  Since Basser Lout does not check
  197. that the left parameter is valid PostScript, it is possible to cause
  198. mysterious errors in the printing device, resulting in no output, if an
  199. incorrect value is given.  It is a good idea to encapsulate graphics
  200. objects in carefully tested definitions, like those of the Fig figure
  201. drawing package [{@Ref kingston92fig}],
  202. fig @Index { Fig figure-drawing package }
  203. to be sure of avoiding these errors.
  204. @PP
  205. PostScript experts may find the following information helpful when
  206. designing advanced graphics features.  The left parameter of @@Graphic
  207. may have two parts, separated by {@Code "//"}:
  208. @ID {
  209. @Code "{" @I {first part} @Code "//" @I {second part} @Code "} @Graphic"
  210. @I object
  211. }
  212. If there is no {@Code "//"}, the second part is taken to be empty.  The
  213. PostScript output has the form
  214. @ID lines @Break {
  215. @Code gsave
  216. @I x @I y @Code translate
  217. @I {Code which defines {@Code xsize}, {@Code ysize}, {@Code xmark}, {@Code ymark}, {@Code ft}, {@Code vs}, and {@Code sp} }
  218. @Code gsave
  219. @I {first part}
  220. @Code grestore
  221. @I {Code which renders the right parameter in translated coordinates}
  222. @I {second part}
  223. @Code grestore
  224. }
  225. where @Eq {x, y} is the position of the lower left corner of the
  226. base.  Having two parts permits bracketing operations, like @Code save
  227. and @Code restore or @Code begin and {@Code end}, to enclose an
  228. object.  See the source file of the Fig package for examples.
  229. @End @Section
  230.