Git Product home page Git Product logo

Comments (9)

behdad avatar behdad commented on May 8, 2024

This happens because:

  1. The font has wrong bounding box info in the glyf table (ie, claims xmin=0 while it's clearly not the case),
  2. Reference implementation always throws away the bounding box. That has been a known issue. Ie, check sbbox_ in transform.cc; it's never set to true.

from woff2.

Templarian avatar Templarian commented on May 8, 2024

Interesting. This whole library is a bit over my head, or I would try to do a pull request (not even sure where to start).

WOFF2 Spec on Bounding Box

By the way I think this is the only open source WOFF2 converter, so hopefully someone that runs into it can solve it.

from woff2.

behdad avatar behdad commented on May 8, 2024

There's also this:
fonttools/fonttools#222

I haven't merged it yet.

from woff2.

khaledhosny avatar khaledhosny commented on May 8, 2024

Setting sbox_ to true is not enough since the bounding box is already normalized (i.e. recalculated) at this point. To fix this one needs to drop NormalizeSimpleGlyphBoundingBox() and instead use similar code in WriteSimpleGlyph() to calculate the bounding box, compare it with the original and if it is different call WriteBbox(). The sbbox_ as well as cbbox_ member variables should just be dropped.

from woff2.

rsheeter avatar rsheeter commented on May 8, 2024

Have you seen a conformance test that would cover this? If not, I suppose
we should add one.

On Fri, Apr 10, 2015 at 12:33 PM, Khaled Hosny [email protected]
wrote:

Setting sbox_ to true is not enough since the bounding box is already
normalized (i.e. recalculated) at this point. To fix this one needs to drop
NormalizeSimpleGlyphBoundingBox() and instead use similar code in
WriteSimpleGlyph() to calculate the bounding box, compare it with the
original and if it is different call WriteBbox(). The sbbox_ as well as
cbbox_ member variables should just be dropped.

β€”
Reply to this email directly or view it on GitHub
#12 (comment).

from woff2.

khaledhosny avatar khaledhosny commented on May 8, 2024

Yes, there is http://dev.w3.org/webfonts/WOFF2/spec/#conform-mustCalculateOmitBBoxValues and http://dev.w3.org/webfonts/WOFF2/spec/#conform-mustHaveCompositeBBox.

from woff2.

behdad avatar behdad commented on May 8, 2024

Just for the record, an alternative, more filesize-friendly, way to fix it is: if the incoming bounding box of a glyph is wrong, fix it (ie. normalize it), but adjust the lsb in hmtx to offset the change, so the glyph doesn't shift.

from woff2.

khaledhosny avatar khaledhosny commented on May 8, 2024

But this would work only for this particular case, not for the general case of setting a bounding box different from what the font actually has.

(Playing with the bounding box is not something I have seen in the wild, but for a while I wanted to explore it in math fonts to control glyph stacking to be uniform for some glyphs that have different β€œnatural” bounding boxes, a trick used by some traditional TeX math fonts).

from woff2.

Templarian avatar Templarian commented on May 8, 2024

I just got around to testing the patch that @khaledhosny has suggested and it solves the issue for me.

Comparison vs Third Party

My test font has 1035 glyphs. This is an odd comparison obviously, but thought I would share it to illustrate that a third party tool does have a smaller size.

Broken Patched Third Party WOFF2
53.0 KB (54,304 bytes) 54.7 KB (56,072 bytes) 53.8 KB (55,136 bytes)
Generated from TTF Generated from TTF Generated from WOFF

from woff2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.