Some questions about OT-SVG glyph metrics and bounding boxes

Hi all,

I am a GSoC student working with the FreeType project where I am adding the
support of OT-SVG fonts to FreeType. Werner LEMBERG and Toshiya Suzuki are
my mentors. Ever since we started the project, I have had some questions
about SVG glyphs. I wish I had discovered this mailing list earlier. I am
writing here in the hope of getting the answers. My English is weak and I
am usually unable to ask questions in the most efficient manner. I
apologize if they are extra lengthy here.

The questions are:

1. How do I render a glyph tightly while using an SVG rendering library.
Please see the attachments `not-tight.png' and `tight.png' to see what I
mean by `tight'. If you just send an SVG glyph to a rendering library, it'd
just render everything in the ( +x & +y ) quadrant. In the case of most
characters (characters like `j' are an exception) there's barely anything
below the baseline. The solution I found is, get the tight bounding box for
the glyph in SVG coordinates and then use `translate' and `scale'
transforms to render exactly that bbox. This works perfectly, but the
question is, how do I get the bounding box in SVG coordinates? Some SVG
libraries do provide functions which can get these bounding boxes, but even
they don't give accurate bounding boxes if `clipping' has been used. I
realized that the bounding box in the SVG glyph is EXACTLY the same as that
of CFF/TTF outline for the same character (apart from some `scaling' and
`translation' between the two coordinate systems of course). So, the
approach I am using now is I get the bounding box of the TTF/CFF outlines
and then do the necessary `scaling' and `translation' calculations to get
the bounding box of the SVG glyph in the SVG coordinates and ultimately use
that to get a tight rendering. This has worked PERFECTLY for EVERY font and
test font I tested with, except one that I encountered just yesterday. It's
https://bixacolor.com. In the case of this font, the bounding boxes for
both coordinate systems are different (the glyphs themselves are slightly
different too), due to that there's minor clipping in rendering the SVG
glyphs. Please tell me if my approach is correct or not? If it is not,
please tell me which approach is the right one?

2. How do I get the bearingX (distance from the current pen position to the
left edge of the bounding box of a glyph) and bearingY (distance from
current pen position to the top edge of the bounding box of a glyph) for
the SVG glyph? The approach I use is to simply get these from the bounding
box I calculate as described in 1. Is that the right approach?

3. Can an SVG document that neither has a `viewbox' nor has
`width'/`height' attributes on its root `svg' node be considered a legal
document? Is it against the SVG specs or the OT-SVG specs? The SVG glyphs
in `Bixa Color' are like this.

Thanks in advance. :)

Moazin

Received on Monday, 29 July 2019 08:59:42 UTC