layout.js
1 import assert from 'assert'; 2 import { Font, Path, Glyph } from '../src/opentype'; 3 import Layout from '../src/layout'; 4 5 describe('layout.js', function() { 6 let font; 7 let layout; 8 const notdefGlyph = new Glyph({ 9 name: '.notdef', 10 unicode: 0, 11 path: new Path() 12 }); 13 const defaultLayoutTable = { 14 version: 1, 15 scripts: [], 16 features: [], 17 lookups: [] 18 }; 19 20 const glyphs = [notdefGlyph].concat('abcdefghijklmnopqrstuvwxyz'.split('').map(function (c) { 21 return new Glyph({ 22 name: c, 23 unicode: c.charCodeAt(0), 24 path: new Path() 25 }); 26 })); 27 28 beforeEach(function() { 29 font = new Font({ 30 familyName: 'MyFont', 31 styleName: 'Medium', 32 unitsPerEm: 1000, 33 ascender: 800, 34 descender: -200, 35 glyphs: glyphs 36 }); 37 layout = new Layout(font, 'gsub'); 38 layout.createDefaultTable = function() { return defaultLayoutTable; }; 39 }); 40 41 describe('getTable', function() { 42 it('must not always create an empty default layout table', function() { 43 assert.equal(layout.getTable(), undefined); 44 assert.equal(layout.getTable(false), undefined); 45 }); 46 47 it('must create an empty default layout table on demand', function() { 48 assert.equal(layout.getTable(true), defaultLayoutTable); 49 }); 50 }); 51 52 describe('getScriptTable', function() { 53 it('must not create a new script table if it does not exist', function() { 54 assert.equal(layout.getScriptTable('DFLT'), undefined); 55 assert.equal(layout.getScriptTable('DFLT', false), undefined); 56 }); 57 58 it('must create an new script table only on demand and if it does not exist', function() { 59 const scriptTable = layout.getScriptTable('DFLT', true); 60 assert.notEqual(scriptTable, undefined); 61 assert.notEqual(scriptTable.defaultLangSys, undefined); 62 assert.equal(layout.getScriptTable('DFLT', true), scriptTable, 'must create only one instance for each tag'); 63 }); 64 }); 65 });