

                             [43m Learning PostScript [0m

                                 ~ Part Two ~


                                 By Peter Goed



   Ed: Check out Part I of this fine series on MD 31.


[32m   ]] 32 [[ ]] 32 [[ ]] 32 [[ ]] 32 [[ ]] 32 [[ ]] 32 [[ ]] 32 [[ ]] 32 [[


   How did you like the little assignment that I left you to complete last
  month?  Did you solve it?  Well here is the result that you should have
  obtained.

486 396 moveto
-180 180 rlineto   % Side one

-180 -180 rlineto  % Side two
180 -180 rlineto   % Side Three
closepath          % Side four
stroke

showpage


   Side two is drawn by moving left and and down 180 points each, relative to
  the current point, therefore both operands are negative.  Side three moves
  right and down 180 points relative to the current point, requiring a
  negative and positive number, respectively.  Side four is constructed
  using the 'closepath' operator, which completes the diamond.  Then the
  diamond is painted with the 'stroke' operator, and the 'showpage' operator
  to send it to the printer.

   As you have by now no doubt determined, PostScript is not really a
  difficult language to come to terms with.  At this stage you should be
  capable of constructing any type of object comprised of straight lines on
  any part of your page, so let us move on to text.

   PostScript uses POSTFIX NOTATION, a system in which operands precede
  operators.  PostScript treats space, tab, and new line (carriage return or
  line feed) characters - even several in a row - as a single space
  character.  You can use these characteristics to advantage in making your
  code more readable and understandable, without changing the way that it
  operates.  Remember that all operators are always in lower case and the
  language is extremely case sensitive.




[1mText as Graphics

   Although PostScript is best known for graphics drawing, one of the main
  reasons for choosing PostScript is for its superb font handling
  capabilities.  Using PostScript for text processing provides two primary
  functions.

   First, the characters in any PostScript typeface are stored as individual
  Bezier outlines that can be scaled to form a font of any desired point size
  on demand.  This makes PostScript very versatile and storage efficient,
  compared to other typographical methods that require pre-formed font
  bitmaps for each point size.

   Secondly, the outlines from which the PostScript interpreter generates
  individual characters are based on the same model used for rendering
  graphics.  Fonts are therefore subject to all types of graphical
  manipulation, including rotation, scaling, reflection, skewing, and
  clipping.  Thus, in PostScript, text is said to be "fully integrated" with
  graphics.  Elaborate textual designs can be created as easily as other
  graphics.

   Bezier curves are one of several ways of representing curved surfaces in
  computer graphics.  Because they define the curves' endpoints and use two
  other control points to define the shape of the curve, they are ideally
  suited for use in interactive comp uter graphics, where a pointing device
  such as a mouse can be used to mould the curve to the desired shape, as
  happens in most Amiga PostScript programs that let you draw a Bezier curve.


[1mBezier Outlines

   Bezier outlines are specialized pre-formed graphics that have all the
  elements of a PostScript page description; an underlying x/y coordinate
  system with a point of origin in the lower left corner, an initial 'moveto'
  instruction to begin a path, a series of 'lineto' and 'curveto'
  instructions necessary to construct the straight and curved line segments
  that comprise the character shape, and a final 'closepath' instruction to
  complete the character.


[1mFont Selection

   To select a font in PostScript it is first necessary to identify the
  desired typeface.

/Times-BoldItalic

   The slash character (/) at the beginning of this instruction is a special
  PostScript character that always identifies a "literal" name - in this
  case, "Times-BoldItalic".

   "Times" identifies the typeface family, of which this particular typeface
  is a part.  Many typeface families used in desktop publishing contain four
  typefaces: normal, bold, Italic (oblique), and bold-italic, although some
  of these may be described by other names.


findfont

   PostScript stores the outlines for available typefaces internally.  The
  PostScript 'findfont' operator searches for the requested font, and if it
  finds it, establishes it as the current font.

/Times-BoldItalic findfont

   PostScript interpreters that are aligned to an Adobe release, contain at
  least 13 internal typefaces: four typefaces in the Times, Helvetica, and
  Courier families, plus the Symbol font.  Interpreters with 13 typefaces are
  said to be compatible with the o riginal Apple Laser Writer.  Most recent
  PostScript interpreters have access to the 35 internal typefaces shown in
  the following list.  These interpreters are classed as being compatible
  with the Apple Laser Writer Plus.

   The typeface name must be specified exactly as it appears in the list,
  otherwise the interpreter will be unable to locate the desired typeface and
  will use the default typeface, which is normally Courier.

[1m35 Standard Typefaces:

AvantGarde-Book            AvantGarde-BookOblique
AvantGarde-Demi            AvantGarde-DemiOblique
Bookman-Demi               Bookman-DemiItalic
Bookman-Light              Bookman-LightItalic
Courier                    Courier-Bold
Courier-BoldOblique        Courier-Oblique
Helvetica                  Helvetica-Bold
Helvetica-Oblique          Helvetica-BoldOblique
Helvetica-Narrow           Helvetica-Narrow-Bold
Helvetica-Narrow-Oblique   Helvetica-Narrow-BoldOblique
NewCenturySchlbk-Bold      NewCenturySchlbk-BoldItalic
NewCenturySchlbk-Italic    NewCenturySchlbk-Roman
Palatino-Bold              Palatino-BoldItalic
Palatino-Italic            Palatino-Roman
Symbol (Symbol)            Times-Bold
Times-BoldItalic           Times-Italic
Times-Roman                ZapfChancery-MediumItalic
ZapfDingbats (ZapfDingbats)


[1mscalefont

   Once you've selected a typeface with 'findfont', you can set the size of
  the type with the 'scalefont' operator.

   Because characters are scaled uniformly in both the x and y directions,
  the 'scalefont' operator requires only one operand. (Non uniform scaling
  of fonts is possible and will be discussed in a future tutorial).

/Times-BoldItalic findfont
72 scalefont

   Bezier outlines are stored internally in the interpreter as 1000 point
  outlines that 'findfont' factors by .001 to return a 1 point font, this is
  then scaled to the point size specified by the 'scalefont' operand.

[1msetfont

   The 'setfont' operator establishes the specified typeface and font point
  size as the current font, to be used for subsequent character operations.

/Times-BoldItalic findfont
72 scalefont
setfont


[1mCharacter Strings

   Once you've defined a current font, you're ready to tell the PostScript
  interpreter what characters to draw in that font.  First you establish a
  new path with an initial 'moveto' instruction, then specify the string of
  characters you want printed.

/Times-BoldItalic findfont
72 scalefont
setfont
72 648 moveto
(Your Text)

   Left and right parentheses are used in PostScript to identify a string of
  characters.  The string may contain one or any number of characters or even
  no characters.

[1mshow

   The character string is now ready to be painted, this is accomplished with
  a special text operator 'show'.  The 'show' operator fills the specified
  character string with the current colour and moves the current point to the
  end of the string

/Times-BoldItalic findfont
72 scalefont
setfont
72 648 moveto
(Your Text) show

showpage    % last command needed to print the page


[1mashow

   There are other PostScript operators beside 'show' that you can use for
  painting text characters, one of these is 'ashow', which provides the means
  to modify the distance between the characters in any string, either along
  the horizontal or vertical axis.

   The following page description is identical to the previous example, but
  the 'ashow' operator is substituted for 'show' and firstly used to alter
  the horizontal and then both the horizontal and vertical spacing between
  each character in the string.

/Times-BoldItalic findfont
72 scalefont
setfont
72 648 moveto
12 0 (Your Text) ashow

72 648 moveto
12 -72 (Your Text) ashow

showpage

   The 'ashow' operator requires three operands - the x and y values of
  additional spacing (1 point is the standard default) between each
  character, in either or both the horizontal and vertical directions, and
  the string of characters to be drawn.

   As with other x/y values the operands for 'ashow' specify distances in
  points.  The first instance of 'ashow' moves each character 12 points
  right, the second moves each character 12 points right and 72 points down.


[1mcharpath

   When the 'show' operator fills text characters with the current colour,
  the 'stroke' operator produces character outlines by painting along the
  character path ('true charpath') of each character.  The 'charpath'
  operator, combined with the operand 'true ', defines the characters' path -
  the outline of the characters; you can then act on that path as you can any
  other path.

/Times-BoldItalic findfont
72 scalefont
setfont
72 648 moveto
(Your Text) true charpath
stroke     % Produces outline text
           % Had we used show, filled
           % characters would have resulted

showpage


   NOTE: The following instructions will accomplish the same result as using
  the 'show' operator, using 'true charpath fill' is slower than 'show'.

/Times-BoldItalic findfont
72 scalefont
setfont
72 648 moveto
(Your Text) true charpath
fill       % Produces filled (solid) text

showpage


[1mUnderlined Text

   The following instructions will write "Your Text" and then produce a
  rectangle as a heavy underline below it.

/Times-BoldItalic findfont
72 scalefont
setfont
72 648 moveto
(Your Text)
show

72 612 moveto
288 0 rlineto
0 18 rlineto
-288 0 rlineto
closepath
fill

showpage


[1mrmoveto

   In the previous example, the 4 inch underline (that you created in part
  one of this tutorial) is not really a suitable underline as there is no
  guarantee that it ends at the end of your character string, hence we use
  the instruction 'rmoveto' to align the end of the rectangle used as the
  underline with the end of the text string.

   This is accomplished by moving to a point directly under the end of the
  string (the new current point that results when we 'show' the string) and
  drawing the rectangle from right to left, back to the point of origin for
  the string, which we know is def ined as 72x.

/Times-BoldItalic findfont
72 scalefont setfont
72 648 moveto
(Your Text) show

0 -18 moveto   % move 18 points below the current point
0 -18 rlineto  % draw a line from the current point down 18 points
72 612 lineto  % note the use of the absolute 'lineto'
0 18 rlineto   % draw a line from the new current point up 18 points
closepath      % complete the rectangle
fill

showpage


[1m   PostScript String Syntax

   The following special rules apply to PostScript strings.

   * Strings are always enclosed in left end right parentheses.

   * Strings can contain special PostScript characters such as "%".

   * They can contain ((balanced)) left and right parentheses.

   * Strings can also be empty or nul, as ().

   * Within a string the backslash character (\) is a special PostScript
  "escape" character used to define things such as unbalanced parentheses, or
  the continuation of a string on a new line.

\(    unbalanced left parentheses
\)    unbalanced right parentheses
\r    carriage return
\n    line feed
\f    form feed
\t    horizontal tab
\b    backspace
\\    backslash
\nnn  octal character code for accessing ASCII characters


   The use of octal codes will be covered in a later episode, if we all get
  that far!


[1m   Homework time!

   That brings us to the end of this month's tutorial.  Hopefully you have
  come to grips with text in this episode and as for last month, it brings us
  to homework time again.

   During the next month construct some code that will draw a rectangle
  having a margin of 1/2 inch all around the outer edges of the page.  Within
  this rectangle, at a point 1 inch below the top of the rectangle and one
  inch from the left, write the words "Brisbane" giving a space of 3 points
  between characters and underline it with a 6 point filled rectangle.

   If you feel confident enough, as an extra, also write the word "Brisbane"
  going down from the horizontal one, but space the characters half an inch
  apart vertically, in a direct vertical descent starting with the same "B".

   A helpful hint is to draw out a full size representation of the figure 1
  in last month's tutorial and work out your points on this.


Till next time

Peter Goed



[32m   ]] 32 [[ ]] 32 [[ ]] 32 [[ ]] 32 [[ ]] 32 [[ ]] 32 [[ ]] 32 [[ ]] 32 [[



