MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: text bounding box size

  • To: mathgroup at smc.vnet.net
  • Subject: [mg64317] Re: text bounding box size
  • From: bghiggins at ucdavis.edu
  • Date: Sat, 11 Feb 2006 03:32:46 -0500 (EST)
  • References: <dshfie$hna$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Fred, Try this:

Suppose you have the graphic
plt=Plot[Sin[x],{x,0,2p}];

Convert the graphic to a DisplayString with the "EPS" format.i.e.,

DisplayString[plt,"EPS"]

The size of the Bounding box info for the graphic is near the top of
the String file and begins like:

%%BoundingBox: 88 4 376 182

You can use  StringCases with  an appropriate RegularExpression  to
extract out the values:
Here is an example:

res=Flatten[StringCases[

DisplayString[plt,"EPS"],RegularExpression["%%BoundingBox:(\\s+(\\d+)\\s+(\
\\d+)\\s+(\\d+)\\s+(\\d+))"]:>{ToExpression["$2"],ToExpression["$\
3"],ToExpression["$4"].ToExpression["$5"]}]]

{88,4,376.182}

The format for the Bounding Box data is xo,yo,x1,y1, where (x0,y0) and
(x1,y1) are the coordinates of the lower-left and upper-right corners,
respectively.
measured in points.

Hope this helps

Cheers,

Brian



Fred Soo wrote:
> hi,
>
> I know this has been asked before, but I haven't seen any response.  Has
> anyone found an easy way to get the bounding box size (height, width) of
> a Text expression for a given DisplayFunction?  Or for that matter, the
> size of any Graphics object being displayed?
>
> I've tried a few things, but this is way too difficult, and there aren't
> even any kludgy workarounds.
>
> For instance, to get text height, I tried to pull the FontSize->x out of
> any Text expression.  This is ok, but of course, doesn't work if no
> FontSize is specified.
>
> As for reading the default TextStyle, there doesn't seem to be a way
> unless you use $TextStyle.  In addition, if you use Show[expr,
> DefaultFont:>x] to change all of the fonts in a graphic, it doesn't
> appear to modify $TextStyle or pass DefaultFont->x, so there is no way
> to tell what font x is.
>
> Text width is kind of hopeless, as there doesn't seem (unless somebody
> knows, please let me know) a way of getting a font metric.
>
> I've looked at the PostScript output from DisplayString, and can find
> some bits and pieces which make some sense, but not being a PostScript
> expert, this would take a lot of time to figure out.
>
> Any suggestions?
>
> Thanks!
>
> Fred
>
> Department of Physiology and Biophysics
> University of Washington
> Seattle, WA 98199
> (206) 616-2510


  • Prev by Date: Re: Legendre transform
  • Next by Date: Awesome PDF writer
  • Previous by thread: Re: Plot question
  • Next by thread: Re: text bounding box size