Socket
Socket
Sign inDemoInstall

opentype.js

Package Overview
Dependencies
Maintainers
2
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

opentype.js - npm Package Compare versions

Comparing version 0.7.1 to 0.7.2

.reify-cache/008ea0c644a81527a76ceddc6b39081958d480b0.js

29

bin/server.js
#!/usr/bin/env node
'use strict';
var fs = require('fs');
var http = require('http');
var path = require('path');
var rollup = require('rollup');
var watch = require('rollup-watch');
var rollupConfig = require('../rollup.config');

@@ -15,3 +16,5 @@ var CONTENT_TYPES = {

'.ttf': 'font/otf',
'.otf': 'font/otf'
'.otf': 'font/otf',
'.woff': 'font/woff',
'.woff2': 'font/woff2',
};

@@ -25,8 +28,2 @@

rewrite = ' -> ' + url;
} else if (url === 'dist/opentype.js') {
url = 'build/opentype.js';
rewrite = ' -> ' + url;
} else if (url === '../dist/opentype.js') {
url = '../build/opentype.js';
rewrite = ' -> ' + url;
}

@@ -50,3 +47,15 @@

}).listen(8080);
console.log('Server running at http://localhost:8080/');
console.log('Server running on port 8080.');
var watcher = watch(rollup, rollupConfig);
watcher.on('event', function(e) {
if (e.code === 'BUILD_START') {
console.log('Bundling...');
} else if (e.code === 'BUILD_END') {
console.log('Bundled in ' + e.duration + 'ms.');
} else if (e.code === 'ERROR') {
console.error(e.error);
} else {
console.error('Unknown watch event', e);
}
});
{
"name": "opentype.js",
"version": "0.7.1",
"version": "0.7.2",
"main": "dist/opentype.js",

@@ -5,0 +5,0 @@ "keywords": [

@@ -7,3 +7,3 @@ # Contributing

We use [browserify](http://browserify.org/) to combine this into a single package with every release.
We use [rollup](https://rollupjs.org/) to combine this into a single package with every release.

@@ -25,3 +25,3 @@ When creating a pull request, you **don't** need to run `npm run dist` -- we'll do that when creating a release.

4. Install the development dependencies (browserify, watchify, jshint, ...):
4. Install the development dependencies:

@@ -35,4 +35,3 @@ `cd opentype.js`

Note that the compiled file ends up in the `build` folder, not the `dist` folder! The development server
rewrites the JavaScript URL from `dist/opentype.min.js` to `build/opentype.js`.
This bundles all source files under `dist/opentype.js`.

@@ -39,0 +38,0 @@ 6. Make some changes

// This example shows how to create a font from scratch using node.js.
'use strict';
import { Font, Glyph, Path } from '../src/opentype';
var opentype = require('../src/opentype');
// These are the global measurements of the typeface.

@@ -87,14 +85,14 @@ var UNITS_PER_EM = 1000;

// The notdefGlyph always needs to be included.
var notdefGlyph = new opentype.Glyph({
var notdefGlyph = new Glyph({
name: '.notdef',
advanceWidth: 650,
path: new opentype.Path()
path: new Path()
});
// Our glyph map can't properly encode a space character, so we make one here.
var spaceGlyph = new opentype.Glyph({
var spaceGlyph = new Glyph({
name: 'space',
unicode: 32,
advanceWidth: 10 * SCALE,
path: new opentype.Path()
path: new Path()
});

@@ -112,3 +110,3 @@

// Create a path by looping over all the points and multiplying by the SCALE.
var path = new opentype.Path();
var path = new Path();
var points = GLYPH_MAP[glyphName];

@@ -129,3 +127,3 @@ // Remember the width of the character, to set the advanceWidth.

// Create the glyph. The advanceWidth is the widest part of the letter + 1.
var glyph = new opentype.Glyph({
var glyph = new Glyph({
name: ttfName,

@@ -140,3 +138,3 @@ unicode: glyphName.charCodeAt(0),

// Create the font using measurements + glyphs defined above.
var font = new opentype.Font({
var font = new Font({
familyName: 'Pyramid',

@@ -143,0 +141,0 @@ styleName: 'Regular',

{
"name": "opentype.js",
"description": "OpenType font parser",
"version": "0.7.1",
"version": "0.7.2",
"author": {

@@ -22,3 +22,4 @@ "name": "Frederik De Bleser",

},
"main": "src/opentype.js",
"main": "dist/opentype.js",
"module": "src/opentype.js",
"bin": {

@@ -28,20 +29,24 @@ "ot": "./bin/ot"

"scripts": {
"watch": "watchify src/opentype.js --standalone opentype --debug -o build/opentype.js -v",
"start": "mkdirp build && parallelshell \"npm run watch\" \"node ./bin/server.js\"",
"test": "mocha --recursive && jshint . && jscs .",
"browserify": "browserify src/opentype.js -p licensify --bare --standalone opentype > dist/opentype.js",
"uglify": "browserify src/opentype.js -p licensify --bare --standalone opentype -g uglifyify > dist/opentype.min.js",
"dist": "rimraf build && rimraf dist && mkdirp build && mkdirp dist && npm run test && npm run browserify && npm run uglify"
"start": "node ./bin/server.js",
"watch": "rollup -c -w",
"test": "mocha --require reify --compilers js:buble/register --recursive && jshint . && jscs .",
"build": "rollup -c",
"minify": "uglifyjs ./dist/opentype.js > ./dist/opentype.min.js",
"dist": "npm run test && npm run build && npm run minify"
},
"devDependencies": {
"browserify": "^13.0.1",
"buble": "^0.15.2",
"cross-env": "^5.0.0",
"jscs": "^3.0.3",
"jshint": "^2.9.2",
"mkdirp": "^0.5.1",
"mocha": "^2.5.3",
"parallelshell": "^2.0.0",
"rimraf": "^2.5.2",
"uglifyify": "^3.0.1",
"watchify": "^3.7.0",
"licensify": "^3.1.2"
"reify": "^0.11.0",
"rollup": "^0.41.6",
"rollup-plugin-buble": "^0.15.0",
"rollup-plugin-commonjs": "^8.0.2",
"rollup-plugin-license": "^0.4.0",
"rollup-plugin-node-resolve": "^3.0.0",
"rollup-watch": "^3.2.2",
"uglify-js": "^3.0.14",
"uglifyjs": "^2.4.11"
},

@@ -48,0 +53,0 @@ "browser": {

@@ -29,3 +29,3 @@ opentype.js

See [the project website](http://nodebox.github.io/opentype.js/) for a live demo.
See [the project website](https://opentype.js.org/) for a live demo.

@@ -51,2 +51,8 @@ Features

### Using npm
npm install --save opentype.js
OpenType.js uses ES6-style imports, so debugging it in Node.js requires running `npm run build` first. Use `npm run watch` to automatically rebuild when files change.
### Using Bower

@@ -62,8 +68,2 @@

### Using Browserify
To install using [Browserify](http://browserify.org/), enter the following command in your project directory:
npm install --save opentype.js
API

@@ -70,0 +70,0 @@ ===

@@ -0,1 +1,7 @@

0.7.2 (June 7, 2017)
====================
* WOFF fonts with cvt tables now parse correctly.
* Migrated to ES6 modules and let/const.
* Use Rollup to bundle the JavaScript.
0.7.1 (Apr 25, 2017)

@@ -2,0 +8,0 @@ ====================

// The Bounding Box object
'use strict';
function derive(v0, v1, v2, v3, t) {

@@ -104,6 +102,6 @@ return Math.pow(1 - t, 3) * v0 +

var p0 = [x0, y0];
var p1 = [x1, y1];
var p2 = [x2, y2];
var p3 = [x, y];
const p0 = [x0, y0];
const p1 = [x1, y1];
const p2 = [x2, y2];
const p3 = [x, y];

@@ -113,10 +111,10 @@ this.addPoint(x0, y0);

for (var i = 0; i <= 1; i++) {
var b = 6 * p0[i] - 12 * p1[i] + 6 * p2[i];
var a = -3 * p0[i] + 9 * p1[i] - 9 * p2[i] + 3 * p3[i];
var c = 3 * p1[i] - 3 * p0[i];
for (let i = 0; i <= 1; i++) {
const b = 6 * p0[i] - 12 * p1[i] + 6 * p2[i];
const a = -3 * p0[i] + 9 * p1[i] - 9 * p2[i] + 3 * p3[i];
const c = 3 * p1[i] - 3 * p0[i];
if (a === 0) {
if (b === 0) continue;
var t = -c / b;
const t = -c / b;
if (0 < t && t < 1) {

@@ -129,5 +127,5 @@ if (i === 0) this.addX(derive(p0[i], p1[i], p2[i], p3[i], t));

var b2ac = Math.pow(b, 2) - 4 * c * a;
const b2ac = Math.pow(b, 2) - 4 * c * a;
if (b2ac < 0) continue;
var t1 = (-b + Math.sqrt(b2ac)) / (2 * a);
const t1 = (-b + Math.sqrt(b2ac)) / (2 * a);
if (0 < t1 && t1 < 1) {

@@ -137,3 +135,3 @@ if (i === 0) this.addX(derive(p0[i], p1[i], p2[i], p3[i], t1));

}
var t2 = (-b - Math.sqrt(b2ac)) / (2 * a);
const t2 = (-b - Math.sqrt(b2ac)) / (2 * a);
if (0 < t2 && t2 < 1) {

@@ -157,9 +155,9 @@ if (i === 0) this.addX(derive(p0[i], p1[i], p2[i], p3[i], t2));

BoundingBox.prototype.addQuad = function(x0, y0, x1, y1, x, y) {
var cp1x = x0 + 2 / 3 * (x1 - x0);
var cp1y = y0 + 2 / 3 * (y1 - y0);
var cp2x = cp1x + 1 / 3 * (x - x0);
var cp2y = cp1y + 1 / 3 * (y - y0);
const cp1x = x0 + 2 / 3 * (x1 - x0);
const cp1y = y0 + 2 / 3 * (y1 - y0);
const cp2x = cp1x + 1 / 3 * (x - x0);
const cp2y = cp1y + 1 / 3 * (y - y0);
this.addBezier(x0, y0, cp1x, cp1y, cp2x, cp2y, x, y);
};
exports.BoundingBox = BoundingBox;
export default BoundingBox;
// Run-time checking of preconditions.
'use strict';
exports.fail = function(message) {
function fail(message) {
throw new Error(message);
};
}
// Precondition function that checks if the given predicate is true.
// If not, it will throw an error.
exports.argument = function(predicate, message) {
function argument(predicate, message) {
if (!predicate) {
exports.fail(message);
fail(message);
}
};
}
// Precondition function that checks if the given assertion is true.
// If not, it will throw an error.
exports.assert = exports.argument;
export { fail, argument, argument as assert };
export default { fail, argument, assert: argument };
// Drawing utility functions.
'use strict';
// Draw a line on the given context from point `x1,y1` to point `x2,y2`.

@@ -13,2 +11,2 @@ function line(ctx, x1, y1, x2, y2) {

exports.line = line;
export default { line };
// Glyph encoding
'use strict';
var cffStandardStrings = [
const cffStandardStrings = [
'.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent', 'ampersand', 'quoteright',

@@ -50,3 +48,3 @@ 'parenleft', 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two',

var cffStandardEncoding = [
const cffStandardEncoding = [
'', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',

@@ -70,3 +68,3 @@ '', '', '', '', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent', 'ampersand', 'quoteright',

var cffExpertEncoding = [
const cffExpertEncoding = [
'', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',

@@ -99,3 +97,3 @@ '', '', '', '', 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle', 'dollarsuperior',

var standardNames = [
const standardNames = [
'.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',

@@ -141,8 +139,8 @@ 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',

DefaultEncoding.prototype.charToGlyphIndex = function(c) {
var code = c.charCodeAt(0);
var glyphs = this.font.glyphs;
const code = c.charCodeAt(0);
const glyphs = this.font.glyphs;
if (glyphs) {
for (var i = 0; i < glyphs.length; i += 1) {
var glyph = glyphs.get(i);
for (var j = 0; j < glyph.unicodes.length; j += 1) {
for (let i = 0; i < glyphs.length; i += 1) {
const glyph = glyphs.get(i);
for (let j = 0; j < glyph.unicodes.length; j += 1) {
if (glyph.unicodes[j] === code) {

@@ -153,5 +151,4 @@ return i;

}
} else {
return null;
}
return null;
};

@@ -182,3 +179,3 @@

* @param {string} encoding - The encoding
* @param {Array} charset - The charcater set.
* @param {Array} charset - The character set.
*/

@@ -195,4 +192,4 @@ function CffEncoding(encoding, charset) {

CffEncoding.prototype.charToGlyphIndex = function(s) {
var code = s.charCodeAt(0);
var charName = this.encoding[code];
const code = s.charCodeAt(0);
const charName = this.encoding[code];
return this.charset.indexOf(charName);

@@ -208,14 +205,13 @@ };

function GlyphNames(post) {
var i;
switch (post.version) {
case 1:
this.names = exports.standardNames.slice();
this.names = standardNames.slice();
break;
case 2:
this.names = new Array(post.numberOfGlyphs);
for (i = 0; i < post.numberOfGlyphs; i++) {
if (post.glyphNameIndex[i] < exports.standardNames.length) {
this.names[i] = exports.standardNames[post.glyphNameIndex[i]];
for (let i = 0; i < post.numberOfGlyphs; i++) {
if (post.glyphNameIndex[i] < standardNames.length) {
this.names[i] = standardNames[post.glyphNameIndex[i]];
} else {
this.names[i] = post.names[post.glyphNameIndex[i] - exports.standardNames.length];
this.names[i] = post.names[post.glyphNameIndex[i] - standardNames.length];
}

@@ -227,4 +223,4 @@ }

this.names = new Array(post.numberOfGlyphs);
for (i = 0; i < post.numberOfGlyphs; i++) {
this.names[i] = exports.standardNames[i + post.glyphNameIndex[i]];
for (let i = 0; i < post.numberOfGlyphs; i++) {
this.names[i] = standardNames[i + post.glyphNameIndex[i]];
}

@@ -236,2 +232,5 @@

break;
default:
this.names = [];
break;
}

@@ -262,9 +261,9 @@ }

function addGlyphNames(font) {
var glyph;
var glyphIndexMap = font.tables.cmap.glyphIndexMap;
var charCodes = Object.keys(glyphIndexMap);
let glyph;
const glyphIndexMap = font.tables.cmap.glyphIndexMap;
const charCodes = Object.keys(glyphIndexMap);
for (var i = 0; i < charCodes.length; i += 1) {
var c = charCodes[i];
var glyphIndex = glyphIndexMap[c];
for (let i = 0; i < charCodes.length; i += 1) {
const c = charCodes[i];
const glyphIndex = glyphIndexMap[c];
glyph = font.glyphs.get(glyphIndex);

@@ -274,3 +273,3 @@ glyph.addUnicode(parseInt(c));

for (i = 0; i < font.glyphs.length; i += 1) {
for (let i = 0; i < font.glyphs.length; i += 1) {
glyph = font.glyphs.get(i);

@@ -289,10 +288,12 @@ if (font.cffEncoding) {

exports.cffStandardStrings = cffStandardStrings;
exports.cffStandardEncoding = cffStandardEncoding;
exports.cffExpertEncoding = cffExpertEncoding;
exports.standardNames = standardNames;
exports.DefaultEncoding = DefaultEncoding;
exports.CmapEncoding = CmapEncoding;
exports.CffEncoding = CffEncoding;
exports.GlyphNames = GlyphNames;
exports.addGlyphNames = addGlyphNames;
export {
cffStandardStrings,
cffStandardEncoding,
cffExpertEncoding,
standardNames,
DefaultEncoding,
CmapEncoding,
CffEncoding,
GlyphNames,
addGlyphNames
};
// The Font object
'use strict';
import Path from './path';
import sfnt from './tables/sfnt';
import { DefaultEncoding } from './encoding';
import glyphset from './glyphset';
import Substitution from './substitution';
import { isBrowser, checkArgument, arrayBufferToNodeBuffer } from './util';
import HintingTrueType from './hintingtt';
var path = require('./path');
var sfnt = require('./tables/sfnt');
var encoding = require('./encoding');
var glyphset = require('./glyphset');
var Substitution = require('./substitution');
var util = require('./util');
var HintingTrueType = require('./hintingtt');
/**

@@ -54,8 +52,8 @@ * @typedef FontOptions

// Check that we've provided the minimum set of names.
util.checkArgument(options.familyName, 'When creating a new Font object, familyName is required.');
util.checkArgument(options.styleName, 'When creating a new Font object, styleName is required.');
util.checkArgument(options.unitsPerEm, 'When creating a new Font object, unitsPerEm is required.');
util.checkArgument(options.ascender, 'When creating a new Font object, ascender is required.');
util.checkArgument(options.descender, 'When creating a new Font object, descender is required.');
util.checkArgument(options.descender < 0, 'Descender should be negative (e.g. -512).');
checkArgument(options.familyName, 'When creating a new Font object, familyName is required.');
checkArgument(options.styleName, 'When creating a new Font object, styleName is required.');
checkArgument(options.unitsPerEm, 'When creating a new Font object, unitsPerEm is required.');
checkArgument(options.ascender, 'When creating a new Font object, ascender is required.');
checkArgument(options.descender, 'When creating a new Font object, descender is required.');
checkArgument(options.descender < 0, 'Descender should be negative (e.g. -512).');

@@ -92,3 +90,3 @@ // OS X will complain if the names are empty, so we put a single space everywhere by default.

this.glyphs = new glyphset.GlyphSet(this, options.glyphs || []);
this.encoding = new encoding.DefaultEncoding(this);
this.encoding = new DefaultEncoding(this);
this.substitution = new Substitution(this);

@@ -135,4 +133,4 @@ this.tables = this.tables || {};

Font.prototype.charToGlyph = function(c) {
var glyphIndex = this.charToGlyphIndex(c);
var glyph = this.glyphs.get(glyphIndex);
const glyphIndex = this.charToGlyphIndex(c);
let glyph = this.glyphs.get(glyphIndex);
if (!glyph) {

@@ -157,23 +155,22 @@ // .notdef

options = options || this.defaultRenderOptions;
var i;
// Get glyph indexes
var indexes = [];
for (i = 0; i < s.length; i += 1) {
var c = s[i];
const indexes = [];
for (let i = 0; i < s.length; i += 1) {
const c = s[i];
indexes.push(this.charToGlyphIndex(c));
}
var length = indexes.length;
let length = indexes.length;
// Apply substitutions on glyph indexes
if (options.features) {
var script = options.script || this.substitution.getDefaultScriptName();
var manyToOne = [];
const script = options.script || this.substitution.getDefaultScriptName();
let manyToOne = [];
if (options.features.liga) manyToOne = manyToOne.concat(this.substitution.getFeature('liga', script, options.language));
if (options.features.rlig) manyToOne = manyToOne.concat(this.substitution.getFeature('rlig', script, options.language));
for (i = 0; i < length; i += 1) {
for (var j = 0; j < manyToOne.length; j++) {
var ligature = manyToOne[j];
var components = ligature.sub;
var compCount = components.length;
var k = 0;
for (let i = 0; i < length; i += 1) {
for (let j = 0; j < manyToOne.length; j++) {
const ligature = manyToOne[j];
const components = ligature.sub;
const compCount = components.length;
let k = 0;
while (k < compCount && components[k] === indexes[i + k]) k++;

@@ -189,5 +186,5 @@ if (k === compCount) {

// convert glyph indexes to glyph objects
var glyphs = new Array(length);
var notdef = this.glyphs.get(0);
for (i = 0; i < length; i += 1) {
const glyphs = new Array(length);
const notdef = this.glyphs.get(0);
for (let i = 0; i < length; i += 1) {
glyphs[i] = this.glyphs.get(indexes[i]) || notdef;

@@ -211,4 +208,4 @@ }

Font.prototype.nameToGlyph = function(name) {
var glyphIndex = this.nameToGlyphIndex(name);
var glyph = this.glyphs.get(glyphIndex);
const glyphIndex = this.nameToGlyphIndex(name);
let glyph = this.glyphs.get(glyphIndex);
if (!glyph) {

@@ -246,3 +243,3 @@ // .notdef

rightGlyph = rightGlyph.index || rightGlyph;
var gposKerning = this.getGposKerningValue;
const gposKerning = this.getGposKerningValue;
return gposKerning ? gposKerning(leftGlyph, rightGlyph) :

@@ -286,6 +283,6 @@ (this.kerningPairs[leftGlyph + ',' + rightGlyph] || 0);

options = options || this.defaultRenderOptions;
var fontScale = 1 / this.unitsPerEm * fontSize;
var glyphs = this.stringToGlyphs(text, options);
for (var i = 0; i < glyphs.length; i += 1) {
var glyph = glyphs[i];
const fontScale = 1 / this.unitsPerEm * fontSize;
const glyphs = this.stringToGlyphs(text, options);
for (let i = 0; i < glyphs.length; i += 1) {
const glyph = glyphs[i];
callback.call(this, glyph, x, y, fontSize, options);

@@ -297,3 +294,3 @@ if (glyph.advanceWidth) {

if (options.kerning && i < glyphs.length - 1) {
var kerningValue = this.getKerningValue(glyph, glyphs[i + 1]);
const kerningValue = this.getKerningValue(glyph, glyphs[i + 1]);
x += kerningValue * fontScale;

@@ -321,5 +318,5 @@ }

Font.prototype.getPath = function(text, x, y, fontSize, options) {
var fullPath = new path.Path();
const fullPath = new Path();
this.forEachGlyph(text, x, y, fontSize, options, function(glyph, gX, gY, gFontSize) {
var glyphPath = glyph.getPath(gX, gY, gFontSize, options, this);
const glyphPath = glyph.getPath(gX, gY, gFontSize, options, this);
fullPath.extend(glyphPath);

@@ -331,3 +328,3 @@ });

/**
* Create an array of Path objects that represent the glyps of a given text.
* Create an array of Path objects that represent the glyphs of a given text.
* @param {string} text - The text to create.

@@ -341,5 +338,5 @@ * @param {number} [x=0] - Horizontal position of the beginning of the text.

Font.prototype.getPaths = function(text, x, y, fontSize, options) {
var glyphPaths = [];
const glyphPaths = [];
this.forEachGlyph(text, x, y, fontSize, options, function(glyph, gX, gY, gFontSize) {
var glyphPath = glyph.getPath(gX, gY, gFontSize);
const glyphPath = glyph.getPath(gX, gY, gFontSize);
glyphPaths.push(glyphPath);

@@ -355,3 +352,3 @@ });

* This is something different than Path.getBoundingBox() as for example a
* suffixed whitespace increases the advancewidth but not the bounding box
* suffixed whitespace increases the advanceWidth but not the bounding box
* or an overhanging letter like a calligraphic 'f' might have a quite larger

@@ -423,3 +420,3 @@ * bounding box than its advance width.

Font.prototype.getEnglishName = function(name) {
var translations = this.names[name];
const translations = this.names[name];
if (translations) {

@@ -434,4 +431,4 @@ return translations.en;

Font.prototype.validate = function() {
var warnings = [];
var _this = this;
const warnings = [];
const _this = this;

@@ -445,3 +442,3 @@ function assert(predicate, message) {

function assertNamePresent(name) {
var englishName = _this.getEnglishName(name);
const englishName = _this.getEnglishName(name);
assert(englishName && englishName.trim().length > 0,

@@ -482,7 +479,7 @@ 'No English ' + name + ' specified.');

Font.prototype.toArrayBuffer = function() {
var sfntTable = this.toTables();
var bytes = sfntTable.encode();
var buffer = new ArrayBuffer(bytes.length);
var intArray = new Uint8Array(buffer);
for (var i = 0; i < bytes.length; i++) {
const sfntTable = this.toTables();
const bytes = sfntTable.encode();
const buffer = new ArrayBuffer(bytes.length);
const intArray = new Uint8Array(buffer);
for (let i = 0; i < bytes.length; i++) {
intArray[i] = bytes[i];

@@ -498,8 +495,8 @@ }

Font.prototype.download = function(fileName) {
var familyName = this.getEnglishName('fontFamily');
var styleName = this.getEnglishName('fontSubfamily');
const familyName = this.getEnglishName('fontFamily');
const styleName = this.getEnglishName('fontSubfamily');
fileName = fileName || familyName.replace(/\s/g, '') + '-' + styleName + '.otf';
var arrayBuffer = this.toArrayBuffer();
const arrayBuffer = this.toArrayBuffer();
if (util.isBrowser()) {
if (isBrowser()) {
window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;

@@ -509,4 +506,4 @@ window.requestFileSystem(window.TEMPORARY, arrayBuffer.byteLength, function(fs) {

fileEntry.createWriter(function(writer) {
var dataView = new DataView(arrayBuffer);
var blob = new Blob([dataView], {type: 'font/opentype'});
const dataView = new DataView(arrayBuffer);
const blob = new Blob([dataView], {type: 'font/opentype'});
writer.write(blob);

@@ -525,4 +522,4 @@

} else {
var fs = require('fs');
var buffer = util.arrayBufferToNodeBuffer(arrayBuffer);
const fs = require('fs');
const buffer = arrayBufferToNodeBuffer(arrayBuffer);
fs.writeFileSync(fileName, buffer);

@@ -577,2 +574,2 @@ }

exports.Font = Font;
export default Font;
// The Glyph object
'use strict';
import check from './check';
import draw from './draw';
import Path from './path';
import glyf from './tables/glyf';
var check = require('./check');
var draw = require('./draw');
var path = require('./path');
var glyf = require('./tables/glyf');
function getPathDefinition(glyph, path) {
var _path = path || { commands: [] };
let _path = path || {commands: []};
return {

@@ -64,3 +62,3 @@ configurable: true,

// These three values cannnot be deferred for memory optimization:
// These three values cannot be deferred for memory optimization:
this.name = options.name || null;

@@ -122,3 +120,3 @@ this.unicode = options.unicode || undefined;

* @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.
* @param {Object=} options - xScale, yScale to strech the glyph.
* @param {Object=} options - xScale, yScale to stretch the glyph.
* @param {opentype.Font} if hinting is to be used, the font

@@ -131,7 +129,7 @@ * @return {opentype.Path}

fontSize = fontSize !== undefined ? fontSize : 72;
var commands;
var hPoints;
let commands;
let hPoints;
if (!options) options = { };
var xScale = options.xScale;
var yScale = options.yScale;
let xScale = options.xScale;
let yScale = options.yScale;

@@ -154,3 +152,3 @@ if (options.hinting && font && font.hinting) {

commands = this.path.commands;
var scale = 1 / this.path.unitsPerEm * fontSize;
const scale = 1 / this.path.unitsPerEm * fontSize;
if (xScale === undefined) xScale = scale;

@@ -160,5 +158,5 @@ if (yScale === undefined) yScale = scale;

var p = new path.Path();
for (var i = 0; i < commands.length; i += 1) {
var cmd = commands[i];
const p = new Path();
for (let i = 0; i < commands.length; i += 1) {
const cmd = commands[i];
if (cmd.type === 'M') {

@@ -194,6 +192,6 @@ p.moveTo(x + (cmd.x * xScale), y + (-cmd.y * yScale));

var contours = [];
var currentContour = [];
for (var i = 0; i < this.points.length; i += 1) {
var pt = this.points[i];
const contours = [];
let currentContour = [];
for (let i = 0; i < this.points.length; i += 1) {
const pt = this.points[i];
currentContour.push(pt);

@@ -215,7 +213,7 @@ if (pt.lastPointOfContour) {

Glyph.prototype.getMetrics = function() {
var commands = this.path.commands;
var xCoords = [];
var yCoords = [];
for (var i = 0; i < commands.length; i += 1) {
var cmd = commands[i];
const commands = this.path.commands;
const xCoords = [];
const yCoords = [];
for (let i = 0; i < commands.length; i += 1) {
const cmd = commands[i];
if (cmd.type !== 'Z') {

@@ -237,3 +235,3 @@ xCoords.push(cmd.x);

var metrics = {
const metrics = {
xMin: Math.min.apply(null, xCoords),

@@ -272,3 +270,3 @@ yMin: Math.min.apply(null, yCoords),

* @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.
* @param {Object=} options - xScale, yScale to strech the glyph.
* @param {Object=} options - xScale, yScale to stretch the glyph.
*/

@@ -288,7 +286,6 @@ Glyph.prototype.draw = function(ctx, x, y, fontSize, options) {

Glyph.prototype.drawPoints = function(ctx, x, y, fontSize) {
function drawCircles(l, x, y, scale) {
var PI_SQ = Math.PI * 2;
const PI_SQ = Math.PI * 2;
ctx.beginPath();
for (var j = 0; j < l.length; j += 1) {
for (let j = 0; j < l.length; j += 1) {
ctx.moveTo(x + (l[j].x * scale), y + (l[j].y * scale));

@@ -305,9 +302,9 @@ ctx.arc(x + (l[j].x * scale), y + (l[j].y * scale), 2, 0, PI_SQ, false);

fontSize = fontSize !== undefined ? fontSize : 24;
var scale = 1 / this.path.unitsPerEm * fontSize;
const scale = 1 / this.path.unitsPerEm * fontSize;
var blueCircles = [];
var redCircles = [];
var path = this.path;
for (var i = 0; i < path.commands.length; i += 1) {
var cmd = path.commands[i];
const blueCircles = [];
const redCircles = [];
const path = this.path;
for (let i = 0; i < path.commands.length; i += 1) {
const cmd = path.commands[i];
if (cmd.x !== undefined) {

@@ -343,3 +340,3 @@ blueCircles.push({x: cmd.x, y: -cmd.y});

Glyph.prototype.drawMetrics = function(ctx, x, y, fontSize) {
var scale;
let scale;
x = x !== undefined ? x : 0;

@@ -358,7 +355,7 @@ y = y !== undefined ? y : 0;

// defaults in the constructor, we save a notable amount of memory.
var xMin = this.xMin || 0;
var yMin = this.yMin || 0;
var xMax = this.xMax || 0;
var yMax = this.yMax || 0;
var advanceWidth = this.advanceWidth || 0;
const xMin = this.xMin || 0;
let yMin = this.yMin || 0;
const xMax = this.xMax || 0;
let yMax = this.yMax || 0;
const advanceWidth = this.advanceWidth || 0;

@@ -377,2 +374,2 @@ // Draw the glyph box

exports.Glyph = Glyph;
export default Glyph;
// The GlyphSet object
'use strict';
import Glyph from './glyph';
var _glyph = require('./glyph');
// Define a property on the glyph that depends on the path being loaded.

@@ -36,3 +34,3 @@ function defineDependentProperty(glyph, externalName, internalName) {

if (Array.isArray(glyphs)) {
for (var i = 0; i < glyphs.length; i++) {
for (let i = 0; i < glyphs.length; i++) {
this.glyphs[i] = glyphs[i];

@@ -73,3 +71,3 @@ }

function glyphLoader(font, index) {
return new _glyph.Glyph({index: index, font: font});
return new Glyph({index: index, font: font});
}

@@ -92,7 +90,7 @@

return function() {
var glyph = new _glyph.Glyph({index: index, font: font});
const glyph = new Glyph({index: index, font: font});
glyph.path = function() {
parseGlyph(glyph, data, position);
var path = buildPath(font.glyphs, glyph);
const path = buildPath(font.glyphs, glyph);
path.unitsPerEm = font.unitsPerEm;

@@ -120,6 +118,6 @@ return path;

return function() {
var glyph = new _glyph.Glyph({index: index, font: font});
const glyph = new Glyph({index: index, font: font});
glyph.path = function() {
var path = parseCFFCharstring(font, glyph, charstring);
const path = parseCFFCharstring(font, glyph, charstring);
path.unitsPerEm = font.unitsPerEm;

@@ -133,5 +131,2 @@ return path;

exports.GlyphSet = GlyphSet;
exports.glyphLoader = glyphLoader;
exports.ttfGlyphLoader = ttfGlyphLoader;
exports.cffGlyphLoader = cffGlyphLoader;
export default { GlyphSet, glyphLoader, ttfGlyphLoader, cffGlyphLoader };

@@ -1,15 +0,13 @@

// The Layout object is the prototype of Substition objects, and provides utility methods to manipulate
// common layout tables (GPOS, GSUB, GDEF...)
// The Layout object is the prototype of Substitution objects, and provides
// utility methods to manipulate common layout tables (GPOS, GSUB, GDEF...)
'use strict';
import check from './check';
var check = require('./check');
function searchTag(arr, tag) {
/* jshint bitwise: false */
var imin = 0;
var imax = arr.length - 1;
let imin = 0;
let imax = arr.length - 1;
while (imin <= imax) {
var imid = (imin + imax) >>> 1;
var val = arr[imid].tag;
const imid = (imin + imax) >>> 1;
const val = arr[imid].tag;
if (val === tag) {

@@ -27,7 +25,7 @@ return imid;

/* jshint bitwise: false */
var imin = 0;
var imax = arr.length - 1;
let imin = 0;
let imax = arr.length - 1;
while (imin <= imax) {
var imid = (imin + imax) >>> 1;
var val = arr[imid];
const imid = (imin + imax) >>> 1;
const val = arr[imid];
if (val === value) {

@@ -82,3 +80,3 @@ return imid;

getTable: function(create) {
var layout = this.font.tables[this.tableName];
let layout = this.font.tables[this.tableName];
if (!layout && create) {

@@ -96,3 +94,3 @@ layout = this.font.tables[this.tableName] = this.createDefaultTable();

getScriptNames: function() {
var layout = this.getTable();
let layout = this.getTable();
if (!layout) { return []; }

@@ -111,7 +109,7 @@ return layout.scripts.map(function(script) {

getDefaultScriptName: function() {
var layout = this.getTable();
let layout = this.getTable();
if (!layout) { return; }
var hasLatn = false;
for (var i = 0; i < layout.scripts.length; i++) {
var name = layout.scripts[i].tag;
let hasLatn = false;
for (let i = 0; i < layout.scripts.length; i++) {
const name = layout.scripts[i].tag;
if (name === 'DFLT') return name;

@@ -131,14 +129,14 @@ if (name === 'latn') hasLatn = true;

getScriptTable: function(script, create) {
var layout = this.getTable(create);
const layout = this.getTable(create);
if (layout) {
script = script || 'DFLT';
var scripts = layout.scripts;
var pos = searchTag(layout.scripts, script);
const scripts = layout.scripts;
const pos = searchTag(layout.scripts, script);
if (pos >= 0) {
return scripts[pos].script;
} else if (create) {
var scr = {
const scr = {
tag: script,
script: {
defaultLangSys: { reserved: 0, reqFeatureIndex: 0xffff, featureIndexes: [] },
defaultLangSys: {reserved: 0, reqFeatureIndex: 0xffff, featureIndexes: []},
langSysRecords: []

@@ -162,3 +160,3 @@ }

getLangSysTable: function(script, language, create) {
var scriptTable = this.getScriptTable(script, create);
const scriptTable = this.getScriptTable(script, create);
if (scriptTable) {

@@ -168,9 +166,9 @@ if (!language || language === 'dflt' || language === 'DFLT') {

}
var pos = searchTag(scriptTable.langSysRecords, language);
const pos = searchTag(scriptTable.langSysRecords, language);
if (pos >= 0) {
return scriptTable.langSysRecords[pos].langSys;
} else if (create) {
var langSysRecord = {
const langSysRecord = {
tag: language,
langSys: { reserved: 0, reqFeatureIndex: 0xffff, featureIndexes: [] }
langSys: {reserved: 0, reqFeatureIndex: 0xffff, featureIndexes: []}
};

@@ -193,10 +191,10 @@ scriptTable.langSysRecords.splice(-1 - pos, 0, langSysRecord);

getFeatureTable: function(script, language, feature, create) {
var langSysTable = this.getLangSysTable(script, language, create);
const langSysTable = this.getLangSysTable(script, language, create);
if (langSysTable) {
var featureRecord;
var featIndexes = langSysTable.featureIndexes;
var allFeatures = this.font.tables[this.tableName].features;
let featureRecord;
const featIndexes = langSysTable.featureIndexes;
const allFeatures = this.font.tables[this.tableName].features;
// The FeatureIndex array of indices is in arbitrary order,
// even if allFeatures is sorted alphabetically by feature tag.
for (var i = 0; i < featIndexes.length; i++) {
for (let i = 0; i < featIndexes.length; i++) {
featureRecord = allFeatures[featIndexes[i]];

@@ -208,3 +206,3 @@ if (featureRecord.tag === feature) {

if (create) {
var index = allFeatures.length;
const index = allFeatures.length;
// Automatic ordering of features would require to shift feature indexes in the script list.

@@ -234,10 +232,10 @@ check.assert(index === 0 || feature >= allFeatures[index - 1].tag, 'Features must be added in alphabetical order.');

getLookupTables: function(script, language, feature, lookupType, create) {
var featureTable = this.getFeatureTable(script, language, feature, create);
var tables = [];
const featureTable = this.getFeatureTable(script, language, feature, create);
const tables = [];
if (featureTable) {
var lookupTable;
var lookupListIndexes = featureTable.lookupListIndexes;
var allLookups = this.font.tables[this.tableName].lookups;
// lookupListIndexes are in no particular order, so use naïve search.
for (var i = 0; i < lookupListIndexes.length; i++) {
let lookupTable;
const lookupListIndexes = featureTable.lookupListIndexes;
const allLookups = this.font.tables[this.tableName].lookups;
// lookupListIndexes are in no particular order, so use naive search.
for (let i = 0; i < lookupListIndexes.length; i++) {
lookupTable = allLookups[lookupListIndexes[i]];

@@ -255,3 +253,3 @@ if (lookupTable.lookupType === lookupType) {

};
var index = allLookups.length;
const index = allLookups.length;
allLookups.push(lookupTable);

@@ -277,9 +275,9 @@ lookupListIndexes.push(index);

} else {
var glyphs = [];
var ranges = coverageTable.ranges;
for (var i = 0; i < ranges.length; i++) {
var range = ranges[i];
var start = range.start;
var end = range.end;
for (var j = start; j <= end; j++) {
const glyphs = [];
const ranges = coverageTable.ranges;
for (let i = 0; i < ranges.length; i++) {
const range = ranges[i];
const start = range.start;
const end = range.end;
for (let j = start; j <= end; j++) {
glyphs.push(j);

@@ -294,2 +292,2 @@ }

module.exports = Layout;
export default Layout;

@@ -8,32 +8,28 @@ // opentype.js

'use strict';
import inflate from 'tiny-inflate';
import Font from './font';
import Glyph from './glyph';
import { CmapEncoding, GlyphNames, addGlyphNames } from './encoding';
import parse from './parse';
import BoundingBox from './bbox';
import Path from './path';
import { nodeBufferToArrayBuffer } from './util';
import cmap from './tables/cmap';
import cff from './tables/cff';
import fvar from './tables/fvar';
import glyf from './tables/glyf';
import gpos from './tables/gpos';
import gsub from './tables/gsub';
import head from './tables/head';
import hhea from './tables/hhea';
import hmtx from './tables/hmtx';
import kern from './tables/kern';
import ltag from './tables/ltag';
import loca from './tables/loca';
import maxp from './tables/maxp';
import _name from './tables/name';
import os2 from './tables/os2';
import post from './tables/post';
import meta from './tables/meta';
var inflate = require('tiny-inflate');
var encoding = require('./encoding');
var _font = require('./font');
var glyph = require('./glyph');
var parse = require('./parse');
var bbox = require('./bbox');
var path = require('./path');
var util = require('./util');
var cmap = require('./tables/cmap');
var cff = require('./tables/cff');
var fvar = require('./tables/fvar');
var glyf = require('./tables/glyf');
var gpos = require('./tables/gpos');
var gsub = require('./tables/gsub');
var head = require('./tables/head');
var hhea = require('./tables/hhea');
var hmtx = require('./tables/hmtx');
var kern = require('./tables/kern');
var ltag = require('./tables/ltag');
var loca = require('./tables/loca');
var maxp = require('./tables/maxp');
var _name = require('./tables/name');
var os2 = require('./tables/os2');
var post = require('./tables/post');
var meta = require('./tables/meta');
/**

@@ -52,3 +48,3 @@ * The opentype library.

function loadFromFile(path, callback) {
var fs = require('fs');
const fs = require('fs');
fs.readFile(path, function(err, buffer) {

@@ -59,3 +55,3 @@ if (err) {

callback(null, util.nodeBufferToArrayBuffer(buffer));
callback(null, nodeBufferToArrayBuffer(buffer));
});

@@ -70,3 +66,3 @@ }

function loadFromUrl(url, callback) {
var request = new XMLHttpRequest();
const request = new XMLHttpRequest();
request.open('get', url, true);

@@ -97,9 +93,9 @@ request.responseType = 'arraybuffer';

function parseOpenTypeTableEntries(data, numTables) {
var tableEntries = [];
var p = 12;
for (var i = 0; i < numTables; i += 1) {
var tag = parse.getTag(data, p);
var checksum = parse.getULong(data, p + 4);
var offset = parse.getULong(data, p + 8);
var length = parse.getULong(data, p + 12);
const tableEntries = [];
let p = 12;
for (let i = 0; i < numTables; i += 1) {
const tag = parse.getTag(data, p);
const checksum = parse.getULong(data, p + 4);
const offset = parse.getULong(data, p + 8);
const length = parse.getULong(data, p + 12);
tableEntries.push({tag: tag, checksum: checksum, offset: offset, length: length, compression: false});

@@ -119,10 +115,10 @@ p += 16;

function parseWOFFTableEntries(data, numTables) {
var tableEntries = [];
var p = 44; // offset to the first table directory entry.
for (var i = 0; i < numTables; i += 1) {
var tag = parse.getTag(data, p);
var offset = parse.getULong(data, p + 4);
var compLength = parse.getULong(data, p + 8);
var origLength = parse.getULong(data, p + 12);
var compression;
const tableEntries = [];
let p = 44; // offset to the first table directory entry.
for (let i = 0; i < numTables; i += 1) {
const tag = parse.getTag(data, p);
const offset = parse.getULong(data, p + 4);
const compLength = parse.getULong(data, p + 8);
const origLength = parse.getULong(data, p + 12);
let compression;
if (compLength < origLength) {

@@ -135,3 +131,3 @@ compression = 'WOFF';

tableEntries.push({tag: tag, offset: offset, compression: compression,
compressedLength: compLength, originalLength: origLength});
compressedLength: compLength, length: origLength});
p += 20;

@@ -157,10 +153,10 @@ }

if (tableEntry.compression === 'WOFF') {
var inBuffer = new Uint8Array(data.buffer, tableEntry.offset + 2, tableEntry.compressedLength - 2);
var outBuffer = new Uint8Array(tableEntry.originalLength);
const inBuffer = new Uint8Array(data.buffer, tableEntry.offset + 2, tableEntry.compressedLength - 2);
const outBuffer = new Uint8Array(tableEntry.length);
inflate(inBuffer, outBuffer);
if (outBuffer.byteLength !== tableEntry.originalLength) {
if (outBuffer.byteLength !== tableEntry.length) {
throw new Error('Decompression error: ' + tableEntry.tag + ' decompressed length doesn\'t match recorded length');
}
var view = new DataView(outBuffer.buffer, 0);
const view = new DataView(outBuffer.buffer, 0);
return {data: view, offset: 0};

@@ -181,8 +177,8 @@ } else {

function parseBuffer(buffer) {
var indexToLocFormat;
var ltagTable;
let indexToLocFormat;
let ltagTable;
// Since the constructor can also be called to create new fonts from scratch, we indicate this
// should be an empty font that we'll fill with our own data.
var font = new _font.Font({empty: true});
const font = new Font({empty: true});

@@ -192,6 +188,6 @@ // OpenType fonts use big endian byte ordering.

// Instead we use DataViews where we can specify endianness.
var data = new DataView(buffer, 0);
var numTables;
var tableEntries = [];
var signature = parse.getTag(data, 0);
const data = new DataView(buffer, 0);
let numTables;
let tableEntries = [];
const signature = parse.getTag(data, 0);
if (signature === String.fromCharCode(0, 1, 0, 0) || signature === 'true' || signature === 'typ1') {

@@ -206,3 +202,3 @@ font.outlinesFormat = 'truetype';

} else if (signature === 'wOFF') {
var flavor = parse.getTag(data, 4);
const flavor = parse.getTag(data, 4);
if (flavor === String.fromCharCode(0, 1, 0, 0)) {

@@ -222,17 +218,17 @@ font.outlinesFormat = 'truetype';

var cffTableEntry;
var fvarTableEntry;
var glyfTableEntry;
var gposTableEntry;
var gsubTableEntry;
var hmtxTableEntry;
var kernTableEntry;
var locaTableEntry;
var nameTableEntry;
var metaTableEntry;
var p;
let cffTableEntry;
let fvarTableEntry;
let glyfTableEntry;
let gposTableEntry;
let gsubTableEntry;
let hmtxTableEntry;
let kernTableEntry;
let locaTableEntry;
let nameTableEntry;
let metaTableEntry;
let p;
for (var i = 0; i < numTables; i += 1) {
var tableEntry = tableEntries[i];
var table;
for (let i = 0; i < numTables; i += 1) {
const tableEntry = tableEntries[i];
let table;
switch (tableEntry.tag) {

@@ -242,3 +238,3 @@ case 'cmap':

font.tables.cmap = cmap.parse(table.data, table.offset);
font.encoding = new encoding.CmapEncoding(font.tables.cmap);
font.encoding = new CmapEncoding(font.tables.cmap);
break;

@@ -293,3 +289,3 @@ case 'cvt ' :

font.tables.post = post.parse(table.data, table.offset);
font.glyphNames = new encoding.GlyphNames(font.tables.post);
font.glyphNames = new GlyphNames(font.tables.post);
break;

@@ -325,3 +321,3 @@ case 'prep' :

var nameTable = uncompressTable(data, nameTableEntry);
const nameTable = uncompressTable(data, nameTableEntry);
font.tables.name = _name.parse(nameTable.data, nameTable.offset, ltagTable);

@@ -331,9 +327,9 @@ font.names = font.tables.name;

if (glyfTableEntry && locaTableEntry) {
var shortVersion = indexToLocFormat === 0;
var locaTable = uncompressTable(data, locaTableEntry);
var locaOffsets = loca.parse(locaTable.data, locaTable.offset, font.numGlyphs, shortVersion);
var glyfTable = uncompressTable(data, glyfTableEntry);
const shortVersion = indexToLocFormat === 0;
const locaTable = uncompressTable(data, locaTableEntry);
const locaOffsets = loca.parse(locaTable.data, locaTable.offset, font.numGlyphs, shortVersion);
const glyfTable = uncompressTable(data, glyfTableEntry);
font.glyphs = glyf.parse(glyfTable.data, glyfTable.offset, locaOffsets, font);
} else if (cffTableEntry) {
var cffTable = uncompressTable(data, cffTableEntry);
const cffTable = uncompressTable(data, cffTableEntry);
cff.parse(cffTable.data, cffTable.offset, font);

@@ -344,8 +340,8 @@ } else {

var hmtxTable = uncompressTable(data, hmtxTableEntry);
const hmtxTable = uncompressTable(data, hmtxTableEntry);
hmtx.parse(hmtxTable.data, hmtxTable.offset, font.numberOfHMetrics, font.numGlyphs, font.glyphs);
encoding.addGlyphNames(font);
addGlyphNames(font);
if (kernTableEntry) {
var kernTable = uncompressTable(data, kernTableEntry);
const kernTable = uncompressTable(data, kernTableEntry);
font.kerningPairs = kern.parse(kernTable.data, kernTable.offset);

@@ -357,3 +353,3 @@ } else {

if (gposTableEntry) {
var gposTable = uncompressTable(data, gposTableEntry);
const gposTable = uncompressTable(data, gposTableEntry);
gpos.parse(gposTable.data, gposTable.offset, font);

@@ -363,3 +359,3 @@ }

if (gsubTableEntry) {
var gsubTable = uncompressTable(data, gsubTableEntry);
const gsubTable = uncompressTable(data, gsubTableEntry);
font.tables.gsub = gsub.parse(gsubTable.data, gsubTable.offset);

@@ -369,3 +365,3 @@ }

if (fvarTableEntry) {
var fvarTable = uncompressTable(data, fvarTableEntry);
const fvarTable = uncompressTable(data, fvarTableEntry);
font.tables.fvar = fvar.parse(fvarTable.data, fvarTable.offset, font.names);

@@ -375,3 +371,3 @@ }

if (metaTableEntry) {
var metaTable = uncompressTable(data, metaTableEntry);
const metaTable = uncompressTable(data, metaTableEntry);
font.tables.meta = meta.parse(metaTable.data, metaTable.offset);

@@ -395,4 +391,4 @@ font.metas = font.tables.meta;

function load(url, callback) {
var isNode = typeof window === 'undefined';
var loadFn = isNode ? loadFromFile : loadFromUrl;
const isNode = typeof window === 'undefined';
const loadFn = isNode ? loadFromFile : loadFromUrl;
loadFn(url, function(err, arrayBuffer) {

@@ -402,3 +398,3 @@ if (err) {

}
var font;
let font;
try {

@@ -421,14 +417,16 @@ font = parseBuffer(arrayBuffer);

function loadSync(url) {
var fs = require('fs');
var buffer = fs.readFileSync(url);
return parseBuffer(util.nodeBufferToArrayBuffer(buffer));
const fs = require('fs');
const buffer = fs.readFileSync(url);
return parseBuffer(nodeBufferToArrayBuffer(buffer));
}
exports._parse = parse;
exports.Font = _font.Font;
exports.Glyph = glyph.Glyph;
exports.Path = path.Path;
exports.BoundingBox = bbox.BoundingBox;
exports.parse = parseBuffer;
exports.load = load;
exports.loadSync = loadSync;
export {
Font,
Glyph,
Path,
BoundingBox,
parse as _parse,
parseBuffer as parse,
load,
loadSync
};
// Parsing utility functions
'use strict';
import check from './check';
var check = require('./check');
// Retrieve an unsigned byte from the DataView.
exports.getByte = function getByte(dataView, offset) {
function getByte(dataView, offset) {
return dataView.getUint8(offset);
};
}
exports.getCard8 = exports.getByte;
// Retrieve an unsigned 16-bit short from the DataView.

@@ -20,29 +16,27 @@ // The value is stored in big endian.

exports.getUShort = exports.getCard16 = getUShort;
// Retrieve a signed 16-bit short from the DataView.
// The value is stored in big endian.
exports.getShort = function(dataView, offset) {
function getShort(dataView, offset) {
return dataView.getInt16(offset, false);
};
}
// Retrieve an unsigned 32-bit long from the DataView.
// The value is stored in big endian.
exports.getULong = function(dataView, offset) {
function getULong(dataView, offset) {
return dataView.getUint32(offset, false);
};
}
// Retrieve a 32-bit signed fixed-point number (16.16) from the DataView.
// The value is stored in big endian.
exports.getFixed = function(dataView, offset) {
var decimal = dataView.getInt16(offset, false);
var fraction = dataView.getUint16(offset + 2, false);
function getFixed(dataView, offset) {
const decimal = dataView.getInt16(offset, false);
const fraction = dataView.getUint16(offset + 2, false);
return decimal + fraction / 65535;
};
}
// Retrieve a 4-character tag from the DataView.
// Tags are used to identify tables.
exports.getTag = function(dataView, offset) {
var tag = '';
for (var i = offset; i < offset + 4; i += 1) {
function getTag(dataView, offset) {
let tag = '';
for (let i = offset; i < offset + 4; i += 1) {
tag += String.fromCharCode(dataView.getInt8(i));

@@ -52,9 +46,9 @@ }

return tag;
};
}
// Retrieve an offset from the DataView.
// Offsets are 1 to 4 bytes in length, depending on the offSize argument.
exports.getOffset = function(dataView, offset, offSize) {
var v = 0;
for (var i = 0; i < offSize; i += 1) {
function getOffset(dataView, offset, offSize) {
let v = 0;
for (let i = 0; i < offSize; i += 1) {
v <<= 8;

@@ -65,8 +59,8 @@ v += dataView.getUint8(offset + i);

return v;
};
}
// Retrieve a number of bytes from start offset to the end offset from the DataView.
exports.getBytes = function(dataView, startOffset, endOffset) {
var bytes = [];
for (var i = startOffset; i < endOffset; i += 1) {
function getBytes(dataView, startOffset, endOffset) {
const bytes = [];
for (let i = startOffset; i < endOffset; i += 1) {
bytes.push(dataView.getUint8(i));

@@ -76,8 +70,8 @@ }

return bytes;
};
}
// Convert the list of bytes to a string.
exports.bytesToString = function(bytes) {
var s = '';
for (var i = 0; i < bytes.length; i += 1) {
function bytesToString(bytes) {
let s = '';
for (let i = 0; i < bytes.length; i += 1) {
s += String.fromCharCode(bytes[i]);

@@ -87,5 +81,5 @@ }

return s;
};
}
var typeOffsets = {
const typeOffsets = {
byte: 1,

@@ -109,3 +103,3 @@ uShort: 2,

Parser.prototype.parseByte = function() {
var v = this.data.getUint8(this.offset + this.relativeOffset);
const v = this.data.getUint8(this.offset + this.relativeOffset);
this.relativeOffset += 1;

@@ -116,3 +110,3 @@ return v;

Parser.prototype.parseChar = function() {
var v = this.data.getInt8(this.offset + this.relativeOffset);
const v = this.data.getInt8(this.offset + this.relativeOffset);
this.relativeOffset += 1;

@@ -125,3 +119,3 @@ return v;

Parser.prototype.parseUShort = function() {
var v = this.data.getUint16(this.offset + this.relativeOffset);
const v = this.data.getUint16(this.offset + this.relativeOffset);
this.relativeOffset += 2;

@@ -136,3 +130,3 @@ return v;

Parser.prototype.parseShort = function() {
var v = this.data.getInt16(this.offset + this.relativeOffset);
const v = this.data.getInt16(this.offset + this.relativeOffset);
this.relativeOffset += 2;

@@ -143,3 +137,3 @@ return v;

Parser.prototype.parseF2Dot14 = function() {
var v = this.data.getInt16(this.offset + this.relativeOffset) / 16384;
const v = this.data.getInt16(this.offset + this.relativeOffset) / 16384;
this.relativeOffset += 2;

@@ -150,3 +144,3 @@ return v;

Parser.prototype.parseULong = function() {
var v = exports.getULong(this.data, this.offset + this.relativeOffset);
const v = getULong(this.data, this.offset + this.relativeOffset);
this.relativeOffset += 4;

@@ -157,3 +151,3 @@ return v;

Parser.prototype.parseFixed = function() {
var v = exports.getFixed(this.data, this.offset + this.relativeOffset);
const v = getFixed(this.data, this.offset + this.relativeOffset);
this.relativeOffset += 4;

@@ -164,7 +158,7 @@ return v;

Parser.prototype.parseString = function(length) {
var dataView = this.data;
var offset = this.offset + this.relativeOffset;
var string = '';
const dataView = this.data;
const offset = this.offset + this.relativeOffset;
let string = '';
this.relativeOffset += length;
for (var i = 0; i < length; i++) {
for (let i = 0; i < length; i++) {
string += String.fromCharCode(dataView.getUint8(offset + i));

@@ -185,5 +179,5 @@ }

Parser.prototype.parseLongDateTime = function() {
var v = exports.getULong(this.data, this.offset + this.relativeOffset + 4);
let v = getULong(this.data, this.offset + this.relativeOffset + 4);
// Subtract seconds between 01/01/1904 and 01/01/1970
// to convert Apple Mac timstamp to Standard Unix timestamp
// to convert Apple Mac timestamp to Standard Unix timestamp
v -= 2082844800;

@@ -195,7 +189,7 @@ this.relativeOffset += 8;

Parser.prototype.parseVersion = function() {
var major = getUShort(this.data, this.offset + this.relativeOffset);
const major = getUShort(this.data, this.offset + this.relativeOffset);
// How to interpret the minor version is very vague in the spec. 0x5000 is 5, 0x1000 is 1
// This returns the correct number if minor = 0xN000 where N is 0-9
var minor = getUShort(this.data, this.offset + this.relativeOffset + 2);
const minor = getUShort(this.data, this.offset + this.relativeOffset + 2);
this.relativeOffset += 4;

@@ -220,6 +214,6 @@ return major + minor / 0x1000 / 10;

if (count === undefined) { count = this.parseUShort(); }
var offsets = new Array(count);
var dataView = this.data;
var offset = this.offset + this.relativeOffset;
for (var i = 0; i < count; i++) {
const offsets = new Array(count);
const dataView = this.data;
let offset = this.offset + this.relativeOffset;
for (let i = 0; i < count; i++) {
offsets[i] = dataView.getUint16(offset);

@@ -235,6 +229,6 @@ offset += 2;

Parser.prototype.parseShortList = function(count) {
var list = new Array(count);
var dataView = this.data;
var offset = this.offset + this.relativeOffset;
for (var i = 0; i < count; i++) {
const list = new Array(count);
const dataView = this.data;
let offset = this.offset + this.relativeOffset;
for (let i = 0; i < count; i++) {
list[i] = dataView.getInt16(offset);

@@ -250,6 +244,6 @@ offset += 2;

Parser.prototype.parseByteList = function(count) {
var list = new Array(count);
var dataView = this.data;
var offset = this.offset + this.relativeOffset;
for (var i = 0; i < count; i++) {
const list = new Array(count);
const dataView = this.data;
let offset = this.offset + this.relativeOffset;
for (let i = 0; i < count; i++) {
list[i] = dataView.getUint8(offset++);

@@ -272,4 +266,4 @@ }

}
var list = new Array(count);
for (var i = 0; i < count; i++) {
const list = new Array(count);
for (let i = 0; i < count; i++) {
list[i] = itemCallback.call(this);

@@ -291,9 +285,9 @@ }

}
var records = new Array(count);
var fields = Object.keys(recordDescription);
for (var i = 0; i < count; i++) {
var rec = {};
for (var j = 0; j < fields.length; j++) {
var fieldName = fields[j];
var fieldType = recordDescription[fieldName];
const records = new Array(count);
const fields = Object.keys(recordDescription);
for (let i = 0; i < count; i++) {
const rec = {};
for (let j = 0; j < fields.length; j++) {
const fieldName = fields[j];
const fieldType = recordDescription[fieldName];
rec[fieldName] = fieldType.call(this);

@@ -312,7 +306,7 @@ }

} else {
var fields = Object.keys(description);
var struct = {};
for (var j = 0; j < fields.length; j++) {
var fieldName = fields[j];
var fieldType = description[fieldName];
const fields = Object.keys(description);
const struct = {};
for (let j = 0; j < fields.length; j++) {
const fieldName = fields[j];
const fieldType = description[fieldName];
struct[fieldName] = fieldType.call(this);

@@ -325,6 +319,7 @@ }

Parser.prototype.parsePointer = function(description) {
var structOffset = this.parseOffset16();
if (structOffset > 0) { // NULL offset => return indefined
const structOffset = this.parseOffset16();
if (structOffset > 0) { // NULL offset => return undefined
return new Parser(this.data, this.offset + structOffset).parseStruct(description);
}
return undefined;
};

@@ -340,8 +335,8 @@

Parser.prototype.parseListOfLists = function(itemCallback) {
var offsets = this.parseOffset16List();
var count = offsets.length;
var relativeOffset = this.relativeOffset;
var list = new Array(count);
for (var i = 0; i < count; i++) {
var start = offsets[i];
const offsets = this.parseOffset16List();
const count = offsets.length;
const relativeOffset = this.relativeOffset;
const list = new Array(count);
for (let i = 0; i < count; i++) {
const start = offsets[i];
if (start === 0) { // NULL offset

@@ -353,5 +348,5 @@ list[i] = undefined; // Add i as owned property to list. Convenient with assert.

if (itemCallback) {
var subOffsets = this.parseOffset16List();
var subList = new Array(subOffsets.length);
for (var j = 0; j < subOffsets.length; j++) {
const subOffsets = this.parseOffset16List();
const subList = new Array(subOffsets.length);
for (let j = 0; j < subOffsets.length; j++) {
this.relativeOffset = start + subOffsets[j];

@@ -375,5 +370,5 @@ subList[j] = itemCallback.call(this);

Parser.prototype.parseCoverage = function() {
var startOffset = this.offset + this.relativeOffset;
var format = this.parseUShort();
var count = this.parseUShort();
const startOffset = this.offset + this.relativeOffset;
const format = this.parseUShort();
const count = this.parseUShort();
if (format === 1) {

@@ -385,4 +380,4 @@ return {

} else if (format === 2) {
var ranges = new Array(count);
for (var i = 0; i < count; i++) {
const ranges = new Array(count);
for (let i = 0; i < count; i++) {
ranges[i] = {

@@ -399,3 +394,3 @@ start: this.parseUShort(),

}
check.assert(false, '0x' + startOffset.toString(16) + ': Coverage format must be 1 or 2.');
throw new Error('0x' + startOffset.toString(16) + ': Coverage format must be 1 or 2.');
};

@@ -406,4 +401,4 @@

Parser.prototype.parseClassDef = function() {
var startOffset = this.offset + this.relativeOffset;
var format = this.parseUShort();
const startOffset = this.offset + this.relativeOffset;
const format = this.parseUShort();
if (format === 1) {

@@ -425,3 +420,3 @@ return {

}
check.assert(false, '0x' + startOffset.toString(16) + ': ClassDef format must be 1 or 2.');
throw new Error('0x' + startOffset.toString(16) + ': ClassDef format must be 1 or 2.');
};

@@ -461,3 +456,3 @@

var langSysTable = {
const langSysTable = {
reserved: Parser.uShort,

@@ -493,6 +488,6 @@ reqFeatureIndex: Parser.uShort,

return this.parsePointer(Parser.list(Parser.pointer(function() {
var lookupType = this.parseUShort();
const lookupType = this.parseUShort();
check.argument(1 <= lookupType && lookupType <= 8, 'GSUB lookup type ' + lookupType + ' unknown.');
var lookupFlag = this.parseUShort();
var useMarkFilteringSet = lookupFlag & 0x10;
const lookupFlag = this.parseUShort();
const useMarkFilteringSet = lookupFlag & 0x10;
return {

@@ -507,2 +502,17 @@ lookupType: lookupType,

exports.Parser = Parser;
export default {
getByte,
getCard8: getByte,
getUShort,
getCard16: getUShort,
getShort,
getULong,
getFixed,
getTag,
getOffset,
getBytes,
bytesToString,
Parser,
};
export { Parser };
// Geometric objects
'use strict';
import BoundingBox from './bbox';
var bbox = require('./bbox');
/**

@@ -138,4 +136,4 @@ * A bézier path containing a set of path commands similar to a SVG path.

pathOrCommands = pathOrCommands.commands;
} else if (pathOrCommands instanceof bbox.BoundingBox) {
var box = pathOrCommands;
} else if (pathOrCommands instanceof BoundingBox) {
const box = pathOrCommands;
this.moveTo(box.x1, box.y1);

@@ -157,10 +155,10 @@ this.lineTo(box.x2, box.y1);

Path.prototype.getBoundingBox = function() {
var box = new bbox.BoundingBox();
const box = new BoundingBox();
var startX = 0;
var startY = 0;
var prevX = 0;
var prevY = 0;
for (var i = 0; i < this.commands.length; i++) {
var cmd = this.commands[i];
let startX = 0;
let startY = 0;
let prevX = 0;
let prevY = 0;
for (let i = 0; i < this.commands.length; i++) {
const cmd = this.commands[i];
switch (cmd.type) {

@@ -192,3 +190,3 @@ case 'M':

default:
throw new Error('Unexpected path commmand ' + cmd.type);
throw new Error('Unexpected path command ' + cmd.type);
}

@@ -208,4 +206,4 @@ }

ctx.beginPath();
for (var i = 0; i < this.commands.length; i += 1) {
var cmd = this.commands[i];
for (let i = 0; i < this.commands.length; i += 1) {
const cmd = this.commands[i];
if (cmd.type === 'M') {

@@ -254,5 +252,5 @@ ctx.moveTo(cmd.x, cmd.y);

function packValues() {
var s = '';
for (var i = 0; i < arguments.length; i += 1) {
var v = arguments[i];
let s = '';
for (let i = 0; i < arguments.length; i += 1) {
const v = arguments[i];
if (v >= 0 && i > 0) {

@@ -268,5 +266,5 @@ s += ' ';

var d = '';
for (var i = 0; i < this.commands.length; i += 1) {
var cmd = this.commands[i];
let d = '';
for (let i = 0; i < this.commands.length; i += 1) {
const cmd = this.commands[i];
if (cmd.type === 'M') {

@@ -294,3 +292,3 @@ d += 'M' + packValues(cmd.x, cmd.y);

Path.prototype.toSVG = function(decimalPlaces) {
var svg = '<path d="';
let svg = '<path d="';
svg += this.toPathData(decimalPlaces);

@@ -320,4 +318,4 @@ svg += '"';

Path.prototype.toDOMElement = function(decimalPlaces) {
var temporaryPath = this.toPathData(decimalPlaces);
var newPath = document.createElementNS('http://www.w3.org/2000/svg', 'path');
const temporaryPath = this.toPathData(decimalPlaces);
const newPath = document.createElementNS('http://www.w3.org/2000/svg', 'path');

@@ -329,2 +327,2 @@ newPath.setAttribute('d', temporaryPath);

exports.Path = Path;
export default Path;
// The Substitution object provides utility methods to manipulate
// the GSUB substitution table.
'use strict';
import check from './check';
import Layout from './layout';
var check = require('./check');
var Layout = require('./layout');
/**

@@ -16,11 +14,11 @@ * @exports opentype.Substitution

*/
var Substitution = function(font) {
function Substitution(font) {
Layout.call(this, font, 'gsub');
};
}
// Check if 2 arrays of primitives are equal.
function arraysEqual(ar1, ar2) {
var n = ar1.length;
const n = ar1.length;
if (n !== ar2.length) { return false; }
for (var i = 0; i < n; i++) {
for (let i = 0; i < n; i++) {
if (ar1[i] !== ar2[i]) { return false; }

@@ -33,5 +31,5 @@ }

function getSubstFormat(lookupTable, format, defaultSubtable) {
var subtables = lookupTable.subtables;
for (var i = 0; i < subtables.length; i++) {
var subtable = subtables[i];
const subtables = lookupTable.subtables;
for (let i = 0; i < subtables.length; i++) {
const subtable = subtables[i];
if (subtable.substFormat === format) {

@@ -45,2 +43,3 @@ return subtable;

}
return undefined;
}

@@ -78,18 +77,18 @@

Substitution.prototype.getSingle = function(feature, script, language) {
var substitutions = [];
var lookupTables = this.getLookupTables(script, language, feature, 1);
for (var idx = 0; idx < lookupTables.length; idx++) {
var subtables = lookupTables[idx].subtables;
for (var i = 0; i < subtables.length; i++) {
var subtable = subtables[i];
var glyphs = this.expandCoverage(subtable.coverage);
var j;
const substitutions = [];
const lookupTables = this.getLookupTables(script, language, feature, 1);
for (let idx = 0; idx < lookupTables.length; idx++) {
const subtables = lookupTables[idx].subtables;
for (let i = 0; i < subtables.length; i++) {
const subtable = subtables[i];
const glyphs = this.expandCoverage(subtable.coverage);
let j;
if (subtable.substFormat === 1) {
var delta = subtable.deltaGlyphId;
const delta = subtable.deltaGlyphId;
for (j = 0; j < glyphs.length; j++) {
var glyph = glyphs[j];
const glyph = glyphs[j];
substitutions.push({ sub: glyph, by: glyph + delta });
}
} else {
var substitute = subtable.substitute;
const substitute = subtable.substitute;
for (j = 0; j < glyphs.length; j++) {

@@ -112,11 +111,11 @@ substitutions.push({ sub: glyphs[j], by: substitute[j] });

Substitution.prototype.getAlternates = function(feature, script, language) {
var alternates = [];
var lookupTables = this.getLookupTables(script, language, feature, 3);
for (var idx = 0; idx < lookupTables.length; idx++) {
var subtables = lookupTables[idx].subtables;
for (var i = 0; i < subtables.length; i++) {
var subtable = subtables[i];
var glyphs = this.expandCoverage(subtable.coverage);
var alternateSets = subtable.alternateSets;
for (var j = 0; j < glyphs.length; j++) {
const alternates = [];
const lookupTables = this.getLookupTables(script, language, feature, 3);
for (let idx = 0; idx < lookupTables.length; idx++) {
const subtables = lookupTables[idx].subtables;
for (let i = 0; i < subtables.length; i++) {
const subtable = subtables[i];
const glyphs = this.expandCoverage(subtable.coverage);
const alternateSets = subtable.alternateSets;
for (let j = 0; j < glyphs.length; j++) {
alternates.push({ sub: glyphs[j], by: alternateSets[j] });

@@ -138,15 +137,15 @@ }

Substitution.prototype.getLigatures = function(feature, script, language) {
var ligatures = [];
var lookupTables = this.getLookupTables(script, language, feature, 4);
for (var idx = 0; idx < lookupTables.length; idx++) {
var subtables = lookupTables[idx].subtables;
for (var i = 0; i < subtables.length; i++) {
var subtable = subtables[i];
var glyphs = this.expandCoverage(subtable.coverage);
var ligatureSets = subtable.ligatureSets;
for (var j = 0; j < glyphs.length; j++) {
var startGlyph = glyphs[j];
var ligSet = ligatureSets[j];
for (var k = 0; k < ligSet.length; k++) {
var lig = ligSet[k];
const ligatures = [];
const lookupTables = this.getLookupTables(script, language, feature, 4);
for (let idx = 0; idx < lookupTables.length; idx++) {
const subtables = lookupTables[idx].subtables;
for (let i = 0; i < subtables.length; i++) {
const subtable = subtables[i];
const glyphs = this.expandCoverage(subtable.coverage);
const ligatureSets = subtable.ligatureSets;
for (let j = 0; j < glyphs.length; j++) {
const startGlyph = glyphs[j];
const ligSet = ligatureSets[j];
for (let k = 0; k < ligSet.length; k++) {
const lig = ligSet[k];
ligatures.push({

@@ -172,11 +171,11 @@ sub: [startGlyph].concat(lig.components),

Substitution.prototype.addSingle = function(feature, substitution, script, language) {
var lookupTable = this.getLookupTables(script, language, feature, 1, true)[0];
var subtable = getSubstFormat(lookupTable, 2, { // lookup type 1 subtable, format 2, coverage format 1
const lookupTable = this.getLookupTables(script, language, feature, 1, true)[0];
const subtable = getSubstFormat(lookupTable, 2, { // lookup type 1 subtable, format 2, coverage format 1
substFormat: 2,
coverage: { format: 1, glyphs: [] },
coverage: {format: 1, glyphs: []},
substitute: []
});
check.assert(subtable.coverage.format === 1, 'Ligature: unable to modify coverage table format ' + subtable.coverage.format);
var coverageGlyph = substitution.sub;
var pos = this.binSearch(subtable.coverage.glyphs, coverageGlyph);
const coverageGlyph = substitution.sub;
let pos = this.binSearch(subtable.coverage.glyphs, coverageGlyph);
if (pos < 0) {

@@ -198,11 +197,11 @@ pos = -1 - pos;

Substitution.prototype.addAlternate = function(feature, substitution, script, language) {
var lookupTable = this.getLookupTables(script, language, feature, 3, true)[0];
var subtable = getSubstFormat(lookupTable, 1, { // lookup type 3 subtable, format 1, coverage format 1
const lookupTable = this.getLookupTables(script, language, feature, 3, true)[0];
const subtable = getSubstFormat(lookupTable, 1, { // lookup type 3 subtable, format 1, coverage format 1
substFormat: 1,
coverage: { format: 1, glyphs: [] },
coverage: {format: 1, glyphs: []},
alternateSets: []
});
check.assert(subtable.coverage.format === 1, 'Ligature: unable to modify coverage table format ' + subtable.coverage.format);
var coverageGlyph = substitution.sub;
var pos = this.binSearch(subtable.coverage.glyphs, coverageGlyph);
const coverageGlyph = substitution.sub;
let pos = this.binSearch(subtable.coverage.glyphs, coverageGlyph);
if (pos < 0) {

@@ -225,4 +224,4 @@ pos = -1 - pos;

Substitution.prototype.addLigature = function(feature, ligature, script, language) {
var lookupTable = this.getLookupTables(script, language, feature, 4, true)[0];
var subtable = lookupTable.subtables[0];
const lookupTable = this.getLookupTables(script, language, feature, 4, true)[0];
let subtable = lookupTable.subtables[0];
if (!subtable) {

@@ -237,13 +236,13 @@ subtable = { // lookup type 4 subtable, format 1, coverage format 1

check.assert(subtable.coverage.format === 1, 'Ligature: unable to modify coverage table format ' + subtable.coverage.format);
var coverageGlyph = ligature.sub[0];
var ligComponents = ligature.sub.slice(1);
var ligatureTable = {
const coverageGlyph = ligature.sub[0];
const ligComponents = ligature.sub.slice(1);
const ligatureTable = {
ligGlyph: ligature.by,
components: ligComponents
};
var pos = this.binSearch(subtable.coverage.glyphs, coverageGlyph);
let pos = this.binSearch(subtable.coverage.glyphs, coverageGlyph);
if (pos >= 0) {
// ligatureSet already exists
var ligatureSet = subtable.ligatureSets[pos];
for (var i = 0; i < ligatureSet.length; i++) {
const ligatureSet = subtable.ligatureSets[pos];
for (let i = 0; i < ligatureSet.length; i++) {
// If ligature already exists, return.

@@ -284,2 +283,3 @@ if (arraysEqual(ligatureSet[i].components, ligComponents)) {

}
return undefined;
};

@@ -310,4 +310,5 @@

}
return undefined;
};
module.exports = Substitution;
export default Substitution;
// Table metadata
'use strict';
import check from './check';
import { encode, sizeOf } from './types';
var check = require('./check');
var encode = require('./types').encode;
var sizeOf = require('./types').sizeOf;
/**

@@ -17,5 +15,4 @@ * @exports opentype.Table

function Table(tableName, fields, options) {
var i;
for (i = 0; i < fields.length; i += 1) {
var field = fields[i];
for (let i = 0; i < fields.length; i += 1) {
const field = fields[i];
this[field.name] = field.value;

@@ -27,6 +24,6 @@ }

if (options) {
var optionKeys = Object.keys(options);
for (i = 0; i < optionKeys.length; i += 1) {
var k = optionKeys[i];
var v = options[k];
const optionKeys = Object.keys(options);
for (let i = 0; i < optionKeys.length; i += 1) {
const k = optionKeys[i];
const v = options[k];
if (this[k] !== undefined) {

@@ -62,5 +59,5 @@ this[k] = v;

}
var fields = new Array(list.length + 1);
const fields = new Array(list.length + 1);
fields[0] = {name: itemName + 'Count', type: 'USHORT', value: count};
for (var i = 0; i < list.length; i++) {
for (let i = 0; i < list.length; i++) {
fields[i + 1] = {name: itemName + i, type: 'USHORT', value: list[i]};

@@ -75,6 +72,6 @@ }

function tableList(itemName, records, itemCallback) {
var count = records.length;
var fields = new Array(count + 1);
const count = records.length;
const fields = new Array(count + 1);
fields[0] = {name: itemName + 'Count', type: 'USHORT', value: count};
for (var i = 0; i < count; i++) {
for (let i = 0; i < count; i++) {
fields[i + 1] = {name: itemName + i, type: 'TABLE', value: itemCallback(records[i], i)};

@@ -89,6 +86,6 @@ }

function recordList(itemName, records, itemCallback) {
var count = records.length;
var fields = [];
const count = records.length;
let fields = [];
fields[0] = {name: itemName + 'Count', type: 'USHORT', value: count};
for (var i = 0; i < count; i++) {
for (let i = 0; i < count; i++) {
fields = fields.concat(itemCallback(records[i], i));

@@ -124,4 +121,4 @@ }

recordList('scriptRecord', scriptListTable, function(scriptRecord, i) {
var script = scriptRecord.script;
var defaultLangSys = script.defaultLangSys;
const script = scriptRecord.script;
let defaultLangSys = script.defaultLangSys;
check.assert(!!defaultLangSys, 'Unable to write GSUB: script ' + scriptRecord.tag + ' has no default language system.');

@@ -136,3 +133,3 @@ return [

].concat(recordList('langSys', script.langSysRecords, function(langSysRecord, i) {
var langSys = langSysRecord.langSys;
const langSys = langSysRecord.langSys;
return [

@@ -163,3 +160,3 @@ {name: 'langSysTag' + i, type: 'TAG', value: langSysRecord.tag},

recordList('featureRecord', featureListTable, function(featureRecord, i) {
var feature = featureRecord.feature;
const feature = featureRecord.feature;
return [

@@ -187,3 +184,3 @@ {name: 'featureTag' + i, type: 'TAG', value: featureRecord.tag},

Table.call(this, 'lookupListTable', tableList('lookup', lookupListTable, function(lookupTable) {
var subtableCallback = subtableMakers[lookupTable.lookupType];
let subtableCallback = subtableMakers[lookupTable.lookupType];
check.assert(!!subtableCallback, 'Unable to write GSUB lookup type ' + lookupTable.lookupType + ' tables.');

@@ -201,10 +198,12 @@ return new Table('lookupTable', [

// Don't use offsets inside Records (probable bug), only in Tables.
exports.Record = exports.Table = Table;
exports.Coverage = Coverage;
exports.ScriptList = ScriptList;
exports.FeatureList = FeatureList;
exports.LookupList = LookupList;
exports.ushortList = ushortList;
exports.tableList = tableList;
exports.recordList = recordList;
export default {
Table,
Record: Table,
Coverage,
ScriptList,
FeatureList,
LookupList,
ushortList,
tableList,
recordList,
};

@@ -6,10 +6,8 @@ // The `CFF` table contains the glyph outlines in PostScript format.

'use strict';
import { CffEncoding, cffStandardEncoding, cffExpertEncoding, cffStandardStrings } from '../encoding';
import glyphset from '../glyphset';
import parse from '../parse';
import Path from '../path';
import table from '../table';
var encoding = require('../encoding');
var glyphset = require('../glyphset');
var parse = require('../parse');
var path = require('../path');
var table = require('../table');
// Custom equals function that can also check lists.

@@ -24,3 +22,3 @@ function equals(a, b) {

for (var i = 0; i < a.length; i += 1) {
for (let i = 0; i < a.length; i += 1) {
if (!equals(a[i], b[i])) {

@@ -40,3 +38,3 @@ return false;

function calcCFFSubroutineBias(subrs) {
var bias;
let bias;
if (subrs.length < 1240) {

@@ -56,14 +54,12 @@ bias = 107;

function parseCFFIndex(data, start, conversionFn) {
//var i, objectOffset, endOffset;
var offsets = [];
var objects = [];
var count = parse.getCard16(data, start);
var i;
var objectOffset;
var endOffset;
const offsets = [];
const objects = [];
const count = parse.getCard16(data, start);
let objectOffset;
let endOffset;
if (count !== 0) {
var offsetSize = parse.getByte(data, start + 2);
const offsetSize = parse.getByte(data, start + 2);
objectOffset = start + ((count + 1) * offsetSize) + 2;
var pos = start + 3;
for (i = 0; i < count + 1; i += 1) {
let pos = start + 3;
for (let i = 0; i < count + 1; i += 1) {
offsets.push(parse.getOffset(data, pos, offsetSize));

@@ -79,4 +75,4 @@ pos += offsetSize;

for (i = 0; i < offsets.length - 1; i += 1) {
var value = parse.getBytes(data, objectOffset + offsets[i], objectOffset + offsets[i + 1]);
for (let i = 0; i < offsets.length - 1; i += 1) {
let value = parse.getBytes(data, objectOffset + offsets[i], objectOffset + offsets[i + 1]);
if (conversionFn) {

@@ -94,9 +90,9 @@ value = conversionFn(value);

function parseFloatOperand(parser) {
var s = '';
var eof = 15;
var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', 'E', 'E-', null, '-'];
let s = '';
const eof = 15;
const lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', 'E', 'E-', null, '-'];
while (true) {
var b = parser.parseByte();
var n1 = b >> 4;
var n2 = b & 15;
const b = parser.parseByte();
const n1 = b >> 4;
const n2 = b & 15;

@@ -121,6 +117,6 @@ if (n1 === eof) {

function parseOperand(parser, b0) {
var b1;
var b2;
var b3;
var b4;
let b1;
let b2;
let b3;
let b4;
if (b0 === 28) {

@@ -164,7 +160,7 @@ b1 = parser.parseByte();

function entriesToObject(entries) {
var o = {};
for (var i = 0; i < entries.length; i += 1) {
var key = entries[i][0];
var values = entries[i][1];
var value;
const o = {};
for (let i = 0; i < entries.length; i += 1) {
const key = entries[i][0];
const values = entries[i][1];
let value;
if (values.length === 1) {

@@ -190,9 +186,9 @@ value = values[0];

start = start !== undefined ? start : 0;
var parser = new parse.Parser(data, start);
var entries = [];
var operands = [];
const parser = new parse.Parser(data, start);
const entries = [];
let operands = [];
size = size !== undefined ? size : data.length;
while (parser.relativeOffset < size) {
var op = parser.parseByte();
let op = parser.parseByte();

@@ -223,3 +219,3 @@ // The first byte for each dict item distinguishes between operator (key) and operand (value).

if (index <= 390) {
index = encoding.cffStandardStrings[index];
index = cffStandardStrings[index];
} else {

@@ -235,14 +231,14 @@ index = strings[index - 391];

function interpretDict(dict, meta, strings) {
var newDict = {};
var value;
const newDict = {};
let value;
// Because we also want to include missing values, we start out from the meta list
// and lookup values in the dict.
for (var i = 0; i < meta.length; i += 1) {
var m = meta[i];
for (let i = 0; i < meta.length; i += 1) {
const m = meta[i];
if (Array.isArray(m.type)) {
var values = [];
const values = [];
values.length = m.type.length;
for (var j = 0; j < m.type.length; j++) {
for (let j = 0; j < m.type.length; j++) {
value = dict[m.op] !== undefined ? dict[m.op][j] : undefined;

@@ -276,3 +272,3 @@ if (value === undefined) {

function parseCFFHeader(data, start) {
var header = {};
const header = {};
header.formatMajor = parse.getCard8(data, start);

@@ -287,3 +283,3 @@ header.formatMinor = parse.getCard8(data, start + 1);

var TOP_DICT_META = [
const TOP_DICT_META = [
{name: 'version', op: 0, type: 'SID'},

@@ -301,3 +297,8 @@ {name: 'notice', op: 1, type: 'SID'},

{name: 'charstringType', op: 1206, type: 'number', value: 2},
{name: 'fontMatrix', op: 1207, type: ['real', 'real', 'real', 'real', 'real', 'real'], value: [0.001, 0, 0, 0.001, 0, 0]},
{
name: 'fontMatrix',
op: 1207,
type: ['real', 'real', 'real', 'real', 'real', 'real'],
value: [0.001, 0, 0, 0.001, 0, 0]
},
{name: 'uniqueId', op: 13, type: 'number'},

@@ -322,3 +323,3 @@ {name: 'fontBBox', op: 5, type: ['number', 'number', 'number', 'number'], value: [0, 0, 0, 0]},

var PRIVATE_DICT_META = [
const PRIVATE_DICT_META = [
{name: 'subrs', op: 19, type: 'offset', value: 0},

@@ -332,3 +333,3 @@ {name: 'defaultWidthX', op: 20, type: 'number', value: 0},

function parseCFFTopDict(data, strings) {
var dict = parseCFFDict(data, 0, data.byteLength);
const dict = parseCFFDict(data, 0, data.byteLength);
return interpretDict(dict, TOP_DICT_META, strings);

@@ -339,3 +340,3 @@ }

function parseCFFPrivateDict(data, start, size, strings) {
var dict = parseCFFDict(data, start, size);
const dict = parseCFFDict(data, start, size);
return interpretDict(dict, PRIVATE_DICT_META, strings);

@@ -360,17 +361,17 @@ }

function gatherCFFTopDicts(data, start, cffIndex, strings) {
var topDictArray = [];
for (var iTopDict = 0; iTopDict < cffIndex.length; iTopDict += 1) {
var topDictData = new DataView(new Uint8Array(cffIndex[iTopDict]).buffer);
var topDict = parseCFFTopDict(topDictData, strings);
const topDictArray = [];
for (let iTopDict = 0; iTopDict < cffIndex.length; iTopDict += 1) {
const topDictData = new DataView(new Uint8Array(cffIndex[iTopDict]).buffer);
const topDict = parseCFFTopDict(topDictData, strings);
topDict._subrs = [];
topDict._subrsBias = 0;
var privateSize = topDict.private[0];
var privateOffset = topDict.private[1];
const privateSize = topDict.private[0];
const privateOffset = topDict.private[1];
if (privateSize !== 0 && privateOffset !== 0) {
var privateDict = parseCFFPrivateDict(data, privateOffset + start, privateSize, strings);
const privateDict = parseCFFPrivateDict(data, privateOffset + start, privateSize, strings);
topDict._defaultWidthX = privateDict.defaultWidthX;
topDict._nominalWidthX = privateDict.nominalWidthX;
if (privateDict.subrs !== 0) {
var subrOffset = privateOffset + privateDict.subrs;
var subrIndex = parseCFFIndex(data, subrOffset + start);
const subrOffset = privateOffset + privateDict.subrs;
const subrIndex = parseCFFIndex(data, subrOffset + start);
topDict._subrs = subrIndex.objects;

@@ -390,14 +391,13 @@ topDict._subrsBias = calcCFFSubroutineBias(topDict._subrs);

function parseCFFCharset(data, start, nGlyphs, strings) {
var i;
var sid;
var count;
var parser = new parse.Parser(data, start);
let sid;
let count;
const parser = new parse.Parser(data, start);
// The .notdef glyph is not included, so subtract 1.
nGlyphs -= 1;
var charset = ['.notdef'];
const charset = ['.notdef'];
var format = parser.parseCard8();
const format = parser.parseCard8();
if (format === 0) {
for (i = 0; i < nGlyphs; i += 1) {
for (let i = 0; i < nGlyphs; i += 1) {
sid = parser.parseSID();

@@ -410,3 +410,3 @@ charset.push(getCFFString(strings, sid));

count = parser.parseCard8();
for (i = 0; i <= count; i += 1) {
for (let i = 0; i <= count; i += 1) {
charset.push(getCFFString(strings, sid));

@@ -420,3 +420,3 @@ sid += 1;

count = parser.parseCard16();
for (i = 0; i <= count; i += 1) {
for (let i = 0; i <= count; i += 1) {
charset.push(getCFFString(strings, sid));

@@ -436,10 +436,9 @@ sid += 1;

function parseCFFEncoding(data, start, charset) {
var i;
var code;
var enc = {};
var parser = new parse.Parser(data, start);
var format = parser.parseCard8();
let code;
const enc = {};
const parser = new parse.Parser(data, start);
const format = parser.parseCard8();
if (format === 0) {
var nCodes = parser.parseCard8();
for (i = 0; i < nCodes; i += 1) {
const nCodes = parser.parseCard8();
for (let i = 0; i < nCodes; i += 1) {
code = parser.parseCard8();

@@ -449,8 +448,8 @@ enc[code] = i;

} else if (format === 1) {
var nRanges = parser.parseCard8();
const nRanges = parser.parseCard8();
code = 1;
for (i = 0; i < nRanges; i += 1) {
var first = parser.parseCard8();
var nLeft = parser.parseCard8();
for (var j = first; j <= first + nLeft; j += 1) {
for (let i = 0; i < nRanges; i += 1) {
const first = parser.parseCard8();
const nLeft = parser.parseCard8();
for (let j = first; j <= first + nLeft; j += 1) {
enc[j] = code;

@@ -464,3 +463,3 @@ code += 1;

return new encoding.CffEncoding(enc, charset);
return new CffEncoding(enc, charset);
}

@@ -472,20 +471,20 @@

function parseCFFCharstring(font, glyph, code) {
var c1x;
var c1y;
var c2x;
var c2y;
var p = new path.Path();
var stack = [];
var nStems = 0;
var haveWidth = false;
var open = false;
var x = 0;
var y = 0;
var subrs;
var subrsBias;
var defaultWidthX;
var nominalWidthX;
let c1x;
let c1y;
let c2x;
let c2y;
const p = new Path();
const stack = [];
let nStems = 0;
let haveWidth = false;
let open = false;
let x = 0;
let y = 0;
let subrs;
let subrsBias;
let defaultWidthX;
let nominalWidthX;
if (font.isCIDFont) {
var fdIndex = font.tables.cff.topDict._fdSelect[glyph.index];
var fdDict = font.tables.cff.topDict._fdArray[fdIndex];
const fdIndex = font.tables.cff.topDict._fdSelect[glyph.index];
const fdDict = font.tables.cff.topDict._fdArray[fdIndex];
subrs = fdDict._subrs;

@@ -501,3 +500,3 @@ subrsBias = fdDict._subrsBias;

}
var width = defaultWidthX;
let width = defaultWidthX;

@@ -514,3 +513,3 @@ function newContour(x, y) {

function parseStems() {
var hasWidthArg;
let hasWidthArg;

@@ -530,18 +529,18 @@ // The number of stem operators on the stack is always even.

function parse(code) {
var b1;
var b2;
var b3;
var b4;
var codeIndex;
var subrCode;
var jpx;
var jpy;
var c3x;
var c3y;
var c4x;
var c4y;
let b1;
let b2;
let b3;
let b4;
let codeIndex;
let subrCode;
let jpx;
let jpy;
let c3x;
let c3y;
let c4x;
let c4y;
var i = 0;
let i = 0;
while (i < code.length) {
var v = code[i];
let v = code[i];
i += 1;

@@ -896,9 +895,9 @@ switch (v) {

function parseCFFFDSelect(data, start, nGlyphs, fdArrayCount) {
var fdSelect = [];
var fdIndex;
var parser = new parse.Parser(data, start);
var format = parser.parseCard8();
const fdSelect = [];
let fdIndex;
const parser = new parse.Parser(data, start);
const format = parser.parseCard8();
if (format === 0) {
// Simple list of nGlyphs elements
for (var iGid = 0; iGid < nGlyphs; iGid++) {
for (let iGid = 0; iGid < nGlyphs; iGid++) {
fdIndex = parser.parseCard8();

@@ -912,9 +911,9 @@ if (fdIndex >= fdArrayCount) {

// Ranges
var nRanges = parser.parseCard16();
var first = parser.parseCard16();
const nRanges = parser.parseCard16();
let first = parser.parseCard16();
if (first !== 0) {
throw new Error('CFF Table CID Font FDSelect format 3 range has bad initial GID ' + first);
}
var next;
for (var iRange = 0; iRange < nRanges; iRange++) {
let next;
for (let iRange = 0; iRange < nRanges; iRange++) {
fdIndex = parser.parseCard8();

@@ -945,16 +944,16 @@ next = parser.parseCard16();

font.tables.cff = {};
var header = parseCFFHeader(data, start);
var nameIndex = parseCFFIndex(data, header.endOffset, parse.bytesToString);
var topDictIndex = parseCFFIndex(data, nameIndex.endOffset);
var stringIndex = parseCFFIndex(data, topDictIndex.endOffset, parse.bytesToString);
var globalSubrIndex = parseCFFIndex(data, stringIndex.endOffset);
const header = parseCFFHeader(data, start);
const nameIndex = parseCFFIndex(data, header.endOffset, parse.bytesToString);
const topDictIndex = parseCFFIndex(data, nameIndex.endOffset);
const stringIndex = parseCFFIndex(data, topDictIndex.endOffset, parse.bytesToString);
const globalSubrIndex = parseCFFIndex(data, stringIndex.endOffset);
font.gsubrs = globalSubrIndex.objects;
font.gsubrsBias = calcCFFSubroutineBias(font.gsubrs);
var topDictArray = gatherCFFTopDicts(data, start, topDictIndex.objects, stringIndex.objects);
const topDictArray = gatherCFFTopDicts(data, start, topDictIndex.objects, stringIndex.objects);
if (topDictArray.length !== 1) {
throw new Error('CFF table has too many fonts in \'FontSet\' - ' + 'count of fonts NameIndex.length = ' + topDictArray.length);
throw new Error('CFF table has too many fonts in \'FontSet\' - count of fonts NameIndex.length = ' + topDictArray.length);
}
var topDict = topDictArray[0];
const topDict = topDictArray[0];
font.tables.cff.topDict = topDict;

@@ -972,4 +971,4 @@

if (font.isCIDFont) {
var fdArrayOffset = topDict.fdArray;
var fdSelectOffset = topDict.fdSelect;
let fdArrayOffset = topDict.fdArray;
let fdSelectOffset = topDict.fdSelect;
if (fdArrayOffset === 0 || fdSelectOffset === 0) {

@@ -979,4 +978,4 @@ throw new Error('Font is marked as a CID font, but FDArray and/or FDSelect information is missing');

fdArrayOffset += start;
var fdArrayIndex = parseCFFIndex(data, fdArrayOffset);
var fdArray = gatherCFFTopDicts(data, start, fdArrayIndex.objects, stringIndex.objects);
const fdArrayIndex = parseCFFIndex(data, fdArrayOffset);
const fdArray = gatherCFFTopDicts(data, start, fdArrayIndex.objects, stringIndex.objects);
topDict._fdArray = fdArray;

@@ -987,4 +986,4 @@ fdSelectOffset += start;

var privateDictOffset = start + topDict['private'][1];
var privateDict = parseCFFPrivateDict(data, privateDictOffset, topDict['private'][0], stringIndex.objects);
const privateDictOffset = start + topDict.private[1];
const privateDict = parseCFFPrivateDict(data, privateDictOffset, topDict.private[0], stringIndex.objects);
font.defaultWidthX = privateDict.defaultWidthX;

@@ -994,4 +993,4 @@ font.nominalWidthX = privateDict.nominalWidthX;

if (privateDict.subrs !== 0) {
var subrOffset = privateDictOffset + privateDict.subrs;
var subrIndex = parseCFFIndex(data, subrOffset);
const subrOffset = privateDictOffset + privateDict.subrs;
const subrIndex = parseCFFIndex(data, subrOffset);
font.subrs = subrIndex.objects;

@@ -1005,10 +1004,10 @@ font.subrsBias = calcCFFSubroutineBias(font.subrs);

// Offsets in the top dict are relative to the beginning of the CFF data, so add the CFF start offset.
var charStringsIndex = parseCFFIndex(data, start + topDict.charStrings);
const charStringsIndex = parseCFFIndex(data, start + topDict.charStrings);
font.nGlyphs = charStringsIndex.objects.length;
var charset = parseCFFCharset(data, start + topDict.charset, font.nGlyphs, stringIndex.objects);
const charset = parseCFFCharset(data, start + topDict.charset, font.nGlyphs, stringIndex.objects);
if (topDict.encoding === 0) { // Standard encoding
font.cffEncoding = new encoding.CffEncoding(encoding.cffStandardEncoding, charset);
font.cffEncoding = new CffEncoding(cffStandardEncoding, charset);
} else if (topDict.encoding === 1) { // Expert encoding
font.cffEncoding = new encoding.CffEncoding(encoding.cffExpertEncoding, charset);
font.cffEncoding = new CffEncoding(cffExpertEncoding, charset);
} else {

@@ -1022,4 +1021,4 @@ font.cffEncoding = parseCFFEncoding(data, start + topDict.encoding, charset);

font.glyphs = new glyphset.GlyphSet(font);
for (var i = 0; i < font.nGlyphs; i += 1) {
var charString = charStringsIndex.objects[i];
for (let i = 0; i < font.nGlyphs; i += 1) {
const charString = charStringsIndex.objects[i];
font.glyphs.push(i, glyphset.cffGlyphLoader(font, i, parseCFFCharstring, charString));

@@ -1032,6 +1031,6 @@ }

function encodeString(s, strings) {
var sid;
let sid;
// Is the string in the CFF standard strings?
var i = encoding.cffStandardStrings.indexOf(s);
let i = cffStandardStrings.indexOf(s);
if (i >= 0) {

@@ -1044,5 +1043,5 @@ sid = i;

if (i >= 0) {
sid = i + encoding.cffStandardStrings.length;
sid = i + cffStandardStrings.length;
} else {
sid = encoding.cffStandardStrings.length + strings.length;
sid = cffStandardStrings.length + strings.length;
strings.push(s);

@@ -1064,7 +1063,7 @@ }

function makeNameIndex(fontNames) {
var t = new table.Record('Name INDEX', [
const t = new table.Record('Name INDEX', [
{name: 'names', type: 'INDEX', value: []}
]);
t.names = [];
for (var i = 0; i < fontNames.length; i += 1) {
for (let i = 0; i < fontNames.length; i += 1) {
t.names.push({name: 'name_' + i, type: 'NAME', value: fontNames[i]});

@@ -1078,6 +1077,6 @@ }

function makeDict(meta, attrs, strings) {
var m = {};
for (var i = 0; i < meta.length; i += 1) {
var entry = meta[i];
var value = attrs[entry.name];
const m = {};
for (let i = 0; i < meta.length; i += 1) {
const entry = meta[i];
let value = attrs[entry.name];
if (value !== undefined && !equals(value, entry.value)) {

@@ -1097,3 +1096,3 @@ if (entry.type === 'SID') {

function makeTopDict(attrs, strings) {
var t = new table.Record('Top DICT', [
const t = new table.Record('Top DICT', [
{name: 'dict', type: 'DICT', value: {}}

@@ -1106,3 +1105,3 @@ ]);

function makeTopDictIndex(topDict) {
var t = new table.Record('Top DICT INDEX', [
const t = new table.Record('Top DICT INDEX', [
{name: 'topDicts', type: 'INDEX', value: []}

@@ -1115,7 +1114,7 @@ ]);

function makeStringIndex(strings) {
var t = new table.Record('String INDEX', [
const t = new table.Record('String INDEX', [
{name: 'strings', type: 'INDEX', value: []}
]);
t.strings = [];
for (var i = 0; i < strings.length; i += 1) {
for (let i = 0; i < strings.length; i += 1) {
t.strings.push({name: 'string_' + i, type: 'STRING', value: strings[i]});

@@ -1135,8 +1134,8 @@ }

function makeCharsets(glyphNames, strings) {
var t = new table.Record('Charsets', [
const t = new table.Record('Charsets', [
{name: 'format', type: 'Card8', value: 0}
]);
for (var i = 0; i < glyphNames.length; i += 1) {
var glyphName = glyphNames[i];
var glyphSID = encodeString(glyphName, strings);
for (let i = 0; i < glyphNames.length; i += 1) {
const glyphName = glyphNames[i];
const glyphSID = encodeString(glyphName, strings);
t.fields.push({name: 'glyph_' + i, type: 'SID', value: glyphSID});

@@ -1149,15 +1148,15 @@ }

function glyphToOps(glyph) {
var ops = [];
var path = glyph.path;
const ops = [];
const path = glyph.path;
ops.push({name: 'width', type: 'NUMBER', value: glyph.advanceWidth});
var x = 0;
var y = 0;
for (var i = 0; i < path.commands.length; i += 1) {
var dx;
var dy;
var cmd = path.commands[i];
let x = 0;
let y = 0;
for (let i = 0; i < path.commands.length; i += 1) {
let dx;
let dy;
let cmd = path.commands[i];
if (cmd.type === 'Q') {
// CFF only supports bézier curves, so convert the quad to a bézier.
var _13 = 1 / 3;
var _23 = 2 / 3;
const _13 = 1 / 3;
const _23 = 2 / 3;

@@ -1193,6 +1192,6 @@ // We're going to create a new command so we don't change the original path.

} else if (cmd.type === 'C') {
var dx1 = Math.round(cmd.x1 - x);
var dy1 = Math.round(cmd.y1 - y);
var dx2 = Math.round(cmd.x2 - cmd.x1);
var dy2 = Math.round(cmd.y2 - cmd.y1);
const dx1 = Math.round(cmd.x1 - x);
const dy1 = Math.round(cmd.y1 - y);
const dx2 = Math.round(cmd.x2 - cmd.x1);
const dy2 = Math.round(cmd.y2 - cmd.y1);
dx = Math.round(cmd.x - cmd.x2);

@@ -1212,3 +1211,2 @@ dy = Math.round(cmd.y - cmd.y2);

// Contours are closed automatically.
}

@@ -1221,9 +1219,9 @@

function makeCharStringsIndex(glyphs) {
var t = new table.Record('CharStrings INDEX', [
const t = new table.Record('CharStrings INDEX', [
{name: 'charStrings', type: 'INDEX', value: []}
]);
for (var i = 0; i < glyphs.length; i += 1) {
var glyph = glyphs.get(i);
var ops = glyphToOps(glyph);
for (let i = 0; i < glyphs.length; i += 1) {
const glyph = glyphs.get(i);
const ops = glyphToOps(glyph);
t.charStrings.push({name: glyph.name, type: 'CHARSTRING', value: ops});

@@ -1236,3 +1234,3 @@ }

function makePrivateDict(attrs, strings) {
var t = new table.Record('Private DICT', [
const t = new table.Record('Private DICT', [
{name: 'dict', type: 'DICT', value: {}}

@@ -1245,3 +1243,3 @@ ]);

function makeCFFTable(glyphs, options) {
var t = new table.Table('CFF ', [
const t = new table.Table('CFF ', [
{name: 'header', type: 'RECORD'},

@@ -1257,7 +1255,7 @@ {name: 'nameIndex', type: 'RECORD'},

var fontScale = 1 / options.unitsPerEm;
const fontScale = 1 / options.unitsPerEm;
// We use non-zero values for the offsets so that the DICT encodes them.
// This is important because the size of the Top DICT plays a role in offset calculation,
// and the size shouldn't change after we've written correct offsets.
var attrs = {
const attrs = {
version: options.version,

@@ -1275,9 +1273,9 @@ fullName: options.fullName,

var privateAttrs = {};
const privateAttrs = {};
var glyphNames = [];
var glyph;
const glyphNames = [];
let glyph;
// Skip first glyph (.notdef)
for (var i = 1; i < glyphs.length; i += 1) {
for (let i = 1; i < glyphs.length; i += 1) {
glyph = glyphs.get(i);

@@ -1287,7 +1285,7 @@ glyphNames.push(glyph.name);

var strings = [];
const strings = [];
t.header = makeHeader();
t.nameIndex = makeNameIndex([options.postScriptName]);
var topDict = makeTopDict(attrs, strings);
let topDict = makeTopDict(attrs, strings);
t.topDictIndex = makeTopDictIndex(topDict);

@@ -1302,3 +1300,3 @@ t.globalSubrIndex = makeGlobalSubrIndex();

var startOffset = t.header.sizeOf() +
const startOffset = t.header.sizeOf() +
t.nameIndex.sizeOf() +

@@ -1322,3 +1320,2 @@ t.topDictIndex.sizeOf() +

exports.parse = parseCFFTable;
exports.make = makeCFFTable;
export default { parse: parseCFFTable, make: makeCFFTable };
// The `cmap` table stores the mappings from characters to glyphs.
// https://www.microsoft.com/typography/OTSPEC/cmap.htm
'use strict';
import check from '../check';
import parse from '../parse';
import table from '../table';
var check = require('../check');
var parse = require('../parse');
var table = require('../table');
function parseCmapTableFormat12(cmap, p) {
var i;
//Skip reserved.

@@ -20,12 +16,12 @@ p.parseUShort();

var groupCount;
let groupCount;
cmap.groupCount = groupCount = p.parseULong();
cmap.glyphIndexMap = {};
for (i = 0; i < groupCount; i += 1) {
var startCharCode = p.parseULong();
var endCharCode = p.parseULong();
var startGlyphId = p.parseULong();
for (let i = 0; i < groupCount; i += 1) {
const startCharCode = p.parseULong();
const endCharCode = p.parseULong();
let startGlyphId = p.parseULong();
for (var c = startCharCode; c <= endCharCode; c += 1) {
for (let c = startCharCode; c <= endCharCode; c += 1) {
cmap.glyphIndexMap[c] = startGlyphId;

@@ -38,4 +34,2 @@ startGlyphId++;

function parseCmapTableFormat4(cmap, p, data, start, offset) {
var i;
// Length in bytes of the sub-tables.

@@ -46,3 +40,3 @@ cmap.length = p.parseUShort();

// segCount is stored x 2.
var segCount;
let segCount;
cmap.segCount = segCount = p.parseUShort() >> 1;

@@ -55,14 +49,14 @@

cmap.glyphIndexMap = {};
var endCountParser = new parse.Parser(data, start + offset + 14);
var startCountParser = new parse.Parser(data, start + offset + 16 + segCount * 2);
var idDeltaParser = new parse.Parser(data, start + offset + 16 + segCount * 4);
var idRangeOffsetParser = new parse.Parser(data, start + offset + 16 + segCount * 6);
var glyphIndexOffset = start + offset + 16 + segCount * 8;
for (i = 0; i < segCount - 1; i += 1) {
var glyphIndex;
var endCount = endCountParser.parseUShort();
var startCount = startCountParser.parseUShort();
var idDelta = idDeltaParser.parseShort();
var idRangeOffset = idRangeOffsetParser.parseUShort();
for (var c = startCount; c <= endCount; c += 1) {
const endCountParser = new parse.Parser(data, start + offset + 14);
const startCountParser = new parse.Parser(data, start + offset + 16 + segCount * 2);
const idDeltaParser = new parse.Parser(data, start + offset + 16 + segCount * 4);
const idRangeOffsetParser = new parse.Parser(data, start + offset + 16 + segCount * 6);
let glyphIndexOffset = start + offset + 16 + segCount * 8;
for (let i = 0; i < segCount - 1; i += 1) {
let glyphIndex;
const endCount = endCountParser.parseUShort();
const startCount = startCountParser.parseUShort();
const idDelta = idDeltaParser.parseShort();
const idRangeOffset = idRangeOffsetParser.parseUShort();
for (let c = startCount; c <= endCount; c += 1) {
if (idRangeOffset !== 0) {

@@ -95,4 +89,3 @@ // The idRangeOffset is relative to the current position in the idRangeOffset array.

function parseCmapTable(data, start) {
var i;
var cmap = {};
const cmap = {};
cmap.version = parse.getUShort(data, start);

@@ -104,6 +97,6 @@ check.argument(cmap.version === 0, 'cmap table version should be 0.');

cmap.numTables = parse.getUShort(data, start + 2);
var offset = -1;
for (i = cmap.numTables - 1; i >= 0; i -= 1) {
var platformId = parse.getUShort(data, start + 4 + (i * 8));
var encodingId = parse.getUShort(data, start + 4 + (i * 8) + 2);
let offset = -1;
for (let i = cmap.numTables - 1; i >= 0; i -= 1) {
const platformId = parse.getUShort(data, start + 4 + (i * 8));
const encodingId = parse.getUShort(data, start + 4 + (i * 8) + 2);
if (platformId === 3 && (encodingId === 0 || encodingId === 1 || encodingId === 10)) {

@@ -120,3 +113,3 @@ offset = parse.getULong(data, start + 4 + (i * 8) + 4);

var p = new parse.Parser(data, start + offset);
const p = new parse.Parser(data, start + offset);
cmap.format = p.parseUShort();

@@ -154,4 +147,3 @@

function makeCmapTable(glyphs) {
var i;
var t = new table.Table('cmap', [
const t = new table.Table('cmap', [
{name: 'version', type: 'USHORT', value: 0},

@@ -172,5 +164,5 @@ {name: 'numTables', type: 'USHORT', value: 1},

t.segments = [];
for (i = 0; i < glyphs.length; i += 1) {
var glyph = glyphs.get(i);
for (var j = 0; j < glyph.unicodes.length; j += 1) {
for (let i = 0; i < glyphs.length; i += 1) {
const glyph = glyphs.get(i);
for (let j = 0; j < glyph.unicodes.length; j += 1) {
addSegment(t, glyph.unicodes[j], i);

@@ -186,3 +178,3 @@ }

var segCount;
let segCount;
segCount = t.segments.length;

@@ -195,10 +187,10 @@ t.segCountX2 = segCount * 2;

// Set up parallel segment arrays.
var endCounts = [];
var startCounts = [];
var idDeltas = [];
var idRangeOffsets = [];
var glyphIds = [];
let endCounts = [];
let startCounts = [];
let idDeltas = [];
let idRangeOffsets = [];
let glyphIds = [];
for (i = 0; i < segCount; i += 1) {
var segment = t.segments[i];
for (let i = 0; i < segCount; i += 1) {
const segment = t.segments[i];
endCounts = endCounts.concat({name: 'end_' + i, type: 'USHORT', value: segment.end});

@@ -231,3 +223,2 @@ startCounts = startCounts.concat({name: 'start_' + i, type: 'USHORT', value: segment.start});

exports.parse = parseCmapTable;
exports.make = makeCmapTable;
export default { parse: parseCmapTable, make: makeCmapTable };
// The `fvar` table stores font variation axes and instances.
// https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6fvar.html
'use strict';
import check from '../check';
import parse from '../parse';
import table from '../table';
var check = require('../check');
var parse = require('../parse');
var table = require('../table');
function addName(name, names) {
var nameString = JSON.stringify(name);
var nameID = 256;
for (var nameKey in names) {
var n = parseInt(nameKey);
const nameString = JSON.stringify(name);
let nameID = 256;
for (let nameKey in names) {
let n = parseInt(nameKey);
if (!n || n < 256) {

@@ -33,3 +31,3 @@ continue;

function makeFvarAxis(n, axis, names) {
var nameID = addName(axis.name, names);
const nameID = addName(axis.name, names);
return [

@@ -46,4 +44,4 @@ {name: 'tag_' + n, type: 'TAG', value: axis.tag},

function parseFvarAxis(data, start, names) {
var axis = {};
var p = new parse.Parser(data, start);
const axis = {};
const p = new parse.Parser(data, start);
axis.tag = p.parseTag();

@@ -59,4 +57,4 @@ axis.minValue = p.parseFixed();

function makeFvarInstance(n, inst, axes, names) {
var nameID = addName(inst.name, names);
var fields = [
const nameID = addName(inst.name, names);
const fields = [
{name: 'nameID_' + n, type: 'USHORT', value: nameID},

@@ -66,4 +64,4 @@ {name: 'flags_' + n, type: 'USHORT', value: 0}

for (var i = 0; i < axes.length; ++i) {
var axisTag = axes[i].tag;
for (let i = 0; i < axes.length; ++i) {
const axisTag = axes[i].tag;
fields.push({

@@ -80,4 +78,4 @@ name: 'axis_' + n + ' ' + axisTag,

function parseFvarInstance(data, start, axes, names) {
var inst = {};
var p = new parse.Parser(data, start);
const inst = {};
const p = new parse.Parser(data, start);
inst.name = names[p.parseUShort()] || {};

@@ -87,3 +85,3 @@ p.skip('uShort', 1); // reserved for flags; no values defined

inst.coordinates = {};
for (var i = 0; i < axes.length; ++i) {
for (let i = 0; i < axes.length; ++i) {
inst.coordinates[axes[i].tag] = p.parseFixed();

@@ -96,3 +94,3 @@ }

function makeFvarTable(fvar, names) {
var result = new table.Table('fvar', [
const result = new table.Table('fvar', [
{name: 'version', type: 'ULONG', value: 0x10000},

@@ -108,7 +106,7 @@ {name: 'offsetToData', type: 'USHORT', value: 0},

for (var i = 0; i < fvar.axes.length; i++) {
for (let i = 0; i < fvar.axes.length; i++) {
result.fields = result.fields.concat(makeFvarAxis(i, fvar.axes[i], names));
}
for (var j = 0; j < fvar.instances.length; j++) {
for (let j = 0; j < fvar.instances.length; j++) {
result.fields = result.fields.concat(makeFvarInstance(j, fvar.instances[j], fvar.axes, names));

@@ -121,21 +119,21 @@ }

function parseFvarTable(data, start, names) {
var p = new parse.Parser(data, start);
var tableVersion = p.parseULong();
const p = new parse.Parser(data, start);
const tableVersion = p.parseULong();
check.argument(tableVersion === 0x00010000, 'Unsupported fvar table version.');
var offsetToData = p.parseOffset16();
const offsetToData = p.parseOffset16();
// Skip countSizePairs.
p.skip('uShort', 1);
var axisCount = p.parseUShort();
var axisSize = p.parseUShort();
var instanceCount = p.parseUShort();
var instanceSize = p.parseUShort();
const axisCount = p.parseUShort();
const axisSize = p.parseUShort();
const instanceCount = p.parseUShort();
const instanceSize = p.parseUShort();
var axes = [];
for (var i = 0; i < axisCount; i++) {
const axes = [];
for (let i = 0; i < axisCount; i++) {
axes.push(parseFvarAxis(data, start + offsetToData + i * axisSize, names));
}
var instances = [];
var instanceStart = start + offsetToData + axisCount * axisSize;
for (var j = 0; j < instanceCount; j++) {
const instances = [];
const instanceStart = start + offsetToData + axisCount * axisSize;
for (let j = 0; j < instanceCount; j++) {
instances.push(parseFvarInstance(data, instanceStart + j * instanceSize, axes, names));

@@ -147,3 +145,2 @@ }

exports.make = makeFvarTable;
exports.parse = parseFvarTable;
export default { make: makeFvarTable, parse: parseFvarTable };
// The `glyf` table describes the glyphs in TrueType outline format.
// http://www.microsoft.com/typography/otspec/glyf.htm
'use strict';
import check from '../check';
import glyphset from '../glyphset';
import parse from '../parse';
import Path from '../path';
var check = require('../check');
var glyphset = require('../glyphset');
var parse = require('../parse');
var path = require('../path');
// Parse the coordinate data for a glyph.
function parseGlyphCoordinate(p, flag, previousValue, shortVectorBitMask, sameBitMask) {
var v;
let v;
if ((flag & shortVectorBitMask) > 0) {

@@ -39,3 +37,3 @@ // The coordinate is 1 byte long.

function parseGlyph(glyph, data, start) {
var p = new parse.Parser(data, start);
const p = new parse.Parser(data, start);
glyph.numberOfContours = p.parseShort();

@@ -46,10 +44,9 @@ glyph._xMin = p.parseShort();

glyph._yMax = p.parseShort();
var flags;
var flag;
var i;
let flags;
let flag;
if (glyph.numberOfContours > 0) {
// This glyph is not a composite.
var endPointIndices = glyph.endPointIndices = [];
for (i = 0; i < glyph.numberOfContours; i += 1) {
const endPointIndices = glyph.endPointIndices = [];
for (let i = 0; i < glyph.numberOfContours; i += 1) {
endPointIndices.push(p.parseUShort());

@@ -60,9 +57,9 @@ }

glyph.instructions = [];
for (i = 0; i < glyph.instructionLength; i += 1) {
for (let i = 0; i < glyph.instructionLength; i += 1) {
glyph.instructions.push(p.parseByte());
}
var numberOfCoordinates = endPointIndices[endPointIndices.length - 1] + 1;
const numberOfCoordinates = endPointIndices[endPointIndices.length - 1] + 1;
flags = [];
for (i = 0; i < numberOfCoordinates; i += 1) {
for (let i = 0; i < numberOfCoordinates; i += 1) {
flag = p.parseByte();

@@ -72,4 +69,4 @@ flags.push(flag);

if ((flag & 8) > 0) {
var repeatCount = p.parseByte();
for (var j = 0; j < repeatCount; j += 1) {
const repeatCount = p.parseByte();
for (let j = 0; j < repeatCount; j += 1) {
flags.push(flag);

@@ -84,7 +81,7 @@ i += 1;

if (endPointIndices.length > 0) {
var points = [];
var point;
const points = [];
let point;
// X/Y coordinates are relative to the previous point, except for the first point which is relative to 0,0.
if (numberOfCoordinates > 0) {
for (i = 0; i < numberOfCoordinates; i += 1) {
for (let i = 0; i < numberOfCoordinates; i += 1) {
flag = flags[i];

@@ -97,4 +94,4 @@ point = {};

var px = 0;
for (i = 0; i < numberOfCoordinates; i += 1) {
let px = 0;
for (let i = 0; i < numberOfCoordinates; i += 1) {
flag = flags[i];

@@ -106,4 +103,4 @@ point = points[i];

var py = 0;
for (i = 0; i < numberOfCoordinates; i += 1) {
let py = 0;
for (let i = 0; i < numberOfCoordinates; i += 1) {
flag = flags[i];

@@ -126,6 +123,6 @@ point = points[i];

glyph.components = [];
var moreComponents = true;
let moreComponents = true;
while (moreComponents) {
flags = p.parseUShort();
var component = {
const component = {
glyphIndex: p.parseUShort(),

@@ -184,3 +181,3 @@ xScale: 1,

glyph.instructions = [];
for (i = 0; i < glyph.instructionLength; i += 1) {
for (let i = 0; i < glyph.instructionLength; i += 1) {
glyph.instructions.push(p.parseByte());

@@ -194,6 +191,6 @@ }

function transformPoints(points, transform) {
var newPoints = [];
for (var i = 0; i < points.length; i += 1) {
var pt = points[i];
var newPt = {
const newPoints = [];
for (let i = 0; i < points.length; i += 1) {
const pt = points[i];
const newPt = {
x: transform.xScale * pt.x + transform.scale01 * pt.y + transform.dx,

@@ -211,6 +208,6 @@ y: transform.scale10 * pt.x + transform.yScale * pt.y + transform.dy,

function getContours(points) {
var contours = [];
var currentContour = [];
for (var i = 0; i < points.length; i += 1) {
var pt = points[i];
const contours = [];
let currentContour = [];
for (let i = 0; i < points.length; i += 1) {
const pt = points[i];
currentContour.push(pt);

@@ -229,3 +226,3 @@ if (pt.lastPointOfContour) {

function getPath(points) {
var p = new path.Path();
const p = new Path();
if (!points) {

@@ -235,10 +232,10 @@ return p;

var contours = getContours(points);
const contours = getContours(points);
for (var contourIndex = 0; contourIndex < contours.length; ++contourIndex) {
var contour = contours[contourIndex];
for (let contourIndex = 0; contourIndex < contours.length; ++contourIndex) {
const contour = contours[contourIndex];
var prev = null;
var curr = contour[contour.length - 1];
var next = contour[0];
let prev = null;
let curr = contour[contour.length - 1];
let next = contour[0];

@@ -252,3 +249,3 @@ if (curr.onCurve) {

// If both first and last points are off-curve, start at their middle.
var start = { x: (curr.x + next.x) * 0.5, y: (curr.y + next.y) * 0.5 };
const start = {x: (curr.x + next.x) * 0.5, y: (curr.y + next.y) * 0.5};
p.moveTo(start.x, start.y);

@@ -258,3 +255,3 @@ }

for (var i = 0; i < contour.length; ++i) {
for (let i = 0; i < contour.length; ++i) {
prev = curr;

@@ -268,4 +265,4 @@ curr = next;

} else {
var prev2 = prev;
var next2 = next;
let prev2 = prev;
let next2 = next;

@@ -285,5 +282,5 @@ if (!prev.onCurve) {

}
p.closePath();
}
p.closePath();
return p;

@@ -294,9 +291,9 @@ }

if (glyph.isComposite) {
for (var j = 0; j < glyph.components.length; j += 1) {
var component = glyph.components[j];
var componentGlyph = glyphs.get(component.glyphIndex);
for (let j = 0; j < glyph.components.length; j += 1) {
const component = glyph.components[j];
const componentGlyph = glyphs.get(component.glyphIndex);
// Force the ttfGlyphLoader to parse the glyph.
componentGlyph.getPath();
if (componentGlyph.points) {
var transformedPoints;
let transformedPoints;
if (component.matchedPoints === undefined) {

@@ -311,5 +308,5 @@ // component positioned by offset

}
var firstPt = glyph.points[component.matchedPoints[0]];
var secondPt = componentGlyph.points[component.matchedPoints[1]];
var transform = {
const firstPt = glyph.points[component.matchedPoints[0]];
let secondPt = componentGlyph.points[component.matchedPoints[1]];
const transform = {
xScale: component.xScale, scale01: component.scale01,

@@ -334,9 +331,8 @@ scale10: component.scale10, yScale: component.yScale,

function parseGlyfTable(data, start, loca, font) {
var glyphs = new glyphset.GlyphSet(font);
var i;
const glyphs = new glyphset.GlyphSet(font);
// The last element of the loca table is invalid.
for (i = 0; i < loca.length - 1; i += 1) {
var offset = loca[i];
var nextOffset = loca[i + 1];
for (let i = 0; i < loca.length - 1; i += 1) {
const offset = loca[i];
const nextOffset = loca[i + 1];
if (offset !== nextOffset) {

@@ -352,4 +348,2 @@ glyphs.push(i, glyphset.ttfGlyphLoader(font, i, parseGlyph, data, start + offset, buildPath));

exports.getPath = getPath;
exports.parse = parseGlyfTable;
export default { getPath, parse: parseGlyfTable };
// The `GPOS` table contains kerning pairs, among other things.
// https://www.microsoft.com/typography/OTSPEC/gpos.htm
'use strict';
import check from '../check';
import parse from '../parse';
var check = require('../check');
var parse = require('../parse');
// Parse ScriptList and FeatureList tables of GPOS, GSUB, GDEF, BASE, JSTF tables.
// These lists are unused by now, this function is just the basis for a real parsing.
function parseTaggedListTable(data, start) {
var p = new parse.Parser(data, start);
var n = p.parseUShort();
var list = [];
for (var i = 0; i < n; i++) {
const p = new parse.Parser(data, start);
const n = p.parseUShort();
const list = [];
for (let i = 0; i < n; i++) {
list[p.parseTag()] = { offset: p.parseUShort() };

@@ -26,14 +24,14 @@ }

function parseCoverageTable(data, start) {
var p = new parse.Parser(data, start);
var format = p.parseUShort();
var count = p.parseUShort();
const p = new parse.Parser(data, start);
const format = p.parseUShort();
let count = p.parseUShort();
if (format === 1) {
return p.parseUShortList(count);
} else if (format === 2) {
var coverage = [];
const coverage = [];
for (; count--;) {
var begin = p.parseUShort();
var end = p.parseUShort();
var index = p.parseUShort();
for (var i = begin; i <= end; i++) {
const begin = p.parseUShort();
const end = p.parseUShort();
let index = p.parseUShort();
for (let i = begin; i <= end; i++) {
coverage[index++] = i;

@@ -50,9 +48,9 @@ }

function parseClassDefTable(data, start) {
var p = new parse.Parser(data, start);
var format = p.parseUShort();
const p = new parse.Parser(data, start);
const format = p.parseUShort();
if (format === 1) {
// Format 1 specifies a range of consecutive glyph indices, one class per glyph ID.
var startGlyph = p.parseUShort();
var glyphCount = p.parseUShort();
var classes = p.parseUShortList(glyphCount);
const startGlyph = p.parseUShort();
const glyphCount = p.parseUShort();
const classes = p.parseUShortList(glyphCount);
return function(glyphID) {

@@ -63,7 +61,7 @@ return classes[glyphID - startGlyph] || 0;

// Format 2 defines multiple groups of glyph indices that belong to the same class.
var rangeCount = p.parseUShort();
var startGlyphs = [];
var endGlyphs = [];
var classValues = [];
for (var i = 0; i < rangeCount; i++) {
const rangeCount = p.parseUShort();
const startGlyphs = [];
const endGlyphs = [];
const classValues = [];
for (let i = 0; i < rangeCount; i++) {
startGlyphs[i] = p.parseUShort();

@@ -75,6 +73,6 @@ endGlyphs[i] = p.parseUShort();

return function(glyphID) {
var l = 0;
var r = startGlyphs.length - 1;
let l = 0;
let r = startGlyphs.length - 1;
while (l < r) {
var c = (l + r + 1) >> 1;
const c = (l + r + 1) >> 1;
if (glyphID < startGlyphs[c]) {

@@ -99,24 +97,24 @@ r = c - 1;

function parsePairPosSubTable(data, start) {
var p = new parse.Parser(data, start);
const p = new parse.Parser(data, start);
// This part is common to format 1 and format 2 subtables
var format = p.parseUShort();
var coverageOffset = p.parseUShort();
var coverage = parseCoverageTable(data, start + coverageOffset);
const format = p.parseUShort();
const coverageOffset = p.parseUShort();
const coverage = parseCoverageTable(data, start + coverageOffset);
// valueFormat 4: XAdvance only, 1: XPlacement only, 0: no ValueRecord for second glyph
// Only valueFormat1=4 and valueFormat2=0 is supported.
var valueFormat1 = p.parseUShort();
var valueFormat2 = p.parseUShort();
var value1;
var value2;
const valueFormat1 = p.parseUShort();
const valueFormat2 = p.parseUShort();
let value1;
let value2;
if (valueFormat1 !== 4 || valueFormat2 !== 0) return;
var sharedPairSets = {};
const sharedPairSets = {};
if (format === 1) {
// Pair Positioning Adjustment: Format 1
var pairSetCount = p.parseUShort();
var pairSet = [];
const pairSetCount = p.parseUShort();
const pairSet = [];
// Array of offsets to PairSet tables-from beginning of PairPos subtable-ordered by Coverage Index
var pairSetOffsets = p.parseOffset16List(pairSetCount);
for (var firstGlyph = 0; firstGlyph < pairSetCount; firstGlyph++) {
var pairSetOffset = pairSetOffsets[firstGlyph];
var sharedPairSet = sharedPairSets[pairSetOffset];
const pairSetOffsets = p.parseOffset16List(pairSetCount);
for (let firstGlyph = 0; firstGlyph < pairSetCount; firstGlyph++) {
const pairSetOffset = pairSetOffsets[firstGlyph];
let sharedPairSet = sharedPairSets[pairSetOffset];
if (!sharedPairSet) {

@@ -126,5 +124,5 @@ // Parse a pairset table in a pair adjustment subtable format 1

p.relativeOffset = pairSetOffset;
var pairValueCount = p.parseUShort();
let pairValueCount = p.parseUShort();
for (; pairValueCount--;) {
var secondGlyph = p.parseUShort();
const secondGlyph = p.parseUShort();
if (valueFormat1) value1 = p.parseShort();

@@ -142,3 +140,3 @@ if (valueFormat2) value2 = p.parseShort();

return function(leftGlyph, rightGlyph) {
var pairs = pairSet[leftGlyph];
const pairs = pairSet[leftGlyph];
if (pairs) return pairs[rightGlyph];

@@ -148,14 +146,14 @@ };

// Pair Positioning Adjustment: Format 2
var classDef1Offset = p.parseUShort();
var classDef2Offset = p.parseUShort();
var class1Count = p.parseUShort();
var class2Count = p.parseUShort();
var getClass1 = parseClassDefTable(data, start + classDef1Offset);
var getClass2 = parseClassDefTable(data, start + classDef2Offset);
const classDef1Offset = p.parseUShort();
const classDef2Offset = p.parseUShort();
const class1Count = p.parseUShort();
const class2Count = p.parseUShort();
const getClass1 = parseClassDefTable(data, start + classDef1Offset);
const getClass2 = parseClassDefTable(data, start + classDef2Offset);
// Parse kerning values by class pair.
var kerningMatrix = [];
for (var i = 0; i < class1Count; i++) {
var kerningRow = kerningMatrix[i] = [];
for (var j = 0; j < class2Count; j++) {
const kerningMatrix = [];
for (let i = 0; i < class1Count; i++) {
const kerningRow = kerningMatrix[i] = [];
for (let j = 0; j < class2Count; j++) {
if (valueFormat1) value1 = p.parseShort();

@@ -170,4 +168,6 @@ if (valueFormat2) value2 = p.parseShort();

// Convert coverage list to a hash
var covered = {};
for (i = 0; i < coverage.length; i++) covered[coverage[i]] = 1;
const covered = {};
for (let i = 0; i < coverage.length; i++) {
covered[coverage[i]] = 1;
}

@@ -177,5 +177,5 @@ // Get the kerning value for a specific glyph pair.

if (!covered[leftGlyph]) return;
var class1 = getClass1(leftGlyph);
var class2 = getClass2(rightGlyph);
var kerningRow = kerningMatrix[class1];
const class1 = getClass1(leftGlyph);
const class2 = getClass2(rightGlyph);
const kerningRow = kerningMatrix[class1];

@@ -191,9 +191,9 @@ if (kerningRow) {

function parseLookupTable(data, start) {
var p = new parse.Parser(data, start);
var lookupType = p.parseUShort();
var lookupFlag = p.parseUShort();
var useMarkFilteringSet = lookupFlag & 0x10;
var subTableCount = p.parseUShort();
var subTableOffsets = p.parseOffset16List(subTableCount);
var table = {
const p = new parse.Parser(data, start);
const lookupType = p.parseUShort();
const lookupFlag = p.parseUShort();
const useMarkFilteringSet = lookupFlag & 0x10;
const subTableCount = p.parseUShort();
const subTableOffsets = p.parseOffset16List(subTableCount);
const table = {
lookupType: lookupType,

@@ -205,5 +205,5 @@ lookupFlag: lookupFlag,

if (lookupType === 2) {
var subtables = [];
for (var i = 0; i < subTableCount; i++) {
var pairPosSubTable = parsePairPosSubTable(data, start + subTableOffsets[i]);
const subtables = [];
for (let i = 0; i < subTableCount; i++) {
const pairPosSubTable = parsePairPosSubTable(data, start + subTableOffsets[i]);
if (pairPosSubTable) subtables.push(pairPosSubTable);

@@ -213,4 +213,4 @@ }

table.getKerningValue = function(leftGlyph, rightGlyph) {
for (var i = subtables.length; i--;) {
var value = subtables[i](leftGlyph, rightGlyph);
for (let i = subtables.length; i--;) {
const value = subtables[i](leftGlyph, rightGlyph);
if (value !== undefined) return value;

@@ -229,4 +229,4 @@ }

function parseGposTable(data, start, font) {
var p = new parse.Parser(data, start);
var tableVersion = p.parseFixed();
const p = new parse.Parser(data, start);
const tableVersion = p.parseFixed();
check.argument(tableVersion === 1, 'Unsupported GPOS table version.');

@@ -240,9 +240,9 @@

// LookupList
var lookupListOffset = p.parseUShort();
const lookupListOffset = p.parseUShort();
p.relativeOffset = lookupListOffset;
var lookupCount = p.parseUShort();
var lookupTableOffsets = p.parseOffset16List(lookupCount);
var lookupListAbsoluteOffset = start + lookupListOffset;
for (var i = 0; i < lookupCount; i++) {
var table = parseLookupTable(data, lookupListAbsoluteOffset + lookupTableOffsets[i]);
const lookupCount = p.parseUShort();
const lookupTableOffsets = p.parseOffset16List(lookupCount);
const lookupListAbsoluteOffset = start + lookupListOffset;
for (let i = 0; i < lookupCount; i++) {
const table = parseLookupTable(data, lookupListAbsoluteOffset + lookupTableOffsets[i]);
if (table.lookupType === 2 && !font.getGposKerningValue) font.getGposKerningValue = table.getKerningValue;

@@ -252,2 +252,2 @@ }

exports.parse = parseGposTable;
export default { parse: parseGposTable };
// The `GSUB` table contains ligatures, among other things.
// https://www.microsoft.com/typography/OTSPEC/gsub.htm
'use strict';
import check from '../check';
import { Parser } from '../parse';
import table from '../table';
var check = require('../check');
var Parser = require('../parse').Parser;
var subtableParsers = new Array(9); // subtableParsers[0] is unused
var table = require('../table');
const subtableParsers = new Array(9); // subtableParsers[0] is unused
// https://www.microsoft.com/typography/OTSPEC/GSUB.htm#SS
subtableParsers[1] = function parseLookup1() {
var start = this.offset + this.relativeOffset;
var substFormat = this.parseUShort();
const start = this.offset + this.relativeOffset;
const substFormat = this.parseUShort();
if (substFormat === 1) {

@@ -33,3 +32,3 @@ return {

subtableParsers[2] = function parseLookup2() {
var substFormat = this.parseUShort();
const substFormat = this.parseUShort();
check.argument(substFormat === 1, 'GSUB Multiple Substitution Subtable identifier-format must be 1');

@@ -45,3 +44,3 @@ return {

subtableParsers[3] = function parseLookup3() {
var substFormat = this.parseUShort();
const substFormat = this.parseUShort();
check.argument(substFormat === 1, 'GSUB Alternate Substitution Subtable identifier-format must be 1');

@@ -57,3 +56,3 @@ return {

subtableParsers[4] = function parseLookup4() {
var substFormat = this.parseUShort();
const substFormat = this.parseUShort();
check.argument(substFormat === 1, 'GSUB ligature table identifier-format must be 1');

@@ -72,3 +71,3 @@ return {

var lookupRecordDesc = {
const lookupRecordDesc = {
sequenceIndex: Parser.uShort,

@@ -80,4 +79,4 @@ lookupListIndex: Parser.uShort

subtableParsers[5] = function parseLookup5() {
var start = this.offset + this.relativeOffset;
var substFormat = this.parseUShort();
const start = this.offset + this.relativeOffset;
const substFormat = this.parseUShort();

@@ -89,4 +88,4 @@ if (substFormat === 1) {

ruleSets: this.parseListOfLists(function() {
var glyphCount = this.parseUShort();
var substCount = this.parseUShort();
const glyphCount = this.parseUShort();
const substCount = this.parseUShort();
return {

@@ -104,4 +103,4 @@ input: this.parseUShortList(glyphCount - 1),

classSets: this.parseListOfLists(function() {
var glyphCount = this.parseUShort();
var substCount = this.parseUShort();
const glyphCount = this.parseUShort();
const substCount = this.parseUShort();
return {

@@ -114,4 +113,4 @@ classes: this.parseUShortList(glyphCount - 1),

} else if (substFormat === 3) {
var glyphCount = this.parseUShort();
var substCount = this.parseUShort();
const glyphCount = this.parseUShort();
const substCount = this.parseUShort();
return {

@@ -128,4 +127,4 @@ substFormat: substFormat,

subtableParsers[6] = function parseLookup6() {
var start = this.offset + this.relativeOffset;
var substFormat = this.parseUShort();
const start = this.offset + this.relativeOffset;
const substFormat = this.parseUShort();
if (substFormat === 1) {

@@ -175,6 +174,6 @@ return {

// Extension Substitution subtable
var substFormat = this.parseUShort();
const substFormat = this.parseUShort();
check.argument(substFormat === 1, 'GSUB Extension Substitution subtable identifier-format must be 1');
var extensionLookupType = this.parseUShort();
var extensionParser = new Parser(this.data, this.offset + this.parseULong());
const extensionLookupType = this.parseUShort();
const extensionParser = new Parser(this.data, this.offset + this.parseULong());
return {

@@ -189,3 +188,3 @@ substFormat: 1,

subtableParsers[8] = function parseLookup8() {
var substFormat = this.parseUShort();
const substFormat = this.parseUShort();
check.argument(substFormat === 1, 'GSUB Reverse Chaining Contextual Single Substitution Subtable identifier-format must be 1');

@@ -204,4 +203,4 @@ return {

start = start || 0;
var p = new Parser(data, start);
var tableVersion = p.parseVersion();
const p = new Parser(data, start);
const tableVersion = p.parseVersion();
check.argument(tableVersion === 1, 'Unsupported GSUB table version.');

@@ -217,3 +216,3 @@ return {

// GSUB Writing //////////////////////////////////////////////
var subtableMakers = new Array(9);
const subtableMakers = new Array(9);

@@ -270,3 +269,2 @@ subtableMakers[1] = function makeLookup1(subtable) {

exports.parse = parseGsubTable;
exports.make = makeGsubTable;
export default { parse: parseGsubTable, make: makeGsubTable };
// The `head` table contains global information about the font.
// https://www.microsoft.com/typography/OTSPEC/head.htm
'use strict';
import check from '../check';
import parse from '../parse';
import table from '../table';
var check = require('../check');
var parse = require('../parse');
var table = require('../table');
// Parse the header `head` table
function parseHeadTable(data, start) {
var head = {};
var p = new parse.Parser(data, start);
const head = {};
const p = new parse.Parser(data, start);
head.version = p.parseVersion();

@@ -37,4 +35,4 @@ head.fontRevision = Math.round(p.parseFixed() * 1000) / 1000;

// Apple Mac timestamp epoch is 01/01/1904 not 01/01/1970
var timestamp = Math.round(new Date().getTime() / 1000) + 2082844800;
var createdTimestamp = timestamp;
const timestamp = Math.round(new Date().getTime() / 1000) + 2082844800;
let createdTimestamp = timestamp;

@@ -66,3 +64,2 @@ if (options.createdTimestamp) {

exports.parse = parseHeadTable;
exports.make = makeHeadTable;
export default { parse: parseHeadTable, make: makeHeadTable };
// The `hhea` table contains information for horizontal layout.
// https://www.microsoft.com/typography/OTSPEC/hhea.htm
'use strict';
import parse from '../parse';
import table from '../table';
var parse = require('../parse');
var table = require('../table');
// Parse the horizontal header `hhea` table
function parseHheaTable(data, start) {
var hhea = {};
var p = new parse.Parser(data, start);
const hhea = {};
const p = new parse.Parser(data, start);
hhea.version = p.parseVersion();

@@ -52,3 +50,2 @@ hhea.ascender = p.parseShort();

exports.parse = parseHheaTable;
exports.make = makeHheaTable;
export default { parse: parseHheaTable, make: makeHheaTable };
// The `hmtx` table contains the horizontal metrics for all glyphs.
// https://www.microsoft.com/typography/OTSPEC/hmtx.htm
'use strict';
import parse from '../parse';
import table from '../table';
var parse = require('../parse');
var table = require('../table');
// Parse the `hmtx` table, which contains the horizontal metrics for all glyphs.
// This function augments the glyph array, adding the advanceWidth and leftSideBearing to each glyph.
function parseHmtxTable(data, start, numMetrics, numGlyphs, glyphs) {
var advanceWidth;
var leftSideBearing;
var p = new parse.Parser(data, start);
for (var i = 0; i < numGlyphs; i += 1) {
let advanceWidth;
let leftSideBearing;
const p = new parse.Parser(data, start);
for (let i = 0; i < numGlyphs; i += 1) {
// If the font is monospaced, only one entry is needed. This last entry applies to all subsequent glyphs.

@@ -22,3 +20,3 @@ if (i < numMetrics) {

var glyph = glyphs.get(i);
const glyph = glyphs.get(i);
glyph.advanceWidth = advanceWidth;

@@ -30,7 +28,7 @@ glyph.leftSideBearing = leftSideBearing;

function makeHmtxTable(glyphs) {
var t = new table.Table('hmtx', []);
for (var i = 0; i < glyphs.length; i += 1) {
var glyph = glyphs.get(i);
var advanceWidth = glyph.advanceWidth || 0;
var leftSideBearing = glyph.leftSideBearing || 0;
const t = new table.Table('hmtx', []);
for (let i = 0; i < glyphs.length; i += 1) {
const glyph = glyphs.get(i);
const advanceWidth = glyph.advanceWidth || 0;
const leftSideBearing = glyph.leftSideBearing || 0;
t.fields.push({name: 'advanceWidth_' + i, type: 'USHORT', value: advanceWidth});

@@ -43,3 +41,2 @@ t.fields.push({name: 'leftSideBearing_' + i, type: 'SHORT', value: leftSideBearing});

exports.parse = parseHmtxTable;
exports.make = makeHmtxTable;
export default { parse: parseHmtxTable, make: makeHmtxTable };

@@ -5,22 +5,20 @@ // The `kern` table contains kerning pairs.

'use strict';
import check from '../check';
import parse from '../parse';
var check = require('../check');
var parse = require('../parse');
function parseWindowsKernTable(p) {
var pairs = {};
const pairs = {};
// Skip nTables.
p.skip('uShort');
var subtableVersion = p.parseUShort();
const subtableVersion = p.parseUShort();
check.argument(subtableVersion === 0, 'Unsupported kern sub-table version.');
// Skip subtableLength, subtableCoverage
p.skip('uShort', 2);
var nPairs = p.parseUShort();
const nPairs = p.parseUShort();
// Skip searchRange, entrySelector, rangeShift.
p.skip('uShort', 3);
for (var i = 0; i < nPairs; i += 1) {
var leftIndex = p.parseUShort();
var rightIndex = p.parseUShort();
var value = p.parseShort();
for (let i = 0; i < nPairs; i += 1) {
const leftIndex = p.parseUShort();
const rightIndex = p.parseUShort();
const value = p.parseShort();
pairs[leftIndex + ',' + rightIndex] = value;

@@ -32,7 +30,7 @@ }

function parseMacKernTable(p) {
var pairs = {};
const pairs = {};
// The Mac kern table stores the version as a fixed (32 bits) but we only loaded the first 16 bits.
// Skip the rest.
p.skip('uShort');
var nTables = p.parseULong();
const nTables = p.parseULong();
//check.argument(nTables === 1, 'Only 1 subtable is supported (got ' + nTables + ').');

@@ -43,13 +41,13 @@ if (nTables > 1) {

p.skip('uLong');
var coverage = p.parseUShort();
var subtableVersion = coverage & 0xFF;
const coverage = p.parseUShort();
const subtableVersion = coverage & 0xFF;
p.skip('uShort');
if (subtableVersion === 0) {
var nPairs = p.parseUShort();
const nPairs = p.parseUShort();
// Skip searchRange, entrySelector, rangeShift.
p.skip('uShort', 3);
for (var i = 0; i < nPairs; i += 1) {
var leftIndex = p.parseUShort();
var rightIndex = p.parseUShort();
var value = p.parseShort();
for (let i = 0; i < nPairs; i += 1) {
const leftIndex = p.parseUShort();
const rightIndex = p.parseUShort();
const value = p.parseShort();
pairs[leftIndex + ',' + rightIndex] = value;

@@ -63,4 +61,4 @@ }

function parseKernTable(data, start) {
var p = new parse.Parser(data, start);
var tableVersion = p.parseUShort();
const p = new parse.Parser(data, start);
const tableVersion = p.parseUShort();
if (tableVersion === 0) {

@@ -75,2 +73,2 @@ return parseWindowsKernTable(p);

exports.parse = parseKernTable;
export default { parse: parseKernTable };
// The `loca` table stores the offsets to the locations of the glyphs in the font.
// https://www.microsoft.com/typography/OTSPEC/loca.htm
'use strict';
import parse from '../parse';
var parse = require('../parse');
// Parse the `loca` table. This table stores the offsets to the locations of the glyphs in the font,

@@ -15,9 +13,9 @@ // relative to the beginning of the glyphData table.

function parseLocaTable(data, start, numGlyphs, shortVersion) {
var p = new parse.Parser(data, start);
var parseFn = shortVersion ? p.parseUShort : p.parseULong;
const p = new parse.Parser(data, start);
const parseFn = shortVersion ? p.parseUShort : p.parseULong;
// There is an extra entry after the last index element to compute the length of the last glyph.
// That's why we use numGlyphs + 1.
var glyphOffsets = [];
for (var i = 0; i < numGlyphs + 1; i += 1) {
var glyphOffset = parseFn.call(p);
const glyphOffsets = [];
for (let i = 0; i < numGlyphs + 1; i += 1) {
let glyphOffset = parseFn.call(p);
if (shortVersion) {

@@ -34,2 +32,2 @@ // The short table version stores the actual offset divided by 2.

exports.parse = parseLocaTable;
export default { parse: parseLocaTable };

@@ -7,10 +7,8 @@ // The `ltag` table stores IETF BCP-47 language tags. It allows supporting

'use strict';
import check from '../check';
import parse from '../parse';
import table from '../table';
var check = require('../check');
var parse = require('../parse');
var table = require('../table');
function makeLtagTable(tags) {
var result = new table.Table('ltag', [
const result = new table.Table('ltag', [
{name: 'version', type: 'ULONG', value: 1},

@@ -21,6 +19,6 @@ {name: 'flags', type: 'ULONG', value: 0},

var stringPool = '';
var stringPoolOffset = 12 + tags.length * 4;
for (var i = 0; i < tags.length; ++i) {
var pos = stringPool.indexOf(tags[i]);
let stringPool = '';
const stringPoolOffset = 12 + tags.length * 4;
for (let i = 0; i < tags.length; ++i) {
let pos = stringPool.indexOf(tags[i]);
if (pos < 0) {

@@ -40,15 +38,15 @@ pos = stringPool.length;

function parseLtagTable(data, start) {
var p = new parse.Parser(data, start);
var tableVersion = p.parseULong();
const p = new parse.Parser(data, start);
const tableVersion = p.parseULong();
check.argument(tableVersion === 1, 'Unsupported ltag table version.');
// The 'ltag' specification does not define any flags; skip the field.
p.skip('uLong', 1);
var numTags = p.parseULong();
const numTags = p.parseULong();
var tags = [];
for (var i = 0; i < numTags; i++) {
var tag = '';
var offset = start + p.parseUShort();
var length = p.parseUShort();
for (var j = offset; j < offset + length; ++j) {
const tags = [];
for (let i = 0; i < numTags; i++) {
let tag = '';
const offset = start + p.parseUShort();
const length = p.parseUShort();
for (let j = offset; j < offset + length; ++j) {
tag += String.fromCharCode(data.getInt8(j));

@@ -63,3 +61,2 @@ }

exports.make = makeLtagTable;
exports.parse = parseLtagTable;
export default { make: makeLtagTable, parse: parseLtagTable };

@@ -5,11 +5,9 @@ // The `maxp` table establishes the memory requirements for the font.

'use strict';
import parse from '../parse';
import table from '../table';
var parse = require('../parse');
var table = require('../table');
// Parse the maximum profile `maxp` table.
function parseMaxpTable(data, start) {
var maxp = {};
var p = new parse.Parser(data, start);
const maxp = {};
const p = new parse.Parser(data, start);
maxp.version = p.parseVersion();

@@ -43,3 +41,2 @@ maxp.numGlyphs = p.parseUShort();

exports.parse = parseMaxpTable;
exports.make = makeMaxpTable;
export default { parse: parseMaxpTable, make: makeMaxpTable };
// The `GPOS` table contains kerning pairs, among other things.
// https://www.microsoft.com/typography/OTSPEC/gpos.htm
'use strict';
import check from '../check';
import { decode } from '../types';
import parse from '../parse';
import table from '../table';
var types = require('../types');
var decode = types.decode;
var check = require('../check');
var parse = require('../parse');
var table = require('../table');
// Parse the metadata `meta` table.
// https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6meta.html
function parseMetaTable(data, start) {
var p = new parse.Parser(data, start);
var tableVersion = p.parseULong();
const p = new parse.Parser(data, start);
const tableVersion = p.parseULong();
check.argument(tableVersion === 1, 'Unsupported META table version.');
p.parseULong(); // flags - currently unused and set to 0
p.parseULong(); // tableOffset
var numDataMaps = p.parseULong();
const numDataMaps = p.parseULong();
var tags = {};
for (var i = 0; i < numDataMaps; i++) {
var tag = p.parseTag();
var dataOffset = p.parseULong();
var dataLength = p.parseULong();
var text = decode.UTF8(data, start + dataOffset, dataLength);
const tags = {};
for (let i = 0; i < numDataMaps; i++) {
const tag = p.parseTag();
const dataOffset = p.parseULong();
const dataLength = p.parseULong();
const text = decode.UTF8(data, start + dataOffset, dataLength);

@@ -35,7 +32,7 @@ tags[tag] = text;

function makeMetaTable(tags) {
var numTags = Object.keys(tags).length;
var stringPool = '';
var stringPoolOffset = 16 + numTags * 12;
const numTags = Object.keys(tags).length;
let stringPool = '';
const stringPoolOffset = 16 + numTags * 12;
var result = new table.Table('meta', [
const result = new table.Table('meta', [
{name: 'version', type: 'ULONG', value: 1},

@@ -47,4 +44,4 @@ {name: 'flags', type: 'ULONG', value: 0},

for (var tag in tags) {
var pos = stringPool.length;
for (let tag in tags) {
const pos = stringPool.length;
stringPool += tags[tag];

@@ -62,3 +59,2 @@

exports.parse = parseMetaTable;
exports.make = makeMetaTable;
export default { parse: parseMetaTable, make: makeMetaTable };
// The `name` naming table.
// https://www.microsoft.com/typography/OTSPEC/name.htm
'use strict';
import { decode, encode } from '../types';
import parse from '../parse';
import table from '../table';
var types = require('../types');
var decode = types.decode;
var encode = types.encode;
var parse = require('../parse');
var table = require('../table');
// NameIDs for the name table.
var nameTableNames = [
const nameTableNames = [
'copyright', // 0

@@ -39,3 +35,3 @@ 'fontFamily', // 1

var macLanguages = {
const macLanguages = {
0: 'en',

@@ -174,3 +170,3 @@ 1: 'fr',

// http://unicode.org/Public/MAPPINGS/VENDORS/APPLE/Readme.txt
var macLanguageToScript = {
const macLanguageToScript = {
0: 0, // langEnglish → smRoman

@@ -313,3 +309,3 @@ 1: 0, // langFrench → smRoman

// http://www.iana.org/assignments/language-subtag-registry/language-subtag-registry
var windowsLanguages = {
const windowsLanguages = {
0x0436: 'af',

@@ -554,7 +550,7 @@ 0x041C: 'sq',

var utf16 = 'utf-16';
const utf16 = 'utf-16';
// MacOS script ID → encoding. This table stores the default case,
// which can be overridden by macLanguageEncodings.
var macScriptEncodings = {
const macScriptEncodings = {
0: 'macintosh', // smRoman

@@ -597,3 +593,3 @@ 1: 'x-mac-japanese', // smJapanese

// http://unicode.org/Public/MAPPINGS/VENDORS/APPLE/Readme.txt
var macLanguageEncodings = {
const macLanguageEncodings = {
15: 'x-mac-icelandic', // langIcelandic

@@ -639,19 +635,19 @@ 17: 'x-mac-turkish', // langTurkish

function parseNameTable(data, start, ltag) {
var name = {};
var p = new parse.Parser(data, start);
var format = p.parseUShort();
var count = p.parseUShort();
var stringOffset = p.offset + p.parseUShort();
for (var i = 0; i < count; i++) {
var platformID = p.parseUShort();
var encodingID = p.parseUShort();
var languageID = p.parseUShort();
var nameID = p.parseUShort();
var property = nameTableNames[nameID] || nameID;
var byteLength = p.parseUShort();
var offset = p.parseUShort();
var language = getLanguageCode(platformID, languageID, ltag);
var encoding = getEncoding(platformID, encodingID, languageID);
const name = {};
const p = new parse.Parser(data, start);
const format = p.parseUShort();
const count = p.parseUShort();
const stringOffset = p.offset + p.parseUShort();
for (let i = 0; i < count; i++) {
const platformID = p.parseUShort();
const encodingID = p.parseUShort();
const languageID = p.parseUShort();
const nameID = p.parseUShort();
const property = nameTableNames[nameID] || nameID;
const byteLength = p.parseUShort();
const offset = p.parseUShort();
const language = getLanguageCode(platformID, languageID, ltag);
const encoding = getEncoding(platformID, encodingID, languageID);
if (encoding !== undefined && language !== undefined) {
var text;
let text;
if (encoding === utf16) {

@@ -664,3 +660,3 @@ text = decode.UTF16(data, stringOffset + offset, byteLength);

if (text) {
var translations = name[property];
let translations = name[property];
if (translations === undefined) {

@@ -675,3 +671,3 @@ translations = name[property] = {};

var langTagCount = 0;
let langTagCount = 0;
if (format === 1) {

@@ -688,4 +684,4 @@ // FIXME: Also handle Microsoft's 'name' table 1.

function reverseDict(dict) {
var result = {};
for (var key in dict) {
const result = {};
for (let key in dict) {
result[dict[key]] = parseInt(key);

@@ -711,9 +707,9 @@ }

function findSubArray(needle, haystack) {
var needleLength = needle.length;
var limit = haystack.length - needleLength + 1;
const needleLength = needle.length;
const limit = haystack.length - needleLength + 1;
loop:
for (var pos = 0; pos < limit; pos++) {
for (let pos = 0; pos < limit; pos++) {
for (; pos < limit; pos++) {
for (var k = 0; k < needleLength; k++) {
for (let k = 0; k < needleLength; k++) {
if (haystack[pos + k] !== needle[k]) {

@@ -732,6 +728,8 @@ continue loop;

function addStringToPool(s, pool) {
var offset = findSubArray(s, pool);
let offset = findSubArray(s, pool);
if (offset < 0) {
offset = pool.length;
for (var i = 0, len = s.length; i < len; ++i) {
let i = 0;
const len = s.length;
for (; i < len; ++i) {
pool.push(s[i]);

@@ -746,9 +744,9 @@ }

function makeNameTable(names, ltag) {
var nameID;
var nameIDs = [];
let nameID;
const nameIDs = [];
var namesWithNumericKeys = {};
var nameTableIds = reverseDict(nameTableNames);
for (var key in names) {
var id = nameTableIds[key];
const namesWithNumericKeys = {};
const nameTableIds = reverseDict(nameTableNames);
for (let key in names) {
let id = nameTableIds[key];
if (id === undefined) {

@@ -768,13 +766,13 @@ id = key;

var macLanguageIds = reverseDict(macLanguages);
var windowsLanguageIds = reverseDict(windowsLanguages);
const macLanguageIds = reverseDict(macLanguages);
const windowsLanguageIds = reverseDict(windowsLanguages);
var nameRecords = [];
var stringPool = [];
const nameRecords = [];
const stringPool = [];
for (var i = 0; i < nameIDs.length; i++) {
for (let i = 0; i < nameIDs.length; i++) {
nameID = nameIDs[i];
var translations = namesWithNumericKeys[nameID];
for (var lang in translations) {
var text = translations[lang];
const translations = namesWithNumericKeys[nameID];
for (let lang in translations) {
const text = translations[lang];

@@ -795,7 +793,7 @@ // For MacOS, we try to emit the name in the form that was introduced

// the ancient form (silently skipping the unrecognized names).
var macPlatform = 1; // Macintosh
var macLanguage = macLanguageIds[lang];
var macScript = macLanguageToScript[macLanguage];
var macEncoding = getEncoding(macPlatform, macScript, macLanguage);
var macName = encode.MACSTRING(text, macEncoding);
let macPlatform = 1; // Macintosh
let macLanguage = macLanguageIds[lang];
let macScript = macLanguageToScript[macLanguage];
const macEncoding = getEncoding(macPlatform, macScript, macLanguage);
let macName = encode.MACSTRING(text, macEncoding);
if (macName === undefined) {

@@ -813,10 +811,10 @@ macPlatform = 0; // Unicode

var macNameOffset = addStringToPool(macName, stringPool);
const macNameOffset = addStringToPool(macName, stringPool);
nameRecords.push(makeNameRecord(macPlatform, macScript, macLanguage,
nameID, macName.length, macNameOffset));
var winLanguage = windowsLanguageIds[lang];
const winLanguage = windowsLanguageIds[lang];
if (winLanguage !== undefined) {
var winName = encode.UTF16(text);
var winNameOffset = addStringToPool(winName, stringPool);
const winName = encode.UTF16(text);
const winNameOffset = addStringToPool(winName, stringPool);
nameRecords.push(makeNameRecord(3, 1, winLanguage,

@@ -835,3 +833,3 @@ nameID, winName.length, winNameOffset));

var t = new table.Table('name', [
const t = new table.Table('name', [
{name: 'format', type: 'USHORT', value: 0},

@@ -842,3 +840,3 @@ {name: 'count', type: 'USHORT', value: nameRecords.length},

for (var r = 0; r < nameRecords.length; r++) {
for (let r = 0; r < nameRecords.length; r++) {
t.fields.push({name: 'record_' + r, type: 'RECORD', value: nameRecords[r]});

@@ -851,3 +849,2 @@ }

exports.parse = parseNameTable;
exports.make = makeNameTable;
export default { parse: parseNameTable, make: makeNameTable };
// The `OS/2` table contains metrics required in OpenType fonts.
// https://www.microsoft.com/typography/OTSPEC/os2.htm
'use strict';
import parse from '../parse';
import table from '../table';
var parse = require('../parse');
var table = require('../table');
var unicodeRanges = [
const unicodeRanges = [
{begin: 0x0000, end: 0x007F}, // Basic Latin

@@ -136,4 +134,4 @@ {begin: 0x0080, end: 0x00FF}, // Latin-1 Supplement

function getUnicodeRange(unicode) {
for (var i = 0; i < unicodeRanges.length; i += 1) {
var range = unicodeRanges[i];
for (let i = 0; i < unicodeRanges.length; i += 1) {
const range = unicodeRanges[i];
if (unicode >= range.begin && unicode < range.end) {

@@ -149,4 +147,4 @@ return i;

function parseOS2Table(data, start) {
var os2 = {};
var p = new parse.Parser(data, start);
const os2 = {};
const p = new parse.Parser(data, start);
os2.version = p.parseUShort();

@@ -169,3 +167,3 @@ os2.xAvgCharWidth = p.parseShort();

os2.panose = [];
for (var i = 0; i < 10; i++) {
for (let i = 0; i < 10; i++) {
os2.panose[i] = p.parseByte();

@@ -254,5 +252,2 @@ }

exports.unicodeRanges = unicodeRanges;
exports.getUnicodeRange = getUnicodeRange;
exports.parse = parseOS2Table;
exports.make = makeOS2Table;
export default { parse: parseOS2Table, make: makeOS2Table, unicodeRanges, getUnicodeRange };
// The `post` table stores additional PostScript information, such as glyph names.
// https://www.microsoft.com/typography/OTSPEC/post.htm
'use strict';
import { standardNames } from '../encoding';
import parse from '../parse';
import table from '../table';
var encoding = require('../encoding');
var parse = require('../parse');
var table = require('../table');
// Parse the PostScript `post` table
function parsePostTable(data, start) {
var post = {};
var p = new parse.Parser(data, start);
var i;
const post = {};
const p = new parse.Parser(data, start);
post.version = p.parseVersion();

@@ -26,3 +23,3 @@ post.italicAngle = p.parseFixed();

case 1:
post.names = encoding.standardNames.slice();
post.names = standardNames.slice();
break;

@@ -32,3 +29,3 @@ case 2:

post.glyphNameIndex = new Array(post.numberOfGlyphs);
for (i = 0; i < post.numberOfGlyphs; i++) {
for (let i = 0; i < post.numberOfGlyphs; i++) {
post.glyphNameIndex[i] = p.parseUShort();

@@ -38,5 +35,5 @@ }

post.names = [];
for (i = 0; i < post.numberOfGlyphs; i++) {
if (post.glyphNameIndex[i] >= encoding.standardNames.length) {
var nameLength = p.parseChar();
for (let i = 0; i < post.numberOfGlyphs; i++) {
if (post.glyphNameIndex[i] >= standardNames.length) {
const nameLength = p.parseChar();
post.names.push(p.parseString(nameLength));

@@ -50,3 +47,3 @@ }

post.offset = new Array(post.numberOfGlyphs);
for (i = 0; i < post.numberOfGlyphs; i++) {
for (let i = 0; i < post.numberOfGlyphs; i++) {
post.offset[i] = p.parseChar();

@@ -74,3 +71,2 @@ }

exports.parse = parsePostTable;
exports.make = makePostTable;
export default { parse: parsePostTable, make: makePostTable };

@@ -7,20 +7,18 @@ // The `sfnt` wrapper provides organization for the tables in the font.

'use strict';
import check from '../check';
import table from '../table';
var check = require('../check');
var table = require('../table');
import cmap from './cmap';
import cff from './cff';
import head from './head';
import hhea from './hhea';
import hmtx from './hmtx';
import ltag from './ltag';
import maxp from './maxp';
import _name from './name';
import os2 from './os2';
import post from './post';
import gsub from './gsub';
import meta from './meta';
var cmap = require('./cmap');
var cff = require('./cff');
var head = require('./head');
var hhea = require('./hhea');
var hmtx = require('./hmtx');
var ltag = require('./ltag');
var maxp = require('./maxp');
var _name = require('./name');
var os2 = require('./os2');
var post = require('./post');
var gsub = require('./gsub');
var meta = require('./meta');
function log2(v) {

@@ -35,4 +33,4 @@ return Math.log(v) / Math.log(2) | 0;

var sum = 0;
for (var i = 0; i < bytes.length; i += 4) {
let sum = 0;
for (let i = 0; i < bytes.length; i += 4) {
sum += (bytes[i] << 24) +

@@ -58,3 +56,3 @@ (bytes[i + 1] << 16) +

function makeSfntTable(tables) {
var sfnt = new table.Table('sfnt', [
const sfnt = new table.Table('sfnt', [
{name: 'version', type: 'TAG', value: 'OTTO'},

@@ -68,3 +66,3 @@ {name: 'numTables', type: 'USHORT', value: 0},

sfnt.numTables = tables.length;
var highestPowerOf2 = Math.pow(2, log2(sfnt.numTables));
const highestPowerOf2 = Math.pow(2, log2(sfnt.numTables));
sfnt.searchRange = 16 * highestPowerOf2;

@@ -74,6 +72,6 @@ sfnt.entrySelector = log2(highestPowerOf2);

var recordFields = [];
var tableFields = [];
const recordFields = [];
const tableFields = [];
var offset = sfnt.sizeOf() + (makeTableRecord().sizeOf() * sfnt.numTables);
let offset = sfnt.sizeOf() + (makeTableRecord().sizeOf() * sfnt.numTables);
while (offset % 4 !== 0) {

@@ -84,7 +82,7 @@ offset += 1;

for (var i = 0; i < tables.length; i += 1) {
var t = tables[i];
for (let i = 0; i < tables.length; i += 1) {
const t = tables[i];
check.argument(t.tableName.length === 4, 'Table name' + t.tableName + ' is invalid.');
var tableLength = t.sizeOf();
var tableRecord = makeTableRecord(t.tableName, computeCheckSum(t.encode()), offset, tableLength);
const tableLength = t.sizeOf();
const tableRecord = makeTableRecord(t.tableName, computeCheckSum(t.encode()), offset, tableLength);
recordFields.push({name: tableRecord.tag + ' Table Record', type: 'RECORD', value: tableRecord});

@@ -118,6 +116,6 @@ tableFields.push({name: t.tableName + ' table', type: 'RECORD', value: t});

function metricsForChar(font, chars, notFoundMetrics) {
for (var i = 0; i < chars.length; i += 1) {
var glyphIndex = font.charToGlyphIndex(chars[i]);
for (let i = 0; i < chars.length; i += 1) {
const glyphIndex = font.charToGlyphIndex(chars[i]);
if (glyphIndex > 0) {
var glyph = font.glyphs.get(glyphIndex);
const glyph = font.glyphs.get(glyphIndex);
return glyph.getMetrics();

@@ -131,4 +129,4 @@ }

function average(vs) {
var sum = 0;
for (var i = 0; i < vs.length; i += 1) {
let sum = 0;
for (let i = 0; i < vs.length; i += 1) {
sum += vs[i];

@@ -143,19 +141,19 @@ }

function fontToSfntTable(font) {
var xMins = [];
var yMins = [];
var xMaxs = [];
var yMaxs = [];
var advanceWidths = [];
var leftSideBearings = [];
var rightSideBearings = [];
var firstCharIndex;
var lastCharIndex = 0;
var ulUnicodeRange1 = 0;
var ulUnicodeRange2 = 0;
var ulUnicodeRange3 = 0;
var ulUnicodeRange4 = 0;
const xMins = [];
const yMins = [];
const xMaxs = [];
const yMaxs = [];
const advanceWidths = [];
const leftSideBearings = [];
const rightSideBearings = [];
let firstCharIndex;
let lastCharIndex = 0;
let ulUnicodeRange1 = 0;
let ulUnicodeRange2 = 0;
let ulUnicodeRange3 = 0;
let ulUnicodeRange4 = 0;
for (var i = 0; i < font.glyphs.length; i += 1) {
var glyph = font.glyphs.get(i);
var unicode = glyph.unicode | 0;
for (let i = 0; i < font.glyphs.length; i += 1) {
const glyph = font.glyphs.get(i);
const unicode = glyph.unicode | 0;

@@ -177,3 +175,3 @@ if (isNaN(glyph.advanceWidth)) {

var position = os2.getUnicodeRange(unicode);
const position = os2.getUnicodeRange(unicode);
if (position < 32) {

@@ -192,3 +190,3 @@ ulUnicodeRange1 |= 1 << position;

if (glyph.name === '.notdef') continue;
var metrics = glyph.getMetrics();
const metrics = glyph.getMetrics();
xMins.push(metrics.xMin);

@@ -203,3 +201,3 @@ yMins.push(metrics.yMin);

var globals = {
const globals = {
xMin: Math.min.apply(null, xMins),

@@ -218,3 +216,3 @@ yMin: Math.min.apply(null, yMins),

var headTable = head.make({
const headTable = head.make({
flags: 3, // 00000011 (baseline for font at y=0; left sidebearing point at x=0)

@@ -230,3 +228,3 @@ unitsPerEm: font.unitsPerEm,

var hheaTable = hhea.make({
const hheaTable = hhea.make({
ascender: globals.ascender,

@@ -241,5 +239,5 @@ descender: globals.descender,

var maxpTable = maxp.make(font.glyphs.length);
const maxpTable = maxp.make(font.glyphs.length);
var os2Table = os2.make({
const os2Table = os2.make({
xAvgCharWidth: Math.round(globals.advanceWidthAvg),

@@ -271,9 +269,9 @@ usWeightClass: font.tables.os2.usWeightClass,

var hmtxTable = hmtx.make(font.glyphs);
var cmapTable = cmap.make(font.glyphs);
const hmtxTable = hmtx.make(font.glyphs);
const cmapTable = cmap.make(font.glyphs);
var englishFamilyName = font.getEnglishName('fontFamily');
var englishStyleName = font.getEnglishName('fontSubfamily');
var englishFullName = englishFamilyName + ' ' + englishStyleName;
var postScriptName = font.getEnglishName('postScriptName');
const englishFamilyName = font.getEnglishName('fontFamily');
const englishStyleName = font.getEnglishName('fontSubfamily');
const englishFullName = englishFamilyName + ' ' + englishStyleName;
let postScriptName = font.getEnglishName('postScriptName');
if (!postScriptName) {

@@ -283,4 +281,4 @@ postScriptName = englishFamilyName.replace(/\s/g, '') + '-' + englishStyleName;

var names = {};
for (var n in font.names) {
const names = {};
for (let n in font.names) {
names[n] = font.names[n];

@@ -305,8 +303,8 @@ }

var languageTags = [];
var nameTable = _name.make(names, languageTags);
var ltagTable = (languageTags.length > 0 ? ltag.make(languageTags) : undefined);
const languageTags = [];
const nameTable = _name.make(names, languageTags);
const ltagTable = (languageTags.length > 0 ? ltag.make(languageTags) : undefined);
var postTable = post.make();
var cffTable = cff.make(font.glyphs, {
const postTable = post.make();
const cffTable = cff.make(font.glyphs, {
version: font.getEnglishName('version'),

@@ -321,6 +319,6 @@ fullName: englishFullName,

var metaTable = (font.metas && Object.keys(font.metas).length > 0) ? meta.make(font.metas) : undefined;
const metaTable = (font.metas && Object.keys(font.metas).length > 0) ? meta.make(font.metas) : undefined;
// The order does not matter because makeSfntTable() will sort them.
var tables = [headTable, hheaTable, maxpTable, os2Table, nameTable, cmapTable, postTable, cffTable, hmtxTable];
const tables = [headTable, hheaTable, maxpTable, os2Table, nameTable, cmapTable, postTable, cffTable, hmtxTable];
if (ltagTable) {

@@ -337,10 +335,10 @@ tables.push(ltagTable);

var sfntTable = makeSfntTable(tables);
const sfntTable = makeSfntTable(tables);
// Compute the font's checkSum and store it in head.checkSumAdjustment.
var bytes = sfntTable.encode();
var checkSum = computeCheckSum(bytes);
var tableFields = sfntTable.fields;
var checkSumAdjusted = false;
for (i = 0; i < tableFields.length; i += 1) {
const bytes = sfntTable.encode();
const checkSum = computeCheckSum(bytes);
const tableFields = sfntTable.fields;
let checkSumAdjusted = false;
for (let i = 0; i < tableFields.length; i += 1) {
if (tableFields[i].name === 'head table') {

@@ -360,4 +358,2 @@ tableFields[i].value.checkSumAdjustment = 0xB1B0AFBA - checkSum;

exports.computeCheckSum = computeCheckSum;
exports.make = makeSfntTable;
exports.fontToTable = fontToSfntTable;
export default { make: makeSfntTable, fontToTable: fontToSfntTable, computeCheckSum };
// Data types used in the OpenType font file.
// All OpenType fonts use Motorola-style byte ordering (Big Endian)
/* global WeakMap */
import check from './check';
'use strict';
const LIMIT16 = 32768; // The limit at which a 16-bit number switches signs == 2^15
const LIMIT32 = 2147483648; // The limit at which a 32-bit number switches signs == 2 ^ 31
var check = require('./check');
var LIMIT16 = 32768; // The limit at which a 16-bit number switches signs == 2^15
var LIMIT32 = 2147483648; // The limit at which a 32-bit number switches signs == 2 ^ 31
/**

@@ -17,3 +13,3 @@ * @exports opentype.decode

*/
var decode = {};
const decode = {};
/**

@@ -23,3 +19,3 @@ * @exports opentype.encode

*/
var encode = {};
const encode = {};
/**

@@ -29,3 +25,3 @@ * @exports opentype.sizeOf

*/
var sizeOf = {};
const sizeOf = {};

@@ -77,4 +73,4 @@ // Return a function that always returns the same value.

encode.CHARARRAY = function(v) {
var b = [];
for (var i = 0; i < v.length; i += 1) {
const b = [];
for (let i = 0; i < v.length; i += 1) {
b[i] = v.charCodeAt(i);

@@ -304,17 +300,15 @@ }

encode.REAL = function(v) {
var value = v.toString();
let value = v.toString();
// Some numbers use an epsilon to encode the value. (e.g. JavaScript will store 0.0000001 as 1e-7)
// This code converts it back to a number without the epsilon.
var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
const m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
if (m) {
var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
const epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
value = (Math.round(v * epsilon) / epsilon).toString();
}
var nibbles = '';
var i;
var ii;
for (i = 0, ii = value.length; i < ii; i += 1) {
var c = value[i];
let nibbles = '';
for (let i = 0, ii = value.length; i < ii; i += 1) {
const c = value[i];
if (c === 'e') {

@@ -332,4 +326,4 @@ nibbles += value[++i] === '-' ? 'c' : 'b';

nibbles += (nibbles.length & 1) ? 'f' : 'ff';
var out = [30];
for (i = 0, ii = nibbles.length; i < ii; i += 2) {
const out = [30];
for (let i = 0, ii = nibbles.length; i < ii; i += 2) {
out.push(parseInt(nibbles.substr(i, 2), 16));

@@ -362,5 +356,5 @@ }

decode.UTF8 = function(data, offset, numBytes) {
var codePoints = [];
var numChars = numBytes;
for (var j = 0; j < numChars; j++, offset += 1) {
const codePoints = [];
const numChars = numBytes;
for (let j = 0; j < numChars; j++, offset += 1) {
codePoints[j] = data.getUint8(offset);

@@ -379,5 +373,5 @@ }

decode.UTF16 = function(data, offset, numBytes) {
var codePoints = [];
var numChars = numBytes / 2;
for (var j = 0; j < numChars; j++, offset += 2) {
const codePoints = [];
const numChars = numBytes / 2;
for (let j = 0; j < numChars; j++, offset += 2) {
codePoints[j] = data.getUint16(offset);

@@ -395,5 +389,5 @@ }

encode.UTF16 = function(v) {
var b = [];
for (var i = 0; i < v.length; i += 1) {
var codepoint = v.charCodeAt(i);
const b = [];
for (let i = 0; i < v.length; i += 1) {
const codepoint = v.charCodeAt(i);
b[b.length] = (codepoint >> 8) & 0xFF;

@@ -417,3 +411,3 @@ b[b.length] = codepoint & 0xFF;

// and needs more memory. The assumption is that all opentype.js users
// want to open fonts, but saving a font will be comperatively rare
// want to open fonts, but saving a font will be comparatively rare
// so it can be more expensive. Keyed by IANA character set name.

@@ -428,35 +422,33 @@ //

*/
var eightBitMacEncodings = {
const eightBitMacEncodings = {
'x-mac-croatian': // Python: 'mac_croatian'
'ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®Š™´¨≠ŽØ∞±≤≥∆µ∂∑∏š∫ªºΩžø' +
'¿¡¬√ƒ≈Ć«Č… ÀÃÕŒœĐ—“”‘’÷◊©⁄€‹›Æ»–·‚„‰ÂćÁčÈÍÎÏÌÓÔđÒÚÛÙıˆ˜¯πË˚¸Êæˇ',
'ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®Š™´¨≠ŽØ∞±≤≥∆µ∂∑∏š∫ªºΩžø' +
'¿¡¬√ƒ≈Ć«Č… ÀÃÕŒœĐ—“”‘’÷◊©⁄€‹›Æ»–·‚„‰ÂćÁčÈÍÎÏÌÓÔđÒÚÛÙıˆ˜¯πË˚¸Êæˇ',
'x-mac-cyrillic': // Python: 'mac_cyrillic'
'АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ†°Ґ£§•¶І®©™Ђђ≠Ѓѓ∞±≤≥іµґЈЄєЇїЉљЊњ' +
'јЅ¬√ƒ≈∆«»… ЋћЌќѕ–—“”‘’÷„ЎўЏџ№Ёёяабвгдежзийклмнопрстуфхцчшщъыьэю',
'x-mac-gaelic':
// http://unicode.org/Public/MAPPINGS/VENDORS/APPLE/GAELIC.TXT
'ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØḂ±≤≥ḃĊċḊḋḞḟĠġṀæø' +
'ṁṖṗɼƒſṠ«»… ÀÃÕŒœ–—“”‘’ṡẛÿŸṪ€‹›Ŷŷṫ·Ỳỳ⁊ÂÊÁËÈÍÎÏÌÓÔ♣ÒÚÛÙıÝýŴŵẄẅẀẁẂẃ',
'АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ†°Ґ£§•¶І®©™Ђђ≠Ѓѓ∞±≤≥іµґЈЄєЇїЉљЊњ' +
'јЅ¬√ƒ≈∆«»… ЋћЌќѕ–—“”‘’÷„ЎўЏџ№Ёёяабвгдежзийклмнопрстуфхцчшщъыьэю',
'x-mac-gaelic': // http://unicode.org/Public/MAPPINGS/VENDORS/APPLE/GAELIC.TXT
'ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØḂ±≤≥ḃĊċḊḋḞḟĠġṀæø' +
'ṁṖṗɼƒſṠ«»… ÀÃÕŒœ–—“”‘’ṡẛÿŸṪ€‹›Ŷŷṫ·Ỳỳ⁊ÂÊÁËÈÍÎÏÌÓÔ♣ÒÚÛÙıÝýŴŵẄẅẀẁẂẃ',
'x-mac-greek': // Python: 'mac_greek'
'Ĺ²É³ÖÜ΅àâä΄¨çéèê룙î‰ôö¦€ùûü†ΓΔΘΛΞΠß®©ΣΪ§≠°·Α±≤≥¥ΒΕΖΗΙΚΜΦΫΨΩ' +
'άΝ¬ΟΡ≈Τ«»… ΥΧΆΈœ–―“”‘’÷ΉΊΌΎέήίόΏύαβψδεφγηιξκλμνοπώρστθωςχυζϊϋΐΰ\u00AD',
'Ĺ²É³ÖÜ΅àâä΄¨çéèê룙î‰ôö¦€ùûü†ΓΔΘΛΞΠß®©ΣΪ§≠°·Α±≤≥¥ΒΕΖΗΙΚΜΦΫΨΩ' +
'άΝ¬ΟΡ≈Τ«»… ΥΧΆΈœ–―“”‘’÷ΉΊΌΎέήίόΏύαβψδεφγηιξκλμνοπώρστθωςχυζϊϋΐΰ\u00AD',
'x-mac-icelandic': // Python: 'mac_iceland'
'ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûüÝ°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø' +
'¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€ÐðÞþý·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ',
'x-mac-inuit':
// http://unicode.org/Public/MAPPINGS/VENDORS/APPLE/INUIT.TXT
'ᐃᐄᐅᐆᐊᐋᐱᐲᐳᐴᐸᐹᑉᑎᑏᑐᑑᑕᑖᑦᑭᑮᑯᑰᑲᑳᒃᒋᒌᒍᒎᒐᒑ°ᒡᒥᒦ•¶ᒧ®©™ᒨᒪᒫᒻᓂᓃᓄᓅᓇᓈᓐᓯᓰᓱᓲᓴᓵᔅᓕᓖᓗ' +
'ᓘᓚᓛᓪᔨᔩᔪᔫᔭ… ᔮᔾᕕᕖᕗ–—“”‘’ᕘᕙᕚᕝᕆᕇᕈᕉᕋᕌᕐᕿᖀᖁᖂᖃᖄᖅᖏᖐᖑᖒᖓᖔᖕᙱᙲᙳᙴᙵᙶᖖᖠᖡᖢᖣᖤᖥᖦᕼŁł',
'ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûüÝ°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø' +
'¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€ÐðÞþý·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ',
'x-mac-inuit': // http://unicode.org/Public/MAPPINGS/VENDORS/APPLE/INUIT.TXT
'ᐃᐄᐅᐆᐊᐋᐱᐲᐳᐴᐸᐹᑉᑎᑏᑐᑑᑕᑖᑦᑭᑮᑯᑰᑲᑳᒃᒋᒌᒍᒎᒐᒑ°ᒡᒥᒦ•¶ᒧ®©™ᒨᒪᒫᒻᓂᓃᓄᓅᓇᓈᓐᓯᓰᓱᓲᓴᓵᔅᓕᓖᓗ' +
'ᓘᓚᓛᓪᔨᔩᔪᔫᔭ… ᔮᔾᕕᕖᕗ–—“”‘’ᕘᕙᕚᕝᕆᕇᕈᕉᕋᕌᕐᕿᖀᖁᖂᖃᖄᖅᖏᖐᖑᖒᖓᖔᖕᙱᙲᙳᙴᙵᙶᖖᖠᖡᖢᖣᖤᖥᖦᕼŁł',
'x-mac-ce': // Python: 'mac_latin2'
'ÄĀāÉĄÖÜáąČäčĆć鏟ĎíďĒēĖóėôöõúĚěü†°Ę£§•¶ß®©™ę¨≠ģĮįĪ≤≥īĶ∂∑łĻļĽľĹĺŅ' +
'ņѬ√ńŇ∆«»… ňŐÕőŌ–—“”‘’÷◊ōŔŕŘ‹›řŖŗŠ‚„šŚśÁŤťÍŽžŪÓÔūŮÚůŰűŲųÝýķŻŁżĢˇ',
'ÄĀāÉĄÖÜáąČäčĆć鏟ĎíďĒēĖóėôöõúĚěü†°Ę£§•¶ß®©™ę¨≠ģĮįĪ≤≥īĶ∂∑łĻļĽľĹĺŅ' +
'ņѬ√ńŇ∆«»… ňŐÕőŌ–—“”‘’÷◊ōŔŕŘ‹›řŖŗŠ‚„šŚśÁŤťÍŽžŪÓÔūŮÚůŰűŲųÝýķŻŁżĢˇ',
macintosh: // Python: 'mac_roman'
'ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø' +
'¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€‹›fifl‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ',
'ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø' +
'¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€‹›fifl‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ',
'x-mac-romanian': // Python: 'mac_romanian'
'ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ĂȘ∞±≤≥¥µ∂∑∏π∫ªºΩăș' +
'¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€‹›Țț‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ',
'ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ĂȘ∞±≤≥¥µ∂∑∏π∫ªºΩăș' +
'¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€‹›Țț‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ',
'x-mac-turkish': // Python: 'mac_turkish'
'ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø' +
'¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸĞğİıŞş‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙˆ˜¯˘˙˚¸˝˛ˇ'
'ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø' +
'¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸĞğİıŞş‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙˆ˜¯˘˙˚¸˝˛ˇ'
};

@@ -476,3 +468,3 @@

decode.MACSTRING = function(dataView, offset, dataLength, encoding) {
var table = eightBitMacEncodings[encoding];
const table = eightBitMacEncodings[encoding];
if (table === undefined) {

@@ -482,5 +474,5 @@ return undefined;

var result = '';
for (var i = 0; i < dataLength; i++) {
var c = dataView.getUint8(offset + i);
let result = '';
for (let i = 0; i < dataLength; i++) {
const c = dataView.getUint8(offset + i);
// In all eight-bit Mac encodings, the characters 0x00..0x7F are

@@ -502,5 +494,5 @@ // mapped to U+0000..U+007F; we only need to look up the others.

// encoding Macintosh strings is only rarely needed in typical applications.
var macEncodingTableCache = typeof WeakMap === 'function' && new WeakMap();
var macEncodingCacheKeys;
var getMacEncodingTable = function(encoding) {
const macEncodingTableCache = typeof WeakMap === 'function' && new WeakMap();
let macEncodingCacheKeys;
const getMacEncodingTable = function (encoding) {
// Since we use encoding as a cache key for WeakMap, it has to be

@@ -511,3 +503,3 @@ // a String object and not a literal. And at least on NodeJS 2.10.1,

macEncodingCacheKeys = {};
for (var e in eightBitMacEncodings) {
for (let e in eightBitMacEncodings) {
/*jshint -W053 */ // Suppress "Do not use String as a constructor."

@@ -518,3 +510,3 @@ macEncodingCacheKeys[e] = new String(e);

var cacheKey = macEncodingCacheKeys[encoding];
const cacheKey = macEncodingCacheKeys[encoding];
if (cacheKey === undefined) {

@@ -529,3 +521,3 @@ return undefined;

if (macEncodingTableCache) {
var cachedTable = macEncodingTableCache.get(cacheKey);
const cachedTable = macEncodingTableCache.get(cacheKey);
if (cachedTable !== undefined) {

@@ -536,3 +528,3 @@ return cachedTable;

var decodingTable = eightBitMacEncodings[encoding];
const decodingTable = eightBitMacEncodings[encoding];
if (decodingTable === undefined) {

@@ -542,4 +534,4 @@ return undefined;

var encodingTable = {};
for (var i = 0; i < decodingTable.length; i++) {
const encodingTable = {};
for (let i = 0; i < decodingTable.length; i++) {
encodingTable[decodingTable.charCodeAt(i)] = i + 0x80;

@@ -565,3 +557,3 @@ }

encode.MACSTRING = function(str, encoding) {
var table = getMacEncodingTable(encoding);
const table = getMacEncodingTable(encoding);
if (table === undefined) {

@@ -571,5 +563,5 @@ return undefined;

var result = [];
for (var i = 0; i < str.length; i++) {
var c = str.charCodeAt(i);
const result = [];
for (let i = 0; i < str.length; i++) {
let c = str.charCodeAt(i);

@@ -599,3 +591,3 @@ // In all eight-bit Mac encodings, the characters 0x00..0x7F are

sizeOf.MACSTRING = function(str, encoding) {
var b = encode.MACSTRING(str, encoding);
const b = encode.MACSTRING(str, encoding);
if (b !== undefined) {

@@ -615,4 +607,4 @@ return b.length;

function encodeVarDeltaRunAsZeroes(deltas, pos, result) {
var runLength = 0;
var numDeltas = deltas.length;
let runLength = 0;
const numDeltas = deltas.length;
while (pos < numDeltas && runLength < 64 && deltas[pos] === 0) {

@@ -628,7 +620,7 @@ ++pos;

function encodeVarDeltaRunAsBytes(deltas, offset, result) {
var runLength = 0;
var numDeltas = deltas.length;
var pos = offset;
let runLength = 0;
const numDeltas = deltas.length;
let pos = offset;
while (pos < numDeltas && runLength < 64) {
var value = deltas[pos];
const value = deltas[pos];
if (!isByteEncodable(value)) {

@@ -653,3 +645,3 @@ break;

result.push(runLength - 1);
for (var i = offset; i < pos; ++i) {
for (let i = offset; i < pos; ++i) {
result.push((deltas[i] + 256) & 0xff);

@@ -662,7 +654,7 @@ }

function encodeVarDeltaRunAsWords(deltas, offset, result) {
var runLength = 0;
var numDeltas = deltas.length;
var pos = offset;
let runLength = 0;
const numDeltas = deltas.length;
let pos = offset;
while (pos < numDeltas && runLength < 64) {
var value = deltas[pos];
const value = deltas[pos];

@@ -693,4 +685,4 @@ // Within a word-encoded run of deltas, it is easiest to start

result.push(0x40 | (runLength - 1));
for (var i = offset; i < pos; ++i) {
var val = deltas[i];
for (let i = offset; i < pos; ++i) {
const val = deltas[i];
result.push(((val + 0x10000) >> 8) & 0xff, (val + 0x100) & 0xff);

@@ -714,6 +706,6 @@ }

encode.VARDELTAS = function(deltas) {
var pos = 0;
var result = [];
let pos = 0;
const result = [];
while (pos < deltas.length) {
var value = deltas[pos];
const value = deltas[pos];
if (value === 0) {

@@ -737,3 +729,2 @@ pos = encodeVarDeltaRunAsZeroes(deltas, pos, result);

encode.INDEX = function(l) {
var i;
//var offset, offsets, offsetEncoder, encodedOffsets, encodedOffset, data,

@@ -743,8 +734,8 @@ // i, v;

// we have to go through the values twice: once to encode the data and
// calculate the offets, then again to encode the offsets using the fitting data type.
var offset = 1; // First offset is always 1.
var offsets = [offset];
var data = [];
for (i = 0; i < l.length; i += 1) {
var v = encode.OBJECT(l[i]);
// calculate the offsets, then again to encode the offsets using the fitting data type.
let offset = 1; // First offset is always 1.
const offsets = [offset];
const data = [];
for (let i = 0; i < l.length; i += 1) {
const v = encode.OBJECT(l[i]);
Array.prototype.push.apply(data, v);

@@ -759,7 +750,7 @@ offset += v.length;

var encodedOffsets = [];
var offSize = (1 + Math.floor(Math.log(offset) / Math.log(2)) / 8) | 0;
var offsetEncoder = [undefined, encode.BYTE, encode.USHORT, encode.UINT24, encode.ULONG][offSize];
for (i = 0; i < offsets.length; i += 1) {
var encodedOffset = offsetEncoder(offsets[i]);
const encodedOffsets = [];
const offSize = (1 + Math.floor(Math.log(offset) / Math.log(2)) / 8) | 0;
const offsetEncoder = [undefined, encode.BYTE, encode.USHORT, encode.UINT24, encode.ULONG][offSize];
for (let i = 0; i < offsets.length; i += 1) {
const encodedOffset = offsetEncoder(offsets[i]);
Array.prototype.push.apply(encodedOffsets, encodedOffset);

@@ -790,10 +781,10 @@ }

encode.DICT = function(m) {
var d = [];
var keys = Object.keys(m);
var length = keys.length;
let d = [];
const keys = Object.keys(m);
const length = keys.length;
for (var i = 0; i < length; i += 1) {
for (let i = 0; i < length; i += 1) {
// Object.keys() return string keys, but our keys are always numeric.
var k = parseInt(keys[i], 0);
var v = m[k];
const k = parseInt(keys[i], 0);
const v = m[k];
// Value comes before the key.

@@ -833,5 +824,5 @@ d = d.concat(encode.OPERAND(v.value, v.type));

encode.OPERAND = function(v, type) {
var d = [];
let d = [];
if (Array.isArray(type)) {
for (var i = 0; i < type.length; i += 1) {
for (let i = 0; i < type.length; i += 1) {
check.argument(v.length === type.length, 'Not enough arguments given for type' + type);

@@ -864,3 +855,3 @@ d = d.concat(encode.OPERAND(v[i], type[i]));

// memoize charstring encoding using WeakMap if available
var wmm = typeof WeakMap === 'function' && new WeakMap();
const wmm = typeof WeakMap === 'function' && new WeakMap();

@@ -875,3 +866,3 @@ /**

if (wmm) {
var cachedValue = wmm.get(ops);
const cachedValue = wmm.get(ops);
if (cachedValue !== undefined) {

@@ -882,7 +873,7 @@ return cachedValue;

var d = [];
var length = ops.length;
let d = [];
const length = ops.length;
for (var i = 0; i < length; i += 1) {
var op = ops[i];
for (let i = 0; i < length; i += 1) {
const op = ops[i];
d = d.concat(encode[op.type](op.value));

@@ -914,3 +905,3 @@ }

encode.OBJECT = function(v) {
var encodingFunction = encode[v.type];
const encodingFunction = encode[v.type];
check.argument(encodingFunction !== undefined, 'No encoding function for type ' + v.type);

@@ -925,3 +916,3 @@ return encodingFunction(v.value);

sizeOf.OBJECT = function(v) {
var sizeOfFunction = sizeOf[v.type];
const sizeOfFunction = sizeOf[v.type];
check.argument(sizeOfFunction !== undefined, 'No sizeOf function for type ' + v.type);

@@ -939,13 +930,12 @@ return sizeOfFunction(v.value);

encode.TABLE = function(table) {
var d = [];
var length = table.fields.length;
var subtables = [];
var subtableOffsets = [];
var i;
let d = [];
const length = table.fields.length;
const subtables = [];
const subtableOffsets = [];
for (i = 0; i < length; i += 1) {
var field = table.fields[i];
var encodingFunction = encode[field.type];
for (let i = 0; i < length; i += 1) {
const field = table.fields[i];
const encodingFunction = encode[field.type];
check.argument(encodingFunction !== undefined, 'No encoding function for field type ' + field.type + ' (' + field.name + ')');
var value = table[field.name];
let value = table[field.name];
if (value === undefined) {

@@ -955,3 +945,3 @@ value = field.value;

var bytes = encodingFunction(value);
const bytes = encodingFunction(value);

@@ -967,5 +957,5 @@ if (field.type === 'TABLE') {

for (i = 0; i < subtables.length; i += 1) {
var o = subtableOffsets[i];
var offset = d.length;
for (let i = 0; i < subtables.length; i += 1) {
const o = subtableOffsets[i];
const offset = d.length;
check.argument(offset < 65536, 'Table ' + table.tableName + ' too big.');

@@ -985,10 +975,10 @@ d[o] = offset >> 8;

sizeOf.TABLE = function(table) {
var numBytes = 0;
var length = table.fields.length;
let numBytes = 0;
const length = table.fields.length;
for (var i = 0; i < length; i += 1) {
var field = table.fields[i];
var sizeOfFunction = sizeOf[field.type];
for (let i = 0; i < length; i += 1) {
const field = table.fields[i];
const sizeOfFunction = sizeOf[field.type];
check.argument(sizeOfFunction !== undefined, 'No sizeOf function for field type ' + field.type + ' (' + field.name + ')');
var value = table[field.name];
let value = table[field.name];
if (value === undefined) {

@@ -1021,4 +1011,2 @@ value = field.value;

exports.decode = decode;
exports.encode = encode;
exports.sizeOf = sizeOf;
export { decode, encode, sizeOf };

@@ -1,15 +0,13 @@

'use strict';
exports.isBrowser = function() {
function isBrowser() {
return typeof window !== 'undefined';
};
}
exports.isNode = function() {
function isNode() {
return typeof window === 'undefined';
};
}
exports.nodeBufferToArrayBuffer = function(buffer) {
var ab = new ArrayBuffer(buffer.length);
var view = new Uint8Array(ab);
for (var i = 0; i < buffer.length; ++i) {
function nodeBufferToArrayBuffer(buffer) {
const ab = new ArrayBuffer(buffer.length);
const view = new Uint8Array(ab);
for (let i = 0; i < buffer.length; ++i) {
view[i] = buffer[i];

@@ -19,8 +17,8 @@ }

return ab;
};
}
exports.arrayBufferToNodeBuffer = function(ab) {
var buffer = new Buffer(ab.byteLength);
var view = new Uint8Array(ab);
for (var i = 0; i < buffer.length; ++i) {
function arrayBufferToNodeBuffer(ab) {
const buffer = new Buffer(ab.byteLength);
const view = new Uint8Array(ab);
for (let i = 0; i < buffer.length; ++i) {
buffer[i] = view[i];

@@ -30,8 +28,10 @@ }

return buffer;
};
}
exports.checkArgument = function(expression, message) {
function checkArgument(expression, message) {
if (!expression) {
throw message;
}
};
}
export { isBrowser, isNode, nodeBufferToArrayBuffer, arrayBufferToNodeBuffer, checkArgument };

@@ -1,20 +0,15 @@

/* jshint mocha: true */
import assert from 'assert';
import { Font, Glyph, Path, loadSync } from '../src/opentype';
'use strict';
var assert = require('assert');
var opentype = require('../src/opentype');
describe('font.js', function() {
let font;
var font;
const fGlyph = new Glyph({name: 'f', unicode: 102, path: new Path()});
const iGlyph = new Glyph({name: 'i', unicode: 105, path: new Path()});
const ffGlyph = new Glyph({name: 'f_f', unicode: 0xfb01, path: new Path()});
const fiGlyph = new Glyph({name: 'f_i', unicode: 0xfb02, path: new Path()});
const ffiGlyph = new Glyph({name: 'f_f_i', unicode: 0xfb03, path: new Path()});
var fGlyph = new opentype.Glyph({ name: 'f', unicode: 102, path: new opentype.Path() });
var iGlyph = new opentype.Glyph({ name: 'i', unicode: 105, path: new opentype.Path() });
var ffGlyph = new opentype.Glyph({ name: 'f_f', unicode: 0xfb01, path: new opentype.Path() });
var fiGlyph = new opentype.Glyph({ name: 'f_i', unicode: 0xfb02, path: new opentype.Path() });
var ffiGlyph = new opentype.Glyph({ name: 'f_f_i', unicode: 0xfb03, path: new opentype.Path() });
var glyphs = [
new opentype.Glyph({ name: '.notdef', unicode: 0, path: new opentype.Path() }),
const glyphs = [
new Glyph({name: '.notdef', unicode: 0, path: new Path()}),
fGlyph, iGlyph, ffGlyph, fiGlyph, ffiGlyph

@@ -24,3 +19,3 @@ ];

beforeEach(function() {
font = new opentype.Font({
font = new Font({
familyName: 'MyFont',

@@ -48,10 +43,8 @@ styleName: 'Medium',

it('works on fonts with coverage table format 2', function() {
var vibur = opentype.loadSync('./fonts/Vibur.woff');
var glyphs = vibur.stringToGlyphs('er');
const vibur = loadSync('./fonts/Vibur.woff');
const glyphs = vibur.stringToGlyphs('er');
assert.equal(glyphs.length, 1);
assert.equal(glyphs[0].name, 'er');
});
});
});

@@ -1,15 +0,11 @@

/* jshint mocha: true */
import assert from 'assert';
import { loadSync } from '../src/opentype';
'use strict';
var assert = require('assert');
var opentype = require('../src/opentype.js');
describe('glyph.js', function() {
describe('lazy loading', function() {
var font;
var glyph;
let font;
let glyph;
before(function() {
font = opentype.loadSync('./fonts/Roboto-Black.ttf');
font = loadSync('./fonts/Roboto-Black.ttf');
glyph = font.charToGlyph('A');

@@ -40,13 +36,13 @@ });

describe('bounding box', function() {
var trueTypeFont;
var openTypeFont;
let trueTypeFont;
let openTypeFont;
before(function() {
trueTypeFont = opentype.loadSync('./fonts/Roboto-Black.ttf');
openTypeFont = opentype.loadSync('./fonts/FiraSansMedium.woff');
trueTypeFont = loadSync('./fonts/Roboto-Black.ttf');
openTypeFont = loadSync('./fonts/FiraSansMedium.woff');
});
it('calculates a box for a linear shape', function() {
var glyph = trueTypeFont.charToGlyph('A');
var box = glyph.getBoundingBox();
const glyph = trueTypeFont.charToGlyph('A');
const box = glyph.getBoundingBox();
assert.equal(box.x1, 5);

@@ -59,4 +55,4 @@ assert.equal(box.y1, 0);

it('calculates a box for a quadratic shape', function() {
var glyph = trueTypeFont.charToGlyph('Q');
var box = glyph.getBoundingBox();
const glyph = trueTypeFont.charToGlyph('Q');
const box = glyph.getBoundingBox();
assert.equal(box.x1, 89);

@@ -69,4 +65,4 @@ assert.equal(box.y1, -165);

it('calculates a box for a bezier shape', function() {
var glyph = openTypeFont.charToGlyph('Q');
var box = glyph.getBoundingBox();
const glyph = openTypeFont.charToGlyph('Q');
const box = glyph.getBoundingBox();
assert.equal(box.x1, 62);

@@ -77,4 +73,3 @@ assert.equal(box.y1, -103);

});
});
});

@@ -1,19 +0,14 @@

/* jshint mocha: true */
import assert from 'assert';
import { Font, Path, Glyph } from '../src/opentype';
import Layout from '../src/layout';
'use strict';
var assert = require('assert');
var opentype = require('../src/opentype');
var Layout = require('../src/layout');
describe('layout.js', function() {
var font;
var layout;
var notdefGlyph = new opentype.Glyph({
let font;
let layout;
const notdefGlyph = new Glyph({
name: '.notdef',
unicode: 0,
path: new opentype.Path()
path: new Path()
});
var defaultLayoutTable = {
const defaultLayoutTable = {
version: 1,

@@ -25,7 +20,7 @@ scripts: [],

var glyphs = [notdefGlyph].concat('abcdefghijklmnopqrstuvwxyz'.split('').map(function(c) {
return new opentype.Glyph({
const glyphs = [notdefGlyph].concat('abcdefghijklmnopqrstuvwxyz'.split('').map(function (c) {
return new Glyph({
name: c,
unicode: c.charCodeAt(0),
path: new opentype.Path()
path: new Path()
});

@@ -35,3 +30,3 @@ }));

beforeEach(function() {
font = new opentype.Font({
font = new Font({
familyName: 'MyFont',

@@ -66,3 +61,3 @@ styleName: 'Medium',

it('must create an new script table only on demand and if it does not exist', function() {
var scriptTable = layout.getScriptTable('DFLT', true);
const scriptTable = layout.getScriptTable('DFLT', true);
assert.notEqual(scriptTable, undefined);

@@ -69,0 +64,0 @@ assert.notEqual(scriptTable.defaultLangSys, undefined);

@@ -1,27 +0,22 @@

'use strict';
import assert from 'assert';
import { Font, Path, Glyph, load, loadSync } from '../src/opentype';
var assert = require('assert');
var mocha = require('mocha');
var describe = mocha.describe;
var it = mocha.it;
var opentype = require('../src/opentype.js');
describe('OpenType.js', function() {
describe('opentype.js', function() {
it('can load a TrueType font', function() {
var font = opentype.loadSync('./fonts/Roboto-Black.ttf');
const font = loadSync('./fonts/Roboto-Black.ttf');
assert.deepEqual(font.names.fontFamily, {en: 'Roboto Bk'});
assert.equal(font.unitsPerEm, 2048);
assert.equal(font.glyphs.length, 1037);
var aGlyph = font.charToGlyph('A');
const aGlyph = font.charToGlyph('A');
assert.equal(aGlyph.name, 'A');
assert.equal(aGlyph.unicode, 65);
assert.equal(aGlyph.path.commands.length, 18);
assert.equal(aGlyph.path.commands.length, 19);
});
it('can load a OpenType/CFF font', function() {
var font = opentype.loadSync('./fonts/FiraSansOT-Medium.otf');
const font = loadSync('./fonts/FiraSansOT-Medium.otf');
assert.deepEqual(font.names.fontFamily, {en: 'Fira Sans OT Medium'});
assert.equal(font.unitsPerEm, 1000);
assert.equal(font.glyphs.length, 1151);
var aGlyph = font.charToGlyph('A');
const aGlyph = font.charToGlyph('A');
assert.equal(aGlyph.name, 'A');

@@ -33,3 +28,3 @@ assert.equal(aGlyph.unicode, 65);

it('can load a CID-keyed font', function() {
var font = opentype.loadSync('./fonts/FDArrayTest257.otf');
const font = loadSync('./fonts/FDArrayTest257.otf');
assert.deepEqual(font.names.fontFamily, {en: 'FDArray Test 257'});

@@ -43,3 +38,3 @@ assert.deepEqual(font.tables.cff.topDict.ros, ['Adobe', 'Identity', 0]);

assert.equal(font.glyphs.length, 257);
var aGlyph = font.glyphs.get(2);
const aGlyph = font.glyphs.get(2);
assert.equal(aGlyph.name, 'gid2');

@@ -51,7 +46,7 @@ assert.equal(aGlyph.unicode, 1);

it('can load a WOFF/CFF font', function() {
var font = opentype.loadSync('./fonts/FiraSansMedium.woff');
const font = loadSync('./fonts/FiraSansMedium.woff');
assert.deepEqual(font.names.fontFamily, {en: 'Fira Sans OT'});
assert.equal(font.unitsPerEm, 1000);
assert.equal(font.glyphs.length, 1147);
var aGlyph = font.charToGlyph('A');
const aGlyph = font.charToGlyph('A');
assert.equal(aGlyph.name, 'A');

@@ -63,3 +58,3 @@ assert.equal(aGlyph.unicode, 65);

it('handles a parseBuffer error', function(done) {
opentype.load('./fonts/badfont.ttf', function(err) {
load('./fonts/badfont.ttf', function(err) {
if (err) {

@@ -72,8 +67,8 @@ done();

it('throws an error when advanceWidth is not set', function() {
var notdefGlyph = new opentype.Glyph({
const notdefGlyph = new Glyph({
name: '.notdef',
unicode: 0,
path: new opentype.Path()
path: new Path()
});
var font = new opentype.Font({
const font = new Font({
familyName: 'MyFont',

@@ -88,3 +83,2 @@ styleName: 'Medium',

});
});

@@ -1,14 +0,9 @@

/* jshint mocha: true */
import assert from 'assert';
import { unhex } from './testutil';
import { Parser } from '../src/parse';
'use strict';
var assert = require('assert');
var testutil = require('./testutil');
var Parser = require('../src/parse').Parser;
describe('parse.js', function() {
describe('parseUShortList', function() {
it('can parse an empty list', function() {
var p = new Parser(testutil.unhex('0000'), 0);
const p = new Parser(unhex('0000'), 0);
assert.deepEqual(p.parseUShortList(), []);

@@ -18,3 +13,3 @@ });

it('can parse a list', function() {
var p = new Parser(testutil.unhex('0003 1234 DEAD BEEF'), 0);
const p = new Parser(unhex('0003 1234 DEAD BEEF'), 0);
assert.deepEqual(p.parseUShortList(), [0x1234, 0xdead, 0xbeef]);

@@ -24,3 +19,3 @@ });

it('can parse a list of predefined length', function() {
var p = new Parser(testutil.unhex('1234 DEAD BEEF 5678 9ABC'), 2);
const p = new Parser(unhex('1234 DEAD BEEF 5678 9ABC'), 2);
assert.deepEqual(p.parseUShortList(3), [0xdead, 0xbeef, 0x5678]);

@@ -32,4 +27,4 @@ });

it('can parse a list of values', function() {
var data = '0003 12 34 56 78 9A BC';
var p = new Parser(testutil.unhex(data), 0);
const data = '0003 12 34 56 78 9A BC';
const p = new Parser(unhex(data), 0);
assert.deepEqual(p.parseList(Parser.uShort), [0x1234, 0x5678, 0x9abc]);

@@ -40,4 +35,4 @@ assert.equal(p.relativeOffset, 8);

it('can parse a list of values of predefined length', function() {
var data = '12 34 56 78 9A BC';
var p = new Parser(testutil.unhex(data), 0);
const data = '12 34 56 78 9A BC';
const p = new Parser(unhex(data), 0);
assert.deepEqual(p.parseList(3, Parser.uShort), [0x1234, 0x5678, 0x9abc]);

@@ -50,4 +45,4 @@ assert.equal(p.relativeOffset, 6);

it('can parse a list of records', function() {
var data = '0002 12 34 56 78 9A BC';
var p = new Parser(testutil.unhex(data), 0);
const data = '0002 12 34 56 78 9A BC';
const p = new Parser(unhex(data), 0);
assert.deepEqual(p.parseRecordList({ a: Parser.byte, b: Parser.uShort }), [

@@ -61,4 +56,4 @@ { a: 0x12, b: 0x3456 },

it('can parse an empty list of records', function() {
var data = '0000';
var p = new Parser(testutil.unhex(data), 0);
const data = '0000';
const p = new Parser(unhex(data), 0);
assert.deepEqual(p.parseRecordList({ a: Parser.byte, b: Parser.uShort }), []);

@@ -69,4 +64,4 @@ assert.equal(p.relativeOffset, 2);

it('can parse a list of records of predefined length', function() {
var data = '12 34 56 78 9A BC';
var p = new Parser(testutil.unhex(data), 0);
const data = '12 34 56 78 9A BC';
const p = new Parser(unhex(data), 0);
assert.deepEqual(p.parseRecordList(2, { a: Parser.byte, b: Parser.uShort }), [

@@ -82,7 +77,7 @@ { a: 0x12, b: 0x3456 },

it('can parse a list of lists of 16-bit integers', function() {
var data = '0003 0008 000E 0016' + // 3 lists
const data = '0003 0008 000E 0016' + // 3 lists
'0002 1234 5678' + // list 1
'0003 DEAD BEEF FADE' + // list 2
'0001 9876'; // list 3
var p = new Parser(testutil.unhex(data), 0);
const p = new Parser(unhex(data), 0);
assert.deepEqual(p.parseListOfLists(), [

@@ -96,3 +91,3 @@ [0x1234, 0x5678],

it('can parse an empty list of lists', function() {
var p = new Parser(testutil.unhex('0000'), 0);
const p = new Parser(unhex('0000'), 0);
assert.deepEqual(p.parseListOfLists(), []);

@@ -102,3 +97,3 @@ });

it('can parse list of empty lists', function() {
var p = new Parser(testutil.unhex('0001 0004 0000'), 0);
const p = new Parser(unhex('0001 0004 0000'), 0);
assert.deepEqual(p.parseListOfLists(), [[]]);

@@ -108,7 +103,7 @@ });

it('can parse a list of lists of records', function() {
var data = '0002 0006 0012' + // 2 lists
const data = '0002 0006 0012' + // 2 lists
'0002 0006 0009 12 34 56 78 9A BC' + // list 1
'0001 0004 DE F0 12'; // list 2
var p = new Parser(testutil.unhex(data), 0);
const p = new Parser(unhex(data), 0);
function parseRecord() {

@@ -128,5 +123,5 @@ return { a: p.parseByte(), b: p.parseUShort() };

// https://www.microsoft.com/typography/OTSPEC/chapter2.htm Example 5
var data = '0004 1234' + // coverageOffset + filler
const data = '0004 1234' + // coverageOffset + filler
'0001 0005 0038 003B 0041 0042 004A';
var p = new Parser(testutil.unhex(data), 4);
const p = new Parser(unhex(data), 4);
assert.deepEqual(p.parseCoverage(), {

@@ -141,5 +136,5 @@ format: 1,

// https://www.microsoft.com/typography/OTSPEC/chapter2.htm Example 6
var data = '0004 1234' + // coverageOffset + filler
const data = '0004 1234' + // coverageOffset + filler
'0002 0001 004E 0057 0000';
var p = new Parser(testutil.unhex(data), 4);
const p = new Parser(unhex(data), 4);
assert.deepEqual(p.parseCoverage(), {

@@ -156,6 +151,6 @@ format: 2,

// https://www.microsoft.com/typography/OTSPEC/chapter2.htm Example 7
var data = '0001 0032 001A' +
const data = '0001 0032 001A' +
'0000 0001 0000 0001 0000 0001 0002 0001 0000 0002 0001 0001 0000' +
'0000 0000 0002 0002 0000 0000 0001 0000 0000 0000 0000 0002 0001';
var p = new Parser(testutil.unhex(data), 0);
const p = new Parser(unhex(data), 0);
assert.deepEqual(p.parseClassDef(), {

@@ -174,4 +169,4 @@ format: 1,

// https://www.microsoft.com/typography/OTSPEC/chapter2.htm Example 8
var data = '0002 0003 0030 0031 0002 0040 0041 0003 00D2 00D3 0001';
var p = new Parser(testutil.unhex(data), 0);
const data = '0002 0003 0030 0031 0002 0040 0041 0003 00D2 00D3 0001';
const p = new Parser(unhex(data), 0);
assert.deepEqual(p.parseClassDef(), {

@@ -192,3 +187,3 @@ format: 2,

// https://www.microsoft.com/typography/OTSPEC/chapter2.htm Examples 1 & 2
var data = '0004 1234' + // coverageOffset + filler
const data = '0004 1234' + // coverageOffset + filler
'0003 68616E69 0014 6B616E61 0018 6C61746E 001C' + // Example 1

@@ -199,3 +194,3 @@ '0000 0000 0000 0000' + // 2 empty Script Tables

'0000 0003 0003 0000 0001 0002'; // UrduLangSys
var p = new Parser(testutil.unhex(data), 0);
const p = new Parser(unhex(data), 0);
assert.deepEqual(p.parseScriptList(), [

@@ -227,7 +222,7 @@ { tag: 'hani', script: { defaultLangSys: undefined, langSysRecords: [] } },

// https://www.microsoft.com/typography/OTSPEC/chapter2.htm Example 3
var data = '0004 0000' + // table offset + filler
const data = '0004 0000' + // table offset + filler
'0003 6C696761 0014 6C696761 001A 6C696761 0022' + // feature list
// There is an error in the online example, count is 3 for the 3rd feature.
'0000 0001 0000 0000 0002 0000 0001 0000 0003 0000 0001 0002';
var p = new Parser(testutil.unhex(data), 0);
const p = new Parser(unhex(data), 0);
assert.deepEqual(p.parseFeatureList(), [

@@ -245,3 +240,3 @@ { tag: 'liga', feature: { featureParams: 0, lookupListIndexes: [0] } },

// https://www.microsoft.com/typography/OTSPEC/chapter2.htm Example 4
var data = '0004 0000' + // table offset + filler
const data = '0004 0000' + // table offset + filler
'0003 0008 0010 0018' + // lookup list

@@ -254,4 +249,4 @@ '0004 000C 0001 0018' + // FfiFi lookup

'9ABC';
var lookupTableParsers = [0, 0, 0, 0, Parser.uShort];
var p = new Parser(testutil.unhex(data), 0);
const lookupTableParsers = [0, 0, 0, 0, Parser.uShort];
const p = new Parser(unhex(data), 0);
assert.deepEqual(p.parseLookupList(lookupTableParsers), [

@@ -258,0 +253,0 @@ { lookupType: 4, lookupFlag: 0x000c, subtables: [0x1234], markFilteringSet: undefined },

@@ -1,31 +0,26 @@

/* jshint mocha: true */
import assert from 'assert';
import { Font, Glyph, Path } from '../src/opentype';
import Substitution from '../src/substitution';
'use strict';
var assert = require('assert');
var opentype = require('../src/opentype');
var Substitution = require('../src/substitution');
describe('substitution.js', function() {
var font;
var substitution;
var notdefGlyph = new opentype.Glyph({
let font;
let substitution;
const notdefGlyph = new Glyph({
name: '.notdef',
unicode: 0,
path: new opentype.Path()
path: new Path()
});
var glyphs = [notdefGlyph].concat('abcdefghijklmnopqrstuvwxyz'.split('').map(function(c) {
return new opentype.Glyph({
const glyphs = [notdefGlyph].concat('abcdefghijklmnopqrstuvwxyz'.split('').map(function (c) {
return new Glyph({
name: c,
unicode: c.charCodeAt(0),
path: new opentype.Path()
path: new Path()
});
}));
var defaultScriptList = [{
const defaultScriptList = [{
tag: 'DFLT',
script: {
defaultLangSys: { reserved: 0, reqFeatureIndex: 0xffff, featureIndexes: [0] },
defaultLangSys: {reserved: 0, reqFeatureIndex: 0xffff, featureIndexes: [0]},
langSysRecords: []

@@ -36,3 +31,3 @@ }

beforeEach(function() {
font = new opentype.Font({
font = new Font({
familyName: 'MyFont',

@@ -39,0 +34,0 @@ styleName: 'Medium',

@@ -1,14 +0,9 @@

/* jshint mocha: true */
import assert from 'assert';
import { unhexArray } from './testutil';
import table from '../src/table';
'use strict';
var assert = require('assert');
var testutil = require('./testutil');
var table = require('../src/table');
describe('table.js', function() {
it('should make a ScriptList table', function() {
// https://www.microsoft.com/typography/OTSPEC/chapter2.htm Examples 1 & 2
var expectedData = testutil.unhexArray(
const expectedData = unhexArray(
'0003 68616E69 0014 6B616E61 0020 6C61746E 002E' + // Example 1 (hani, kana, latn)

@@ -54,3 +49,2 @@ '0004 0000 0000 FFFF 0001 0003' + // hani lang sys

});
});

@@ -1,12 +0,7 @@

'use strict';
import assert from 'assert';
import { hex, unhex } from '../testutil';
import fvar from '../../src/tables/fvar';
var assert = require('assert');
var mocha = require('mocha');
var describe = mocha.describe;
var it = mocha.it;
var testutil = require('../testutil.js');
var fvar = require('../../src/tables/fvar.js');
describe('tables/fvar.js', function() {
var data =
const data =
'00 01 00 00 00 10 00 02 00 02 00 14 00 02 00 0C ' +

@@ -18,3 +13,3 @@ '77 67 68 74 00 64 00 00 01 90 00 00 03 84 00 00 00 00 01 01 ' +

var table = {
const table = {
axes: [

@@ -49,3 +44,3 @@ {

it('can parse a font variations table', function() {
var names = {
const names = {
257: {en: 'Weight', ja: 'ウエイト'},

@@ -56,7 +51,7 @@ 258: {en: 'Width', ja: '幅'},

};
assert.deepEqual(table, fvar.parse(testutil.unhex(data), 0, names));
assert.deepEqual(table, fvar.parse(unhex(data), 0, names));
});
it('can make a font variations table', function() {
var names = {
const names = {
// When assigning name IDs, numbers below 256 should be ignored,

@@ -73,3 +68,3 @@ // as these are not valid IDs of ‘fvar’ axis or instance names.

};
assert.deepEqual(data, testutil.hex(fvar.make(table, names).encode()));
assert.deepEqual(data, hex(fvar.make(table, names).encode()));
assert.deepEqual(names, {

@@ -76,0 +71,0 @@ 111: {en: 'Name #111'},

@@ -1,12 +0,8 @@

/* jshint mocha: true */
import assert from 'assert';
import { unhex, unhexArray } from '../testutil';
import gsub from '../../src/tables/gsub';
'use strict';
var assert = require('assert');
var testutil = require('../testutil');
var gsub = require('../../src/tables/gsub');
// Helper that builds a minimal GSUB table to test a lookup subtable.
function parseLookup(lookupType, subTableData) {
var data = testutil.unhex('00010000 000A 000C 000E' + // header
const data = unhex('00010000 000A 000C 000E' + // header
'0000' + // ScriptTable - 0 scripts

@@ -34,6 +30,5 @@ '0000' + // FeatureListTable - 0 features

describe('tables/gsub.js', function() {
//// Header ///////////////////////////////////////////////////////////////
it('can parse a GSUB header', function() {
var data = testutil.unhex(
const data = unhex(
'00010000 000A 000C 000E' + // header

@@ -50,3 +45,3 @@ '0000' + // ScriptTable - 0 scripts

// https://www.microsoft.com/typography/OTSPEC/GSUB.htm#EX2
var data = '0001 0006 00C0 0002 0001 004E 0058 0000';
const data = '0001 0006 00C0 0002 0001 004E 0058 0000';
assert.deepEqual(parseLookup(1, data), {

@@ -64,3 +59,3 @@ substFormat: 1,

// https://www.microsoft.com/typography/OTSPEC/GSUB.htm#EX3
var data = '0002 000E 0004 0131 0135 013E 0143 0001 0004 003C 0040 004B 004F';
const data = '0002 000E 0004 0131 0135 013E 0143 0001 0004 003C 0040 004B 004F';
assert.deepEqual(parseLookup(1, data), {

@@ -79,3 +74,3 @@ substFormat: 2,

// https://www.microsoft.com/typography/OTSPEC/GSUB.htm#EX4
var data = '0001 0008 0001 000E 0001 0001 00F1 0003 001A 001A 001D';
const data = '0001 0008 0001 000E 0001 0001 00F1 0003 001A 001A 001D';
assert.deepEqual(parseLookup(2, data), {

@@ -96,3 +91,3 @@ substFormat: 1,

// https://www.microsoft.com/typography/OTSPEC/GSUB.htm#EX5
var data = '0001 0008 0001 000E 0001 0001 003A 0002 00C9 00CA';
const data = '0001 0008 0001 000E 0001 0001 003A 0002 00C9 00CA';
assert.deepEqual(parseLookup(3, data), {

@@ -113,3 +108,3 @@ substFormat: 1,

// https://www.microsoft.com/typography/OTSPEC/GSUB.htm#EX6
var data = '0001 000A 0002 0014 0020' + // LigatureSubstFormat1
const data = '0001 000A 0002 0014 0020' + // LigatureSubstFormat1
'0002 0001 0019 001A 0000' + // coverage format 2

@@ -139,3 +134,3 @@ '0001 0004 015B 0003 0028 0017' + // Ligature set "etc"

// https://www.microsoft.com/typography/OTSPEC/GSUB.htm#EX7
var data = '0001 000A 0002 0012 0020' + // ContextSubstFormat1
const data = '0001 000A 0002 0012 0020' + // ContextSubstFormat1
'0001 0002 0028 005D' + // coverage format 1

@@ -160,3 +155,3 @@ '0001 0004 0002 0001 005D 0000 0001' + // sub rule set "space and dash"

// https://www.microsoft.com/typography/OTSPEC/GSUB.htm#EX8
var data = '0002 0010 001C 0004 0000 0000 0032 0040' + // ContextSubstFormat2
const data = '0002 0010 001C 0004 0000 0000 0032 0040' + // ContextSubstFormat2
'0001 0004 0030 0031 0040 0041' + // coverage format 1

@@ -193,3 +188,3 @@ '0002 0003 0030 0031 0002 0040 0041 0003 00D2 00D3 0001' + // class def format 2

// var data = '0003 0003 0002 0030 004C 006E 0000 0001 0002 0002'
var data = '0003 0003 0002 0014 0030 0052 0000 0001 0002 0002' + // ContextSubstFormat3
const data = '0003 0003 0002 0014 0030 0052 0000 0001 0002 0002' + // ContextSubstFormat3
'0001 000C 0033 0035 0037 0038 0039 003B 003C 003D 0041 0042 0045 004A' + // coverage format 1

@@ -230,3 +225,3 @@ '0001 000F 0032 0034 0036 003A 003E 003F 0040 0043 0044 0045 0046 0047 0048 0049 004B' + // coverage format 1

// since there is an offset (NULL) to BacktrackCoverage[0]
var data = '0001 0068 0001 0000 0001 0026 000C 00A7 00B9 00C5 00D4 00EA 00F2 00FD 010D 011B 012B 013B 0141' + // ReverseChainSingleSubstFormat1
const data = '0001 0068 0001 0000 0001 0026 000C 00A7 00B9 00C5 00D4 00EA 00F2 00FD 010D 011B 012B 013B 0141' + // ReverseChainSingleSubstFormat1
'0001 001F 00A5 00A9 00AA 00E2 0167 0168 0169 016D 016E 0170 0183' + // coverage format 1

@@ -237,3 +232,3 @@ '0184 0185 0189 018A 018C019F 01A0 01A1 01A2 01A3 01A4 01A5 01A6' +

var parsed = parseLookup(8, data);
const parsed = parseLookup(8, data);
assert.deepEqual(parsed, {

@@ -260,3 +255,3 @@ substFormat: 1,

it('should write a simple GSUB table + lookup type 4', function() {
var expectedData = testutil.unhexArray(
const expectedData = unhexArray(
'00 01 00 00 00 0A 00 1E 00 2C 00 01 44 46 4C 54 00 08 00 04 00 00 00 00 FF FF 00 01 00 00 00 01' +

@@ -268,3 +263,3 @@ '6C 69 67 61 00 08 00 00 00 01 00 00 00 01 00 04 00 04 00 00 00 01 00 08 00 01 00 0A 00 02 00 12' +

var gsubTable = {
const gsubTable = {
version: 1,

@@ -274,7 +269,7 @@ scripts: [{

script: {
defaultLangSys: { reserved: 0, reqFeatureIndex: 65535, featureIndexes: [0] },
defaultLangSys: {reserved: 0, reqFeatureIndex: 65535, featureIndexes: [0]},
langSysRecords: []
}
}],
features: [{ tag: 'liga', feature: { featureParams: 0, lookupListIndexes: [0] } }],
features: [{tag: 'liga', feature: {featureParams: 0, lookupListIndexes: [0]}}],
lookups: [{

@@ -285,3 +280,3 @@ lookupType: 4,

substFormat: 1,
coverage: { format: 1, glyphs: [24, 26] },
coverage: {format: 1, glyphs: [24, 26]},
ligatureSets: [

@@ -305,3 +300,3 @@ [

it('can write lookup1 substFormat 1', function() {
var expectedData = testutil.unhexArray('0001 0006 00C0 0001 0004 003C 0040 004B 004F');
const expectedData = unhexArray('0001 0006 00C0 0001 0004 003C 0040 004B 004F');
assert.deepEqual(makeLookup(1, {

@@ -319,3 +314,3 @@ substFormat: 1,

// https://www.microsoft.com/typography/OTSPEC/GSUB.htm#EX3
var expectedData = testutil.unhexArray('0002 000E 0004 0131 0135 013E 0143 0001 0004 003C 0040 004B 004F');
const expectedData = unhexArray('0002 000E 0004 0131 0135 013E 0143 0001 0004 003C 0040 004B 004F');
assert.deepEqual(makeLookup(1, {

@@ -334,3 +329,3 @@ substFormat: 2,

// https://www.microsoft.com/typography/OTSPEC/GSUB.htm#EX5
var expectedData = testutil.unhexArray('0001 0008 0001 000E 0001 0001 003A 0002 00C9 00CA');
const expectedData = unhexArray('0001 0008 0001 000E 0001 0001 003A 0002 00C9 00CA');
assert.deepEqual(makeLookup(3, {

@@ -337,0 +332,0 @@ substFormat: 1,

@@ -1,13 +0,8 @@

'use strict';
import assert from 'assert';
import { unhex } from '../testutil';
import loca from '../../src/tables/loca';
var assert = require('assert');
var mocha = require('mocha');
var describe = mocha.describe;
var it = mocha.it;
var testutil = require('../testutil.js');
var loca = require('../../src/tables/loca.js');
describe('tables/loca.js', function() {
it('can parse the short version', function() {
var data = testutil.unhex('DEAD BEEF 0010 0100 80CE');
const data = unhex('DEAD BEEF 0010 0100 80CE');
assert.deepEqual([32, 512, 2 * 0x80ce], loca.parse(data, 4, 2, true));

@@ -17,5 +12,5 @@ });

it('can parse the long version', function() {
var data = testutil.unhex('DEADBEEF 00000010 00000100 ABCD5678');
const data = unhex('DEADBEEF 00000010 00000100 ABCD5678');
assert.deepEqual([0x10, 0x100, 0xabcd5678], loca.parse(data, 4, 2, false));
});
});

@@ -1,12 +0,7 @@

'use strict';
import assert from 'assert';
import { hex, unhex } from '../testutil';
import ltag from '../../src/tables/ltag';
var assert = require('assert');
var mocha = require('mocha');
var describe = mocha.describe;
var it = mocha.it;
var testutil = require('../testutil.js');
var ltag = require('../../src/tables/ltag.js');
describe('tables/ltag.js', function() {
var data =
const data =
'00 00 00 01 00 00 00 00 00 00 00 04 00 1C 00 02 ' +

@@ -16,11 +11,11 @@ '00 1E 00 07 00 1E 00 02 00 25 00 13 65 6E 7A 68 ' +

'6C 62 61 2D 31 39 39 34';
var tags = ['en', 'zh-Hant', 'zh', 'sl-rozaj-solba-1994'];
const tags = ['en', 'zh-Hant', 'zh', 'sl-rozaj-solba-1994'];
it('can make a language tag table', function() {
assert.deepEqual(data, testutil.hex(ltag.make(tags).encode()));
assert.deepEqual(data, hex(ltag.make(tags).encode()));
});
it('can parse a language tag table', function() {
assert.deepEqual(tags, ltag.parse(testutil.unhex('DE AD BE EF ' + data), 4));
assert.deepEqual(tags, ltag.parse(unhex('DE AD BE EF ' + data), 4));
});
});

@@ -1,17 +0,11 @@

'use strict';
import assert from 'assert';
import { hex, unhex } from '../testutil';
import meta from '../../src/tables/meta';
var assert = require('assert');
var mocha = require('mocha');
var describe = mocha.describe;
var it = mocha.it;
var testutil = require('../testutil.js');
var meta = require('../../src/tables/meta.js');
// Based on https://github.com/behdad/fonttools/blob/a5968458015b519bc415f3ca7d882a428f45c347/Lib/fontTools/ttLib/tables/_m_e_t_a_test.py
describe('tables/meta.js', function() {
// The 'dlng' and 'slng' tag with text data containing "augmented" BCP 47
// comma-separated or comma-space-separated tags. These should be UTF-8 encoded
// text.
var data =
const data =
'00 00 00 01 00 00 00 00 00 00 00 28 00 00 00 02 ' +

@@ -26,11 +20,11 @@ '64 6C 6E 67 ' + // dlng

it('can parse meta table', function() {
var obj = {
const obj = {
dlng: 'Latn,Grek,Cyrl',
slng: 'Latn,Grek,Cyrl'
};
assert.deepEqual(obj, meta.parse(testutil.unhex(data), 0));
assert.deepEqual(obj, meta.parse(unhex(data), 0));
});
it('can make meta table', function() {
var obj = {
const obj = {
dlng: 'Latn,Grek,Cyrl',

@@ -40,7 +34,6 @@ slng: 'Latn,Grek,Cyrl'

var hex = testutil.hex(meta.make(obj).encode());
meta.parse(testutil.unhex(hex), 0);
assert.deepEqual(data, hex);
const hexString = hex(meta.make(obj).encode());
meta.parse(unhex(hexString), 0);
assert.deepEqual(data, hexString);
});
});

@@ -1,12 +0,7 @@

'use strict';
import assert from 'assert';
import table from '../../src/table';
import { encode } from '../../src/types';
import _name from '../../src/tables/name';
import { hex, unhex } from '../testutil';
var assert = require('assert');
var mocha = require('mocha');
var describe = mocha.describe;
var it = mocha.it;
var table = require('../../src/table');
var testutil = require('../testutil');
var types = require('../../src/types');
var _name = require('../../src/tables/name');
// For testing, we need a custom function that builds name tables.

@@ -21,3 +16,3 @@ // The public name.make() API of opentype.js is hiding the complexity

function makeNameTable(names) {
var t = new table.Table('name', [
const t = new table.Table('name', [
{name: 'format', type: 'USHORT', value: 0},

@@ -27,7 +22,7 @@ {name: 'count', type: 'USHORT', value: names.length},

]);
var stringPool = [];
const stringPool = [];
for (var i = 0; i < names.length; i++) {
var name = names[i];
var text = testutil.unhex(name[1]);
for (let i = 0; i < names.length; i++) {
const name = names[i];
const text = unhex(name[1]);
t.fields.push({name: 'platformID_' + i, type: 'USHORT', value: name[2]});

@@ -39,3 +34,3 @@ t.fields.push({name: 'encodingID_' + i, type: 'USHORT', value: name[3]});

t.fields.push({name: 'offset_' + i, type: 'USHORT', value: stringPool.length});
for (var j = 0; j < text.byteLength; j++) {
for (let j = 0; j < text.byteLength; j++) {
stringPool.push(text.getUint8(j));

@@ -47,5 +42,5 @@ }

var bytes = types.encode.TABLE(t);
var data = new DataView(new ArrayBuffer(bytes.length), 0);
for (var k = 0; k < bytes.length; k++) {
const bytes = encode.TABLE(t);
const data = new DataView(new ArrayBuffer(bytes.length), 0);
for (let k = 0; k < bytes.length; k++) {
data.setUint8(k, bytes[k]);

@@ -62,16 +57,16 @@ }

function getNameRecords(names) {
var result = [];
var stringPool = names.fields[names.fields.length - 1];
const result = [];
const stringPool = names.fields[names.fields.length - 1];
assert(stringPool.name === 'strings');
for (var i = 0; i < names.fields.length; i++) {
var field = names.fields[i];
for (let i = 0; i < names.fields.length; i++) {
const field = names.fields[i];
if (field.name.indexOf('record_') === 0) {
var name = field.value;
var encodedText =
const name = field.value;
const encodedText =
stringPool.value.slice(name.offset, name.offset + name.length);
var plat =
const plat =
{0: 'Uni', 1: 'Mac', 2: 'ISO', 3: 'Win'}[name.platformID] ||
name.platormID;
var enc;
var lang;
let enc;
let lang;
if (name.platformID === 0) {

@@ -102,6 +97,6 @@ enc = {3: 'UCS-2', 4: 'UTF-16'}[name.encodingID];

result.push(plat + ' ' + (enc ? enc : name.encodingID) +
' ' + (lang ? lang : name.languageID) +
result.push(plat + ' ' + (enc || name.encodingID) +
' ' + (lang || name.languageID) +
' N' + name.nameID +
' [' + testutil.hex(encodedText) + ']');
' [' + hex(encodedText) + ']');
}

@@ -143,3 +138,3 @@ }

it('can parse a naming table which refers to an ‘ltag’ table', function() {
var ltag = ['en', 'de', 'de-1901'];
const ltag = ['en', 'de', 'de-1901'];
assert.deepEqual(parseNameTable([

@@ -172,3 +167,3 @@ [1, '0057 0061 006C 0072 0075 0073', 0, 4, 0],

// so we exercise the building of string pools;
var names = {
const names = {
fontFamily: {

@@ -180,3 +175,3 @@ en: 'Walrus',

};
var ltag = [];
const ltag = [];
assert.deepEqual(getNameRecords(_name.make(names, ltag)), [

@@ -198,3 +193,3 @@ 'Mac smRoman langEnglish N1 [57 61 6C 72 75 73]',

// but MacOS does not.
var names = {
const names = {
fontFamily: {

@@ -205,3 +200,3 @@ 'de-1901': 'Walroß',

};
var ltag = [];
const ltag = [];
assert.deepEqual(getNameRecords(_name.make(names, ltag)), [

@@ -221,3 +216,3 @@ 'Uni UTF-16 0 N1 [00 57 00 61 00 6C 00 72 00 6F 00 DF]',

// recognize it but this is better than stripping the string away.
var names = {
const names = {
fontFamily: {

@@ -227,3 +222,3 @@ ja: '海馬'

};
var ltag = [];
const ltag = [];
assert.deepEqual(getNameRecords(_name.make(names, ltag)), [

@@ -239,3 +234,3 @@ 'Uni UTF-16 0 N1 [6D 77 99 AC]',

// building a name table, this case should be handled gracefully.
var names = {
const names = {
fontFamily: {

@@ -245,3 +240,3 @@ en: 'Hello‽'

};
var ltag = [];
const ltag = [];
assert.deepEqual(getNameRecords(_name.make(names, ltag)), [

@@ -260,3 +255,3 @@ 'Uni UTF-16 0 N1 [00 48 00 65 00 6C 00 6C 00 6F 20 3D]',

// corner cases (Inuktitut is not the only one), and this test exercises it.
var names = {
const names = {
fontFamily: {

@@ -266,3 +261,3 @@ iu: 'ᐊᐃᕕᖅ'

};
var ltag = [];
const ltag = [];
assert.deepEqual(getNameRecords(_name.make(names, ltag)), [

@@ -277,3 +272,3 @@ 'Mac smEthiopic langInuktitut N1 [84 80 CD E7]',

// Custom name for a font variation axis.
var names = {
const names = {
256: {

@@ -284,3 +279,3 @@ en: 'Width',

};
var ltag = [];
const ltag = [];
assert.deepEqual(getNameRecords(_name.make(names, ltag)), [

@@ -287,0 +282,0 @@ 'Mac smRoman langEnglish N256 [57 69 64 74 68]',

@@ -1,7 +0,5 @@

'use strict';
var hex = function(bytes) {
var values = [];
for (var i = 0; i < bytes.length; i++) {
var b = bytes[i];
function hex(bytes) {
const values = [];
for (let i = 0; i < bytes.length; i++) {
const b = bytes[i];
if (b < 16) {

@@ -15,9 +13,9 @@ values.push('0' + b.toString(16));

return values.join(' ').toUpperCase();
};
}
var unhex = function(str) {
function unhex(str) {
str = str.split(' ').join('');
var len = str.length / 2;
var data = new DataView(new ArrayBuffer(len), 0);
for (var i = 0; i < len; i++) {
const len = str.length / 2;
const data = new DataView(new ArrayBuffer(len), 0);
for (let i = 0; i < len; i++) {
data.setUint8(i, parseInt(str.slice(i * 2, i * 2 + 2), 16));

@@ -27,8 +25,8 @@ }

return data;
};
}
exports.hex = hex;
exports.unhex = unhex;
exports.unhexArray = function(str) {
function unhexArray(str) {
return Array.prototype.slice.call(new Uint8Array(unhex(str).buffer));
};
}
export { hex, unhex, unhexArray };

@@ -1,15 +0,5 @@

'use strict';
import assert from 'assert';
import { hex, unhex } from './testutil';
import { decode, encode, sizeOf } from '../src/types';
var assert = require('assert');
var mocha = require('mocha');
var describe = mocha.describe;
var it = mocha.it;
var testutil = require('./testutil.js');
var hex = testutil.hex;
var unhex = testutil.unhex;
var types = require('../src/types.js');
var decode = types.decode;
var encode = types.encode;
var sizeOf = types.sizeOf;
describe('types.js', function() {

@@ -211,4 +201,4 @@ it('can handle BYTE', function() {

it('can handle MACSTRING in Central European encoding', function() {
var encoding = 'x-mac-ce';
var data = '42 65 74 F5 74 92 70 75 73';
const encoding = 'x-mac-ce';
const data = '42 65 74 F5 74 92 70 75 73';

@@ -228,4 +218,4 @@ assert.equal(

it('can handle MACSTRING in Croatian encoding', function() {
var encoding = 'x-mac-croatian';
var data = 'A9 74 61 6D 70 61 E8';
const encoding = 'x-mac-croatian';
const data = 'A9 74 61 6D 70 61 E8';

@@ -245,4 +235,4 @@ assert.equal(

it('can handle MACSTRING in Cyrillic encoding', function() {
var encoding = 'x-mac-cyrillic';
var data = '98 F0 E8 F4 F2 20 46 6F 6F';
const encoding = 'x-mac-cyrillic';
const data = '98 F0 E8 F4 F2 20 46 6F 6F';

@@ -262,4 +252,4 @@ assert.equal(

it('can handle MACSTRING in Gaelic encoding', function() {
var encoding = 'x-mac-gaelic';
var data = '44 9C 69 E0 B6 92';
const encoding = 'x-mac-gaelic';
const data = '44 9C 69 E0 B6 92';

@@ -279,4 +269,4 @@ assert.equal(

it('can handle MACSTRING in Greek encoding', function() {
var encoding = 'x-mac-greek';
var data = 'A1 F2 E1 ED ED E1 F4 EF F3 E5 E9 F2 C0 20 2E 85 2E';
const encoding = 'x-mac-greek';
const data = 'A1 F2 E1 ED ED E1 F4 EF F3 E5 E9 F2 C0 20 2E 85 2E';

@@ -296,4 +286,4 @@ assert.equal(

it('can handle MACSTRING in Icelandic encoding', function() {
var encoding = 'x-mac-icelandic';
var data = 'DE 97 72 69 73 64 97 74 74 69 72 20 DF 97 20 61 DD 8E 67';
const encoding = 'x-mac-icelandic';
const data = 'DE 97 72 69 73 64 97 74 74 69 72 20 DF 97 20 61 DD 8E 67';

@@ -313,4 +303,4 @@ assert.equal(

it('can handle MACSTRING in Inuit encoding', function() {
var encoding = 'x-mac-inuit';
var data = '8A 80 8C 8B AB DA CC C6 93';
const encoding = 'x-mac-inuit';
const data = '8A 80 8C 8B AB DA CC C6 93';

@@ -330,4 +320,4 @@ assert.equal(

it('can handle MACSTRING in Roman encoding', function() {
var encoding = 'macintosh';
var data = '86 65 74 6C 69 62 8A 72 67';
const encoding = 'macintosh';
const data = '86 65 74 6C 69 62 8A 72 67';

@@ -347,4 +337,4 @@ assert.equal(

it('can handle MACSTRING in Romanian encoding', function() {
var encoding = 'x-mac-romanian';
var data = '54 69 70 BE 72 69 72 65';
const encoding = 'x-mac-romanian';
const data = '54 69 70 BE 72 69 72 65';

@@ -364,4 +354,4 @@ assert.equal(

it('can handle MACSTRING in Turkish encoding', function() {
var encoding = 'x-mac-turkish';
var data = '42 61 73 DD 6C 6D DD DF';
const encoding = 'x-mac-turkish';
const data = '42 61 73 DD 6C 6D DD DF';

@@ -381,3 +371,3 @@ assert.equal(

it('rejects MACSTRING in unsupported encodings', function() {
var encoding = 'KOI8-R';
const encoding = 'KOI8-R';
assert.equal(decode.MACSTRING(unhex('41 42'), 0, 1, encoding), undefined);

@@ -392,4 +382,4 @@ assert.equal(encode.MACSTRING('AB', encoding), undefined);

var foo = {name: 'foo', type: 'STRING', value: 'hello'};
var bar = {name: 'bar', type: 'NUMBER', value: 23};
const foo = {name: 'foo', type: 'STRING', value: 'hello'};
const bar = {name: 'bar', type: 'NUMBER', value: 23};
assert.equal(hex(encode.INDEX([foo, bar])),

@@ -404,4 +394,4 @@ '00 02 01 01 06 07 68 65 6C 6C 6F A2');

var foo = {name: 'foo', type: 'number', value: -1131};
var bar = {name: 'bar', type: 'number', value: 1131};
const foo = {name: 'foo', type: 'number', value: -1131};
const bar = {name: 'bar', type: 'number', value: 1131};
assert.equal(hex(encode.DICT({7: foo, 42: bar})), 'FE FF 07 FA FF 2A');

@@ -440,7 +430,7 @@ assert.equal(sizeOf.DICT({7: foo, 42: bar}), 6);

// the result seems a little short.
var ops = [
{name: 'width', type: 'NUMBER', value: 42},
{name: 'dx', type: 'NUMBER', value: 17},
{name: 'dy', type: 'NUMBER', value: -23},
{name: 'rlineto', type: 'OP', value: 5}
const ops = [
{name: 'width', type: 'NUMBER', value: 42},
{name: 'dx', type: 'NUMBER', value: 17},
{name: 'dy', type: 'NUMBER', value: -23},
{name: 'rlineto', type: 'OP', value: 5}
];

@@ -456,3 +446,3 @@

it('can handle OBJECT', function() {
var obj = {type: 'TAG', value: 'Font'};
const obj = {type: 'TAG', value: 'Font'};
assert.equal(hex(encode.OBJECT(obj)), '46 6F 6E 74');

@@ -463,3 +453,3 @@ assert.equal(sizeOf.OBJECT(obj), 4);

it('can handle TABLE', function() {
var table = {
const table = {
fields: [

@@ -475,10 +465,12 @@ {name: 'version', type: 'FIXED', value: 0x01234567},

it('can handle subTABLEs', function() {
var table = {
const table = {
fields: [
{name: 'version', type: 'FIXED', value: 0x01234567},
{name: 'subtable', type: 'TABLE', value: {
fields: [
{name: 'flags', type: 'USHORT', value: 0xBEEF}
]
}}
{
name: 'subtable', type: 'TABLE', value: {
fields: [
{name: 'flags', type: 'USHORT', value: 0xBEEF}
]
}
}
]

@@ -492,7 +484,7 @@ };

// First 58 bytes of Roboto-Black.ttf GSUB table.
var expected = '00 01 00 00 00 0A 00 20 00 3A ' + // header
const expected = '00 01 00 00 00 0A 00 20 00 3A ' + // header
'00 01 44 46 4C 54 00 08 00 04 00 00 00 00 FF FF 00 02 00 00 00 01 ' + // script list
'00 02 6C 69 67 61 00 0E 73 6D 63 70 00 14 00 00 00 01 00 01 00 00 00 01 00 00'; // feature list
var table = {
const table = {
fields: [

@@ -504,32 +496,52 @@ {name: 'version', type: 'FIXED', value: 0x00010000},

],
scriptList: { fields: [
{name: 'scriptCount', type: 'USHORT', value: 1},
{name: 'scriptTag_0', type: 'TAG', value: 'DFLT'},
{name: 'script_0', type: 'TABLE', value: { fields: [
{name: 'defaultLangSys', type: 'TABLE', value: { fields: [
{name: 'lookupOrder', type: 'USHORT', value: 0},
{name: 'reqFeatureIndex', type: 'USHORT', value: 0xffff},
{name: 'featureCount', type: 'USHORT', value: 2},
{name: 'featureIndex_0', type: 'USHORT', value: 0},
{name: 'featureIndex_1', type: 'USHORT', value: 1}
]}},
{name: 'langSysCount', type: 'USHORT', value: 0}
]}}
]},
featureList: { fields: [
{name: 'featureCount', type: 'USHORT', value: 2},
{name: 'featureTag_0', type: 'TAG', value: 'liga'},
{name: 'feature_0', type: 'TABLE', value: { fields: [
{name: 'featureParams', type: 'USHORT', value: 0},
{name: 'lookupCount', type: 'USHORT', value: 1},
{name: 'lookupListIndex', type: 'USHORT', value: 1}
]}},
{name: 'featureTag_1', type: 'TAG', value: 'smcp'},
{name: 'feature_1', type: 'TABLE', value: { fields: [
{name: 'featureParams', type: 'USHORT', value: 0},
{name: 'lookupCount', type: 'USHORT', value: 1},
{name: 'lookupListIndex', type: 'USHORT', value: 0}
]}}
]},
lookupList: { fields: [] }
scriptList: {
fields: [
{name: 'scriptCount', type: 'USHORT', value: 1},
{name: 'scriptTag_0', type: 'TAG', value: 'DFLT'},
{
name: 'script_0', type: 'TABLE', value: {
fields: [
{
name: 'defaultLangSys', type: 'TABLE', value: {
fields: [
{name: 'lookupOrder', type: 'USHORT', value: 0},
{name: 'reqFeatureIndex', type: 'USHORT', value: 0xffff},
{name: 'featureCount', type: 'USHORT', value: 2},
{name: 'featureIndex_0', type: 'USHORT', value: 0},
{name: 'featureIndex_1', type: 'USHORT', value: 1}
]
}
},
{name: 'langSysCount', type: 'USHORT', value: 0}
]
}
}
]
},
featureList: {
fields: [
{name: 'featureCount', type: 'USHORT', value: 2},
{name: 'featureTag_0', type: 'TAG', value: 'liga'},
{
name: 'feature_0', type: 'TABLE', value: {
fields: [
{name: 'featureParams', type: 'USHORT', value: 0},
{name: 'lookupCount', type: 'USHORT', value: 1},
{name: 'lookupListIndex', type: 'USHORT', value: 1}
]
}
},
{name: 'featureTag_1', type: 'TAG', value: 'smcp'},
{
name: 'feature_1', type: 'TABLE', value: {
fields: [
{name: 'featureParams', type: 'USHORT', value: 0},
{name: 'lookupCount', type: 'USHORT', value: 1},
{name: 'lookupListIndex', type: 'USHORT', value: 0}
]
}
}
]
},
lookupList: {fields: []}
};

@@ -542,3 +554,3 @@

it('can handle RECORD', function() {
var table = {
const table = {
fields: [

@@ -570,3 +582,5 @@ {name: 'version', type: 'FIXED', value: 0x01234567},

it('can encode VARDELTAS', function() {
var e = function(deltas) { return hex(encode.VARDELTAS(deltas)); };
const e = function (deltas) {
return hex(encode.VARDELTAS(deltas));
};
assert.equal(e([]), '');

@@ -626,5 +640,5 @@

assert.equal(e([0x6666, 2, 0x7777]), '42 66 66 00 02 77 77');
// multiple byte-encodable words are more compated when forming their own run
// multiple byte-encodable words are more compacted when forming their own run
assert.equal(e([0x6666, 2, 2, 0x7777]), '40 66 66 01 02 02 40 77 77');
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc