Re: Some questions about OT-SVG glyph metrics and bounding boxes

Just to weigh in on one aspect of this. As Leonard said, the SVG table spec says:

“Glyph advance widths or heights are the same for SVG glyphs as for TrueType/CFF glyphs, though there may be small differences in glyph ink bounding boxes.”

The “small differences” will of course depend on the design of the font. For example, a face with a section of blue sky around it may be represented in CFF/TT as the face by itself, without the sky, and thus the glyph bbox may be quite different.

It sounds like you need the glyph bboxes in order to use the 3 libraries you mention. If the bboxes are needed just to get a sense of how much memory to allocate for the rasterizing, perhaps you can pad the CFF/TT bbox by some amount to make it a bit bigger? (Of course, the CFF bbox will need to be calculated first…)

But I’m just guessing here. It seems like someone familiar with the libraries may need to weigh in. I’ll check with Dirk re. SVG Native.

The only accurate glyph bbox for SVG (as for CFF) is that obtained *after* the rendering of the glyph.

And yes, please ignore anything animation-related, even though such fonts are valid OT-SVG (even if they are not recommended for portability since they go beyond the minimum recommended subset). Animation is not in scope for the minimum OT-SVG that I believe is the goal of your project.

Thanks for the updates!

Best,
Sairus

From: Moazin Khatri <moazinkhatri@gmail.com>
Date: Monday, July 29, 2019 at 1:59 AM
To: "public-svgopentype@w3.org" <public-svgopentype@w3.org>
Cc: Werner LEMBERG <wl@gnu.org>, suzuki toshiya <mpsuzuki@hiroshima-u.ac.jp>
Subject: Some questions about OT-SVG glyph metrics and bounding boxes
Resent-From: "public-svgopentype@w3.org" <public-svgopentype@w3.org>
Resent-Date: Monday, July 29, 2019 at 1:59 AM

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<https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbixacolor.com%2F&data=02%7C01%7Csppatel%40adobe.com%7Cd4fac5bbd08c4a44eef908d714031f74%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636999875991529543&sdata=%2FPNpyWihFusZACqZ0JDm1Uto52rEaeD4k1xk6yHPlBU%3D&reserved=0>. 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 Friday, 2 August 2019 22:33:02 UTC