?? unx25.htm
字號(hào):
<HTML>
<HEAD>
<TITLE>UNIX Unleashed unx25.htm</TITLE>
<LINK REL="ToC" HREF="index.htm">
<LINK REL="Next" HREF="unx26.htm">
<LINK REL="Previous" HREF="unx24.htm"></HEAD>
<BODY TEXT="#000000" LINK="#0000FF" VLINK="#800080" bgcolor=white>
<P><A HREF="unx24.htm"><IMG SRC="bluprev.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Previous Page"></A>
<A HREF="index.htm"><IMG SRC="blutoc.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="TOC"></A>
<A HREF="unx26.htm"><IMG SRC="blunext.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Next Page"></A>
<A HREF="index.htm"><IMG SRC="bluprev.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Home"></A>
</P><UL>
<UL>
<LI>
<A HREF="#I1">25 — Drawing Pictures with pic</A></LI>
<UL>
<UL>
<UL>
<LI>
<A HREF="#I3">By Susan Peppard</A></LI></UL></UL>
<LI>
<A HREF="#I4">The Basics</A></LI>
<UL>
<LI>
<A HREF="#I5">Required Macros and Primitives</A></LI>
<LI>
<A HREF="#I6">Forbidden Macros and Primitives</A></LI></UL>
<LI>
<A HREF="#I7">Adding Text</A></LI>
<LI>
<A HREF="#I8">Default Placement of Objects</A></LI>
<LI>
<A HREF="#I9">Connecting Objects</A></LI>
<LI>
<A HREF="#I10">More about Placement</A></LI>
<LI>
<A HREF="#I11">Additional Shapes and Functions</A></LI>
<LI>
<A HREF="#I12">Controlling Size</A></LI>
<LI>
<A HREF="#I13">Object Blocks</A></LI>
<LI>
<A HREF="#I14">Macros and Variables</A></LI>
<LI>
<A HREF="#I15">Debugging</A></LI>
<LI>
<A HREF="#I16">pic Tips and Tricks</A></LI>
<LI>
<A HREF="#I17">Summary</A></LI></UL></UL></UL>
<H2 ALIGN="CENTER">
<CENTER><A ID="I1" NAME="I1">
<FONT SIZE=5><A ID="I2" NAME="I2"></A><B>25 — Drawing Pictures with </B><B><I>pic</I></B>
<BR></FONT></A></CENTER></H2>
<H5 ALIGN="CENTER">
<CENTER><A ID="I3" NAME="I3">
<FONT SIZE=3><B>By Susan Peppard</B>
<BR></FONT></A></CENTER></H5>
<P>pic is rarely your first choice as a drawing tool. With pic you can draw lines and a limited variety of shapes—no color, no shading—but you can create a complex and detailed picture, if you're willing to work at it. pic was developed before
everyone had personal computers with sophisticated, mouse-based drawing packages. Today, troff users with graphics terminals can use mouse-based programs such as xcip. These programs provide many of the capabilities—except for color—of the
sophisticated packages, and they don't require a knowledge of pic. xcip produces pic code, which—and here's the point—you can edit if you know pic.
<BR></P>
<P>pic is no substitute for a sophisticated drawing tool. It doesn't have color. It provides shading only inside boxes, circles, and ellipses. It doesn't even let you draw a randomly wiggly line.
<BR></P>
<H3 ALIGN="CENTER">
<CENTER><A ID="I4" NAME="I4">
<FONT SIZE=4><B>The Basics</B>
<BR></FONT></A></CENTER></H3>
<P>To draw a box, type
<BR></P>
<PRE>.PS
box ht 1 wid 1.25
.PE</PRE>
<P>The result is
<BR></P>
<P><B><IMG SRC="25unx01.gif"></B></P>
<P>This example specifies a height and a width. If you don't specify them—you're not required to—the box will be three-quarters inch high and one-half inch wide.
<BR></P>
<P>You can draw circles. For example,
<BR></P>
<PRE>.PS
circle rad .5
.PE</PRE>
<P>produces
<BR></P>
<P><B><IMG SRC="25unx02.gif"></B></P>
<P>You can draw ellipses, too. For example,
<BR></P>
<PRE>.PS
ellipse ht .5 wid 1.25
.PE</PRE>
<P>produces
<BR></P>
<P><B><IMG SRC="25unx03.gif"></B></P>
<P>The default pic unit is inches. pic has default sizes for boxes, circles, and ellipses. The pic default sizes are listed in the "Controlling Size" section later in this chapter.
<BR></P>
<H4 ALIGN="CENTER">
<CENTER><A ID="I5" NAME="I5">
<FONT SIZE=3><B>Required Macros and Primitives</B>
<BR></FONT></A></CENTER></H4>
<P>troff recognizes pic code by its opening and closing macros: .PS and .PE. ms includes a .PF macro for picture flyback. This macro restores you to your last position on the page (vertically and horizontally) before the picture—where you were before
you invoked pic. This feature is rarely used; some pic users surround their pic code with display macros and specify no-fill mode. For example,
<BR></P>
<PRE>.DS
.nf
.PS
.box ht 1 wid 1.25
.
.
.PE
.DE</PRE>
<P>This might look like overkill, but mm likes it.
<BR></P>
<P>The .PS macro also can be used to do the following:
<BR></P>
<TABLE>
<TR>
<TD>
<P>.PS < filename</P>
<TD>
<P>Sources in a pic file; imports an external file called filename and allows it to be processed as if filename were part of your text file.</P>
<TR>
<TD>
<P>.PS wid ht</P>
<TD>
<P>Enables you to specify the width or the height—or both—of the final picture</P></TABLE>
<HR ALIGN=CENTER>
<NOTE>
<IMG SRC="caution.gif" WIDTH = 37 HEIGHT = 35><B>CAUTION: </B>If you have a space after the .PS and no measurements, your figure will be enlarged proportionally so that its width is the current width (line length) of your pages.
<BR></NOTE>
<HR ALIGN=CENTER>
<P>To insert comments in pic code, begin a line with #.
<BR></P>
<H4 ALIGN="CENTER">
<CENTER><A ID="I6" NAME="I6">
<FONT SIZE=3><B>Forbidden Macros and Primitives</B>
<BR></FONT></A></CENTER></H4>
<P>Whatever you do, don't include any spacing requests—.sp, .ls, .vs, .SP, and .P—inside your pic code. pic does its own spacing, and it gets really annoyed if you interfere. Use the move command instead.
<BR></P>
<H3 ALIGN="CENTER">
<CENTER><A ID="I7" NAME="I7">
<FONT SIZE=4><B>Adding Text</B>
<BR></FONT></A></CENTER></H3>
<P>You can put labels in these basic pic shapes. Consider the following code:
<BR></P>
<PRE>.PS
box ht .75 wid .75 "A Square"
move
box ht .75 wid .75 "Another" "Square"
.PE</PRE>
<P>It produces
<BR></P>
<P><B><IMG SRC="25unx04.gif"></B></P>
<P>Each line of text is enclosed in its own set of quotation marks.
<BR></P>
<P>pic attempts to center your text, both vertically and horizontally, which isn't helpful if you want to label a line. For example,
<BR></P>
<PRE>.PS
line right 1i "line"
.PE</PRE>
<P>comes out looking like
<BR></P>
<P><B><IMG SRC="25unx05.gif"></B></P>
<P>Fortunately, pic recognizes the words above and below, so you can position your text so that it is more readable. If you have two lines of text, pic puts one above the line and one below it. For example,
<BR></P>
<PRE>.PS
line right 1i "over" "under"
.PE</PRE>
<P>produces
<BR></P>
<P><B><IMG SRC="25unx06.gif"></B></P>
<P>pic doesn't object if you want to specify the font and point size for your text, so long as you keep the specifications inside the quotation marks. For example,
<BR></P>
<PRE>.PS
line right 1i "\f(HB\s12over" "under\fP\s0"
.PE</PRE>
<P>produces
<BR></P>
<P><B><IMG SRC="25unx07.gif"></B></P>
<HR ALIGN=CENTER>
<NOTE>
<IMG SRC="note.gif" WIDTH = 35 HEIGHT = 35><B>NOTE:</B> To right or left justify text, use rjust or ljust.
<BR></NOTE>
<HR ALIGN=CENTER>
<P>The preceding examples are troff escape sequences and are discussed further in Chapter 21, "Basic Formatting with troff/nroff."
<BR></P>
<H3 ALIGN="CENTER">
<CENTER><A ID="I8" NAME="I8">
<FONT SIZE=4><B>Default Placement of Objects</B>
<BR></FONT></A></CENTER></H3>
<P>pic assumes that all objects it draws should touch one another. Therefore, if you specify
<BR></P>
<PRE>.PS
box ht .5 wid 1 "Box 1"
box ht .5 wid 1 "Box 2"
.PE</PRE>
<P>you will get
<BR></P>
<P><B><IMG SRC="25unx08.gif"></B></P>
<P>Fortunately, pic has a move command, which you can use to separate the boxes. For example,
<BR></P>
<PRE>.PS
box ht .5 wid 1 "Box 1"
move
box ht .5 wid 1 "Box 2"
.PE</PRE>
<P>produces
<BR></P>
<P><B><IMG SRC="25unx09.gif"></B></P>
<P>The move command's default direction is to the right. Its default distance is one-half inch. You can change these defaults by specifying a direction and a distance, as in
<BR></P>
<PRE>.PS
box ht .5 wid 1 "Box 1"
move left 2i
box ht .5 wid 1 "Box 2"
.PE</PRE>
<P>Now the boxes look like
<BR></P>
<P><B><IMG SRC="25unx10.gif"></B></P>
<P>Note that the distance between the two boxes is actually one inch, not the two inches you specified in the move command. The reason is that pic measures from center to center, not from edge to edge.
<BR></P>
<H3 ALIGN="CENTER">
<CENTER><A ID="I9" NAME="I9">
<FONT SIZE=4><B>Connecting Objects</B>
<BR></FONT></A></CENTER></H3>
<P>pic is especially suited for charts and flow diagrams. Consider the following code:
<BR></P>
<PRE>.PS
box; line; box
move right li
box; arrow; box
.PE</PRE>
<P>It produces
<BR></P>
<P><B><IMG SRC="25unx11.gif"></B></P>
<HR ALIGN=CENTER>
<NOTE>
<IMG SRC="note.gif" WIDTH = 35 HEIGHT = 35><B>NOTE:</B> When you write pic code, you specify one command per line, or you can separate commands with semicolons. Long lines require the continuation symbol (\).
<BR></NOTE>
<HR ALIGN=CENTER>
<P>As you can see from the code and the figure, arrow is a synonym for line.
<BR></P>
<P>The following commands are useful as well:
<BR></P>
<TABLE BORDER>
<TR>
<TD>
<P>line -></P>
<TD>
<P>Draws an arrowhead at the end of the arrow. It doesn't necess-arily point to the right.</P>
<TR>
<TD>
<P>line <-</P>
<TD>
<P>Draws an arrowhead at the beginning of the arrow. It doesn't necessarily point to the left.</P>
<TR>
<TD>
<P>line <-></P>
<TD>
<P>Draws arrowheads on both ends of the arrow.</P></TABLE>
<HR ALIGN=CENTER>
<NOTE>
<IMG SRC="imp.gif" WIDTH = 68 HEIGHT = 35><B>TIP: </B>To draw a line with an arrow at both ends, use line <-> or arrow <->. This might seem obvious, but for seven years I drew two-headed arrows using the arrow command twice—drawing a
right-pointing arrow over a left-pointing arrow—because nobody told me about <->.
<BR></NOTE>
<HR ALIGN=CENTER>
<P>Suppose that you want Box 2 directly under Box 1. Consider the following code:
<BR></P>
<PRE>.PS
box "Box 1"
move down
box "Box 2"
.PE</PRE>
<P>It produces
<BR></P>
<P><B><IMG SRC="25unx12.gif"></B></P>
<P>The problem with this code is that pic moves half an inch from wherever it left off drawing the first box, which in this case is the middle of the box top. To place Box 2 correctly, you have to move down another one-half inch and to the left:
<BR></P>
<PRE>.PS
box "Box 1"
move left .375i
move down .75i
box "Box 2"
.PE</PRE>
<P>Figure 25.1 shows you the result.
<BR></P>
<P>
<BR><B><A HREF="25unx13.gif">Figure 25.1. Two boxes positioned correctly.</A></B>
<BR></P>
<P>This is a nuisance, to say the least, because in a complicated drawing you quickly lose track of where pic begins and ends each element of the drawing. You can use reference points with pic so that you know where each element of your drawing will be
placed. They are discussed in the next section.
<BR></P>
<H3 ALIGN="CENTER">
<CENTER><A ID="I10" NAME="I10">
<FONT SIZE=4><B>More about Placement</B>
<BR></FONT></A></CENTER></H3>
<P>To avoid having to think like pic—an exercise that can be dangerous to your mental health—you can refer to parts of objects that you've drawn. pic recognizes all of the following:
<BR></P>
<TABLE BORDER>
<TR>
<TD>
<P>.l left</P>
<TD>
<P>.ne northeast</P>
<TR>
<TD>
<P>.r right</P>
<TD>
<P>.nw northwest</P>
<TR>
<TD>
<P>upper</P>
<TD>
<P>bottom</P>
<TR>
<TD>
<P>lower</P>
<TD>
<P>start</P>
<TR>
<TD>
<P>.t top</P>
<TD>
<P>end</P>
<TR>
<TD>
<P>.n north</P>
<TD>
<P>1st</P>
<TR>
<TD>
<P>.e east</P>
<TD>
<P>2nd</P>
<TR>
<TD>
<P>.w west</P>
<TD>
<P>3rd (and so on)</P>
<TR>
<TD>
<P>.s south</P>
<TD>
<P>last</P>
<TR>
<TD>
<P>.nw northwest</P>
<TD>
<P>2nd last </P>
<TR>
<TD>
<P>.sw southwest</P>
<TD>
<P>3rd last (and so on)</P></TABLE>
<P>pic also understands compass points. Figure 25.2 shows the parts of a pic element to which you can refer.
<BR></P>
<P>
<BR><B><A HREF="25unx14.gif">Figure 25.2. </B><B>pic</B><B> reference points.</A></B>
<BR></P>
<P>The position notation words and the compass points enable you to specify positions like these:
<BR></P>
<PRE>line from upper right of 2nd last box to upper left of last box
arrow from 1st circle.e to 2nd circle.w
box at end of last line
move left 1i from start of last box
line from Box.c to Box.s
move down 1i from bottom of 2nd last ellipse</PRE>
<HR ALIGN=CENTER>
<NOTE>
<IMG SRC="note.gif" WIDTH = 35 HEIGHT = 35><B>NOTE:</B> You can use terms like upper left and lower right, but not top left and lower bottom.
<BR></NOTE>
<HR ALIGN=CENTER>
<P>Now you have several ways of specifying the two boxes shown in Figure 25.1. You could write
<BR></P>
<PRE>.PS
box "Box 1"
move to last box.s down .5
box "Box 2"
.PE</PRE>
<P>or you could write
<BR></P>
<PRE>.PS
box "Box 1"
move to bottom of last box down .5
box "Box 2"
.PE</PRE>
<P>If you want to avoid the wordiness of bottom of last box, you can label your construct
<BR></P>
<PRE>B1: box "Box 1"</PRE>
<P>Labels must begin with a capital letter.
<BR></P>
<P>Using labels enables you to specify the two boxes as follows:
<BR></P>
<PRE>.PS
B1:box "Box 1"
B2:box with .c down 1i from B1.c "Box 2"
.PE</PRE>
<HR ALIGN=CENTER>
<NOTE>
<IMG SRC="imp.gif" WIDTH = 68 HEIGHT = 35><B>TIP: </B>If you reference objects by their centers, you don't have to worry about where pic starts a new object or in which direction the new object is drawn.
<BR></NOTE>
<HR ALIGN=CENTER>
<P>These notations—left, right, .ne, .sw, and so on—assume that you can tell left from right and east from west. If you are directionally challenged like me, you should allow extra debugging time for your pics. I've tried sticking scraps of paper
labelled left/west and right/east on the sides of my monitor. It helps a little.
<BR></P>
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -