Well, you've already discovered the two "shortcuts". The FontBBox gives the bounding box of all the glyphs in the font superposed together. false charpath flattenpath pathbbox
gives the box for a specified string.
For a Type 3 (user-defined) font this is all you can reaonably expect to do; but for the more-popular Type 1 fonts, there is a wealth of metric information both in the font and in a "metrics" file (for other applications).
But this is the part I don't know very well. So I'm going to read-up (in the Adobe Type 1 manual) and expand this answer later.
Edit: Actually, it looks like these may be the best ways in general.
There is an array of vertical alignment values in a Type 1 font, in the /Private dictionary, under the name /BlueValues; but there is no guarantee that the font honors them. The first number in the array is the baseline overshoot; this is the bottom edge of letters like 'O' which dip below the baseline. And the largest value in the array will be either the ascender-height overshoot or the cap-height overshoot (whichever is higher). But any individual character may be plotted without regard to these values (hence, no guarantee).
On the other hand, the FontBBox itself may reflect the bounding box of any "special" characters present in the font, whether or not they're accessible through the encoding vector (ie. you can't show
them, but must glyphshow
them).
So the best bet would probably be to take the pathbbox
of a string of all the characters you intend to use. This would ignore the contribution of any other characters that may be present but are irrelevant to your purpose. And don't forget to flattenpath
to remove the control points from the curves (which may be far outside the "real" bounding box).