Socket
Socket
Sign inDemoInstall

opentype.js

Package Overview
Dependencies
2
Maintainers
2
Versions
47
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.3.3 to 1.3.4

src/tables/gdef.js

4

package.json
{
"name": "opentype.js",
"description": "OpenType font parser",
"version": "1.3.3",
"version": "1.3.4",
"author": {

@@ -70,2 +70,2 @@ "name": "Frederik De Bleser",

}
}
}
# opentype.js · [![Build Status](https://img.shields.io/travis/opentypejs/opentype.js.svg?style=flat-square)](https://travis-ci.org/opentypejs/opentype.js) [![npm](https://img.shields.io/npm/v/opentype.js.svg?style=flat-square)](https://www.npmjs.com/package/opentype.js) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://github.com/opentypejs/opentype.js/blob/master/LICENSE) [![david-dm](https://david-dm.org/opentypejs/opentype.js.svg)](https://david-dm.org/opentypejs/opentype.js) [![Gitter](https://badges.gitter.im/opentypejs/opentype.js.svg)](https://gitter.im/opentypejs/opentype.js)
# opentype.js · [![Build Status](https://travis-ci.org/opentypejs/opentype.js.svg?branch=master)](https://travis-ci.org/opentypejs/opentype.js) [![npm](https://img.shields.io/npm/v/opentype.js.svg?style=flat-square)](https://www.npmjs.com/package/opentype.js) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://github.com/opentypejs/opentype.js/blob/master/LICENSE) [![david-dm](https://david-dm.org/opentypejs/opentype.js.svg)](https://david-dm.org/opentypejs/opentype.js)

@@ -28,9 +28,11 @@ opentype.js is a JavaScript parser and writer for TrueType and OpenType fonts.

npm install opentype.js
```js
const opentype = require('opentype.js');
const opentype = require('opentype.js');
import opentype from 'opentype.js'
import opentype from 'opentype.js'
import { load } from 'opentype.js'
```
import { load } from 'opentype.js'
Using TypeScript? [See this example](examples/typescript)

@@ -37,0 +39,0 @@

@@ -0,1 +1,6 @@

1.3.4 (October 8, 2021)
=====================
* fix Quadratic to Cubic rounding issue in Glyph to CFF Ops stage (#468)
* update dependencies with `npm audit fix`
1.3.3 (April 20, 2020)

@@ -9,3 +14,3 @@ =====================

* 1.3.1 (April 13, 2020)
1.3.1 (April 13, 2020)
=====================

@@ -162,3 +167,3 @@ * Revert Fix Path.toPathData and Path.toSVG - X Axis is flipped (#369)

* Better API documentation using [JSDoc](http://usejsdoc.org/).
* Accessing xMin/... metrics works before path load.

* Accessing xMin/... metrics works before path load.

@@ -165,0 +170,0 @@ 0.6.4 (June 30, 2016)

@@ -21,2 +21,3 @@ // opentype.js

import glyf from './tables/glyf';
import gdef from './tables/gdef';
import gpos from './tables/gpos';

@@ -215,2 +216,3 @@ import gsub from './tables/gsub';

let glyfTableEntry;
let gdefTableEntry;
let gposTableEntry;

@@ -301,2 +303,5 @@ let gsubTableEntry;

break;
case 'GDEF':
gdefTableEntry = tableEntry;
break;
case 'GPOS':

@@ -342,2 +347,7 @@ gposTableEntry = tableEntry;

if (gdefTableEntry) {
const gdefTable = uncompressTable(data, gdefTableEntry);
font.tables.gdef = gdef.parse(gdefTable.data, gdefTable.offset);
}
if (gposTableEntry) {

@@ -379,4 +389,5 @@ const gposTable = uncompressTable(data, gposTableEntry);

function load(url, callback, opt) {
opt = (opt === undefined || opt === null) ? {} : opt;
const isNode = typeof window === 'undefined';
const loadFn = isNode ? loadFromFile : loadFromUrl;
const loadFn = isNode && !opt.isUrl ? loadFromFile : loadFromUrl;

@@ -383,0 +394,0 @@ return new Promise((resolve, reject) => {

@@ -100,2 +100,29 @@ // The Substitution object provides utility methods to manipulate

/**
* List all multiple substitutions (lookup type 2) for a given script, language, and feature.
* @param {string} [script='DFLT']
* @param {string} [language='dflt']
* @param {string} feature - 4-character feature name ('ccmp', 'stch')
* @return {Array} substitutions - The list of substitutions.
*/
Substitution.prototype.getMultiple = function(feature, script, language) {
const substitutions = [];
const lookupTables = this.getLookupTables(script, language, feature, 2);
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;
for (j = 0; j < glyphs.length; j++) {
const glyph = glyphs[j];
const replacements = subtable.sequences[j];
substitutions.push({ sub: glyph, by: replacements });
}
}
}
return substitutions;
};
/**
* List all alternates (lookup type 3) for a given script, language, and feature.

@@ -161,3 +188,3 @@ * @param {string} [script='DFLT']

* @param {string} feature - 4-letter feature name ('liga', 'rlig', 'dlig'...)
* @param {Object} substitution - { sub: id, delta: number } for format 1 or { sub: id, by: id } for format 2.
* @param {Object} substitution - { sub: id, by: id } (format 1 is not supported)
* @param {string} [script='DFLT']

@@ -173,3 +200,3 @@ * @param {string} [language='dflt']

});
check.assert(subtable.coverage.format === 1, 'Ligature: unable to modify coverage table format ' + subtable.coverage.format);
check.assert(subtable.coverage.format === 1, 'Single: unable to modify coverage table format ' + subtable.coverage.format);
const coverageGlyph = substitution.sub;

@@ -186,3 +213,29 @@ let pos = this.binSearch(subtable.coverage.glyphs, coverageGlyph);

/**
* Add or modify an alternate substitution (lookup type 1)
* Add or modify a multiple substitution (lookup type 2)
* @param {string} feature - 4-letter feature name ('ccmp', 'stch')
* @param {Object} substitution - { sub: id, by: [id] } for format 2.
* @param {string} [script='DFLT']
* @param {string} [language='dflt']
*/
Substitution.prototype.addMultiple = function(feature, substitution, script, language) {
check.assert(substitution.by instanceof Array && substitution.by.length > 1, 'Multiple: "by" must be an array of two or more ids');
const lookupTable = this.getLookupTables(script, language, feature, 2, true)[0];
const subtable = getSubstFormat(lookupTable, 1, { // lookup type 2 subtable, format 1, coverage format 1
substFormat: 1,
coverage: {format: 1, glyphs: []},
sequences: []
});
check.assert(subtable.coverage.format === 1, 'Multiple: unable to modify coverage table format ' + subtable.coverage.format);
const coverageGlyph = substitution.sub;
let pos = this.binSearch(subtable.coverage.glyphs, coverageGlyph);
if (pos < 0) {
pos = -1 - pos;
subtable.coverage.glyphs.splice(pos, 0, coverageGlyph);
subtable.sequences.splice(pos, 0, 0);
}
subtable.sequences[pos] = substitution.by;
};
/**
* Add or modify an alternate substitution (lookup type 3)
* @param {string} feature - 4-letter feature name ('liga', 'rlig', 'dlig'...)

@@ -200,3 +253,3 @@ * @param {Object} substitution - { sub: id, by: [ids] }

});
check.assert(subtable.coverage.format === 1, 'Ligature: unable to modify coverage table format ' + subtable.coverage.format);
check.assert(subtable.coverage.format === 1, 'Alternate: unable to modify coverage table format ' + subtable.coverage.format);
const coverageGlyph = substitution.sub;

@@ -277,3 +330,9 @@ let pos = this.binSearch(subtable.coverage.glyphs, coverageGlyph);

case 'liga':
case 'rlig': return this.getLigatures(feature, script, language);
case 'rlig':
return this.getLigatures(feature, script, language);
case 'ccmp':
return this.getMultiple(feature, script, language)
.concat(this.getLigatures(feature, script, language));
case 'stch':
return this.getMultiple(feature, script, language);
}

@@ -306,2 +365,7 @@ return undefined;

return this.addLigature(feature, sub, script, language);
case 'ccmp':
if (sub.by instanceof Array) {
return this.addMultiple(feature, sub, script, language);
}
return this.addLigature(feature, sub, script, language);
}

@@ -308,0 +372,0 @@ return undefined;

@@ -15,5 +15,10 @@ // Table metadata

function Table(tableName, fields, options) {
for (let i = 0; i < fields.length; i += 1) {
const field = fields[i];
this[field.name] = field.value;
// For coverage tables with coverage format 2, we do not want to add the coverage data directly to the table object,
// as this will result in wrong encoding order of the coverage data on serialization to bytes.
// The fallback of using the field values directly when not present on the table is handled in types.encode.TABLE() already.
if (fields.length && (fields[0].name !== 'coverageFormat' || fields[0].value === 1)) {
for (let i = 0; i < fields.length; i += 1) {
const field = fields[i];
this[field.name] = field.value;
}
}

@@ -107,4 +112,15 @@

);
} else if (coverageTable.format === 2) {
Table.call(this, 'coverageTable',
[{name: 'coverageFormat', type: 'USHORT', value: 2}]
.concat(recordList('rangeRecord', coverageTable.ranges, function(RangeRecord) {
return [
{name: 'startGlyphID', type: 'USHORT', value: RangeRecord.start},
{name: 'endGlyphID', type: 'USHORT', value: RangeRecord.end},
{name: 'startCoverageIndex', type: 'USHORT', value: RangeRecord.index},
];
}))
);
} else {
check.assert(false, 'Can\'t create coverage table format 2 yet.');
check.assert(false, 'Coverage format must be 1 or 2.');
}

@@ -111,0 +127,0 @@ }

@@ -387,2 +387,4 @@ // The `CFF` table contains the glyph outlines in PostScript format.

topDict._subrsBias = 0;
topDict._defaultWidthX = 0;
topDict._nominalWidthX = 0;
const privateSize = topDict.private[0];

@@ -1171,2 +1173,3 @@ const privateOffset = topDict.private[1];

// We're going to create a new command so we don't change the original path.
// Since all coordinates are relative, we round() them ASAP to avoid propagating errors.
cmd = {

@@ -1176,6 +1179,6 @@ type: 'C',

y: cmd.y,
x1: _13 * x + _23 * cmd.x1,
y1: _13 * y + _23 * cmd.y1,
x2: _13 * cmd.x + _23 * cmd.x1,
y2: _13 * cmd.y + _23 * cmd.y1
x1: Math.round(_13 * x + _23 * cmd.x1),
y1: Math.round(_13 * y + _23 * cmd.y1),
x2: Math.round(_13 * cmd.x + _23 * cmd.x1),
y2: Math.round(_13 * cmd.y + _23 * cmd.y1)
};

@@ -1182,0 +1185,0 @@ }

@@ -233,2 +233,12 @@ // The `GSUB` table contains ligatures, among other things.

subtableMakers[2] = function makeLookup2(subtable) {
check.assert(subtable.substFormat === 1, 'Lookup type 2 substFormat must be 1.');
return new table.Table('substitutionTable', [
{name: 'substFormat', type: 'USHORT', value: 1},
{name: 'coverage', type: 'TABLE', value: new table.Coverage(subtable.coverage)}
].concat(table.tableList('seqSet', subtable.sequences, function(sequenceSet) {
return new table.Table('sequenceSetTable', table.ushortList('sequence', sequenceSet));
})));
};
subtableMakers[3] = function makeLookup3(subtable) {

@@ -259,2 +269,58 @@ check.assert(subtable.substFormat === 1, 'Lookup type 3 substFormat must be 1.');

subtableMakers[6] = function makeLookup6(subtable) {
if (subtable.substFormat === 1) {
let returnTable = new table.Table('chainContextTable', [
{name: 'substFormat', type: 'USHORT', value: subtable.substFormat},
{name: 'coverage', type: 'TABLE', value: new table.Coverage(subtable.coverage)}
].concat(table.tableList('chainRuleSet', subtable.chainRuleSets, function(chainRuleSet) {
return new table.Table('chainRuleSetTable', table.tableList('chainRule', chainRuleSet, function(chainRule) {
let tableData = table.ushortList('backtrackGlyph', chainRule.backtrack, chainRule.backtrack.length)
.concat(table.ushortList('inputGlyph', chainRule.input, chainRule.input.length + 1))
.concat(table.ushortList('lookaheadGlyph', chainRule.lookahead, chainRule.lookahead.length))
.concat(table.ushortList('substitution', [], chainRule.lookupRecords.length));
chainRule.lookupRecords.forEach((record, i) => {
tableData = tableData
.concat({name: 'sequenceIndex' + i, type: 'USHORT', value: record.sequenceIndex})
.concat({name: 'lookupListIndex' + i, type: 'USHORT', value: record.lookupListIndex});
});
return new table.Table('chainRuleTable', tableData);
}));
})));
return returnTable;
} else if (subtable.substFormat === 2) {
check.assert(false, 'lookup type 6 format 2 is not yet supported.');
} else if (subtable.substFormat === 3) {
let tableData = [
{name: 'substFormat', type: 'USHORT', value: subtable.substFormat},
];
tableData.push({name: 'backtrackGlyphCount', type: 'USHORT', value: subtable.backtrackCoverage.length});
subtable.backtrackCoverage.forEach((coverage, i) => {
tableData.push({name: 'backtrackCoverage' + i, type: 'TABLE', value: new table.Coverage(coverage)});
});
tableData.push({name: 'inputGlyphCount', type: 'USHORT', value: subtable.inputCoverage.length});
subtable.inputCoverage.forEach((coverage, i) => {
tableData.push({name: 'inputCoverage' + i, type: 'TABLE', value: new table.Coverage(coverage)});
});
tableData.push({name: 'lookaheadGlyphCount', type: 'USHORT', value: subtable.lookaheadCoverage.length});
subtable.lookaheadCoverage.forEach((coverage, i) => {
tableData.push({name: 'lookaheadCoverage' + i, type: 'TABLE', value: new table.Coverage(coverage)});
});
tableData.push({name: 'substitutionCount', type: 'USHORT', value: subtable.lookupRecords.length});
subtable.lookupRecords.forEach((record, i) => {
tableData = tableData
.concat({name: 'sequenceIndex' + i, type: 'USHORT', value: record.sequenceIndex})
.concat({name: 'lookupListIndex' + i, type: 'USHORT', value: record.lookupListIndex});
});
let returnTable = new table.Table('chainContextTable', tableData);
return returnTable;
}
check.assert(false, 'lookup type 6 format must be 1, 2 or 3.');
};
function makeGsubTable(gsub) {

@@ -261,0 +327,0 @@ return new table.Table('GSUB', [

@@ -70,2 +70,6 @@ // Data types used in the OpenType font file.

encode.CHARARRAY = function(v) {
if (typeof v === 'undefined') {
v = '';
console.warn('Undefined CHARARRAY encountered and treated as an empty string. This is probably caused by a missing glyph name.');
}
const b = [];

@@ -84,2 +88,5 @@ for (let i = 0; i < v.length; i += 1) {

sizeOf.CHARARRAY = function(v) {
if (typeof v === 'undefined') {
return 0;
}
return v.length;

@@ -86,0 +93,0 @@ };

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 too big to display

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 not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc