Back to Table of Contents Next: Document processing

Graphical objects


Introduction to graphical objects

Groff has a number of inline escapes for drawing rules, polygons, ellipses and splines. All begin with \D (presumably for “Draw”) and are documented in the groff info manual:
info groff \D The escapes allow you to draw just about any simple graphical object you can think of, but owing to their syntax they’re not always easy to read, which can make tweaking them difficult. Additionally, while they perform in a consistent manner, they don’t always perform in an expected manner.

Experience shows that the most common graphical elements typesetters need are rules (horizontal and vertical), boxes, and circles (or ellipses). For this reason, mom provides macros to draw these objects in an easy-to-understand way; the results are predictable, and mom’s syntax makes fixes or tweaks painless.

For example, if you want to draw a 2-inch square outline box at the left margin using groff’s \D escapes, it looks like this:
back up by weight +-------+ | | \D't 500'\h'-500u'\D'p 2i 0 0 2i -2i 0 0 -2i' | | | | +-------+ +------------------------+ set rule draw box, 1 line at a time weight Obviously, this isn’t very efficient for something as simple as a box.

Here’s the same box, drawn with mom’s box drawing macro DBX:
left margin indent--+ +--box width | | .DBX .5 0 2i 2i | | rule weight--+ +--box depth (in points)

Mom’s graphical object macros allow—in fact, require—giving the rule weight (“thickness”) for the object (or saying that you want it filled), an indent from the left margin where the object begins, the dimensions of the object, and optionally a colour for the object.

There are no defaults for the arguments to mom’s graphical object macros, which means you must supply the arguments every time you invoke them.

Note: As stated above, mom only provides macros for commonly-used graphical objects (rules, boxes, circles). More complex objects (polygons, non-straight lines, splines) must be drawn using groff’s \D escapes.

Graphical object behaviour

Mom’s graphical object macros all behave in the following, carved-in-stone ways:

  1. Objects are drawn from the baseline down, including horizontal rules.
  2. Objects begin precisely at the left indent supplied as an argument to the macro.
  3. Objects are drawn from left to right.
  4. Enclosed objects (boxes, circles) are drawn from the perimeter inward.
  5. Objects return to their horizontal/vertical point of origin.

The consistency means that once you’ve mastered the very simple order of arguments that applies to invoking graphical object macros, you can draw objects with full confidence that you know exactly where they’re placed and how much room they occupy. Furthermore, because all return to their point of origin, you’ll know exactly where you are on the page.

Order of arguments

The order of arguments to the graphical object macros is the same for every macro:

Graphical objects macros

Drawing horizontal rules

Macro: DRH <none> | <weight> <indent> <width> [<colour>]

•  the argument to <weight> is in points, but do not append the unit of measure, p
•  <indent> and <width> require a unit of measure
•  arithmetic expressions to <indent> and <width> must be surrounded by parentheses

If all you want is to draw a rule from your current left margin to your current right margin (in other words, a "full measure" rule), you may invoke .DRH without any arguments.

Note: DRH is the only graphical object macro that may be invoked without arguments. The weight (“thickness”) of the rule is determined by the argument you last gave the macro RULE_WEIGHT. DRH, used this way, is exactly equivalent to entering the inline escape \*[RULE].

To draw horizontal rules of a specified width, you must, at a minimum, supply DRH with the arguments weight, indent (measured from the current left margin) and width.

Optionally, you may give a color argument. The colour may be either one defined with NEWCOLOR, or a named X-color initialized with XCOLOR, or an X-color alias (again, initialized with XCOLOR).

Say, for example, you want to draw a 1-1/4 point horizontal rule that starts 2 picas from the current left margin and runs for 3 inches. To do so, you’d invoke .DRH like this:
weight width | | .DRH 1.25 2P 3i | indent (Note that the rule weight argument, which is expressed in points, must not have the unit of measure p appended to it.)

If, in addition, you want the rule blue:
.DRH 1.25 2P 3i blue

How mom handles the positioning of horizontal rules

Horizontal rules are drawn from left to right, and from the baseline down. “From the baseline down” means that if you request a rule with a weight of four points, the four points of rule fall entirely below the baseline.

Furthermore, after the rule is drawn, mom returns you to the current left margin, at the same vertical position on the page as when DRH was invoked. In other words, DRH causes no movement on the page, either horizontal or vertical.

Drawing vertical rules

Macro: DRV <weight> <indent> <depth> [<colour>]

•  the argument to <weight> is in points, but do not append the unit of measure, p
•  <indent> and <depth> require a unit of measure
•  arithmetic expressions to <indent> and <depth> must be surrounded by parentheses

To draw vertical rules of a specified depth, you must, at a minimum, supply DRV with the arguments weight, indent (measured from the current left margin) and depth.

Optionally, you may give a color argument. The colour may be either one defined with NEWCOLOR, or a named X-color initialized with XCOLOR, or an X-color alias (again, initialized with XCOLOR).

Say, for example, you want to draw a 3/4-point vertical rule that starts 19-1/2 picas from the current left margin and has a depth of 6 centimetres. To do so, you’d invoke .DRV like this:
weight depth | | .DRV .75 19P+6p 6c | indent (Note that the rule weight argument, which is expressed in points, must not have the unit of measure p appended to it.)

If, in addition, you want the rule red:
.DRV .75 19P+6p 6c red

How mom handles the positioning of vertical rules

Vertical rules are drawn from the baseline down, and from left to right. "Left to right" means that if you request a rule with a weight of four points, the four points of rule fall entirely to the right of the indent given to DRV.

Furthermore, after the rule is drawn, mom returns you to the current left margin, at the same vertical position on the page as when DRV was invoked. In other words, DRV causes no movement on the page, either horizontal or vertical.

Drawing boxes

Macro: DBX <weight>|SOLID <indent> <width>|FULL_MEASURE <depth> [<color>]

•  the argument to <weight> is in points, but do not append the unit of measure p
• <indent>, <width>, and <depth> require a unit of measure
•  arithmetic expressions to <indent>, <width>, and <depth> must be enclosed in parentheses.

To draw boxes you must, at a minimum, supply DBX with the arguments weight or SOLID, indent, width or FULL_MEASURE, and depth.

weight is the rule weight of outlined boxes, given in points but without the unit of measure p appended.

If SOLID is given as the first argument, the box is filled rather than outlined and no weight argument should be supplied.

indent is measured from the current left margin. If FULL_MEASURE is given, indent should be set to “0”.

width is the width of the box with a unit of measure appended, caclculated from indent argument.

If FULL_MEASURE is given instead of width, it circumvents having to calculate the width when left and/or right indents are in effect; mom draws the box from the current left margin to the current right margin. When no indents are in effect, FULL_MEASURE or \n[.l]u—the groff way of saying “the current line length”—have the same effect.

Optionally, you may give a color argument. The colour may be either one defined with NEWCOLOR, or a named X-color initialized with XCOLOR, or an X-color alias (again, initialized with XCOLOR).

Say, for example, you want to draw a 1/2 point outline box that starts one inch from the current left margin and has the dimensions 12 picas x 6 picas. To do so, you’d invoke .DBX like this:
indent depth | | .DBX .5 1i 12P 6P | | weight width (Note that the box weight argument, which is expressed in points, must not have the unit of measure p appended to it.)

If you want the same box, but solid (“filled”) rather than drawn as an outline:
.DBX SOLID 1i 12P 6P Additionally, if you want the box green:
.DBX .5 1i 12P 6P green or .DBX SOLID 1i 12P 6P green

How mom handles the positioning of boxes

Boxes are drawn from the baseline down, from left to right, and from the perimeter inward. “From the perimeter inward” means that if you request a box weight of six points, the 6-point rules used to draw the outline of the box fall entirely within the dimensions of the box.

Furthermore, after the box is drawn, mom returns you to the current left margin, at the same vertical position on the page as when DBX was invoked. In other words, DBX causes no movement on the page, either horizontal or vertical.

Drawing circles (ellipses)

Macro: DCL <weight>|SOLID <indent> <width>|FULL_MEASURE <depth> [<color>]

•  the argument to <weight> is in points, but do not append the unit of measure p
• <indent>, <width>, and <depth> require a unit of measure
•  arithmetic expressions to <indent>, <width>, and <depth> must be enclosed in parentheses.

To draw circles you must, at a minimum, supply DCL with the arguments weight or SOLID, indent, width or FULL_MEASURE, and depth.

weight is the rule weight of outlined circles, given in points but without the unit of measure unit of measure p appended.

If SOLID is given as the first argument, the circle is filled rather than outlined and no weight argument should be supplied.

indent is measured from the current left margin. If FULL_MEASURE is given, indent should be set to “0”.

width is the width of the circle with a unit of measure appended, caclculated from indent argument.

If FULL_MEASURE is given instead of width, it circumvents having to calculate the width when left and/or right indents are in effect; mom draws the circle from the current left margin to the current right margin. When no indents are in effect, FULL_MEASURE or \n[.l]u—the groff way of saying “the current line length”—have the same effect.

Optionally, you may give a color argument. The colour may be either one defined with NEWCOLOR, or a named X-color initialized with XCOLOR, or an X-color alias (again, initialized with XCOLOR).

Say, for example, you want to draw a 1/2 point outline circle that starts one inch from the current left margin and has the dimensions 12 picas x 6 picas. To do so, you’d invoke .DCL like this:
indent depth | | .DCL .5 1i 12P 6P | | weight width (Note that the circle weight argument, which is expressed in points, must not have the unit of measure p appended to it.)

If you want the same circle, but solid (“filled”) rather than drawn as an outline:
.DCL SOLID 1i 12P 6P Additionally, if you want the circle green:
.DCL .5 1i 12P 6P green or .DCL SOLID 1i 12P 6P green

How mom handles the positioning of circles (ellipses)

Circles (ellipses) are drawn from the baseline down, from left to right, and from the perimeter inward. “From the perimeter inward” means that if you request a circle weight of six points, the 6-point rule used to draw the outline of the circle or ellipse falls entirely within the dimensions of the circle or ellipse.

Furthermore, after the circle is drawn, mom returns you to the current left margin, at the same vertical position on the page as when DCL was invoked. In other words, DCL causes no movement on the page, either horizontal or vertical.


Back to Table of Contents Top Next: Document processing