[comp.lang.postscript] drawing a filled box

rokicki@Neon.Stanford.EDU (Tomas G. Rokicki) (12/12/90)

Does anyone know how to draw a filled box to a precise device-dependent size?
For instance, I want exactly a 2 pixel by 100 pixel filled rectangle on a
300 dpi device.

Now some constraints.  If that same image is printed at 1270, I want to get
the correct (ie, 2*1270/300, 100*1270/300) size, within a pixel or two.
(So just subtracting one from the size and using fill doesn't work.)  I
want to get the same size rectangle no matter where on the page it is
found (so transform/itransform should help.)

I can do this with image.  Let us say for the moment that image and
imagemask don't exist; I need to do this with fill.

I need this to work on an original LaserWriter and more recent PostScript
devices.

Any suggestions?

This is a recent attempt:

%! PostScript
72 300 div dup scale
1000 1000 moveto
% width height drawfilledbox -
/baddrawfilledbox {
   .01 sub /height exch def .01 sub /width exch def
   gsave
      currentpoint transform round exch round exch itransform moveto
      0 width rlineto height 0 rlineto 0 width neg rlineto fill
   grestore
} def
/gooddrawfilledbox {
   /height exch def /width exch def
   gsave
      currentpoint translate height width scale
      1 1 false [1 0 0 1 0 0] { 8 string } imagemask
   grestore
} def
100 { 2 100 baddrawfilledbox 0 4 rmoveto } repeat
0 100 rmoveto
100 { 2 100 gooddrawfilledbox 0 4 rmoveto } repeat
showpage