opentype.js
Advanced tools
Comparing version 0.4.4 to 0.4.5
{ | ||
"name": "opentype.js", | ||
"version": "0.4.4", | ||
"version": "0.4.5", | ||
"main": "dist/opentype.js", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
{ | ||
"name": "opentype.js", | ||
"description": "OpenType font parser", | ||
"version": "0.4.4", | ||
"version": "0.4.5", | ||
"author": { | ||
"name": "Frederik De Bleser", | ||
"email": "frederik@burocrazy.com" | ||
"email": "frederik@debleser.be" | ||
}, | ||
@@ -44,3 +44,6 @@ "keywords": [ | ||
"watchify": "^2.1.1" | ||
}, | ||
"browser" : { | ||
"fs": false | ||
} | ||
} |
@@ -23,3 +23,3 @@ opentype.js | ||
} | ||
} | ||
}); | ||
@@ -26,0 +26,0 @@ See [the project website](http://nodebox.github.io/opentype.js/) for a live demo. |
@@ -0,1 +1,7 @@ | ||
0.4.5 (March 10, 2015) | ||
====================== | ||
* Add support for writing quad curves. | ||
* Add support for CFF flex operators. | ||
* Close CFF subpaths. | ||
0.4.4 (Dec 8, 2014) | ||
@@ -2,0 +8,0 @@ =================== |
@@ -145,5 +145,5 @@ // The Font object | ||
var fullPath = new path.Path(); | ||
this.forEachGlyph(text, x, y, fontSize, options, function (glyph, x, y, fontSize) { | ||
var path = glyph.getPath(x, y, fontSize); | ||
fullPath.extend(path); | ||
this.forEachGlyph(text, x, y, fontSize, options, function (glyph, gX, gY, gFontSize) { | ||
var glyphPath = glyph.getPath(gX, gY, gFontSize); | ||
fullPath.extend(glyphPath); | ||
}); | ||
@@ -177,4 +177,4 @@ return fullPath; | ||
Font.prototype.drawPoints = function (ctx, text, x, y, fontSize, options) { | ||
this.forEachGlyph(text, x, y, fontSize, options, function (glyph, x, y, fontSize) { | ||
glyph.drawPoints(ctx, x, y, fontSize); | ||
this.forEachGlyph(text, x, y, fontSize, options, function (glyph, gX, gY, gFontSize) { | ||
glyph.drawPoints(ctx, gX, gY, gFontSize); | ||
}); | ||
@@ -196,4 +196,4 @@ }; | ||
Font.prototype.drawMetrics = function (ctx, text, x, y, fontSize, options) { | ||
this.forEachGlyph(text, x, y, fontSize, options, function (glyph, x, y, fontSize) { | ||
glyph.drawMetrics(ctx, x, y, fontSize); | ||
this.forEachGlyph(text, x, y, fontSize, options, function (glyph, gX, gY, gFontSize) { | ||
glyph.drawMetrics(ctx, gX, gY, gFontSize); | ||
}); | ||
@@ -200,0 +200,0 @@ }; |
@@ -334,3 +334,3 @@ // The `CFF` table contains the glyph outlines in PostScript format. | ||
function parseCFFCharstring(code, font, index) { | ||
var p, glyph, stack, nStems, haveWidth, width, x, y, c1x, c1y, c2x, c2y, v; | ||
var p, glyph, stack, nStems, haveWidth, width, open, x, y, c1x, c1y, c2x, c2y, v; | ||
p = new path.Path(); | ||
@@ -341,4 +341,13 @@ stack = []; | ||
width = font.defaultWidthX; | ||
open = false; | ||
x = y = 0; | ||
function newContour(x, y) { | ||
if (open) { | ||
p.closePath(); | ||
} | ||
p.moveTo(x, y); | ||
open = true; | ||
} | ||
function parseStems() { | ||
@@ -376,3 +385,3 @@ var hasWidthArg; | ||
y += stack.pop(); | ||
p.moveTo(x, y); | ||
newContour(x, y); | ||
break; | ||
@@ -428,5 +437,84 @@ case 5: // rlineto | ||
return; | ||
case 12: // escape | ||
case 12: // flex operators | ||
v = code[i]; | ||
i += 1; | ||
var jpx, jpy, c3x, c3y, c4x, c4y, fd; | ||
switch (v) { | ||
case 35: // flex | ||
// |- dx1 dy1 dx2 dy2 dx3 dy3 dx4 dy4 dx5 dy5 dx6 dy6 fd flex (12 35) |- | ||
c1x = x + stack.shift(); // dx1 | ||
c1y = y + stack.shift(); // dy1 | ||
c2x = c1x + stack.shift(); // dx2 | ||
c2y = c1y + stack.shift(); // dy2 | ||
jpx = c2x + stack.shift(); // dx3 | ||
jpy = c2y + stack.shift(); // dy3 | ||
c3x = jpx + stack.shift(); // dx4 | ||
c3y = jpy + stack.shift(); // dy4 | ||
c4x = c3x + stack.shift(); // dx5 | ||
c4y = c3y + stack.shift(); // dy5 | ||
x = c4x + stack.shift(); // dx6 | ||
y = c4y + stack.shift(); // dy6 | ||
fd = stack.shift(); // flex depth | ||
p.curveTo(c1x, c1y, c2x, c2y, jpx, jpy); | ||
p.curveTo(c3x, c3y, c4x, c4y, x, y); | ||
break; | ||
case 34: // hflex | ||
// |- dx1 dx2 dy2 dx3 dx4 dx5 dx6 hflex (12 34) |- | ||
c1x = x + stack.shift(); // dx1 | ||
c1y = y; // dy1 | ||
c2x = c1x + stack.shift(); // dx2 | ||
c2y = c1y + stack.shift(); // dy2 | ||
jpx = c2x + stack.shift(); // dx3 | ||
jpy = c2y; // dy3 | ||
c3x = jpx + stack.shift(); // dx4 | ||
c3y = c2y; // dy4 | ||
c4x = c3x + stack.shift(); // dx5 | ||
c4y = y; // dy5 | ||
x = c4x + stack.shift(); // dx6 | ||
// y = y; // dy6 | ||
p.curveTo(c1x, c1y, c2x, c2y, jpx, jpy); | ||
p.curveTo(c3x, c3y, c4x, c4y, x, y); | ||
break; | ||
case 36: // hflex1 | ||
// |- dx1 dy1 dx2 dy2 dx3 dx4 dx5 dy5 dx6 hflex1 (12 36) |- | ||
c1x = x + stack.shift(); // dx1 | ||
c1y = y + stack.shift(); // dy1 | ||
c2x = c1x + stack.shift(); // dx2 | ||
c2y = c1y + stack.shift(); // dy2 | ||
jpx = c2x + stack.shift(); // dx3 | ||
jpy = c2y; // dy3 | ||
c3x = jpx + stack.shift(); // dx4 | ||
c3y = c2y; // dy4 | ||
c4x = c3x + stack.shift(); // dx5 | ||
c4y = c3y + stack.shift(); // dy5 | ||
x = c4x + stack.shift(); // dx6 | ||
// y = y; // dy6 | ||
p.curveTo(c1x, c1y, c2x, c2y, jpx, jpy); | ||
p.curveTo(c3x, c3y, c4x, c4y, x, y); | ||
break; | ||
case 37: // flex1 | ||
// |- dx1 dy1 dx2 dy2 dx3 dy3 dx4 dy4 dx5 dy5 d6 flex1 (12 37) |- | ||
c1x = x + stack.shift(); // dx1 | ||
c1y = y + stack.shift(); // dy1 | ||
c2x = c1x + stack.shift(); // dx2 | ||
c2y = c1y + stack.shift(); // dy2 | ||
jpx = c2x + stack.shift(); // dx3 | ||
jpy = c2y + stack.shift(); // dy3 | ||
c3x = jpx + stack.shift(); // dx4 | ||
c3y = jpy + stack.shift(); // dy4 | ||
c4x = c3x + stack.shift(); // dx5 | ||
c4y = c3y + stack.shift(); // dy5 | ||
if (Math.abs(c4x - x) > Math.abs(c4y - y)) { | ||
x = c4x + stack.shift(); // d6 | ||
} else { | ||
y = c4y + stack.shift(); // d6 | ||
} | ||
p.curveTo(c1x, c1y, c2x, c2y, jpx, jpy); | ||
p.curveTo(c3x, c3y, c4x, c4y, x, y); | ||
break; | ||
default: | ||
console.log('Glyph ' + index + ': unknown operator ' + 1200 + v); | ||
stack.length = 0; | ||
} | ||
break; | ||
@@ -439,2 +527,3 @@ case 14: // endchar | ||
p.closePath(); | ||
open = false; | ||
break; | ||
@@ -456,3 +545,3 @@ case 18: // hstemhm | ||
x += stack.pop(); | ||
p.moveTo(x, y); | ||
newContour(x, y); | ||
break; | ||
@@ -465,3 +554,3 @@ case 22: // hmoveto | ||
x += stack.pop(); | ||
p.moveTo(x, y); | ||
newContour(x, y); | ||
break; | ||
@@ -793,2 +882,18 @@ case 23: // vstemhm | ||
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; | ||
// We're going to create a new command so we don't change the original path. | ||
cmd = { | ||
type: 'C', | ||
x: cmd.x, | ||
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 | ||
}; | ||
} | ||
if (cmd.type === 'M') { | ||
@@ -810,5 +915,2 @@ dx = cmd.x - x; | ||
y = cmd.y; | ||
} else if (cmd.type === 'Q') { | ||
// FIXME: Add support for quad curves | ||
throw new Error('Writing quad curves is currently not supported.'); | ||
} else if (cmd.type === 'C') { | ||
@@ -815,0 +917,0 @@ dx1 = cmd.x1 - x; |
@@ -99,3 +99,3 @@ // The `GPOS` table contains kerning pairs, among other things. | ||
coverageOffset = p.parseUShort(); | ||
coverage = parseCoverageTable(data, start+coverageOffset); | ||
coverage = parseCoverageTable(data, start + coverageOffset); | ||
// valueFormat 4: XAdvance only, 1: XPlacement only, 0: no ValueRecord for second glyph | ||
@@ -168,7 +168,10 @@ // Only valueFormat1=4 and valueFormat2=0 is supported. | ||
return function(leftGlyph, rightGlyph) { | ||
if (!covered[leftGlyph]) return null; | ||
if (!covered[leftGlyph]) return; | ||
var class1 = getClass1(leftGlyph), | ||
class2 = getClass2(rightGlyph), | ||
kerningRow = kerningMatrix[class1]; | ||
return kerningRow ? kerningRow[class2] : null; | ||
if (kerningRow) { | ||
return kerningRow[class2]; | ||
} | ||
}; | ||
@@ -175,0 +178,0 @@ } |
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 too big to display
Sorry, the diff of this file is not supported yet
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
874772
47
13439
11