opentype.js
Advanced tools
Comparing version 0.8.0 to 0.9.0
@@ -7,3 +7,2 @@ #!/usr/bin/env node | ||
var rollup = require('rollup'); | ||
var watch = require('rollup-watch'); | ||
var rollupConfig = require('../rollup.config'); | ||
@@ -48,13 +47,20 @@ | ||
var watcher = watch(rollup, rollupConfig); | ||
watcher.on('event', function(e) { | ||
if (e.code === 'BUILD_START') { | ||
// Watch changes and rebundle | ||
var watcher = rollup.watch(rollupConfig); | ||
watcher.on('event', e => { | ||
// event.code can be one of: | ||
// START — the watcher is (re)starting | ||
// BUNDLE_START — building an individual bundle | ||
// BUNDLE_END — finished building a bundle | ||
// END — finished building all bundles | ||
// ERROR — encountered an error while bundling | ||
// FATAL — encountered an unrecoverable error | ||
if (e.code === 'BUNDLE_START') { | ||
console.log('Bundling...'); | ||
} else if (e.code === 'BUILD_END') { | ||
} else if (e.code === 'BUNDLE_END') { | ||
console.log('Bundled in ' + e.duration + 'ms.'); | ||
} else if (e.code === 'ERROR') { | ||
} else if (e.code === 'ERROR' || e.code === 'FATAL') { | ||
console.error(e.error); | ||
} else { | ||
console.error('Unknown watch event', e); | ||
} | ||
}); |
{ | ||
"name": "opentype.js", | ||
"version": "0.8.0", | ||
"version": "0.9.0", | ||
"main": "dist/opentype.js", | ||
"keywords": [ | ||
"vector", | ||
"graphics", | ||
"canvas", | ||
"2d" | ||
"fonts", | ||
"opentype", | ||
"otf", | ||
"ttf", | ||
"woff", | ||
"type" | ||
], | ||
@@ -11,0 +14,0 @@ "ignore": [ |
// This example shows how to create a font from scratch using node.js. | ||
import { Font, Glyph, Path } from '../src/opentype'; | ||
const { Font, Glyph, Path } = require('../dist/opentype'); | ||
@@ -5,0 +5,0 @@ // These are the global measurements of the typeface. |
{ | ||
"name": "opentype.js", | ||
"description": "OpenType font parser", | ||
"version": "0.8.0", | ||
"version": "0.9.0", | ||
"author": { | ||
@@ -37,15 +37,15 @@ "name": "Frederik De Bleser", | ||
"devDependencies": { | ||
"buble": "^0.15.2", | ||
"cross-env": "^5.0.0", | ||
"jscs": "^3.0.3", | ||
"jshint": "^2.9.2", | ||
"mocha": "^2.5.3", | ||
"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.3.10" | ||
"@babel/preset-env": "^7.0.0-beta.51", | ||
"buble": "^0.19.3", | ||
"cross-env": "^5.2.0", | ||
"jscs": "^3.0.7", | ||
"jshint": "^2.9.5", | ||
"mocha": "^5.2.0", | ||
"reify": "^0.16.2", | ||
"rollup": "^0.61.1", | ||
"rollup-plugin-buble": "^0.19.2", | ||
"rollup-plugin-commonjs": "^9.1.3", | ||
"rollup-plugin-license": "^0.6.0", | ||
"rollup-plugin-node-resolve": "^3.3.0", | ||
"uglify-js": "^3.4.1" | ||
}, | ||
@@ -56,4 +56,5 @@ "browser": { | ||
"dependencies": { | ||
"string.prototype.codepointat": "^0.2.1", | ||
"tiny-inflate": "^1.0.2" | ||
} | ||
} |
@@ -0,1 +1,12 @@ | ||
0.9.0 (June 21, 2018) | ||
===================== | ||
* Update/Migrate rollup, update all dependencies, add package-lock.json and fix circular dependency (thanks @jolg42!) | ||
* Parse cmap table with platform id 0 as well (PR #350, fixes #348) (thanks @moyogo!) | ||
* Prevent auto-generated postScriptName from containing whitespace (#339) (thanks @mqudsi!) | ||
* Support non-Basic-Multilingual-Plane (BMP) characters (#338) (thanks @antonytse!) | ||
* GPOS: display correct error message in some cases of malformed data (#336) (thanks @fpirsch!) | ||
* Restore simple GPOS kerning in font.getKerningValue (#335) (thanks @fpirsch!) | ||
* Fix duplicated lineTo when using `getPath` (#328) (thanks @jolg42!) | ||
* Change example generate-font-node.js to be compatible with any Node.js version (thanks @jolg42!) | ||
0.8.0 (March 6, 2018) | ||
@@ -2,0 +13,0 @@ ===================== |
@@ -6,8 +6,10 @@ var buble = require('rollup-plugin-buble'); | ||
module.exports = { | ||
entry: 'src/opentype.js', | ||
dest: 'dist/opentype.js', | ||
moduleName: 'opentype', | ||
format: 'umd', | ||
sourceMap: true, | ||
module.exports = { | ||
input: 'src/opentype.js', | ||
output: { | ||
file: 'dist/opentype.js', | ||
format: 'umd', | ||
name: 'opentype', | ||
sourcemap: true | ||
}, | ||
plugins: [ | ||
@@ -22,5 +24,9 @@ resolve({ | ||
license({ | ||
banner: 'https://opentype.js.org v<%= pkg.version %> | (c) Frederik De Bleser and other contributors | MIT License | Uses tiny-inflate by Devon Govett' | ||
}), | ||
] | ||
banner: 'https://opentype.js.org v<%= pkg.version %> | (c) Frederik De Bleser and other contributors | MIT License | Uses tiny-inflate by Devon Govett' + | ||
' and string.prototype.codepointat polyfill by Mathias Bynens' | ||
}) | ||
], | ||
watch: { | ||
include: 'src/**' | ||
} | ||
}; |
@@ -136,3 +136,3 @@ // Glyph encoding | ||
DefaultEncoding.prototype.charToGlyphIndex = function(c) { | ||
const code = c.charCodeAt(0); | ||
const code = c.codePointAt(0); | ||
const glyphs = this.font.glyphs; | ||
@@ -167,3 +167,3 @@ if (glyphs) { | ||
CmapEncoding.prototype.charToGlyphIndex = function(c) { | ||
return this.cmap.glyphIndexMap[c.charCodeAt(0)] || 0; | ||
return this.cmap.glyphIndexMap[c.codePointAt(0)] || 0; | ||
}; | ||
@@ -188,3 +188,3 @@ | ||
CffEncoding.prototype.charToGlyphIndex = function(s) { | ||
const code = s.charCodeAt(0); | ||
const code = s.codePointAt(0); | ||
const charName = this.encoding[code]; | ||
@@ -191,0 +191,0 @@ return this.charset.indexOf(charName); |
@@ -12,2 +12,5 @@ // The Font object | ||
// This code is based on Array.from implementation for strings in https://github.com/mathiasbynens/Array.from | ||
const arrayFromString = Array.from || (s => s.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]?|[^\uD800-\uDFFF]|./g) || []); | ||
/** | ||
@@ -66,3 +69,4 @@ * @typedef FontOptions | ||
fullName: {en: options.fullName || options.familyName + ' ' + options.styleName}, | ||
postScriptName: {en: options.postScriptName || options.familyName + options.styleName}, | ||
// postScriptName may not contain any whitespace | ||
postScriptName: {en: options.postScriptName || (options.familyName + options.styleName).replace(/\s/g, '')}, | ||
designer: {en: options.designer || ' '}, | ||
@@ -157,5 +161,6 @@ designerURL: {en: options.designerURL || ' '}, | ||
// Get glyph indexes | ||
const chars = arrayFromString(s); | ||
const indexes = []; | ||
for (let i = 0; i < s.length; i += 1) { | ||
const c = s[i]; | ||
for (let i = 0; i < chars.length; i += 1) { | ||
const c = chars[i]; | ||
indexes.push(this.charToGlyphIndex(c)); | ||
@@ -235,2 +240,4 @@ } | ||
* between glyphs. | ||
* For GPOS kerning, this method uses the default script and language, which covers | ||
* most use cases. To have greater control, use font.position.getKerningValue . | ||
* @param {opentype.Glyph} leftGlyph | ||
@@ -243,2 +250,7 @@ * @param {opentype.Glyph} rightGlyph | ||
rightGlyph = rightGlyph.index || rightGlyph; | ||
const gposKerning = this.position.defaultKerningTables; | ||
if (gposKerning) { | ||
return this.position.getKerningValue(gposKerning, leftGlyph, rightGlyph); | ||
} | ||
// "kern" table | ||
return this.kerningPairs[leftGlyph + ',' + rightGlyph] || 0; | ||
@@ -245,0 +257,0 @@ }; |
@@ -6,3 +6,3 @@ // The Glyph object | ||
import Path from './path'; | ||
import glyf from './tables/glyf'; | ||
// import glyf from './tables/glyf' Can't be imported here, because it's a circular dependency | ||
@@ -143,3 +143,4 @@ function getPathDefinition(glyph, path) { | ||
if (hPoints) { | ||
commands = glyf.getPath(hPoints).commands; | ||
// Call font.hinting.getCommands instead of `glyf.getPath(hPoints).commands` to avoid a circular dependency | ||
commands = font.hinting.getCommands(hPoints); | ||
x = Math.round(x); | ||
@@ -146,0 +147,0 @@ y = Math.round(y); |
@@ -8,2 +8,3 @@ // opentype.js | ||
import 'string.prototype.codepointat'; | ||
import inflate from 'tiny-inflate'; | ||
@@ -339,2 +340,3 @@ import Font from './font'; | ||
font.tables.gpos = gpos.parse(gposTable.data, gposTable.offset); | ||
font.position.init(); | ||
} | ||
@@ -341,0 +343,0 @@ |
@@ -20,2 +20,10 @@ // The Position object provides utility methods to manipulate | ||
/** | ||
* Init some data for faster and easier access later. | ||
*/ | ||
Position.prototype.init = function() { | ||
const script = this.getDefaultScriptName(); | ||
this.defaultKerningTables = this.getKerningTables(script); | ||
}; | ||
/** | ||
* Find a glyph pair in a list of lookup tables of type 2 and retrieve the xAdvance kerning value. | ||
@@ -22,0 +30,0 @@ * |
@@ -90,3 +90,3 @@ // The `cmap` table stores the mappings from characters to glyphs. | ||
// The cmap table can contain many sub-tables, each with their own format. | ||
// We're only interested in a "platform 3" table. This is a Windows format. | ||
// We're only interested in a "platform 0" (Unicode format) and "platform 3" (Windows format) table. | ||
cmap.numTables = parse.getUShort(data, start + 2); | ||
@@ -97,3 +97,4 @@ let offset = -1; | ||
const encodingId = parse.getUShort(data, start + 4 + (i * 8) + 2); | ||
if (platformId === 3 && (encodingId === 0 || encodingId === 1 || encodingId === 10)) { | ||
if ((platformId === 3 && (encodingId === 0 || encodingId === 1 || encodingId === 10)) || | ||
(platformId === 0 && (encodingId === 0 || encodingId === 1 || encodingId === 2 || encodingId === 3 || encodingId === 4))) { | ||
offset = parse.getULong(data, start + 4 + (i * 8) + 4); | ||
@@ -100,0 +101,0 @@ break; |
@@ -255,3 +255,2 @@ // The `glyf` table describes the glyphs in TrueType outline format. | ||
prev2 = { x: (curr.x + prev.x) * 0.5, y: (curr.y + prev.y) * 0.5 }; | ||
p.lineTo(prev2.x, prev2.y); | ||
} | ||
@@ -263,3 +262,2 @@ | ||
p.lineTo(prev2.x, prev2.y); | ||
p.quadraticCurveTo(curr.x, curr.y, next2.x, next2.y); | ||
@@ -266,0 +264,0 @@ } |
@@ -35,2 +35,3 @@ // The `GPOS` table contains kerning pairs, among other things. | ||
const posFormat = this.parseUShort(); | ||
check.assert(posFormat === 1 || posFormat === 2, '0x' + start.toString(16) + ': GPOS lookup type 2 format must be 1 or 2.'); | ||
const coverage = this.parsePointer(Parser.coverage); | ||
@@ -77,3 +78,2 @@ const valueFormat1 = this.parseUShort(); | ||
} | ||
check.assert(false, '0x' + start.toString(16) + ': GPOS lookup type 2 format must be 1 or 2.'); | ||
}; | ||
@@ -80,0 +80,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 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
2273251
87
28321
2
+ Addedstring.prototype.codepointat@0.2.1(transitive)