🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.postscript
Article #1779

Re: Centering Strings in PostScript

#1779
From: Dick Dunn
Date: Fri, 14 Aug 1992 23:41
21 lines
1527 bytes
klehr@bae.bellcore.com (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?

Assuming the reference point is the current point, the horizontal centering
is an easy PostScript idiom:
	(some string) dup stringwidth pop neg 2 div 0 rmoveto show

The vertical centering is considerably harder, because it's not clear what
you mean by "centering" vertically.  The optical center of a string doesn't
necessarily occur at the middle of its vertical extent.  For example, in
many fonts "belch" and "eruction" will have almost the same vertical size,
but "belch" has a higher apparent center because it has three ascenders in
only five characters.  A good choice might be to center at the middle of
the x-height of the font--if you like that, grab the bounding box of a
lower case "x", divide the vertical distance by 2 and move your baseline
down that much from the reference point.
-- 
Dick Dunn    rcd@raven.eklektix.com   -or-   raven!rcd    Boulder, Colorado
				Cats!
Technical Details
Message-ID: <1992Aug14.234116@eklektix.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!wupost!gumby!destroyer!ncar!csn!raven!rcd
References: <KLEHR.92Aug14101809@creamer.bellcore>

Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.postscript
Path: arc1-ca.pugleaf.net!sparky!uunet!wupost!gumby!destroyer!ncar!csn!raven!rcd
From: rcd@raven.eklektix.com (Dick Dunn)
Subject: Re: Centering Strings in PostScript
Message-ID: <1992Aug14.234116@eklektix.com>
Summary: horizontal is easy, vertical is hard
Organization: eklektix - Boulder, Colorado
References: <KLEHR.92Aug14101809@creamer.bellcore>
Date: Fri, 14 Aug 1992 23:41:16 GMT
Lines: 21