                           [42m Learning PostScript [0m

                                [42m ~ Part 3 ~ [0m

                              [3m By Peter Goed [0m


[32m   || 33 ||| 33 ||| 33 ||| 33 ||| 33 ||| 33 ||| 33 ||| 33 ||| 33 ||| 33 ||
[0m

[33m   Graphics
[0m
   As we have already seen, a PostScript page description is built up by
  applying paint to graphics and text with the 'stroke', 'fill', and 'show'
  operators.  Paint can be applied in black, white, or any shade of grey; or
  in any colour, for PostScript devi ces that handle colour.

   We can modify the elements of the current graphics state in a similar
  fashion to an artist changing a brush or paint colour before rendering text
  and graphic elements on your page.

   PostScript interpreters remember the current graphics state parameters,
  any of which may be modified either temporarily or permanently at any point
  in a page description to affect just a small specified area or the entire
  page.

   In part one of these tutorials you learned to initialize and to modify two
  of the most fundamental graphics state parameters: the current point and
  the current path.

   In part two you learned to select the graphics shapes or characters that
  define the current font.

   In this session we will examine two graphics state parameters that are
  used to change the appearance of graphics or text: the width of the line
  produced by the 'stroke' operator and the colour of the graphic produced by
  the painting operators 'stroke', 'fill', and 'show'.

[33m   Colour
[0m
   Because very few people have access to colour PostScript output devices, I
  will limit this section to cover black, white and grey shades only.

   Let us begin with the following small page description.

        0 0 moveto
        612 0 rlineto 0 792 rlineto -612 0 rlineto
        closepath fill

        /Times-BoldItalic findfont 24 scalefont setfont
        306 100 moveto
        1 setgray
        (Amiga Forever ...) show

        showpage

   This page description constructs a rectangle the full size of the page
  (612 by 792) and fills it with the default colour black, we then selected a
  font and showed the text string (Amiga Forever ...) at the specified place
  on the page.

[33m   setgray
[0m
   The 1 'setgray' instruction caused the text to be painted white.  This
  technique is commonly referred to as a reverse, because it reverses the
  natural order of printing black characters on a white page.

   The 'setgray' operator is one of the simplest in the PostScript
  vocabulary.  In addition to reversing the natural order of black on white,
  it can also be used to create the illusion of depth or of a three
  dimensional aspect by altering background and fo reground colours, and by
  shading some graphic elements in relationship to others.

   The 'setgray' operator requires only one operand, ranging from 0 for black
  to 1 for white (no colour), or any intermediate value representing a
  percentage of black and white.  For example, .1 is 10 percent white - in
  other words dark grey; .5 is equal a mounts of black and white - medium
  grey; and .99 is nearly all white - very light grey.

   The following page description will give you an impression of text ranging
  from black to white in 10 steps.

        /Times-Bold findfont 30 scalefont setfont
        144 720 moveto
        0 setgray
        (PostScript) show

        144 648 moveto
        .1 setgray
        (PostScript) show

        144 576 moveto
        .2 setgray
        (PostScript) show

        144 504 moveto
        .3 setgray
        (PostScript) show

        144 432 moveto
        .4 setgray
        (PostScript) show

        144 360 moveto
        .5 setgray
        (PostScript) show

        144 288 moveto
        .6 setgray
        (PostScript) show

        144 216 moveto
        .7 setgray
        (PostScript) show

        144 144 moveto
        .8 setgray
        (PostScript) show

        144 72 moveto
        .9 setgray
        (PostScript) show

        144 0 moveto
        1 setgray               % which being white, will not be seen.
        (PostScript) show

        showpage

[33m   Layering
[0m
   The order in which the 'setgray' operator applies text and graphics to the
  page, using black, white and various shades of grey, is important.

   In the following page description, the shadowing effect of the text
  produced by the .9 'setgray' instruction must be applied before the black
  text produced by the 0 'setgray' instruction, or the shadow would be on top
  of the solid black text, instead of underneath it.

        /Helvetica-Bold findfont 72 scalefont setfont

        .9 setgray              % Grey first
        200 400 moveto
        (Stand) show
        225 325 moveto
        (Out) show

        0 setgray               % Black secondly
        220 425 moveto
        (Stand) show
        245 350 moveto
        (Out) show

        showpage

   This technique of applying paint to text and graphics in a certain order
  is known as "layering".

[33m   Shadowing
[0m
   The rectangle constructed by the code below, appears to be a solid white
  box, outlined with a black line, and with a black shadow underneath that
  causes the box to stand out from the page.  It is the shadow that gives the
  illusion of depth to the box.

   If you study the following instructions you will see that the illusion is
  in fact constructed from three separate boxes; a filled black box on the
  bottom, a white filled box, slightly offset on top of the black box, and a
  third box which is outlined with the stroke operator.


        % Box 1 -- a filled black box
        120 400 moveto
        200 0 rlineto 0 300 rlineto -200 0 rlineto
        closepath fill

        % Box 2 -- a filled white box - offset by 15 points from box 1
        1 setgray
        100 400 moveto
        200 0 rlineto 0 300 rlineto -200 0 rlineto
        closepath fill

        % Box 3 -- a stroked box outline - offset as box 2
        0 setgray
        100 400 moveto
        200 0 rlineto 0 300 rlineto -200 0 rlineto
        closepath stroke

        showpage


[33m   gsave and grestore
[0m
   The following instructions will create the previous example but in a
  slightly different way, to show the "save" and "restore" graphics state
  parameters to temporarily change one or more of the parameters.

   In this example we use the 'gsave' operator to save the default black
  colour used to paint the solid black in box 1, then issue the "1 setgray"
  instruction that sets the colour for box 2.

   The 'grestore' instruction then restores the black colour that was saved
  before we issued the "1 setgray" instruction.  There is now no need for a
  "0 setgray" instruction for the black outline of box 3.

        % Box 1 -- solid black
        115 385 moveto
        200 0 rlineto 0 300 rlineto -200 0 rlineto
        closepath fill

        % Box 2 -- white
        gsave
            1 setgray
            100 400 moveto
            200 0 rlineto 0 300 rlineto -200 0 rlineto
            closepath fill
        grestore

        % Box 3 -- black outline -- 0 setgray not needed
        2 setlinewidth
        100 400 moveto
        200 0 rlineto 0 300 rlineto -200 0 rlineto
        closepath stroke

        showpage

[33m   setlinewidth
[0m
   In the previous example we added the instruction "2 setlinewidth" to
  thicken the black outline stroked around the white box.  In the following
  example we use the 'setlinewidth' operator in place of filling a rectangle,
  as we did in the example in part 2 last month, for underlined text.

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

        0 -27 rmoveto
        72 621 lineto
        18 setlinewidth
        stroke

        showpage

   Instead of constructing and filling a rectangular box 18 points high, and
  underlining the string "Your Text" as in the example in part 2, the same
  object is achieved by stroking a line with the same 18 point thickness.

   NOTE: The 'setlinewidth' operator strokes equally on either side of the
  current path, hence the necessity to set the current path at 18 points plus
  half the linewidth of the 18 point line (9) equalling 27 points.

   The 'setlinewidth' operator is capable of rendering both text and lines at
  below the default of 1 point.  There are often times that you will find
  that a linewidth of .5 can give an attractive appearance to outlined text.

   On the other hand there will be times when you will want to display
  outlined text with a bolder appearance.  The instructions below cover both
  aspects discussed here.

        /Times-BoldItalic findfont 72 scalefont setfont

        72 504 moveto
        (Your Text) true charpath
        .5 setlinewidth                  % Ultra thin text
        stroke

        72 654 moveto
        (Your Text) true charpath
        12 setlinewidth              % This will give you an outline
                             % of 6 points either side of the
                             % 1 point default character outline.
                             % To make the characters look more
                             % attractive, you would normally add
                             % the following instructions to only
                             % give you the outside 6 points of
                             % the character as your outline.
        stroke

        72 654 moveto
        1 setgray                    % Turn on white
        (Your Text) show             % This will dump the normal text in
                             % white, on top of the inside
                             % 6 points of the outline you made,
                             % filling the characters with white.
        showpage

   You can use this principle to advantage in creating fancy looking text
  such as in the following instructions.

   /Times-BoldItalic findfont 72 scalefont setfont

        72 360 moveto
        (Your Text) true charpath
        fill                     % This will give you normal black text

        72 360 moveto
        (Your Text) true charpath
        3 setlinewidth
        stroke                   % This will give you a thicker outline
                                 % stroked around the previous text

        72 360 moveto
        (Your Text) true charpath
        1 setlinewidth
        1 setgray                % This will give you a white outline
        stroke                   % around and on top of the first text
                                 % but inside the outline used above
                                 % and will result in fancy looking text.
        showpage

   Using what we have learned so far in this month's episode, let us now
  construct something that will be useful in many applications.

   Fancy Text within a Shadow Box.

        % Shadow box
        46 566 moveto
        540 0 rlineto 0 100 rlineto -540 0 rlineto
        closepath fill           % Step one is to lay down the
                                 % black box for the background shadow

        % Background box
        gsave
            36 576 moveto
            1 setgray
            540 0 rlineto 0 100 rlineto -540 0 rlineto
            closepath fill       % Step two is to lay the offset white
        grestore                 % box on top of the step one black box

        % Outline box
        36 576 moveto
        2 setlinewidth
        540 0 rlineto 0 100 rlineto -540 0 rlineto
        closepath stroke         % Step three is to lay the black outline
                                 % box on top of the white box in step 2

        /Times-BoldItalic findfont 108 scalefont setfont

        140 590 moveto
        (TITLE) true charpath    % Step four
        fill                     % This lays solid black text on top of
                                 % the outline box in step three

        140 590 moveto
        (TITLE) true charpath
        3 setlinewidth           % Step five
        stroke                   % This lays a 3 point outline text on
                                 % top of the smaller text from step 4.

        140 590 moveto
        (TITLE) true charpath
        1 setlinewidth           % Step Six
        1 setgray                % Lays a one point white outline text
        stroke                   % on top of the outline text of step 5.

        showpage

   These layers must be created in the order given above for the whole show
  to work properly and give the desired result.

[33m   Shaded Box with Shadow Text
[0m
   Using the example we just created but changing a small amount of the code
  we can get another nice effect of shadow text within a shaded and shadowed
  box.

        % Shadow box
        46 566 moveto
        540 0 rlineto 0 100 rlineto -540 0 rlineto
        closepath fill

        % Background box
        gsave
            36 576 moveto
            .9 setgray      % Here we change from 1 to .9 (white to grey)
            540 0 rlineto 0 100 rlineto -540 0 rlineto
            closepath fill
        grestore

        % Outline box
        36 576 moveto
        2 setlinewidth
        540 0 rlineto 0 100 rlineto -540 0 rlineto
        closepath stroke         % Step three is to lay the black outline
                                 % box on top of the white box in step 2

        /Times-BoldItalic findfont 108 scalefont setfont

        90 587 moveto              % The instructions here are changed
        (T I T L E) show           % Paint solid black characters

        gsave                      % Save graphic state
            1 setgray              % Set white
            87 590 moveto          % Offset 3 points left and 3 points up
            (T I T L E) show       % Paint solid white characters
        grestore                   % Restore graphic state

        .5 setlinewidth
        87 590 moveto              % Offset 3 points left
        (T I T L E) true Charpath  % Paint a .5 point line in black
        stroke                     % around the characters, thus allowing
                                   % us to more easily see the break
                                   % between the white text and grey box
        showpage


   That brings us to the end of this month's lesson.  For homework this time,
  I will make it easy for you.  Using the two previous examples, create a
  page description that will give us a black box in the same position as in
  the last example.  Make this box 550 by 110 points and draw a white box
  that is 10 points smaller in height and width than the black box, but
  central within it.

   Now Central to this place the word TITLE in it using the 'ashow' operator
  to give a spacing of 24 points between characters.

   If you can handle this exercise comfortably, then you are with us, if you
  are having problems, I suggest that some revision of parts one and two will
  get you back on track again.  Good Luck!




[32m   || 33 ||| 33 ||| 33 ||| 33 ||| 33 ||| 33 ||| 33 ||| 33 ||| 33 ||| 33 ||
[0m



