Comparing version 1.0.2 to 1.0.3
{ | ||
"name": "fontkit", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "An advanced font engine for Node and the browser", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -153,2 +153,6 @@ # fontkit | ||
### `collection.fonts` | ||
This property is a lazily-loaded array of all of the fonts in the collection. | ||
## Glyph objects | ||
@@ -155,0 +159,0 @@ |
@@ -58,6 +58,6 @@ // Generated by CoffeeScript 1.8.0 | ||
1: { | ||
ranges: new r.Array(Range1, '') | ||
ranges: new r.Array(Range1, 0) | ||
}, | ||
2: { | ||
ranges: new r.Array(Range2, '') | ||
ranges: new r.Array(Range2, 0) | ||
} | ||
@@ -64,0 +64,0 @@ }); |
@@ -10,3 +10,3 @@ // Generated by CoffeeScript 1.8.0 | ||
DFont = (function() { | ||
var DFontData, DFontHeader, DFontMap, DFontName, Ref, Type, TypeList; | ||
var DFontData, DFontHeader, DFontMap, DFontName, Ref, Type, TypeList, get; | ||
@@ -104,3 +104,3 @@ DFontName = new r.String(r.uint8); | ||
DFont.prototype.getFont = function(name) { | ||
var ref, substream, _i, _len, _ref; | ||
var font, pos, ref, stream, _i, _len, _ref; | ||
if (!this.sfnt) { | ||
@@ -112,6 +112,7 @@ return null; | ||
ref = _ref[_i]; | ||
if (ref.name === name) { | ||
substream = new r.DecodeStream(this.stream.buffer); | ||
substream.pos = this.header.dataOffset + ref.dataOffset + 4; | ||
return new TTFFont(substream); | ||
pos = this.header.dataOffset + ref.dataOffset + 4; | ||
stream = new r.DecodeStream(this.stream.buffer.slice(pos)); | ||
font = new TTFFont(stream); | ||
if (font.postscriptName === name) { | ||
return font; | ||
} | ||
@@ -122,2 +123,22 @@ } | ||
get = function(key, fn) { | ||
return Object.defineProperty(DFont.prototype, key, { | ||
get: fn, | ||
enumerable: true | ||
}); | ||
}; | ||
get('fonts', function() { | ||
var fonts, pos, ref, stream, _i, _len, _ref; | ||
fonts = []; | ||
_ref = this.sfnt.refList; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
ref = _ref[_i]; | ||
pos = this.header.dataOffset + ref.dataOffset + 4; | ||
stream = new r.DecodeStream(this.stream.buffer.slice(pos)); | ||
fonts.push(new TTFFont(stream)); | ||
} | ||
return fonts; | ||
}); | ||
return DFont; | ||
@@ -124,0 +145,0 @@ |
@@ -25,7 +25,8 @@ // Generated by CoffeeScript 1.8.0 | ||
} | ||
glyph = this.glyphs[this.glyphIndex]; | ||
switch (table.version) { | ||
case 1: | ||
return this.glyphs[this.glyphIndex] = this.font.getGlyph(this.glyphs[this.glyphIndex].id + table.deltaGlyphID); | ||
return this.glyphs[this.glyphIndex] = this.font.getGlyph(glyph.id + table.deltaGlyphID, glyph.codePoints); | ||
case 2: | ||
return this.glyphs[this.glyphIndex] = this.font.getGlyph(table.substitute[index]); | ||
return this.glyphs[this.glyphIndex] = this.font.getGlyph(table.substitute[index], glyph.codePoints); | ||
} | ||
@@ -42,3 +43,3 @@ break; | ||
if (index !== -1) { | ||
return this.glyphs[this.glyphIndex] = this.font.getGlyph(table.alternateSet[USER_INDEX]); | ||
return this.glyphs[this.glyphIndex] = this.font.getGlyph(table.alternateSet[USER_INDEX], this.glyphs[this.glyphIndex].codePoints); | ||
} | ||
@@ -45,0 +46,0 @@ break; |
// Generated by CoffeeScript 1.8.0 | ||
(function() { | ||
var OpenTypeProcessor; | ||
var OpenTypeProcessor, | ||
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; | ||
OpenTypeProcessor = (function() { | ||
function OpenTypeProcessor(font, table) { | ||
var featureIndex, record, _i, _len, _ref; | ||
this.font = font; | ||
@@ -16,2 +18,9 @@ this.table = table; | ||
this.selectScript(); | ||
this.features = {}; | ||
_ref = this.language.featureIndexes; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
featureIndex = _ref[_i]; | ||
record = this.table.featureList[featureIndex]; | ||
this.features[record.tag] = record.feature; | ||
} | ||
this.glyphIndex = 0; | ||
@@ -35,3 +44,3 @@ this.glyphs = []; | ||
OpenTypeProcessor.prototype.selectScript = function(script, language) { | ||
var entry, featureIndex, lang, lookupIndex, lookups, record, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2; | ||
var entry, lang, _i, _len, _ref; | ||
if ((this.script == null) || script !== this.scriptTag) { | ||
@@ -67,24 +76,37 @@ if (script != null) { | ||
} | ||
if (this.language == null) { | ||
this.language = this.script.defaultLangSys; | ||
return this.language != null ? this.language : this.language = this.script.defaultLangSys; | ||
}; | ||
OpenTypeProcessor.prototype.lookupsForFeatures = function(userFeatures, exclude) { | ||
var feature, lookupIndex, lookups, tag, _i, _j, _len, _len1, _ref; | ||
if (userFeatures == null) { | ||
userFeatures = []; | ||
} | ||
this.features = {}; | ||
this.lookups = {}; | ||
_ref1 = this.language.featureIndexes; | ||
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { | ||
featureIndex = _ref1[_j]; | ||
record = this.table.featureList[featureIndex]; | ||
this.features[record.tag] = record.feature; | ||
lookups = []; | ||
_ref2 = record.feature.lookupListIndexes; | ||
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) { | ||
lookupIndex = _ref2[_k]; | ||
lookups = []; | ||
for (_i = 0, _len = userFeatures.length; _i < _len; _i++) { | ||
tag = userFeatures[_i]; | ||
feature = this.features[tag]; | ||
if (!feature) { | ||
continue; | ||
} | ||
_ref = feature.lookupListIndexes; | ||
for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { | ||
lookupIndex = _ref[_j]; | ||
if (exclude && __indexOf.call(exclude, lookupIndex) >= 0) { | ||
continue; | ||
} | ||
lookups.push(this.table.lookupList[lookupIndex]); | ||
} | ||
this.lookups[record.tag] = lookups; | ||
} | ||
return lookups; | ||
}; | ||
OpenTypeProcessor.prototype.applyFeatures = function(userFeatures, glyphs, advances) { | ||
var feature, lookup, table, _i, _j, _k, _len, _len1, _len2, _ref, _ref1; | ||
var lookups; | ||
lookups = this.lookupsForFeatures(userFeatures); | ||
return this.applyLookups(lookups, glyphs, advances); | ||
}; | ||
OpenTypeProcessor.prototype.applyLookups = function(lookups, glyphs, advances) { | ||
var lookup, table, _i, _j, _len, _len1, _ref; | ||
this.glyphs = glyphs; | ||
@@ -94,14 +116,8 @@ this.advances = advances; | ||
while (this.glyphIndex < this.glyphs.length) { | ||
for (_i = 0, _len = userFeatures.length; _i < _len; _i++) { | ||
feature = userFeatures[_i]; | ||
if (feature in this.lookups) { | ||
_ref = this.lookups[feature]; | ||
for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { | ||
lookup = _ref[_j]; | ||
_ref1 = lookup.subTables; | ||
for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) { | ||
table = _ref1[_k]; | ||
this.applyLookup(lookup.lookupType, table); | ||
} | ||
} | ||
for (_i = 0, _len = lookups.length; _i < _len; _i++) { | ||
lookup = lookups[_i]; | ||
_ref = lookup.subTables; | ||
for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { | ||
table = _ref[_j]; | ||
this.applyLookup(lookup.lookupType, table); | ||
} | ||
@@ -108,0 +124,0 @@ } |
@@ -71,4 +71,12 @@ // Generated by CoffeeScript 1.8.0 | ||
exports.bsln = require('./bsln'); | ||
exports.feat = require('./feat'); | ||
exports.just = require('./just'); | ||
exports.morx = require('./morx'); | ||
exports.opbd = require('./opbd'); | ||
}).call(this); |
// Generated by CoffeeScript 1.8.0 | ||
(function() { | ||
var ClassDef, Coverage, Device, FeatureList, GPOSLookup, JstfGSUBModList, JstfLangSys, JstfLangSysRecord, JstfMax, JstfPriority, JstfScript, JstfScriptRecord, LookupList, ScriptList, r, _ref; | ||
var ClassDef, Coverage, Device, FeatureList, GPOSLookup, JstfGSUBModList, JstfLangSys, JstfLangSysRecord, JstfPriority, JstfScript, JstfScriptRecord, LookupList, ScriptList, r, _ref; | ||
@@ -11,4 +11,2 @@ r = require('restructure'); | ||
JstfMax = new r.Array(new r.Pointer(r.uint16, GPOSLookup)); | ||
JstfGSUBModList = new r.Array(r.uint16, r.uint16); | ||
@@ -21,3 +19,3 @@ | ||
shrinkageDisableGPOS: new r.Pointer(r.uint16, JstfGSUBModList), | ||
shrinkageJstfMax: new r.Pointer(r.uint16, JstfMax), | ||
shrinkageJstfMax: new r.Pointer(r.uint16, new LookupList(GPOSLookup)), | ||
extensionEnableGSUB: new r.Pointer(r.uint16, JstfGSUBModList), | ||
@@ -27,3 +25,3 @@ extensionDisableGSUB: new r.Pointer(r.uint16, JstfGSUBModList), | ||
extensionDisableGPOS: new r.Pointer(r.uint16, JstfGSUBModList), | ||
extensionJstfMax: new r.Pointer(r.uint16, JstfMax) | ||
extensionJstfMax: new r.Pointer(r.uint16, new LookupList(GPOSLookup)) | ||
}); | ||
@@ -40,5 +38,5 @@ | ||
extenderGlyphs: new r.Pointer(r.uint16, new r.Array(r.uint16, r.uint16)), | ||
defaultJstfLangSys: new r.Pointer(r.uint16, JstfLangSys), | ||
jstfLangSysCount: r.uint16, | ||
jstfLangSysRecords: new r.Array(JstfLangSysRecord, 'jstfLangSysCount') | ||
defaultLangSys: new r.Pointer(r.uint16, JstfLangSys), | ||
langSysCount: r.uint16, | ||
langSysRecords: new r.Array(JstfLangSysRecord, 'langSysCount') | ||
}); | ||
@@ -48,3 +46,3 @@ | ||
tag: new r.String(4), | ||
jstfScript: new r.Pointer(r.uint16, JstfScript, { | ||
script: new r.Pointer(r.uint16, JstfScript, { | ||
type: 'parent' | ||
@@ -56,6 +54,6 @@ }) | ||
version: r.uint32, | ||
jstfScriptCount: r.uint16, | ||
jstfScriptRecords: new r.Array(JstfScriptRecord, 'jstfScriptCount') | ||
scriptCount: r.uint16, | ||
scriptList: new r.Array(JstfScriptRecord, 'scriptCount') | ||
}); | ||
}).call(this); |
// Generated by CoffeeScript 1.8.0 | ||
(function() { | ||
var BinarySearchHeader, ContextualEntry, ContextualStateHeader, Entry, FeatureEntry, IndicEntry, IndicStateHeader, InsertionStateEntry, InsertionStateHeader, LookupSegmentArray, LookupSegmentSingle, LookupSingle, LookupTable, MorxChain, StateArray, StateHeader, SubstitutionTable, Subtable, SubtableData, UnboundedArray, r, | ||
__hasProp = {}.hasOwnProperty, | ||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; | ||
var ContextualData, FeatureEntry, InsertionData, LigatureData, LookupTable, MorxChain, StateTable, SubstitutionTable, Subtable, SubtableData, UnboundedArray, r, _ref; | ||
r = require('restructure'); | ||
UnboundedArray = (function(_super) { | ||
var UnboundedArrayAccessor; | ||
_ref = require('./aat'), UnboundedArray = _ref.UnboundedArray, LookupTable = _ref.LookupTable, StateTable = _ref.StateTable; | ||
__extends(UnboundedArray, _super); | ||
function UnboundedArray(type) { | ||
this.type = type; | ||
this.length = 0; | ||
} | ||
UnboundedArrayAccessor = (function() { | ||
function UnboundedArrayAccessor(type, stream, parent) { | ||
this.type = type; | ||
this.stream = stream; | ||
this.parent = parent; | ||
this.base = this.stream.pos; | ||
this._items = []; | ||
} | ||
UnboundedArrayAccessor.prototype.getItem = function(index) { | ||
var pos; | ||
if (this._items[index] == null) { | ||
pos = this.stream.pos; | ||
this.stream.pos = this.base + this.type.size(null, this.parent) * index; | ||
this._items[index] = this.type.decode(this.stream, this.parent); | ||
this.stream.pos = pos; | ||
} | ||
return this._items[index]; | ||
}; | ||
UnboundedArrayAccessor.prototype.inspect = function() { | ||
return "[UnboundedArray " + this.type.constructor.name + "]"; | ||
}; | ||
return UnboundedArrayAccessor; | ||
})(); | ||
UnboundedArray.prototype.decode = function(stream, parent) { | ||
return new UnboundedArrayAccessor(this.type, stream, parent); | ||
}; | ||
return UnboundedArray; | ||
})(r.Array); | ||
BinarySearchHeader = new r.Struct({ | ||
unitSize: r.uint16, | ||
nUnits: r.uint16, | ||
searchRange: r.uint16, | ||
entrySelector: r.uint16, | ||
rangeShift: r.uint16 | ||
}); | ||
LookupSegmentSingle = new r.Struct({ | ||
lastGlyph: r.uint16, | ||
firstGlyph: r.uint16, | ||
value: r.uint16 | ||
}); | ||
LookupSegmentArray = new r.Struct({ | ||
lastGlyph: r.uint16, | ||
firstGlyph: r.uint16, | ||
values: new r.Pointer(r.uint16, new r.Array(r.uint16, function() { | ||
return this.lastGlyph - this.firstGlyph + 1; | ||
}), { | ||
type: 'parent' | ||
}) | ||
}); | ||
LookupSingle = new r.Struct({ | ||
glyph: r.uint16, | ||
value: r.uint16 | ||
}); | ||
LookupTable = new r.VersionedStruct(r.uint16, { | ||
0: { | ||
values: new UnboundedArray(r.uint16) | ||
}, | ||
2: { | ||
binarySearchHeader: BinarySearchHeader, | ||
segments: new r.Array(LookupSegmentSingle, function() { | ||
return this.binarySearchHeader.nUnits; | ||
}) | ||
}, | ||
4: { | ||
binarySearchHeader: BinarySearchHeader, | ||
segments: new r.Array(LookupSegmentArray, function() { | ||
return this.binarySearchHeader.nUnits; | ||
}) | ||
}, | ||
6: { | ||
binarySearchHeader: BinarySearchHeader, | ||
segments: new r.Array(LookupSingle, function() { | ||
return this.binarySearchHeader.nUnits; | ||
}) | ||
}, | ||
8: { | ||
firstGlyph: r.uint16, | ||
count: r.uint16, | ||
values: new r.Array(r.uint16, 'count') | ||
} | ||
}); | ||
StateArray = new UnboundedArray(new r.Array(r.uint16, function() { | ||
return this.nClasses; | ||
})); | ||
Entry = new r.Struct({ | ||
newState: r.uint16, | ||
flags: r.uint16, | ||
LigatureData = { | ||
action: r.uint16 | ||
}); | ||
}; | ||
ContextualEntry = new r.Struct({ | ||
newState: r.uint16, | ||
flags: r.uint16, | ||
ContextualData = { | ||
markIndex: r.uint16, | ||
currentIndex: r.uint16 | ||
}); | ||
}; | ||
IndicEntry = new r.Struct({ | ||
newState: r.uint16, | ||
flags: r.uint16 | ||
}); | ||
InsertionStateEntry = new r.Struct({ | ||
newState: r.uint16, | ||
flags: r.uint16, | ||
InsertionData = { | ||
currentInsertIndex: r.uint16, | ||
markedInsertIndex: r.uint16 | ||
}); | ||
}; | ||
StateHeader = new r.Struct({ | ||
nClasses: r.uint32, | ||
classTable: new r.Pointer(r.uint32, LookupTable), | ||
stateArray: new r.Pointer(r.uint32, StateArray), | ||
entryTable: new r.Pointer(r.uint32, new UnboundedArray(Entry)) | ||
}); | ||
IndicStateHeader = new r.Struct({ | ||
nClasses: r.uint32, | ||
classTable: new r.Pointer(r.uint32, LookupTable), | ||
stateArray: new r.Pointer(r.uint32, StateArray), | ||
entryTable: new r.Pointer(r.uint32, new UnboundedArray(IndicEntry)) | ||
}); | ||
ContextualStateHeader = new r.Struct({ | ||
nClasses: r.uint32, | ||
classTable: new r.Pointer(r.uint32, LookupTable), | ||
stateArray: new r.Pointer(r.uint32, StateArray), | ||
entryTable: new r.Pointer(r.uint32, new UnboundedArray(ContextualEntry)) | ||
}); | ||
InsertionStateHeader = new r.Struct({ | ||
nClasses: r.uint32, | ||
classTable: new r.Pointer(r.uint32, LookupTable), | ||
stateArray: new r.Pointer(r.uint32, StateArray), | ||
entryTable: new r.Pointer(r.uint32, new UnboundedArray(InsertionStateEntry)) | ||
}); | ||
SubstitutionTable = new r.Struct({ | ||
items: new UnboundedArray(new r.Pointer(r.uint32, LookupTable)) | ||
items: new UnboundedArray(new r.Pointer(r.uint32, new LookupTable)) | ||
}); | ||
@@ -176,10 +29,10 @@ | ||
0: { | ||
stateTable: IndicStateHeader | ||
stateTable: new StateTable | ||
}, | ||
1: { | ||
stateTable: ContextualStateHeader, | ||
stateTable: new StateTable(ContextualData), | ||
substitutionTable: new r.Pointer(r.uint32, SubstitutionTable) | ||
}, | ||
2: { | ||
stateTable: StateHeader, | ||
stateTable: new StateTable(LigatureData), | ||
ligatureActions: new r.Pointer(r.uint32, new UnboundedArray(r.uint32)), | ||
@@ -190,6 +43,6 @@ components: new r.Pointer(r.uint32, new UnboundedArray(r.uint16)), | ||
4: { | ||
lookupTable: LookupTable | ||
lookupTable: new LookupTable | ||
}, | ||
5: { | ||
stateTable: InsertionStateHeader, | ||
stateTable: new StateTable(InsertionData), | ||
insertionActions: new r.Pointer(r.uint32, new UnboundedArray(r.uint16)) | ||
@@ -196,0 +49,0 @@ } |
@@ -17,3 +17,3 @@ // Generated by CoffeeScript 1.8.0 | ||
type: 'parent', | ||
relativeTo: 'stringOffset', | ||
relativeTo: 'parent.stringOffset', | ||
allowNull: false | ||
@@ -20,0 +20,0 @@ }) |
@@ -9,3 +9,3 @@ // Generated by CoffeeScript 1.8.0 | ||
header: { | ||
italicAngle: r.int32, | ||
italicAngle: r.fixed32, | ||
underlinePosition: r.int16, | ||
@@ -12,0 +12,0 @@ underlineThickness: r.int16, |
@@ -14,3 +14,3 @@ // Generated by CoffeeScript 1.8.0 | ||
TrueTypeCollection = (function() { | ||
var TTCHeader; | ||
var TTCHeader, get; | ||
@@ -40,29 +40,12 @@ TTCHeader = new r.VersionedStruct(r.uint32, { | ||
TrueTypeCollection.prototype.getFont = function(name) { | ||
var directory, lang, nameTable, offset, substream, val, _i, _len, _ref, _ref1; | ||
var font, offset, stream, _i, _len, _ref; | ||
_ref = this.header.offsets; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
offset = _ref[_i]; | ||
this.stream.pos = offset; | ||
directory = Directory.decode(this.stream, { | ||
_startOffset: 0 | ||
}); | ||
nameTable = directory.tables.name; | ||
if (!nameTable) { | ||
throw new Error("Font must have a name table."); | ||
stream = new r.DecodeStream(this.stream.buffer); | ||
stream.pos = offset; | ||
font = new TTFFont(stream); | ||
if (font.postscriptName === name) { | ||
return font; | ||
} | ||
this.stream.pos = nameTable.offset; | ||
nameTable = tables.name.decode(this.stream); | ||
if (!nameTable.records.postscriptName) { | ||
throw new Error("Font must have a postscript name"); | ||
} | ||
_ref1 = nameTable.records.postscriptName; | ||
for (lang in _ref1) { | ||
val = _ref1[lang]; | ||
if (!(val === name)) { | ||
continue; | ||
} | ||
substream = new r.DecodeStream(this.stream.buffer); | ||
substream.pos = offset; | ||
return new TTFFont(substream); | ||
} | ||
} | ||
@@ -72,2 +55,22 @@ return null; | ||
get = function(key, fn) { | ||
return Object.defineProperty(TrueTypeCollection.prototype, key, { | ||
get: fn, | ||
enumerable: true | ||
}); | ||
}; | ||
get('fonts', function() { | ||
var fonts, offset, stream, _i, _len, _ref; | ||
fonts = []; | ||
_ref = this.header.offsets; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
offset = _ref[_i]; | ||
stream = new r.DecodeStream(this.stream.buffer); | ||
stream.pos = offset; | ||
fonts.push(new TTFFont(stream)); | ||
} | ||
return fonts; | ||
}); | ||
return TrueTypeCollection; | ||
@@ -74,0 +77,0 @@ |
@@ -152,3 +152,3 @@ // Generated by CoffeeScript 1.8.0 | ||
get('italicAngle', function() { | ||
return this.post.italicAngle / 65536; | ||
return this.post.italicAngle; | ||
}); | ||
@@ -155,0 +155,0 @@ |
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
251503
79
6986
247