61b7fcbde96205037f1490a8ddf36bb6dc0ea1f0
[platform/upstream/groff.git] / contrib / mom / momdoc / graphical.html
1 <?xml version="1.0" encoding="utf-8"?>
2 <!--
3 This file is part of groff, the GNU roff type-setting system.
4
5 Copyright (C) 2004-2014 Free Software Foundation, Inc.
6 Written by Peter Schaffter (peter@schaffter.ca).
7
8 Permission is granted to copy, distribute and/or modify this document
9 under the terms of the GNU Free Documentation License, Version 1.3 or
10 any later version published by the Free Software Foundation; with the
11 Invariant Sections being this comment section, with no Front-Cover
12 Texts, and with no Back-Cover Texts.
13
14 A copy of the Free Documentation License is included as a file called
15 FDL in the main directory of the groff source package.
16 -->
17
18 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
19 <html xmlns="http://www.w3.org/1999/xhtml">
20
21 <head>
22   <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
23   <title>Mom -- Graphical Objects</title>
24   <link rel="stylesheet" type="text/css" href="stylesheet.css" />
25 </head>
26
27 <body style="background-color: #f5faff;">
28
29 <!-- ==================================================================== -->
30
31 <div id="top" class="page">
32
33 <!-- Navigation links -->
34 <table style="width: 100%;">
35 <tr>
36   <td><a href="toc.html">Back to Table of Contents</a></td>
37   <td style="text-align: right;"><a href="docprocessing.html#top">Next: Document processing</a></td>
38 </tr>
39 </table>
40
41 <h1 class="docs">Graphical objects</h1>
42
43 <div style="text-align: center;">
44 <ul class="no-enumerator" style="margin-left: -2.5em;">
45   <li><a href="#intro-graphical">Introduction to graphical objects</a></li>
46   <li><a href="#behaviour">Graphical objects behaviour</a></li>
47   <li><a href="#order">Order of arguments</a></li>
48   <li><a href="#index-graphical">Index of graphical objects macros</a></li>
49 </ul>
50 </div>
51
52 <div class="rule-medium"><hr/></div>
53
54 <h2 id="intro-graphical" class="docs">Introduction to graphical objects</h2>
55
56 <p>
57 Groff has a number of
58 <a href="definitions.html#inlines">inline escapes</a>
59 for drawing rules, polygons, ellipses and splines.  All begin with
60 <kbd>\D</kbd> (presumably for &#8220;Draw&#8221;) and are documented
61 in the groff info manual:
62 <br/>
63 <span class="pre-in-pp">
64   info groff => Escape index => \D
65 </span>
66 The escapes allow you to draw just about any simple graphical object
67 you can think of, but owing to their syntax, they&#8217;re not always easy
68 to read, which can make tweaking them difficult.  Additionally,
69 while they perform in a <i>consistent</i> manner, they don&#8217;t
70 always perform in an <i>expected</i> manner.
71 </p>
72
73 <p>
74 Experience shows that the most common graphical elements typesetters
75 need are rules (horizontal and vertical), boxes, and circles (or
76 ellipses).  For this reason, mom provides macros
77 to draw these objects in an easy-to-understand way; the results are
78 predictable, and mom&#8217;s syntax makes fixes or tweaks
79 painless.
80 </p>
81
82 <p id="graphical-example">
83 For example, if you want to draw a 2-inch square outline box at the left
84 margin using groff&#8217;s <kbd>\D</kbd> escapes, it looks like this:
85 <br/>
86 <span class="pre-in-pp">
87              back up
88                by
89              weight
90             +-------+
91             |       |
92    \D't 500'\h'-500u'\D'p 2i 0 0 2i -2i 0 0 -2i'
93   |       |          |                        |
94   +-------+          +------------------------+
95    set rule          draw box, 1 line at a time
96     weight
97 </span>
98
99 Obviously, this isn&#8217;t very efficient for something as simple as a
100 box.
101 </p>
102
103 <p>
104 Here&#8217;s the same box, drawn with mom&#8217;s box drawing
105 macro,
106 <kbd><a href="#dbx">DBX</a></kbd>:
107 <br/>
108 <span class="pre-in-pp">
109   left margin indent--+  +--box width
110                       |  |
111              .DBX .5  0  2i  2i
112                   |          |
113      rule weight--+          +--box depth
114      (in points)
115 </span>
116 </p>
117
118 <p>
119 Mom&#8217;s graphical object macros allow&mdash;in fact,
120 require&mdash;giving the rule weight (&#8220;thickness&#8221;) for
121 the object (or saying that you want it filled), an indent from the
122 left margin where the object begins, the dimensions of the object,
123 and optionally a colour for the object.
124 </p>
125
126 <p>
127 There are no defaults for the arguments to mom'a graphical object
128 macros, which means you must supply the arguments every time you
129 invoke them.
130 </p>
131
132 <div class="box-tip">
133 <p class="tip">
134 <span class="note">Note:</span>
135 As stated above, mom only provides macros for commonly-used
136 graphical objects (rules, boxes, circles).  More complex objects
137 (polygons, non-straight lines, splines) must be drawn using
138 groff&#8217;s <kbd>\D</kbd> escapes.
139 </p>
140 </div>
141
142 <h3 id="behaviour" class="docs">Graphical object behaviour</h3>
143
144 <p>
145 Mom&#8217;s graphical object macros all behave in the following,
146 carved-in-stone ways:
147 </p>
148 <ol style="margin-top: -.5em; margin-bottom: -.5em;">
149    <li>Objects are drawn from the
150        <a href="definitions.html#baseline">baseline</a>
151        down, including horizontal rules.</li>
152    <li>Objects begin precisely at the left indent supplied as
153        an argument to the macro.</li>
154    <li>Objects are drawn from left to right.</li>
155    <li>Enclosed objects (boxes, circles) are drawn from the
156        perimeter <i>inward</i>.</li>
157    <li>Objects return to their horizontal/vertical point of origin.</li>
158 </ol>
159
160 <p>
161 The consistency means that once you've mastered the very simple
162 order of arguments that applies to invoking graphical object
163 macros, you can draw objects with full confidence that you know
164 exactly where they&#8217;re placed and how much room they
165 occupy.  Furthermore, because all return to their point of origin,
166 you&#8217;ll know exactly where you are on the page.
167 </p>
168
169 <h3 id="order" class="docs">Order of arguments</h3>
170
171 <p>
172 The order of arguments to the graphical object macros is the same
173 for every macro:
174 </p>
175 <ul style="margin-top: -.5em; margin-bottom: -.5em;">
176   <li>the <kbd><span style="text-decoration: underline">W</span></kbd>eight of the rule
177   <ul style="margin-left: -.75em;">
178     <li>if the object is enclosed (i.e. is a box or circle), the
179         weight of the rule if you want the object outlined</li>
180     <li>the single word, <kbd>SOLID</kbd>, may be used in place
181         of the <b>weight</b> argument if you want the
182         object filled</li>
183   </ul></li>
184   <li>the <kbd><span style="text-decoration: underline">I</span></kbd>ndent from the current left margin at
185       which to begin the object</li>
186   <li>the <kbd><span style="text-decoration: underline">L</span></kbd>ength of the object, if applicable</li>
187   <li>the <kbd><span style="text-decoration: underline">D</span></kbd>epth of the object, if applicable</li>
188   <li>the <kbd><span style="text-decoration: underline">C</span></kbd>olour of the object (optional)</li>
189 </ul>
190
191 <p>
192 A simple mnemonic for the order of arguments is &#8220;<b>WILD
193 C</b>ard&#8221;.  If you fix the mnemonic in your brain and apply
194 a little judicious reasoning, you&#8217;ll always remember how to
195 draw graphical objects.  The &#8220;judicious reasoning&#8221; means
196 that, for example, horizontal rules don&#8217;t require a depth and
197 vertical rules don&#8217;t require a length.  Thus, in the case of
198 drawing a horizontal rule, you supply the macro,
199 <kbd><a href="#drh">DRH</a></kbd>,
200 with only the arguments (from the mnemonic) that apply: <b>W-I-L</b> (and
201 possibly <b>C</b>).
202 </p>
203
204 <div class="macro-list-container">
205 <h3 id="index-graphical" class="macro-list">Graphical objects macros</h3>
206
207 <ul class="macro-list">
208   <li><a href="#drh">DRH</a>
209       &ndash; horizontal rules</li>
210   <li><a href="#drv">DRV</a>
211       &ndash; vertical rules</li>
212   <li><a href="#dbx">DBX</a>
213       &ndash; box</li>
214   <li><a href="#dcl">DCL</a>
215       &ndash; circles or ellipses</li>
216 </ul>
217 </div>
218
219 <!-- -DRH- -->
220
221 <div class="macro-id-overline">
222 <h3 id="drh" class="macro-id">Drawing horizontal rules</h3>
223 </div>
224
225 <div class="box-macro-args">
226 Macro: <b>DRH</b> <kbd class="macro-args">&lt;none&gt; | &lt;weight&gt;  &lt;indent&gt; &lt;length&gt; [&lt;colour&gt;]</kbd>
227 </div>
228
229 <p class="requires">
230 &bull;&nbsp;
231 the argument to <kbd class="normal">&lt;weight&gt;</kbd> is in
232 <a href="definitions.html#picaspoints" class="normal">points</a>,
233 but do <span class="normal">NOT</span> append the
234 <a href="definitions.html#unitsofmeasure">unit of measure</a>,
235 <kbd class="normal">p</kbd>
236 <br/>
237 &bull;&nbsp;
238 <kbd class="normal">&lt;indent&gt;</kbd>
239 and
240 <kbd class="normal">&lt;length&gt;</kbd>
241 require a unit of measure
242 <br/>
243 &bull;&nbsp;
244 arithmetic expressions to
245 <kbd class="normal">&lt;indent&gt;</kbd>
246 and
247 <kbd class="normal">&lt;length&gt;</kbd>
248 must be surrounded by parentheses
249 </p>
250
251 <p>
252 If all you want is to draw a rule from your current left
253 margin to your current right margin (in other words, a &quot;full
254 measure&quot; rule), you may invoke <kbd>.DRH</kbd> without any
255 arguments.
256 </p>
257 <div class="box-tip">
258 <p class="tip">
259 <span class="note">Note:</span>
260 DRH is the only graphical object macro that may be invoked
261 without arguments.  The weight (&#8220;thickness&#8221;) of
262 the rule is determined by the argument you last gave the
263 macro, <a href="inlines.html#rule-weight">RULE_WEIGHT</a>.
264 DRH, used this way, is exactly equivalent to entering the
265 <a href="definitions.html#inlines">inline escape</a>, <a
266 href="inlines.html#inline-rule-mom"><kbd>\*[RULE]</kbd></a>.
267 </p>
268 </div>
269
270 <p style="margin-top: -.5em;">
271 To draw horizontal rules of a specified length, you must, at
272 a minimum, supply DRH with the arguments <kbd>weight,</kbd>
273 <kbd>indent</kbd> (measured from the current left margin) and
274 <kbd>length</kbd>.
275 </p>
276
277 <p>
278 Optionally, you may give a <kbd>colour</kbd> argument.  The colour
279 may be either one defined with
280 <a href="color.html#newcolor">NEWCOLOR</a>,
281 or a named X-colour inititialized with
282 <a href="color.html#xcolor">XCOLOR</a>,
283 or an X-colour alias (again, initialized with XCOLOR).
284 </p>
285
286 <p>
287 Say, for example, you want to draw a 1-1/4 point horizontal rule
288 that starts 2 picas from the current left margin and runs for 3
289 inches.  To do so, you'd invoke <kbd>.DRH</kbd> like this:
290 <br/>
291 <span class="pre-in-pp">
292       weight  length
293          |      |
294   .DRH 1.25 2P 3i
295             |
296           indent
297 </span>
298 (Note that the rule weight argument, which is expressed in points,
299 must NOT have the unit of measure <kbd>p</kbd> appended to it.)
300 </p>
301
302 <p>
303 If, in addition, you want the rule blue:
304 <br/>
305 <span class="pre-in-pp">
306   .DRH 1.25 2P 3i blue
307 </span>
308 </p>
309
310 <h3 class="docs">How mom handles the positioning of horizontal rules</h3>
311
312 <p>
313 Horizontal rules are drawn from left to right, and from the baseline
314 down. &#8220;From the baseline down&#8221; means that if you request
315 a rule with a weight of four points, the four points of rule fall
316 entirely below the baseline.
317 </p>
318
319 <p>
320 Furthermore, after the rule is drawn, mom returns you to the current
321 left margin, at the same vertical position on the page as when DRH
322 was invoked.  In other words, DRH causes no movement on the page,
323 either horizontal or vertical.
324 </p>
325
326 <!-- -DRV- -->
327
328 <div class="macro-id-overline">
329 <h3 id="drv" class="macro-id">Drawing vertical rules</h3>
330 </div>
331
332 <div class="box-macro-args">
333 Macro: <b>DRV</b> <kbd class="macro-args">&lt;weight&gt;  &lt;indent&gt; &lt;depth&gt; [&lt;colour&gt;]</kbd>
334 </div>
335
336 <p class="requires">
337 &bull;&nbsp;
338 the argument to <kbd class="normal">&lt;weight&gt;</kbd> is in
339 <a href="definitions.html#picaspoints" class="normal">points</a>,
340 but do <span class="normal">NOT</span> append the
341 <a href="definitions.html#unitsofmeasure">unit of measure</a>,
342 <kbd class="normal">p</kbd>
343 <br/>
344 &bull;&nbsp;
345 <kbd class="normal">&lt;indent&gt;</kbd>
346 and
347 <kbd class="normal">&lt;depth&gt;</kbd>
348 require a unit of measure
349 <br/>
350 &bull;&nbsp;
351 arithmetic expressions to
352 <kbd class="normal">&lt;indent&gt;</kbd>
353 and
354 <kbd class="normal">&lt;depth&gt;</kbd>
355 must be surrounded by parentheses
356 </p>
357
358 <p>
359 To draw vertical rules of a specified length, you must, at
360 a minimum, supply DRV with the arguments <kbd>weight,</kbd>
361 <kbd>indent</kbd> (measured from the current left margin) and
362 <kbd>depth</kbd>.
363 </p>
364
365 <p>
366 Optionally, you may give a <kbd>colour</kbd> argument.  The colour
367 may be either one defined with
368 <a href="color.html#newcolor">NEWCOLOR</a>,
369 or a named X-colour inititialized with
370 <a href="color.html#xcolor">XCOLOR</a>,
371 or an X-colour alias (again, initialized with XCOLOR).
372 </p>
373
374 <p>
375 Say, for example, you want to draw a 3/4-point vertical rule that
376 starts 19-1/2 picas from the current left margin and has a depth of
377 6 centimeters.  To do so, you'd invoke <kbd>.DRV</kbd> like this:
378 <br/>
379 <span class="pre-in-pp">
380        weight   depth
381          |        |
382   .DRV .75 19P+6p 6c
383              |
384            indent
385 </span>
386 (Note that the rule weight argument, which is expressed in points,
387 must NOT have the unit of measure <kbd>p</kbd> appended to it.)
388 </p>
389
390 <p>
391 If, in addition, you want the rule red:
392 <br/>
393 <span class="pre-in-pp">
394   .DRV .75 19P+6p 6c red
395 </span>
396 </p>
397
398 <h3 class="docs">How mom handles the positioning of vertical rules</h3>
399
400 <p>
401 Vertical rules are drawn from the baseline down, and from left to
402 right. &quot;Left to right&quot; means that if you request a rule
403 with a weight of four points, the four points of rule fall entirely
404 to the left of the indent given to DRV.
405 </p>
406
407 <p>
408 Furthermore, after the rule is drawn, mom returns you to the current
409 left margin, at the same vertical position on the page as when DRV
410 was invoked.  In other words, DRV causes no movement on the page,
411 either horizontal or vertical.
412 </p>
413
414 <!-- -DBX- -->
415
416 <div class="macro-id-overline">
417 <h3 id="dbx" class="macro-id">Drawing boxes</h3>
418 </div>
419
420 <div class="box-macro-args">
421 Macro: <b>DBX</b> <kbd class="macro-args">&lt; &lt;weight&gt; | SOLID &gt; &lt;indent&gt; &lt;length&gt; &lt;depth&gt; [&lt;colour&gt;]</kbd>
422 </div>
423
424 <p class="requires">
425 &bull;&nbsp;
426 the argument to <kbd class="normal">&lt;weight&gt;</kbd> is in
427 <a href="definitions.html#picaspoints" class="normal">points</a>,
428 but do <span class="normal">NOT</span> append the
429 <a href="definitions.html#unitsofmeasure">unit of measure</a>
430 <kbd class="normal">p</kbd>
431 <br/>
432 &bull;&nbsp;<kbd class="normal">&lt;indent&gt;</kbd>,
433 <kbd class="normal">&lt;length&gt;</kbd>,
434 and
435 <kbd class="normal">&lt;depth&gt;</kbd>
436 require a unit of measure
437 <br/>
438 &bull;&nbsp;
439 arithmetic expressions to
440 <kbd class="normal">&lt;indent&gt;</kbd>,
441 <kbd class="normal">&lt;length&gt;</kbd>,
442 and
443 <kbd class="normal">&lt;depth&gt;</kbd>
444 must be surrounded by parentheses
445 </p>
446
447 <p>
448 To draw boxes of specified dimensions, you must, at a minimum,
449 supply DBX with the arguments <kbd>weight</kbd> or <kbd>SOLID</kbd>,
450 <kbd>indent</kbd> (measured from the current left margin),
451 <kbd>length</kbd> and <kbd>depth</kbd>.
452 </p>
453
454 <p>
455 Optionally, you may give a <kbd>colour</kbd> argument.  The colour
456 may be either one defined with
457 <a href="color.html#newcolor">NEWCOLOR</a>,
458 or a named X-colour inititialized with
459 <a href="color.html#xcolor">XCOLOR</a>,
460 or an X-colour alias (again, initialized with XCOLOR).
461 </p>
462
463 <p>
464 Say, for example, you want to draw a 1/2 point outline box that
465 starts one inch from the current left margin and has the dimensions 
466 12 picas x 6 picas.  To do so, you'd invoke <kbd>.DBX</kbd> like this:
467 <br/>
468 <span class="pre-in-pp">
469          indent   depth
470            |        |
471   .DBX .5  1i  12P  6P
472         |       |
473      weight   length
474 </span>
475 (Note that the box weight argument, which is expressed in points,
476 must NOT have the unit of measure <kbd>p</kbd> appended to it.)
477 </p>
478
479 <p>
480 If you want the same box, but solid (&#8220;filled&#8221;) rather
481 than drawn as an outline:
482 <br/>
483 <span class="pre-in-pp">
484   .DBX SOLID 1i 12P 6P
485 </span>
486 Additionally, if you want the box green:
487 <br/>
488 <span class="pre-in-pp">
489   .DBX .5 1i 12P 6P green
490    or
491   .DBX SOLID 1i 12P 6P green
492 </span>
493 </p>
494
495 <h3 class="docs">How mom handles the positioning of boxes</h3>
496
497 <p>
498 Boxes are drawn from the baseline down, from left to right, and
499 from the perimeter <i>inward</i>. &#8220;From the perimeter
500 inward&#8221; means that if you request a box weight of six points,
501 the 6-point rules used to draw the outline of the box fall entirely
502 <i>within</i> the dimensions of the box.
503 </p>
504
505 <p>
506 Furthermore, after the box is drawn, mom returns you to the current
507 left margin, at the same vertical position on the page as when DBX
508 was invoked.  In other words, DBX causes no movement on the page,
509 either horizontal or vertical.
510 </p>
511
512 <!-- -DCL- -->
513
514 <div class="macro-id-overline">
515 <h3 id="dcl" class="macro-id">Drawing circles (ellipses)</h3>
516 </div>
517
518 <div class="box-macro-args">
519 Macro: <b>DCL</b> <kbd class="macro-args">&lt; &lt;weight&gt; | SOLID &gt; &lt;indent&gt; &lt;length&gt; &lt;depth&gt; [&lt;colour&gt;]</kbd>
520 </div>
521
522 <p class="requires">
523 &bull;&nbsp;the argument to <kbd class="normal">&lt;weight&gt;</kbd> is in
524 <a href="definitions.html#picaspoints" class="normal">points</a>,
525 but do <span class="normal">NOT</span> append the
526 <a href="definitions.html#unitsofmeasure">unit of measure</a>,
527 <kbd class="normal">p</kbd>
528 <br/>
529 &bull;&nbsp;
530 the arguments
531 <kbd class="normal">&lt;indent&gt;</kbd>,
532 <kbd class="normal">&lt;length&gt;</kbd>
533 and
534 <kbd class="normal">&lt;depth&gt;</kbd>
535 require a unit of measure
536 <br/>
537 &bull;&nbsp;
538 arithmetic expressions to
539 <kbd class="normal">&lt;indent&gt;</kbd>,
540 <kbd class="normal">&lt;length&gt;</kbd>
541 and
542 <kbd class="normal">&lt;depth&gt;</kbd>
543 must be surrounded by parentheses
544 </p>
545
546 <p>
547 To draw circles of specified dimensions, you must, at a minimum,
548 supply DCL with the arguments <kbd>weight</kbd> or <kbd>SOLID</kbd>,
549 <kbd>indent</kbd> (measured from the current left margin),
550 <kbd>length</kbd> and <kbd>depth</kbd>.
551 </p>
552
553 <p>
554 Optionally, you may give a <kbd>colour</kbd> argument.  The colour
555 may be either one defined with
556 <a href="color.html#newcolor">NEWCOLOR</a>,
557 or a named X-colour inititialized with
558 <a href="color.html#xcolor">XCOLOR</a>,
559 or an X-colour alias (again, initialized with XCOLOR).
560 </p>
561
562 <p>
563 Say, for example, you want to draw a 1/2 point outline circle
564 (ellipse, actually, in this case) that starts one inch from the
565 current left margin and has the dimensions 6 centimeters x 3
566 centimeters.  To do so, you'd invoke <kbd>.DCL</kbd> like this:
567 <br/>
568 <span class="pre-in-pp">
569          indent  depth
570            |       |
571   .DCL .5  1i  6c  3c
572         |      |
573      weight  length
574 </span>
575 (Note that the box weight argument, which is expressed in points,
576 must NOT have the unit of measure <kbd>p</kbd> appended to it.)
577 </p>
578
579 <p>
580 If you want the same box, but solid (&#8220;filled&#8221;) rather
581 than drawn as an outline:
582 <br/>
583 <span class="pre-in-pp">
584   .DCL SOLID 1i 6c 3c
585 </span>
586 Additionally, if you want the circle yellow:
587 <br/>
588 <span class="pre-in-pp">
589   .DCL .5 1i 6c 3c yellow
590    or
591   .DCL SOLID 1i 6c 3c yellow
592 </span>
593 </p>
594
595 <h3 class="docs">How mom handles the positioning of circles (ellipses)</h3>
596
597 <p>
598 Circles (ellipses) are drawn from the baseline down, from left
599 to right, and from the perimeter <i>inward</i>. &#8220;From the
600 perimeter inward&#8221; means that if you request a circle weight of
601 six points, the 6-point rule used to draw the outline of the circle
602 or ellipse falls entirely <i>within</i> the dimensions of the
603 circle or ellipse.
604 </p>
605
606 <p>
607 Furthermore, after the circle is drawn, mom returns you to the
608 current left margin, at the same vertical position on the page as
609 when DCL was invoked.  In other words, DCL causes no movement on the
610 page, either horizontal or vertical.
611 </p>
612
613 <div class="rule-long"><hr/></div>
614
615 <!-- Navigation links -->
616 <table style="width: 100%; margin-top: 12px;">
617 <tr>
618   <td style="width: 33%;"><a href="toc.html">Back to Table of Contents</a></td>
619   <td style="width: 33%; text-align: center;"><a href="#top">Top</a></td>
620   <td style="width: 33%; text-align: right;"><a href="docprocessing.html#top">Next: Document processing</a></td>
621 </tr>
622 </table>
623
624 </div>
625
626 <div class="bottom-spacer"><br/></div>
627
628 </body>
629 </html>
630 <!-- vim: fileencoding=utf-8: nomodified: -->