From f674bf2e3c8a8e0a34083e19f0abe65df20520e3 Mon Sep 17 00:00:00 2001 From: Andrew Dillon Date: Thu, 20 Dec 2018 06:52:25 -0600 Subject: [PATCH] Remove use of spread operator (for React Native Android); Fix tests --- package.json | 5 +-- src/opentype/shapers/IndicShaper.js | 14 ++++++-- src/opentype/shapers/UniversalShaper.js | 7 +++- test/directory.js | 4 ++- test/glyph_mapping.js | 30 ++++++++++++----- test/glyph_positioning.js | 10 ++++-- test/glyphs.js | 23 +++++++++---- test/index.js | 44 ++++++++++--------------- test/metadata.js | 4 ++- test/mocha.opts | 2 +- test/shaping.js | 14 ++++++-- test/subset.js | 20 +++++++---- test/variations.js | 26 ++++++++++----- 13 files changed, 131 insertions(+), 72 deletions(-) diff --git a/package.json b/package.json index d894aacd..039a5421 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@pdf-lib/fontkit", - "version": "0.0.0", + "version": "0.0.1", "description": "An advanced font engine for Node and the browser", "main": "dist/fontkit.umd.js", "unpkg": "dist/fontkit.umd.min.js", @@ -9,7 +9,7 @@ "scripts": { "make": "node Makefile.js", "clean": "node Makefile.js clean", - "test": "mocha", + "test": "MODULE_TYPE=commonjs mocha", "coverage": "cross-env BABEL_ENV=cover nyc mocha" }, "dependencies": { @@ -32,6 +32,7 @@ "@babel/plugin-proposal-class-properties": "^7.2.1", "@babel/plugin-proposal-decorators": "^7.2.2", "@babel/preset-env": "^7.2.0", + "@babel/register": "^7.0.0", "babel-plugin-istanbul": "^4.1.3", "codepoints": "^1.2.0", "concat-stream": "^1.4.6", diff --git a/src/opentype/shapers/IndicShaper.js b/src/opentype/shapers/IndicShaper.js index 6eef7e9f..685f0c1b 100644 --- a/src/opentype/shapers/IndicShaper.js +++ b/src/opentype/shapers/IndicShaper.js @@ -21,8 +21,18 @@ import base64DeflatedTrie from './trieIndic.json'; // Trie is serialized as a Buffer in node, but here // we may be running in a browser so we make an Uint8Array -const indicMachine = JSON.parse(String.fromCharCode(...pako.inflate(base64.decode(base64DeflatedIndicMachine)))); -const useData = JSON.parse(String.fromCharCode(...pako.inflate(base64.decode(base64DeflatedUseData)))); +const indicMachine = JSON.parse( + String.fromCharCode.apply( + String, + pako.inflate(base64.decode(base64DeflatedIndicMachine)), + ), +); +const useData = JSON.parse( + String.fromCharCode.apply( + String, + pako.inflate(base64.decode(base64DeflatedUseData)), + ), +); const trieData = pako.inflate(base64.decode(base64DeflatedTrie)); const {decompositions} = useData; diff --git a/src/opentype/shapers/UniversalShaper.js b/src/opentype/shapers/UniversalShaper.js index 0991e96a..b252e1b6 100644 --- a/src/opentype/shapers/UniversalShaper.js +++ b/src/opentype/shapers/UniversalShaper.js @@ -10,7 +10,12 @@ import base64DeflatedTrie from './trieUse.json'; // Trie is serialized as a Buffer in node, but here // we may be running in a browser so we make an Uint8Array -const useData = JSON.parse(String.fromCharCode(...pako.inflate(base64.decode(base64DeflatedUseData)))); +const useData = JSON.parse( + String.fromCharCode.apply( + String, + pako.inflate(base64.decode(base64DeflatedUseData)), + ), +); const trieData = pako.inflate(base64.decode(base64DeflatedTrie)); const {categories, decompositions} = useData; diff --git a/test/directory.js b/test/directory.js index b47ed283..6838a172 100644 --- a/test/directory.js +++ b/test/directory.js @@ -1,8 +1,10 @@ import fontkit from '../src'; import assert from 'assert'; +import fs from 'fs'; describe('metadata', function() { - let font = fontkit.openSync(__dirname + '/data/OpenSans/OpenSans-Regular.ttf'); + const fontData = fs.readFileSync(__dirname + '/data/OpenSans/OpenSans-Regular.ttf'); + const font = fontkit.create(fontData); it('decodes SFNT directory values correctly', function() { let dir = font.directory; diff --git a/test/glyph_mapping.js b/test/glyph_mapping.js index 255f277e..d681c335 100644 --- a/test/glyph_mapping.js +++ b/test/glyph_mapping.js @@ -1,9 +1,11 @@ import fontkit from '../src'; import assert from 'assert'; +import fs from 'fs'; describe('character to glyph mapping', function() { describe('basic cmap handling', function() { - let font = fontkit.openSync(__dirname + '/data/OpenSans/OpenSans-Regular.ttf'); + const fontData = fs.readFileSync(__dirname + '/data/OpenSans/OpenSans-Regular.ttf'); + const font = fontkit.create(fontData); it('should get characterSet', function() { assert(Array.isArray(font.characterSet)); @@ -30,20 +32,25 @@ describe('character to glyph mapping', function() { }); it('should support unicode variation selectors', function() { - let font = fontkit.openSync(__dirname + '/data/fonttest/TestCMAP14.otf'); + const fontData = fs.readFileSync(__dirname + '/data/fonttest/TestCMAP14.otf'); + const font = fontkit.create(fontData); + let glyphs = font.glyphsForString('\u{82a6}\u{82a6}\u{E0100}\u{82a6}\u{E0101}'); assert.deepEqual(glyphs.map(g => g.id), [1, 1, 2]); }); it('should support legacy encodings when no unicode cmap is found', function() { - let font = fontkit.openSync(__dirname + '/data/fonttest/TestCMAPMacTurkish.ttf'); + const fontData = fs.readFileSync(__dirname + '/data/fonttest/TestCMAPMacTurkish.ttf'); + const font = fontkit.create(fontData); + let glyphs = font.glyphsForString("“ABÇĞIİÖŞÜ”"); assert.deepEqual(glyphs.map(g => g.id), [200, 34, 35, 126, 176, 42, 178, 140, 181, 145, 201]); }); }); describe('opentype features', function() { - let font = fontkit.openSync(__dirname + '/data/SourceSansPro/SourceSansPro-Regular.otf'); + const fontData = fs.readFileSync(__dirname + '/data/SourceSansPro/SourceSansPro-Regular.otf'); + const font = fontkit.create(fontData); it('should list available features', () => assert.deepEqual(font.availableFeatures, [ @@ -73,7 +80,8 @@ describe('character to glyph mapping', function() { }); describe('AAT features', function() { - let font = fontkit.openSync(__dirname + '/data/Play/Play-Regular.ttf'); + const fontData = fs.readFileSync(__dirname + '/data/Play/Play-Regular.ttf'); + const font = fontkit.create(fontData); it('should list available features', () => assert.deepEqual(font.availableFeatures, [ 'tnum', 'sups', 'subs', 'numr', 'onum', 'lnum', 'liga', 'kern' ])); @@ -99,7 +107,9 @@ describe('character to glyph mapping', function() { }); it('should apply indic reordering features', function() { - let f = fontkit.openSync(__dirname + '/data/Khmer/Khmer.ttf'); + const fontData = fs.readFileSync(__dirname + '/data/Khmer/Khmer.ttf'); + const font = fontkit.create(fontData); + let {glyphs} = f.layout('ខ្ញុំអាចញ៉ាំកញ្ចក់បាន ដោយគ្មានបញ្ហា'); assert.deepEqual(glyphs.map(g => g.id), [ 45, 153, 177, 112, 248, 188, 49, 296, 44, 187, 149, 44, 117, 236, 188, 63, 3, 107, @@ -118,13 +128,17 @@ describe('character to glyph mapping', function() { describe('glyph id to strings', function () { it('should return strings from cmap that map to a given glyph', function () { - let font = fontkit.openSync(__dirname + '/data/OpenSans/OpenSans-Regular.ttf'); + const fontData = fs.readFileSync(__dirname + '/data/OpenSans/OpenSans-Regular.ttf'); + const font = fontkit.create(fontData); + let strings = font.stringsForGlyph(68); assert.deepEqual(strings, ['a']); }); it('should return strings from AAT morx table that map to the given glyph', function () { - let font = fontkit.openSync(__dirname + '/data/Play/Play-Regular.ttf'); + const fontData = fs.readFileSync(__dirname + '/data/Play/Play-Regular.ttf'); + const font = fontkit.create(fontData); + let strings = font.stringsForGlyph(767); assert.deepEqual(strings, ['ffi']); }); diff --git a/test/glyph_positioning.js b/test/glyph_positioning.js index c94db70b..79e746ca 100644 --- a/test/glyph_positioning.js +++ b/test/glyph_positioning.js @@ -1,15 +1,18 @@ import fontkit from '../src'; import assert from 'assert'; +import fs from 'fs'; describe('glyph positioning', function() { describe('basic positioning', function() { - let font = fontkit.openSync(__dirname + '/data/SourceSansPro/SourceSansPro-Regular.otf'); + const fontData = fs.readFileSync(__dirname + '/data/SourceSansPro/SourceSansPro-Regular.otf'); + const font = fontkit.create(fontData); it('should get a glyph width', () => assert.equal(font.getGlyph(5).advanceWidth, 615)); }); describe('opentype positioning', function() { - let font = fontkit.openSync(__dirname + '/data/SourceSansPro/SourceSansPro-Regular.otf'); + const fontData = fs.readFileSync(__dirname + '/data/SourceSansPro/SourceSansPro-Regular.otf'); + const font = fontkit.create(fontData); it('should apply opentype GPOS features', function() { let {positions} = font.layout('Twitter'); @@ -23,7 +26,8 @@ describe('glyph positioning', function() { }); describe('AAT features', function() { - let font = fontkit.openSync(__dirname + '/data/Play/Play-Regular.ttf'); + const fontData = fs.readFileSync(__dirname + '/data/Play/Play-Regular.ttf'); + const font = fontkit.create(fontData); it('should apply kerning by default', function() { let {positions} = font.layout('Twitter'); diff --git a/test/glyphs.js b/test/glyphs.js index d078c27f..e3429600 100644 --- a/test/glyphs.js +++ b/test/glyphs.js @@ -1,11 +1,15 @@ import fontkit from '../src'; import assert from 'assert'; import BBox from '../src/glyph/BBox'; +import fs from 'fs'; describe('glyphs', function() { describe('truetype glyphs', function() { - let font = fontkit.openSync(__dirname + '/data/OpenSans/OpenSans-Regular.ttf'); - let mada = fontkit.openSync(__dirname + '/data/Mada/Mada-VF.ttf'); + const fontData = fs.readFileSync(__dirname + '/data/OpenSans/OpenSans-Regular.ttf'); + const font = fontkit.create(fontData); + + const madaData = fs.readFileSync(__dirname + '/data/Mada/Mada-VF.ttf'); + const mada = fontkit.create(fontData); it('should get a TTFGlyph', function() { let glyph = font.getGlyph(39); // D @@ -64,7 +68,8 @@ describe('glyphs', function() { }); describe('CFF glyphs', function() { - let font = fontkit.openSync(__dirname + '/data/SourceSansPro/SourceSansPro-Regular.otf'); + const fontData = fs.readFileSync(__dirname + '/data/SourceSansPro/SourceSansPro-Regular.otf'); + const font = fontkit.create(fontData); it('should get a CFFGlyph', function() { let glyph = font.getGlyph(5); // D @@ -93,7 +98,8 @@ describe('glyphs', function() { }); describe('SBIX glyphs', function() { - let font = fontkit.openSync(__dirname + '/data/ss-emoji/ss-emoji-apple.ttf'); + const fontData = fs.readFileSync(__dirname + '/data/ss-emoji/ss-emoji-apple.ttf'); + const font = fontkit.create(fontData); it('should get an SBIXGlyph', function() { let glyph = font.glyphsForString('😜')[0]; @@ -123,7 +129,8 @@ describe('glyphs', function() { }); describe('COLR glyphs', function() { - let font = fontkit.openSync(__dirname + '/data/ss-emoji/ss-emoji-microsoft.ttf'); + const fontData = fs.readFileSync(__dirname + '/data/ss-emoji/ss-emoji-microsoft.ttf'); + const font = fontkit.create(fontData); it('should get an SBIXGlyph', function() { let glyph = font.glyphsForString('😜')[0]; @@ -156,7 +163,8 @@ describe('glyphs', function() { }); describe('WOFF glyphs', function() { - let font = fontkit.openSync(__dirname + '/data/SourceSansPro/SourceSansPro-Regular.woff'); + const fontData = fs.readFileSync(__dirname + '/data/SourceSansPro/SourceSansPro-Regular.woff'); + const font = fontkit.create(fontData); it('should get a TTFGlyph', function() { let glyph = font.glyphsForString('T')[0]; @@ -175,7 +183,8 @@ describe('glyphs', function() { }); describe('WOFF2 glyph', function() { - let font = fontkit.openSync(__dirname + '/data/SourceSansPro/SourceSansPro-Regular.woff2'); + const fontData = fs.readFileSync(__dirname + '/data/SourceSansPro/SourceSansPro-Regular.woff2'); + const font = fontkit.create(fontData); it('should get a WOFF2Glyph', function() { let glyph = font.glyphsForString('T')[0]; diff --git a/test/index.js b/test/index.js index 14855a62..8f8f22f7 100644 --- a/test/index.js +++ b/test/index.js @@ -1,63 +1,53 @@ import fontkit from '../src'; import assert from 'assert'; +import fs from 'fs'; -describe('fontkit', function() { - it('should open a font asynchronously', () => - fontkit.open(__dirname + '/data/OpenSans/OpenSans-Regular.ttf', function(err, font) { - assert.equal(err, null); - return assert.equal(font.constructor.name, 'TTFFont'); - }) - ); +const openFont = (path, extra) => + fontkit.create(fs.readFileSync(path), extra); +describe('fontkit', function() { it('should open a font synchronously', function() { - let font = fontkit.openSync(__dirname + '/data/OpenSans/OpenSans-Regular.ttf'); + let font = openFont(__dirname + '/data/OpenSans/OpenSans-Regular.ttf'); return assert.equal(font.constructor.name, 'TTFFont'); }); it('should open fonts of different formats', function() { - let font = fontkit.openSync(__dirname + '/data/OpenSans/OpenSans-Regular.ttf'); + let font = openFont(__dirname + '/data/OpenSans/OpenSans-Regular.ttf'); assert.equal(font.constructor.name, 'TTFFont'); - font = fontkit.openSync(__dirname + '/data/SourceSansPro/SourceSansPro-Regular.otf'); + font = openFont(__dirname + '/data/SourceSansPro/SourceSansPro-Regular.otf'); assert.equal(font.constructor.name, 'TTFFont'); - font = fontkit.openSync(__dirname + '/data/NotoSans/NotoSans.ttc'); + font = openFont(__dirname + '/data/NotoSans/NotoSans.ttc'); assert.equal(font.constructor.name, 'TrueTypeCollection'); - font = fontkit.openSync(__dirname + '/data/NotoSans/NotoSans.ttc', 'NotoSans'); + font = openFont(__dirname + '/data/NotoSans/NotoSans.ttc', 'NotoSans'); assert.equal(font.constructor.name, 'TTFFont'); - font = fontkit.openSync(__dirname + '/data/NotoSans/NotoSans.dfont'); + font = openFont(__dirname + '/data/NotoSans/NotoSans.dfont'); assert.equal(font.constructor.name, 'DFont'); - font = fontkit.openSync(__dirname + '/data/NotoSans/NotoSans.dfont', 'NotoSans'); + font = openFont(__dirname + '/data/NotoSans/NotoSans.dfont', 'NotoSans'); assert.equal(font.constructor.name, 'TTFFont'); - font = fontkit.openSync(__dirname + '/data/SourceSansPro/SourceSansPro-Regular.woff'); + font = openFont(__dirname + '/data/SourceSansPro/SourceSansPro-Regular.woff'); assert.equal(font.constructor.name, 'WOFFFont'); - font = fontkit.openSync(__dirname + '/data/SourceSansPro/SourceSansPro-Regular.woff2'); + font = openFont(__dirname + '/data/SourceSansPro/SourceSansPro-Regular.woff2'); assert.equal(font.constructor.name, 'WOFF2Font'); }); it('should open fonts lacking PostScript name', function() { - let font = fontkit.openSync(__dirname + '/data/Mada/Mada-Regular.subset1.ttf'); + let font = openFont(__dirname + '/data/Mada/Mada-Regular.subset1.ttf'); assert.equal(font.postscriptName, null); }); - it('should error when opening an invalid font asynchronously', function() { - fontkit.open(__filename, function(err, font) { - assert(err instanceof Error); - assert.equal(err.message, 'Unknown font format'); - }); - }); - it('should error when opening an invalid font synchronously', function() { - assert.throws(() => fontkit.openSync(__filename), /Unknown font format/); + assert.throws(() => openFont(__filename), /Unknown font format/); }); it('should get collection objects for ttc fonts', function() { - let collection = fontkit.openSync(__dirname + '/data/NotoSans/NotoSans.ttc'); + let collection = openFont(__dirname + '/data/NotoSans/NotoSans.ttc'); assert.equal(collection.constructor.name, 'TrueTypeCollection'); let names = collection.fonts.map(f => f.postscriptName); @@ -68,7 +58,7 @@ describe('fontkit', function() { }); it('should get collection objects for dfonts', function() { - let collection = fontkit.openSync(__dirname + '/data/NotoSans/NotoSans.dfont'); + let collection = openFont(__dirname + '/data/NotoSans/NotoSans.dfont'); assert.equal(collection.constructor.name, 'DFont'); let names = collection.fonts.map(f => f.postscriptName); diff --git a/test/metadata.js b/test/metadata.js index 8dac63b0..ab8aedad 100644 --- a/test/metadata.js +++ b/test/metadata.js @@ -1,9 +1,11 @@ import fontkit from '../src'; import assert from 'assert'; import BBox from '../src/glyph/BBox'; +import fs from 'fs'; describe('metadata', function() { - let font = fontkit.openSync(__dirname + '/data/NotoSans/NotoSans.ttc', 'NotoSans'); + const fontData = fs.readFileSync(__dirname + '/data/NotoSans/NotoSans.ttc'); + const font = fontkit.create(fontData, 'NotoSans'); it('has metadata properties', function() { assert.equal(font.fullName, 'Noto Sans'); diff --git a/test/mocha.opts b/test/mocha.opts index fd3ae628..50b78449 100644 --- a/test/mocha.opts +++ b/test/mocha.opts @@ -1,2 +1,2 @@ --reporter spec ---compilers js:babel-register +--compilers js:@babel/register diff --git a/test/shaping.js b/test/shaping.js index 8b417fe4..f19c6bca 100644 --- a/test/shaping.js +++ b/test/shaping.js @@ -1,11 +1,17 @@ import fontkit from '../src'; import assert from 'assert'; +import fs from 'fs'; describe('shaping', function() { let fontCache = {}; let test = (description, font, text, output) => { it(description, function() { - let f = fontCache[font] || (fontCache[font] = fontkit.openSync(__dirname + '/data/' + font)); + let f = fontCache[font]; + if (!f) { + const fontData = fs.readFileSync(__dirname + '/data/' + font); + f = fontkit.create(fontData); + } + let {glyphs, positions} = f.layout(text); // Generate a compact string representation of the results @@ -28,7 +34,8 @@ describe('shaping', function() { }; describe('general shaping tests', function() { - let font = fontkit.openSync(__dirname + '/data/amiri/amiri-regular.ttf'); + const fontData = fs.readFileSync(__dirname + '/data/amiri/amiri-regular.ttf'); + const font = fontkit.create(fontData); it('should use correct script and language when features are not specified', function() { let {glyphs} = font.layout('۴', 'arab', 'URD'); @@ -70,7 +77,8 @@ describe('shaping', function() { }); describe('hangul shaper', function() { - let font = fontkit.openSync(__dirname + '/data/NotoSansCJK/NotoSansCJKkr-Regular.otf'); + const fontData = fs.readFileSync(__dirname + '/data/NotoSansCJK/NotoSansCJKkr-Regular.otf'); + const font = fontkit.create(fontData); it('should use composed versions if supported by the font', function() { let {glyphs} = font.layout('\uD734\uAC00\u0020\uAC00\u002D\u002D\u0020\u0028\uC624\u002D\u002D\u0029'); diff --git a/test/subset.js b/test/subset.js index 3e1ddfe7..3a87636e 100644 --- a/test/subset.js +++ b/test/subset.js @@ -2,13 +2,14 @@ import fontkit from '../src'; import assert from 'assert'; import concat from 'concat-stream'; import CFFFont from '../src/cff/CFFFont'; -import r from 'restructure'; +import r from '@pdf-lib/restructure'; import CFFGlyph from '../src/glyph/CFFGlyph'; import fs from 'fs'; describe('font subsetting', function() { describe('truetype subsetting', function() { - let font = fontkit.openSync(__dirname + '/data/OpenSans/OpenSans-Regular.ttf'); + const fontData = fs.readFileSync(__dirname + '/data/OpenSans/OpenSans-Regular.ttf'); + const font = fontkit.create(fontData); it('should create a TTFSubset instance', function() { let subset = font.createSubset(); @@ -28,11 +29,13 @@ describe('font subsetting', function() { done(); })); }); - + it('should re-encode variation glyphs', function(done) { if (!fs.existsSync('/Library/Fonts/Skia.ttf')) return done(); - - let font = fontkit.openSync('/Library/Fonts/Skia.ttf', 'Bold'); + + const fontData = fs.readFileSync('/Library/Fonts/Skia.ttf'); + const font = fontkit.create(fontData, 'Bold'); + let subset = font.createSubset(); for (let glyph of font.glyphsForString('e')) { subset.includeGlyph(glyph); @@ -59,7 +62,8 @@ describe('font subsetting', function() { }); describe('CFF subsetting', function() { - let font = fontkit.openSync(__dirname + '/data/SourceSansPro/SourceSansPro-Regular.otf'); + const fontData = fs.readFileSync(__dirname + '/data/SourceSansPro/SourceSansPro-Regular.otf'); + const font = fontkit.create(fontData); it('should create a CFFSubset instance', function() { let subset = font.createSubset(); @@ -84,7 +88,9 @@ describe('font subsetting', function() { }); it('should handle CID fonts', function(done) { - let f = fontkit.openSync(__dirname + '/data/NotoSansCJK/NotoSansCJKkr-Regular.otf'); + const fontData = fs.readFileSync(__dirname + '/data/NotoSansCJK/NotoSansCJKkr-Regular.otf'); + const font = fontkit.create(fontData); + let subset = f.createSubset(); let iterable = f.glyphsForString('갈휸'); for (let i = 0; i < iterable.length; i++) { diff --git a/test/variations.js b/test/variations.js index e108fe14..6c6fc351 100644 --- a/test/variations.js +++ b/test/variations.js @@ -5,7 +5,8 @@ import fs from 'fs'; describe('variations', function() { describe('Skia', function() { if (!fs.existsSync('/Library/Fonts/Skia.ttf')) { return; } - let font = fontkit.openSync('/Library/Fonts/Skia.ttf'); + const fontData = fs.readFileSync('/Library/Fonts/Skia.ttf'); + const font = fontkit.create(fontData); it('should get available variation axes', function() { let axes = font.variationAxes; @@ -63,7 +64,8 @@ describe('variations', function() { describe('truetype variations', function () { it('should support sharing all points', function() { - let font = fontkit.openSync(__dirname + '/data/fonttest/TestGVAROne.ttf'); + const fontData = fs.readFileSync(__dirname + '/data/fonttest/TestGVAROne.ttf'); + const font = fontkit.create(fontData); assert.equal( font.getVariation({wght: 300}).glyphsForString("彌")[0].path.toSVG(), @@ -72,7 +74,8 @@ describe('variations', function() { }); it('should support sharing enumerated points', function() { - let font = fontkit.openSync(__dirname + '/data/fonttest/TestGVARTwo.ttf'); + const fontData = fs.readFileSync(__dirname + '/data/fonttest/TestGVARTwo.ttf'); + const font = fontkit.create(fontData); assert.equal( font.getVariation({wght: 300}).glyphsForString("彌")[0].path.toSVG(), @@ -81,7 +84,8 @@ describe('variations', function() { }); it('should support sharing no points', function() { - let font = fontkit.openSync(__dirname + '/data/fonttest/TestGVARThree.ttf'); + const fontData = fs.readFileSync(__dirname + '/data/fonttest/TestGVARThree.ttf'); + const font = fontkit.create(fontData); assert.equal( font.getVariation({wght: 300}).glyphsForString("彌")[0].path.toSVG(), @@ -90,7 +94,8 @@ describe('variations', function() { }); it('should use the HVAR table when available for variation metrics', function () { - let font = fontkit.openSync(__dirname + '/data/fonttest/TestGVARFour.ttf'); + const fontData = fs.readFileSync(__dirname + '/data/fonttest/TestGVARFour.ttf'); + const font = fontkit.create(fontData); assert.equal( Math.round(font.getVariation({wght: 150}).glyphsForString('O')[0].advanceWidth), @@ -99,7 +104,8 @@ describe('variations', function() { }); it('should fall back to the last entry in an HVAR table', function () { - let font = fontkit.openSync(__dirname + '/data/fonttest/TestHVARTwo.ttf'); + const fontData = fs.readFileSync(__dirname + '/data/fonttest/TestHVARTwo.ttf'); + const font = fontkit.create(fontData); assert.equal( Math.round(font.getVariation({wght: 400}).glyphsForString('A')[0].advanceWidth), @@ -108,7 +114,9 @@ describe('variations', function() { }); it('should support adjusting GPOS mark anchor points for variations', function () { - let font = fontkit.openSync(__dirname + '/data/Mada/Mada-VF.ttf', {wght: 900}); + const fontData = fs.readFileSync(__dirname + '/data/Mada/Mada-VF.ttf'); + const font = fontkit.create(fontData, {wght: 900}); + let run = font.layout('ف'); assert.equal(Math.floor(run.positions[0].xOffset), 639); assert.equal(Math.floor(run.positions[0].yOffset), 542); @@ -116,7 +124,8 @@ describe('variations', function() { }); describe('CFF2 variations', function () { - let font = fontkit.openSync(__dirname + '/data/fonttest/AdobeVFPrototype-Subset.otf'); + const fontData = fs.readFileSync(__dirname + '/data/fonttest/AdobeVFPrototype-Subset.otf'); + const font = fontkit.create(fontData); it('applies variations to CFF2 glyphs', function () { assert.equal( @@ -137,4 +146,3 @@ describe('variations', function() { }); }); }); -