foliojs / fontkit

An advanced font engine for Node and the browser
1.48k stars 219 forks source link

Missing initialisation for pts variable for glyphs #327

Open peteward opened 8 months ago

peteward commented 8 months ago

Hi! πŸ‘‹

Firstly, thanks for your work on this project! even if it does seem to be abandoned nowadays πŸ™‚

Today I used patch-package to patch fontkit@2.0.2 for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/fontkit/src/glyph/CFFGlyph.js b/node_modules/fontkit/src/glyph/CFFGlyph.js
index 70c0aab..bab169c 100644
--- a/node_modules/fontkit/src/glyph/CFFGlyph.js
+++ b/node_modules/fontkit/src/glyph/CFFGlyph.js
@@ -546,7 +546,7 @@ export default class CFFGlyph extends Glyph {
                   let startx = x;
                   let starty = y;

-                  pts = [];
+                  let pts = [];
                   for (let i = 0; i <= 4; i++) {
                     x += stack.shift();
                     y += stack.shift();

This issue body was partially generated by patch-package.

peteward commented 8 months ago

This wasn't the right fix.

There are various scoping issues throughout this file that lead to errors for certain fonts.

In the end I moved the initialisation of lots of variables to the top level so that the order in which they hit various case statements didn't matter.

It would probably be better to block scope each case statement instead though and initialize as required within them.