🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.postscript
Article #457

Re: Finding the height of the current font

#457
From: Peter Davis
Date: Fri, 10 Apr 1992 15:01
50 lines
2039 bytes
In article <1992Apr10.025009.17561@ucc.su.OZ.AU>, mckay@physics.su.OZ.AU (Derek Mckay) writes...
>How can one find the height of the current font. I need it in order
>to centre some text vertically. Please E-Mail. Thanks.
>
>--
> Derek McKay, Chatterton Astronomy Dept.  (mckay@astron.physics.su.oz.au)
> School of Physics (A28)
> University of Sydney, NSW 2006
> AUSTRALIA

Well, most fonts have a value called FontBBox stored in the font dictionary.
This gives the value, in font coordinates, of the union of the bounding boxes
of all the characters in the font.  You have to look at the FontMatrix value
to figure out how to scale the FontBBox to the current point size.

Another, brute force method would be to do something like:

	/YourFont findfont your_point_size scalefont setfont
	/chr 1 string def
	/BBinit false def
	0 1 255 {
	  chr exch 0 exch put
	  newpath
	  chr true charpath pathbbox
	  BBinit {
	    dup BBy2 gt { /BBy2 exch def } { pop } ifelse
	    dup BBx2 gt { /BBx2 exch def } { pop } ifelse
	    dup BBy1 lt { /BBy1 exch def } { pop } ifelse
	    dup BBx1 lt { /BBx1 exch def } { pop } ifelse
	  }{
	    /BBy2 exch def
	    /BBx2 exch def
	    /BBy1 exch def
	    /BBx1 exch def
	    /BBinit true def
	  } ifelse
	} for
	/font_height BBy2 BBy1 sub def

That's probably pretty time consuming, however.


                   /
                  /
        /  /  /  /		Peter Davis,	Digital Equipment Corp.
       /  /  /  /				davis@3d.enet.dec.com
      /__/__/__/
     /
  __/
Technical Details
Message-ID: <1992Apr10.150714.10973@engage.pko.dec.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!decwrl!pa.dec.com!nntpd.lkg.dec.com!engage.pko.dec.com!gauss.enet.dec.com!davis
References: <1992Apr10.025009.17561@ucc.su.OZ.AU>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!decwrl!pa.dec.com!nntpd.lkg.dec.com!engage.pko.dec.com!gauss.enet.dec.com!davis
From: davis@gauss.enet.dec.com (Peter Davis)
Newsgroups: comp.lang.postscript
Subject: Re: Finding the height of the current font
Message-ID: <1992Apr10.150714.10973@engage.pko.dec.com>
Date: 10 Apr 92 15:01:41 GMT
References: <1992Apr10.025009.17561@ucc.su.OZ.AU>
Sender: newsdaemon@engage.pko.dec.com (USENET News Daemon)
Organization: Digital Equipment Corporation
Lines: 50