Pomax / lib-font

This library adds a new Font() object to the JavaScript toolbox, similar to new Image() for images
MIT License
728 stars 72 forks source link

Fonts that trip up LibFont #114

Closed RoelN closed 3 years ago

RoelN commented 3 years ago

These come back from some automated tests, so for most I haven't dug into what exactly goes wrong. My hunch is something with the name table?

Fonts that don't work 😿

Fonts that work 🎉

For completeness sake, a similar issue over at Wakamai Fondue that uses LibFont under the hood: https://github.com/Wakamai-Fondue/wakamai-fondue-site/issues/21 This contains some more (free/open source) fonts we can test with.

Pomax commented 3 years ago

Hm, running test.js on those fonts reveals that woff2 files aren't actually being decoded properly at all, so that's something to dig into.

Pomax commented 3 years ago

I've filed https://github.com/Pomax/lib-font/issues/115 for fixing woff2 parsing

Pomax commented 3 years ago

@RoelN so it looks like at least in the browser all those fonts work fine, but the two "numbers only" fonts don't have GSUB tables, so if your testing doesn't check whether font.opentype.tables.GSUB is undefined that might cause runtime errors rather than test errors:

$ ttx 135abd30-1390-4f9c-b6a2-d843157c3468.woff2
Dumping "135abd30-1390-4f9c-b6a2-d843157c3468.woff2" to "135abd30-1390-4f9c-b6a2-d843157c3468.ttx"...
Dumping 'GlyphOrder' table...
Dumping 'head' table...
Dumping 'hhea' table...
Dumping 'maxp' table...
Dumping 'OS/2' table...
Dumping 'name' table...
Dumping 'cmap' table...
Dumping 'post' table...
Dumping 'CFF ' table...
Dumping 'GPOS' table...
Dumping 'hmtx' table...

and

$ ttx 64017d81-9430-4cba-8219-8f5cc28b923e.woff2
Dumping "64017d81-9430-4cba-8219-8f5cc28b923e.woff2" to "64017d81-9430-4cba-8219-8f5cc28b923e.ttx"...
Dumping 'GlyphOrder' table...
Dumping 'head' table...
Dumping 'hhea' table...
Dumping 'maxp' table...
Dumping 'OS/2' table...
Dumping 'hmtx' table...
Dumping 'LTSH' table...
Dumping 'VDMX' table...
Dumping 'hdmx' table...
Dumping 'cmap' table...
Dumping 'fpgm' table...
Dumping 'prep' table...
Dumping 'cvt ' table...
Dumping 'loca' table...
Dumping 'glyf' table...
ERROR: 'name' table stringOffset incorrect. Expected: 294; Actual: 354
Dumping 'name' table...
Dumping 'post' table...
Dumping 'gasp' table...
Pomax commented 3 years ago

closing this issue as the code fixes for woff2 support are handled in #115 instead.

RoelN commented 3 years ago

We might have cheered too soon! Two fonts still trip up LibFont. For instance, the Proxima Nova one:

import { Font } from "./lib-font.js";

const font = new Font("woff2 testing");
// font.src = `./fonts/broken/BrushPosterGrotesk.woff2`;
// font.src = `./fonts/broken/64017d81-9430-4cba-8219-8f5cc28b923e.woff2`;
// font.src = `./fonts/broken/135abd30-1390-4f9c-b6a2-d843157c3468.woff2`;
font.src = `./fonts/broken/proximanova-regular-webfont.woff2`;
font.onerror = (evt) => console.error(evt);
font.onload = (evt) => {
  let font = evt.detail.font;
  const { name } = font.opentype.tables;
  console.log(name);
};

gives:

$ node test.js
parser getUint16 2 Parser {
  name: 'name',
  length: 1638,
  start: 0,
  offset: 1640,
  data: DataView {
    byteLength: 1638,
    byteOffset: 0,
    buffer: ArrayBuffer {
      [Uint8Contents]: <01 7c 01 7d 01 7e 01 7f 01 80 01 81 01 82 01 83 01 84 01 85 01 86 01 87 01 88 01 89 01 8a 01 8b 01 8c 01 8d 01 8e 01 8f 01 90 01 91 01 92 00 d8 00 e1 01 93 01 94 00 db 00 dc 00 dd 00 e0 00 d9 00 df 01 95 01 96 01 97 01 98 01 99 01 9a 01 9b 01 9c 01 9d 01 9e 01 9f 01 a0 01 a1 01 a2 01 a3 01 a4 01 a5 ... 1538 more bytes>,
      byteLength: 1638
    }
  }
}
parser 0 1640
Event {
  type: 'error',
  detail: RangeError: Offset is outside the bounds of the DataView
      at DataView.getUint16 (<anonymous>)
      at Parser.getValue (file:///Users/roel/code/lib-font/src/parser.js:60:29)
      at Parser.get (file:///Users/roel/code/lib-font/src/parser.js:38:25)
      at new NameRecord (file:///Users/roel/code/lib-font/src/opentype/tables/simple/name.js:60:25)
      at file:///Users/roel/code/lib-font/src/opentype/tables/simple/name.js:20:14
      at Array.map (<anonymous>)
      at new name (file:///Users/roel/code/lib-font/src/opentype/tables/simple/name.js:19:51)
      at createTable (file:///Users/roel/code/lib-font/src/opentype/tables/createTable.js:88:20)
      at file:///Users/roel/code/lib-font/src/opentype/woff2.js:125:14
      at Object.get (file:///Users/roel/code/lib-font/src/lazy.js:15:13),
  msg: 'Failed to load font at ./fonts/broken/proximanova-regular-webfont.woff2'
}

A similar error is given for BrushPosterGrotesk.woff2.

Not sure if this is related to the WOFF2 handling, or something to the name table code specifically?

RoelN commented 3 years ago

I added some more fonts to test with!

Pomax commented 3 years ago

I've had to remove some links from your updated list, because they contained a number of heavily licensed fonts that may most certainly not be redistributed =)

Pomax commented 3 years ago

Flaticon investigation issue: https://github.com/Pomax/lib-font/issues/120

Pomax commented 3 years ago

120 was resolved, with v2.3.0 published to npm: @RoelN this should have fixed all the things, but if not, let me know.

RoelN commented 3 years ago

Thanks @Pomax, this is working nicely! I've integrated it in my local Wakamai Fondue build, and all fond that previously broke it, are now working fine!