hansen@cs.wmich.edu ( Jeff Hansen) (03/28/90)
In a way-old previous article, Ross Jeynes posted a PostScript program
called "scaletoXYsize," which follows. The intention of the program is
to scale text (horizontally and vertically) to fit a pre-defined area.
Unforunately, I can't seem to get it working correctly for multiple lines;
one would assume by passing the same box but different areas of the page
to place the text, it would all line up... If someone could point out
what the problem is, I would be most grateful.
% this will distort text to fit in box
/inch { 72 mul } def
/scaletoXYsize { % string sizex sizey fontname -> string
findfont setfont
2 index % string sizex sizey string
gsave
newpath % so that pathbbox is correct for text
0 0 moveto % set a currentpoint
false charpath flattenpath
pathbbox % ... llx lly urx ury
3 -1 roll % ... llx urx ury lly
sub /smsizy exch def % ... llx urx
exch sub /smsizx exch def % string sizex sizey
smsizy div /scaley exch def % string sizex
smsizx div /scalex exch def % string amt to scale
grestore
currentfont [ scalex 0 0 scaley 0 0 ]
makefont setfont % string % scaled font now is it
} bind def
1 inch 1 inch moveto
(Here is some text) % string on stack
5 inch 1 inch % 5 inches horizontal, 1 inch vertical
/Helvetica % name of face you are after
scaletoXYsize % leaves string on stack
show
1 inch 2.2 inch moveto
(TEXT) % string on stack
5 inch 2 inch % 5 inches horizontal, 2 inches vertical
/Helvetica % name of face you are after
scaletoXYsize % leaves string on stack
show
1 inch 4.3 inch moveto
(Oh) % string on stack
5 inch 2.5 inch % 5 inches horizontal, 2.5 inches vertical
/Helvetica % name of face you are after
scaletoXYsize % leaves string on stack
show
showpage
% jeffhansen|||hansen@cs.wmich.edu|||The Nintendo World Championship...
% Sponsored by The Sugar Trust.