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

Error reading SVG table (ReferenceError: uint16 is not defined) #127

Closed darknoon closed 2 years ago

darknoon commented 2 years ago

Context

Compiling a figma plugin (ui code) with esbuild Trying to read the "SVG" table in an opentype font (Abelone)

Failing code

eg:

import { Font } from "lib-font";

…
const myFont = new Font("namehere");
await myFont.fromDataBuffer(ab, f.name);
myFont.opentype.tables["SVG"] ← crashes here
…

It looks like this line is meant to say p.uint16 perhaps?

As an aside, when I tried to add a failing test to testing/browser/tests/test.otf.js, throwing an exception seems to just hang the test host until timeout instead of failing the test.

Pomax commented 2 years ago

ah, good find: yeah that should absolutely be p.unt16, not a bare uint6!

Pomax commented 2 years ago

Created a testcase in testing/manual/custom/issue-127. with code

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

const font = new Font("SVG testing");
font.src = `./fonts/issue-127/Abelone-FREE.otf`;
font.onerror = (evt) => console.error(evt);
font.onload = (evt) => {
  const font = evt.detail.font;
  const { tables } = font.opentype;
  const SVGTable = tables["SVG"];
  console.log(SVGTable);
};

and result

SVG {
  version: 0,
  offsetToSVGDocumentList: 10,
  documentList: SVGDocumentList {
    numEntries: 96,
    documentRecords: [
      [SVGDocumentRecord], [SVGDocumentRecord], [SVGDocumentRecord],
      [SVGDocumentRecord], [SVGDocumentRecord], [SVGDocumentRecord],
      [SVGDocumentRecord], [SVGDocumentRecord], [SVGDocumentRecord],
      [SVGDocumentRecord], [SVGDocumentRecord], [SVGDocumentRecord],
      [SVGDocumentRecord], [SVGDocumentRecord], [SVGDocumentRecord],
      [SVGDocumentRecord], [SVGDocumentRecord], [SVGDocumentRecord],
      [SVGDocumentRecord], [SVGDocumentRecord], [SVGDocumentRecord],
      [SVGDocumentRecord], [SVGDocumentRecord], [SVGDocumentRecord],
      [SVGDocumentRecord], [SVGDocumentRecord], [SVGDocumentRecord],
      [SVGDocumentRecord], [SVGDocumentRecord], [SVGDocumentRecord],
      [SVGDocumentRecord], [SVGDocumentRecord], [SVGDocumentRecord],
      [SVGDocumentRecord], [SVGDocumentRecord], [SVGDocumentRecord],
      [SVGDocumentRecord], [SVGDocumentRecord], [SVGDocumentRecord],
      [SVGDocumentRecord], [SVGDocumentRecord], [SVGDocumentRecord],
      [SVGDocumentRecord], [SVGDocumentRecord], [SVGDocumentRecord],
      [SVGDocumentRecord], [SVGDocumentRecord], [SVGDocumentRecord],
      [SVGDocumentRecord], [SVGDocumentRecord], [SVGDocumentRecord],
      [SVGDocumentRecord], [SVGDocumentRecord], [SVGDocumentRecord],
      [SVGDocumentRecord], [SVGDocumentRecord], [SVGDocumentRecord],
      [SVGDocumentRecord], [SVGDocumentRecord], [SVGDocumentRecord],
      [SVGDocumentRecord], [SVGDocumentRecord], [SVGDocumentRecord],
      [SVGDocumentRecord], [SVGDocumentRecord], [SVGDocumentRecord],
      [SVGDocumentRecord], [SVGDocumentRecord], [SVGDocumentRecord],
      [SVGDocumentRecord], [SVGDocumentRecord], [SVGDocumentRecord],
      [SVGDocumentRecord], [SVGDocumentRecord], [SVGDocumentRecord],
      [SVGDocumentRecord], [SVGDocumentRecord], [SVGDocumentRecord],
      [SVGDocumentRecord], [SVGDocumentRecord], [SVGDocumentRecord],
      [SVGDocumentRecord], [SVGDocumentRecord], [SVGDocumentRecord],
      [SVGDocumentRecord], [SVGDocumentRecord], [SVGDocumentRecord],
      [SVGDocumentRecord], [SVGDocumentRecord], [SVGDocumentRecord],
      [SVGDocumentRecord], [SVGDocumentRecord], [SVGDocumentRecord],
      [SVGDocumentRecord], [SVGDocumentRecord], [SVGDocumentRecord]
    ]
  }
}
Pomax commented 2 years ago

v2.3.6 published

Pomax commented 2 years ago

https://github.com/Pomax/lib-font/issues/128 filed to follow up on the testing issue.

darknoon commented 2 years ago

Thanks for the speedy turnaround!