opentypejs / opentype.js

Read and write OpenType fonts using JavaScript.
https://opentype.js.org/
MIT License
4.5k stars 478 forks source link

Letter render on top of each other. #423

Open haszzam opened 4 years ago

haszzam commented 4 years ago

Hi i got this weird behavior for multiple fonts before and i have no idea what's wrong. for most fonts it works perfectly but for others, the letters just crumble on top pf each other like you can see here Capture

swingerman commented 3 years ago

Not 100% sure why but for some fonts Opentype mutates the glyph data after already calculated all metrics and overwrites the advance width with NaN. I use this snippet to avoid this:

Object.defineProperty(Glyph.prototype, 'advanceWidth', {
  get() {
    return this.storedAdvanceWidth;
  },
  set(value) {
    if (!Number.isNaN(value)) {
      this.storedAdvanceWidth = value;
    }
  },
});
Connum commented 1 year ago

@Hassan-Azzam @swingerman could you please provide at least one font where this happens?