opentype.js
Advanced tools
Comparing version 1.2.0 to 1.2.1
{ | ||
"name": "opentype.js", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"main": "dist/opentype.js", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
{ | ||
"name": "opentype.js", | ||
"description": "OpenType font parser", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Frederik De Bleser", |
@@ -0,1 +1,7 @@ | ||
1.2.1 (April 13, 2020) | ||
===================== | ||
* Fix Path.toPathData and Path.toSVG - X Axis is flipped (#369) | ||
* Fix use of Promise / async/await in the load function (#427) | ||
* Fix a bug for unsupported SUBSTITUTIONS #403 | ||
1.2.0 (April 13, 2020) | ||
@@ -2,0 +8,0 @@ ===================== |
@@ -69,3 +69,3 @@ import { SubstitutionAction } from './featureQuery'; | ||
function applySubstitution(action, tokens, index) { | ||
if (action instanceof SubstitutionAction) { | ||
if (action instanceof SubstitutionAction && SUBSTITUTIONS[action.id]) { | ||
SUBSTITUTIONS[action.id](action, tokens, index); | ||
@@ -72,0 +72,0 @@ } |
@@ -378,6 +378,10 @@ // opentype.js | ||
return new Promise((resolve) => { | ||
return new Promise((resolve, reject) => { | ||
loadFn(url, function(err, arrayBuffer) { | ||
if (err) { | ||
return callback(err); | ||
if (callback) { | ||
return callback(err); | ||
} else { | ||
reject(err); | ||
} | ||
} | ||
@@ -388,3 +392,7 @@ let font; | ||
} catch (e) { | ||
return callback(e, null); | ||
if (callback) { | ||
return callback(e, null); | ||
} else { | ||
reject(e); | ||
} | ||
} | ||
@@ -391,0 +399,0 @@ if (callback) { |
@@ -214,3 +214,3 @@ // The `glyf` table describes the glyphs in TrueType outline format. | ||
// Convert the TrueType glyph outline to a Path. | ||
function getPath(points) { | ||
function getPath(points, glyph) { | ||
const p = new Path(); | ||
@@ -220,2 +220,6 @@ if (!points) { | ||
} | ||
let flipY = null; | ||
if (glyph) { | ||
flipY = (glyph._yMax + glyph._yMin); | ||
} | ||
@@ -232,10 +236,10 @@ const contours = getContours(points); | ||
if (curr.onCurve) { | ||
p.moveTo(curr.x, curr.y); | ||
p.moveTo(curr.x, flipY == null ? curr.y : (flipY - curr.y)); | ||
} else { | ||
if (next.onCurve) { | ||
p.moveTo(next.x, next.y); | ||
p.moveTo(next.x, flipY == null ? next.y : (flipY - next.y)); | ||
} else { | ||
// If both first and last points are off-curve, start at their middle. | ||
const start = {x: (curr.x + next.x) * 0.5, y: (curr.y + next.y) * 0.5}; | ||
p.moveTo(start.x, start.y); | ||
p.moveTo(start.x, flipY == null ? start.y : (flipY - start.y)); | ||
} | ||
@@ -251,3 +255,3 @@ } | ||
// This is a straight line. | ||
p.lineTo(curr.x, curr.y); | ||
p.lineTo(curr.x, flipY == null ? curr.y : (flipY - curr.y)); | ||
} else { | ||
@@ -265,3 +269,3 @@ let prev2 = prev; | ||
p.quadraticCurveTo(curr.x, curr.y, next2.x, next2.y); | ||
p.quadraticCurveTo(curr.x, flipY == null ? curr.y : (flipY - curr.y), next2.x, flipY == null ? next2.y : (flipY - next2.y)); | ||
} | ||
@@ -310,3 +314,3 @@ } | ||
return getPath(glyph.points); | ||
return getPath(glyph.points, glyph); | ||
} | ||
@@ -313,0 +317,0 @@ |
@@ -15,2 +15,14 @@ import assert from 'assert'; | ||
it('can load a TrueType font as a resolved promise', function(done) { | ||
load('./fonts/Roboto-Black.ttf').then((font) => { | ||
assert.deepEqual(font.names.fontFamily, {en: 'Roboto Black'}); | ||
assert.equal(font.unitsPerEm, 2048); | ||
assert.equal(font.glyphs.length, 1294); | ||
const aGlyph = font.charToGlyph('A'); | ||
assert.equal(aGlyph.unicode, 65); | ||
assert.equal(aGlyph.path.commands.length, 15); | ||
done(); | ||
}); | ||
}); | ||
it('can load a OpenType/CFF font', function() { | ||
@@ -62,2 +74,11 @@ const font = loadSync('./fonts/FiraSansOT-Medium.otf'); | ||
it('handles a parseBuffer error as a rejected promise', function(done) { | ||
load('./fonts/badfont.ttf') | ||
.catch((err) => { | ||
if (err) { | ||
done(); | ||
} | ||
}); | ||
}); | ||
it('throws an error when advanceWidth is not set', function() { | ||
@@ -64,0 +85,0 @@ const notdefGlyph = new Glyph({ |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3919516
41768