On Wednesday, 31 July 2019, 09:05:52 BST, Moazin Khatri <moazinkhatri@gmail.com> wrote:
> Okay, I agree it's impossible.
> What do you think about the side bearings? How should they be obtained? The OT-SVG specs say:
> Should those be obtained from the ink-box, which, just as you said, can only be obtained after rendering the image?
For what purpose do you want the side-bearing, and the ink-box? Even for traditional (ttf/cff), they can't be accurately obtained without rendering, mostly due to hinting adjustments (which can change both bearings and top/bottom edge by up to one pixel). For most layout purposes, the advance widths are useful for offsets before (perhaps parallel) rendering. For the traditional fonts, the cbox (contour box) is quite fast to get; it is also customary to put contour points at the extreme edges, so that the contour box is "close enough" to how the actual glyph's bound box would be. (fontforge has a special operation for doing that, for example).
What I mean is, that, for many fonts, there are heuristics you can do which would do "approximately correct" things, like you found with viewports and width/height in the svg headers; this is the same with "traditional" fonts using the contour box. But if you want a definitive answer that works for every legitimately-constructed font, that's perhaps impossible. For traditional fonts, the contour control points are not required to be at the extreme edges, so the sum of all the contour control points (even if you only select "on-contour" control points) can be larger or smaller than the ink-box. You get clippings in those cases too, if you use the cbox as an approximation to the ink box.