diff --git a/src/glyph/CFFGlyph.js b/src/glyph/CFFGlyph.js index 70c0aab5..1ac182f1 100644 --- a/src/glyph/CFFGlyph.js +++ b/src/glyph/CFFGlyph.js @@ -86,6 +86,10 @@ export default class CFFGlyph extends Glyph { let op = stream.readUInt8(); if (op < 32) { let index, subr, phase; + let c1x, c1y, c2x, c2y, c3x, c3y; + let c4x, c4y, c5x, c5y, c6x, c6y; + let pts; + switch (op) { case 1: // hstem case 3: // vstem @@ -128,10 +132,10 @@ export default class CFFGlyph extends Glyph { case 8: // rrcurveto while (stack.length > 0) { - var c1x = x + stack.shift(); - var c1y = y + stack.shift(); - var c2x = c1x + stack.shift(); - var c2y = c1y + stack.shift(); + c1x = x + stack.shift(); + c1y = y + stack.shift(); + c2x = c1x + stack.shift(); + c2y = c1y + stack.shift(); x = c2x + stack.shift(); y = c2y + stack.shift(); path.bezierCurveTo(c1x, c1y, c2x, c2y, x, y); @@ -143,8 +147,8 @@ export default class CFFGlyph extends Glyph { subr = subrs[index]; if (subr) { usedSubrs[index] = true; - var p = stream.pos; - var e = end; + let p = stream.pos; + let e = end; stream.pos = subr.offset; end = subr.offset + subr.length; parse(); @@ -241,10 +245,10 @@ export default class CFFGlyph extends Glyph { case 24: // rcurveline while (stack.length >= 8) { - var c1x = x + stack.shift(); - var c1y = y + stack.shift(); - var c2x = c1x + stack.shift(); - var c2y = c1y + stack.shift(); + c1x = x + stack.shift(); + c1y = y + stack.shift(); + c2x = c1x + stack.shift(); + c2y = c1y + stack.shift(); x = c2x + stack.shift(); y = c2y + stack.shift(); path.bezierCurveTo(c1x, c1y, c2x, c2y, x, y); @@ -262,10 +266,10 @@ export default class CFFGlyph extends Glyph { path.lineTo(x, y); } - var c1x = x + stack.shift(); - var c1y = y + stack.shift(); - var c2x = c1x + stack.shift(); - var c2y = c1y + stack.shift(); + c1x = x + stack.shift(); + c1y = y + stack.shift(); + c2x = c1x + stack.shift(); + c2y = c1y + stack.shift(); x = c2x + stack.shift(); y = c2y + stack.shift(); path.bezierCurveTo(c1x, c1y, c2x, c2y, x, y); @@ -312,8 +316,8 @@ export default class CFFGlyph extends Glyph { subr = gsubrs[index]; if (subr) { usedGsubrs[index] = true; - var p = stream.pos; - var e = end; + let p = stream.pos; + let e = end; stream.pos = subr.offset; end = subr.offset + subr.length; parse(); @@ -493,14 +497,14 @@ export default class CFFGlyph extends Glyph { c1y = y; c2x = c1x + stack.shift(); c2y = c1y + stack.shift(); - let c3x = c2x + stack.shift(); - let c3y = c2y; - let c4x = c3x + stack.shift(); - let c4y = c3y; - let c5x = c4x + stack.shift(); - let c5y = c4y; - let c6x = c5x + stack.shift(); - let c6y = c5y; + c3x = c2x + stack.shift(); + c3y = c2y; + c4x = c3x + stack.shift(); + c4y = c3y; + c5x = c4x + stack.shift(); + c5y = c4y; + c6x = c5x + stack.shift(); + c6y = c5y; x = c6x; y = c6y; @@ -509,7 +513,7 @@ export default class CFFGlyph extends Glyph { break; case 35: // flex - let pts = []; + pts = []; for (let i = 0; i <= 5; i++) { x += stack.shift(); diff --git a/test/issues.js b/test/issues.js new file mode 100644 index 00000000..ed3d5d5f --- /dev/null +++ b/test/issues.js @@ -0,0 +1,13 @@ +import * as fontkit from 'fontkit'; + +describe('issues', function () { + describe('#282 - ReferenceError: Cannot access \'c3x\' before initialization', function () { + it('should not throw a ReferenceError', function () { + let font = fontkit.openSync(new URL('data/PlayfairDisplay/PlayfairDisplay-Regular.otf', import.meta.url)); + + let glyph = font.getGlyph(5); + + glyph.path; + }); + }); +});