🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.postscript
Article #3631

Re: get current font height or scalefont factor

#3631
From: Jamie Zawinski
Date: Sun, 11 Nov 1990 20:34
30 lines
1954 bytes
In article <90Nov10.185352est.20181@me.utoronto.ca> sun@me.utoronto.ca (Andy Sun Anu-guest) wrote:
> 
> I am writing something that needs to know the maximum character height of
> a scaled font. Ideally I want to get the maximum height of a string of a
> particular font, which is a local maximum depending on the characters (i.e.
> aero will have a smaller font height than AERO). Right now I am defining the 
> scale explictly as a variable so that I can refer to it later but that's
> not flexible/intelligent enough to do the job. Any help will be appreciated.

To get the bounding box of a string in the current font, you can use 

	gsave newpath 0 0 moveto
	  (Some String) true charpath flattenpath pathbbox
        grestore

But getting the height of the current font is a bit trickier:

/currentfont-vextent {  % leaves two numbers on the stack:
			% maximum distances which the current font extends
			% above the baseline, and below (likely negative).
			% This fails if the currentfont doesn't have a 
			% FontBBox defined (unlikely).
    currentfont /FontBBox get dup 0 get exch 1 get
      currentfont /FontMatrix get dtransform		% left bottom
    exch pop						% bottom
    currentfont /FontBBox get dup 2 get exch 3 get
      currentfont /FontMatrix get dtransform		% bottom right top
    exch pop						% bottom top
    exch
} def
Technical Details
Message-ID: <JWZ.90Nov11123411@kolyma.lucid.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!usc!elroy.jpl.nasa.gov!lll-winken!unixhub!shelby!neon!lucid.com!jwz
References: <90Nov10.185352est.20181@me.utoronto.ca>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!usc!elroy.jpl.nasa.gov!lll-winken!unixhub!shelby!neon!lucid.com!jwz
From: jwz@lucid.com (Jamie Zawinski)
Newsgroups: comp.lang.postscript
Subject: Re: get current font height or scalefont factor
Message-ID: <JWZ.90Nov11123411@kolyma.lucid.com>
Date: 11 Nov 90 20:34:11 GMT
References: <90Nov10.185352est.20181@me.utoronto.ca>
Sender: jwz@lucid.com
Organization: Lucid, Inc., Menlo Park, CA
Lines: 30
In-reply-to: sun@me.utoronto.ca's message of 10 Nov 90 23:54:08 GMT