Article View: comp.lang.postscript
Article #1785Re: Centering Strings in PostScript
From: Henry McGilton
Date: Sat, 15 Aug 1992 20:04
Date: Sat, 15 Aug 1992 20:04
61 lines
1872 bytes
1872 bytes
In article <KLEHR.92Aug14101809@creamer.bellcore> klehr@creamer.bellcore
(Thomas J. Klehr) writes:
* I am trying to center a string (horizontally and vertically) at a
* point. What method can I use to compute the height and width of the
* string?
I tried mailing this but it bounced. Here is an example from our
forthcoming book, ``PostScript by Example'', which covers this topic
as well as hundreds more. The book should be on the
shelves in about a month. Addison-Wesley are the publishers.
%!PS
/inch { 72 mul } def
/charheight {
gsave
newpath 0 0 moveto
false charpath
flattenpath pathbbox
exch pop 3 -1 roll pop
grestore
} def
/stringheight {
/lly 0.0 def
/ury 0.0 def
{
( ) dup 0 4 -1 roll put
charheight
dup ury gt {
/ury exch def
} {
pop
} ifelse
dup lly lt {
/lly exch def
} {
pop
} ifelse
} forall
ury lly sub
} def
/descender {
/lly 0.0 def
/ury 0.0 def
{
( ) dup 0 4 -1 roll put
charheight pop
dup lly lt {
/lly exch def
} {
pop
} ifelse
} forall
lly
} def
%!PS
4.25 inch 0 moveto 0 11 inch rlineto
0 5.5 inch moveto 8.5 inch 0 rlineto stroke
/ZapfDingbats findfont 2 inch scalefont setfont
(\140) dup stringwidth pop 2 div 4.25 inch exch sub
5.5 inch 2 index charheight exch pop 2 div sub moveto show
Technical Details
Message-ID:
<1992Aug15.200435.29830@trilithon.mpk.ca.us>Path:
arc1-ca.pugleaf.net!sparky!uunet!nntp1.radiomail.net!fernwood!trilithon!henryReferences:
<KLEHR.92Aug14101809@creamer.bellcore>Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.postscript Path: arc1-ca.pugleaf.net!sparky!uunet!nntp1.radiomail.net!fernwood!trilithon!henry From: henry@trilithon.mpk.ca.us (Henry McGilton) Subject: Re: Centering Strings in PostScript Message-ID: <1992Aug15.200435.29830@trilithon.mpk.ca.us> Sender: henry@trilithon.mpk.ca.us Organization: Trilithon Software References: <KLEHR.92Aug14101809@creamer.bellcore> Distribution: comp Date: Sat, 15 Aug 1992 20:04:35 GMT Lines: 61