[comp.lang.postscript] box function

jasmerb@mist.CS.ORST.EDU (Bryce Jasmer) (06/30/89)

I'm curious as to why there is no box operator in postscript. (note: I only
know about Adobe PS version 1.0 so if a later version has a box operator than
you are permitted to flame me.)

What is the best way to draw a box in postscript? I have written a macro
that does the work but I am wondering if there is a better way to
draw a box (better code, faster code, etc).

% box
% call like this:  x y width height box
% 			bottom - STACK - top
/box {				x y w h
  4 2 roll			w h x y
  moveto			w h
  dup 				w h h
  0 exch rlineto		w h
  exch				h w
  0 rlineto			h
  neg 0 exch rlineto		-
  closepath
} def

-----------

Bryce Jasmer
jasmerb@hobbes.cs.orst.edu

greid@adobe.com (Glenn Reid) (06/30/89)

In article <11455@orstcs.CS.ORST.EDU> jasmerb@mist.CS.ORST.EDU (Bryce Jasmer) writes:
>I'm curious as to why there is no box operator in postscript. (note: I only
>know about Adobe PS version 1.0 so if a later version has a box operator than
>you are permitted to flame me.)

>% box
>% call like this:  x y width height box
>% 			bottom - STACK - top
>/box {				x y w h
>  4 2 roll			w h x y
>  moveto			w h
>  dup 				w h h
>  0 exch rlineto		w h
>  exch				h w
>  0 rlineto			h
>  neg 0 exch rlineto		-
>  closepath
>} def

You have written a very nice procedure.  (You should probably use "bind
def" rather than just "def", to make it a little faster; also, I assume
you just forgot the '%' before the stack trace on the right of each
line....).

Also, new operators have been added to the PostScript language to
handle rectangles, but at present they are only available in Display
PostScript interpreters.  They are "rectfill" and "rectstroke", and
they use arguments in the same fashion that your "box" procedure does.

Glenn Reid
Adobe Systems