@ -1267,7 +1267,7 @@ var Font = (function FontClosure() {
mimetype : null ,
mimetype : null ,
encoding : null ,
encoding : null ,
checkAndRepair : function f ont_checkAndRepair ( name , font , properties ) {
checkAndRepair : function F ont_checkAndRepair ( name , font , properties ) {
function readTableEntry ( file ) {
function readTableEntry ( file ) {
var tag = file . getBytes ( 4 ) ;
var tag = file . getBytes ( 4 ) ;
tag = String . fromCharCode ( tag [ 0 ] ) +
tag = String . fromCharCode ( tag [ 0 ] ) +
@ -1828,8 +1828,9 @@ var Font = (function FontClosure() {
readGlyphNameMap ( post , properties ) ;
readGlyphNameMap ( post , properties ) ;
}
}
// Replace the old CMAP table with a shiny new one
var glyphs , ids ;
if ( properties . type == 'CIDFontType2' ) {
if ( properties . type == 'CIDFontType2' ) {
// Replace the old CMAP table with a shiny new one
// Type2 composite fonts map characters directly to glyphs so the cmap
// Type2 composite fonts map characters directly to glyphs so the cmap
// table must be replaced.
// table must be replaced.
// canvas fillText will reencode some characters even if the font has a
// canvas fillText will reencode some characters even if the font has a
@ -1861,7 +1862,9 @@ var Font = (function FontClosure() {
}
}
}
}
var glyphs = [ ] , ids = [ ] ;
glyphs = [ ] ;
ids = [ ] ;
var usedUnicodes = [ ] ;
var usedUnicodes = [ ] ;
var unassignedUnicodeItems = [ ] ;
var unassignedUnicodeItems = [ ] ;
for ( var i = 1 ; i < numGlyphs ; i ++ ) {
for ( var i = 1 ; i < numGlyphs ; i ++ ) {
@ -1892,11 +1895,12 @@ var Font = (function FontClosure() {
glyphs . push ( { unicode : unicode , code : cid } ) ;
glyphs . push ( { unicode : unicode , code : cid } ) ;
ids . push ( i ) ;
ids . push ( i ) ;
}
}
cmap . data = createCMapTable ( glyphs , ids ) ;
} else {
} else {
var cmapTable = readCMapTable ( cmap , font ) ;
var cmapTable = readCMapTable ( cmap , font ) ;
var glyphs = cmapTable . glyphs ;
var ids = cmapTable . ids ;
glyphs = cmapTable . glyphs ;
ids = cmapTable . ids ;
var hasShortCmap = ! ! cmapTable . hasShortCmap ;
var hasShortCmap = ! ! cmapTable . hasShortCmap ;
var toFontChar = this . toFontChar ;
var toFontChar = this . toFontChar ;
@ -2062,9 +2066,15 @@ var Font = (function FontClosure() {
createGlyphNameMap ( glyphs , ids , properties ) ;
createGlyphNameMap ( glyphs , ids , properties ) ;
this . glyphNameMap = properties . glyphNameMap ;
this . glyphNameMap = properties . glyphNameMap ;
}
// Converting glyphs and ids into font's cmap table
cmap . data = createCMapTable ( glyphs , ids ) ;
cmap . data = createCMapTable ( glyphs , ids ) ;
var unicodeIsEnabled = [ ] ;
for ( var i = 0 , ii = glyphs . length ; i < ii ; i ++ ) {
unicodeIsEnabled [ glyphs [ i ] . unicode ] = true ;
}
}
this . unicodeIsEnabled = unicodeIsEnabled ;
// Rewrite the 'post' table if needed
// Rewrite the 'post' table if needed
if ( requiredTables . indexOf ( 'post' ) != - 1 ) {
if ( requiredTables . indexOf ( 'post' ) != - 1 ) {
@ -2112,7 +2122,7 @@ var Font = (function FontClosure() {
return stringToArray ( ttf . file ) ;
return stringToArray ( ttf . file ) ;
} ,
} ,
convert : function f ont_convert ( fontName , font , properties ) {
convert : function F ont_convert ( fontName , font , properties ) {
function isFixedPitch ( glyphs ) {
function isFixedPitch ( glyphs ) {
for ( var i = 0 , ii = glyphs . length - 1 ; i < ii ; i ++ ) {
for ( var i = 0 , ii = glyphs . length - 1 ; i < ii ; i ++ ) {
if ( glyphs [ i ] != glyphs [ i + 1 ] )
if ( glyphs [ i ] != glyphs [ i + 1 ] )
@ -2254,7 +2264,7 @@ var Font = (function FontClosure() {
return stringToArray ( otf . file ) ;
return stringToArray ( otf . file ) ;
} ,
} ,
buildToFontChar : function f ont_buildToFontChar ( toUnicode ) {
buildToFontChar : function F ont_buildToFontChar ( toUnicode ) {
var result = [ ] ;
var result = [ ] ;
var unusedUnicode = kCmapGlyphOffset ;
var unusedUnicode = kCmapGlyphOffset ;
for ( var i = 0 , ii = toUnicode . length ; i < ii ; i ++ ) {
for ( var i = 0 , ii = toUnicode . length ; i < ii ; i ++ ) {
@ -2267,7 +2277,7 @@ var Font = (function FontClosure() {
return result ;
return result ;
} ,
} ,
rebuildToUnicode : function f ont_rebuildToUnicode ( properties ) {
rebuildToUnicode : function F ont_rebuildToUnicode ( properties ) {
var firstChar = properties . firstChar , lastChar = properties . lastChar ;
var firstChar = properties . firstChar , lastChar = properties . lastChar ;
var map = [ ] ;
var map = [ ] ;
if ( properties . composite ) {
if ( properties . composite ) {
@ -2289,7 +2299,7 @@ var Font = (function FontClosure() {
this . toUnicode = map ;
this . toUnicode = map ;
} ,
} ,
loadCidToUnicode : function f ont_loadCidToUnicode ( properties ) {
loadCidToUnicode : function F ont_loadCidToUnicode ( properties ) {
if ( ! properties . cidSystemInfo )
if ( ! properties . cidSystemInfo )
return ;
return ;
@ -2338,7 +2348,7 @@ var Font = (function FontClosure() {
}
}
} ,
} ,
bindDOM : function font _bindDom ( data ) {
bindDOM : function Font _bindDOM ( data ) {
var fontName = this . loadedName ;
var fontName = this . loadedName ;
// Add the font-face rule to the document
// Add the font-face rule to the document
@ -2390,8 +2400,8 @@ var Font = (function FontClosure() {
return shadow ( this , 'spaceWidth' , width ) ;
return shadow ( this , 'spaceWidth' , width ) ;
} ,
} ,
charToGlyph : function fonts _charToGlyph ( charcode ) {
charToGlyph : function Font _charToGlyph ( charcode ) {
var fontCharCode , width , operatorList ;
var fontCharCode , width , operatorList , disabled ;
var width = this . widths [ charcode ] ;
var width = this . widths [ charcode ] ;
@ -2464,16 +2474,19 @@ var Font = (function FontClosure() {
unicodeChars = String . fromCharCode ( unicodeChars ) ;
unicodeChars = String . fromCharCode ( unicodeChars ) ;
width = ( isNum ( width ) ? width : this . defaultWidth ) * this . widthMultiplier ;
width = ( isNum ( width ) ? width : this . defaultWidth ) * this . widthMultiplier ;
disabled = this . unicodeIsEnabled ?
! this . unicodeIsEnabled [ fontCharCode ] : false ;
return {
return {
fontChar : String . fromCharCode ( fontCharCode ) ,
fontChar : String . fromCharCode ( fontCharCode ) ,
unicode : unicodeChars ,
unicode : unicodeChars ,
width : width ,
width : width ,
disabled : disabled ,
operatorList : operatorList
operatorList : operatorList
} ;
} ;
} ,
} ,
charsToGlyphs : function fonts _charsToGlyphs ( chars ) {
charsToGlyphs : function Font _charsToGlyphs ( chars ) {
var charsCache = this . charsCache ;
var charsCache = this . charsCache ;
var glyphs ;
var glyphs ;
@ -2837,7 +2850,7 @@ var Type1Parser = function type1Parser() {
return c == ' ' || c == '\n' || c == '\x0d' ;
return c == ' ' || c == '\n' || c == '\x0d' ;
}
}
this . extractFontProgram = function t1 _extractFontProgram ( stream ) {
this . extractFontProgram = function Type1Parser _extractFontProgram ( stream ) {
var eexec = decrypt ( stream , kEexecEncryptionKey , 4 ) ;
var eexec = decrypt ( stream , kEexecEncryptionKey , 4 ) ;
var eexecStr = '' ;
var eexecStr = '' ;
for ( var i = 0 , ii = eexec . length ; i < ii ; i ++ )
for ( var i = 0 , ii = eexec . length ; i < ii ; i ++ )
@ -2848,7 +2861,7 @@ var Type1Parser = function type1Parser() {
subrs : [ ] ,
subrs : [ ] ,
charstrings : [ ] ,
charstrings : [ ] ,
properties : {
properties : {
'private' : {
'privateData ' : {
'lenIV' : 4
'lenIV' : 4
}
}
}
}
@ -2877,7 +2890,7 @@ var Type1Parser = function type1Parser() {
( token == 'RD' || token == '-|' ) ) {
( token == 'RD' || token == '-|' ) ) {
i ++ ;
i ++ ;
var data = eexec . slice ( i , i + length ) ;
var data = eexec . slice ( i , i + length ) ;
var lenIV = program . properties . private [ 'lenIV' ] ;
var lenIV = program . properties . privateData [ 'lenIV' ] ;
var encoded = decrypt ( data , kCharStringsEncryptionKey , lenIV ) ;
var encoded = decrypt ( data , kCharStringsEncryptionKey , lenIV ) ;
var str = decodeCharString ( encoded ) ;
var str = decodeCharString ( encoded ) ;
@ -2917,7 +2930,7 @@ var Type1Parser = function type1Parser() {
var length = parseInt ( getToken ( ) , 10 ) ;
var length = parseInt ( getToken ( ) , 10 ) ;
getToken ( ) ; // read in 'RD'
getToken ( ) ; // read in 'RD'
var data = eexec . slice ( i + 1 , i + 1 + length ) ;
var data = eexec . slice ( i + 1 , i + 1 + length ) ;
var lenIV = program . properties . private [ 'lenIV' ] ;
var lenIV = program . properties . privateData [ 'lenIV' ] ;
var encoded = decrypt ( data , kCharStringsEncryptionKey , lenIV ) ;
var encoded = decrypt ( data , kCharStringsEncryptionKey , lenIV ) ;
var str = decodeCharString ( encoded ) ;
var str = decodeCharString ( encoded ) ;
i = i + 1 + length ;
i = i + 1 + length ;
@ -2933,12 +2946,12 @@ var Type1Parser = function type1Parser() {
case '/FamilyOtherBlues' :
case '/FamilyOtherBlues' :
case '/StemSnapH' :
case '/StemSnapH' :
case '/StemSnapV' :
case '/StemSnapV' :
program . properties . private [ token . substring ( 1 ) ] =
program . properties . privateData [ token . substring ( 1 ) ] =
readNumberArray ( eexecStr , i + 1 ) ;
readNumberArray ( eexecStr , i + 1 ) ;
break ;
break ;
case '/StdHW' :
case '/StdHW' :
case '/StdVW' :
case '/StdVW' :
program . properties . private [ token . substring ( 1 ) ] =
program . properties . privateData [ token . substring ( 1 ) ] =
readNumberArray ( eexecStr , i + 2 ) [ 0 ] ;
readNumberArray ( eexecStr , i + 2 ) [ 0 ] ;
break ;
break ;
case '/BlueShift' :
case '/BlueShift' :
@ -2947,7 +2960,7 @@ var Type1Parser = function type1Parser() {
case '/BlueScale' :
case '/BlueScale' :
case '/LanguageGroup' :
case '/LanguageGroup' :
case '/ExpansionFactor' :
case '/ExpansionFactor' :
program . properties . private [ token . substring ( 1 ) ] =
program . properties . privateData [ token . substring ( 1 ) ] =
readNumber ( eexecStr , i + 1 ) ;
readNumber ( eexecStr , i + 1 ) ;
break ;
break ;
}
}
@ -2962,7 +2975,8 @@ var Type1Parser = function type1Parser() {
return program ;
return program ;
} ;
} ;
this . extractFontHeader = function t1 _extractFontHeader ( stream , properties ) {
this . extractFontHeader = function Type1Parser _extractFontHeader ( stream ,
properties ) {
var headerString = '' ;
var headerString = '' ;
for ( var i = 0 , ii = stream . length ; i < ii ; i ++ )
for ( var i = 0 , ii = stream . length ; i < ii ; i ++ )
headerString += String . fromCharCode ( stream [ i ] ) ;
headerString += String . fromCharCode ( stream [ i ] ) ;
@ -2971,14 +2985,14 @@ var Type1Parser = function type1Parser() {
var count = headerString . length ;
var count = headerString . length ;
for ( var i = 0 ; i < count ; i ++ ) {
for ( var i = 0 ; i < count ; i ++ ) {
var getToken = function getToken ( ) {
var getToken = function getToken ( ) {
var cha r = headerString [ i ] ;
var characte r = headerString [ i ] ;
while ( i < count && ( isSeparator ( char ) || cha r == '/' ) )
while ( i < count && ( isSeparator ( character ) || characte r == '/' ) )
cha r = headerString [ ++ i ] ;
characte r = headerString [ ++ i ] ;
var token = '' ;
var token = '' ;
while ( i < count && ! ( isSeparator ( char ) || cha r == '/' ) ) {
while ( i < count && ! ( isSeparator ( character ) || characte r == '/' ) ) {
token += cha r;
token += characte r;
cha r = headerString [ ++ i ] ;
characte r = headerString [ ++ i ] ;
}
}
return token ;
return token ;
@ -3130,7 +3144,8 @@ var Type1Font = function Type1Font(name, file, properties) {
} ;
} ;
Type1Font . prototype = {
Type1Font . prototype = {
createCFFIndexHeader : function createCFFIndexHeader ( objects , isByte ) {
createCFFIndexHeader : function Type1Font _createCFFIndexHeader ( objects ,
isByte ) {
// First 2 bytes contains the number of objects contained into this index
// First 2 bytes contains the number of objects contained into this index
var count = objects . length ;
var count = objects . length ;
@ -3166,7 +3181,7 @@ Type1Font.prototype = {
return data ;
return data ;
} ,
} ,
encodeNumber : function encodeNumber ( value ) {
encodeNumber : function Type1Font _ encodeNumber( value ) {
// some of the fonts has ouf-of-range values
// some of the fonts has ouf-of-range values
// they are just arithmetic overflows
// they are just arithmetic overflows
// make sanitizer happy
// make sanitizer happy
@ -3184,7 +3199,7 @@ Type1Font.prototype = {
}
}
} ,
} ,
getOrderedCharStrings : function t ype1Font_getOrderedCharStrings ( glyphs ,
getOrderedCharStrings : function T ype1Font_getOrderedCharStrings ( glyphs ,
properties ) {
properties ) {
var charstrings = [ ] ;
var charstrings = [ ] ;
var i , length , glyphName ;
var i , length , glyphName ;
@ -3210,7 +3225,8 @@ Type1Font.prototype = {
return charstrings ;
return charstrings ;
} ,
} ,
getType2Charstrings : function getType2Charstrings ( type1Charstrings ) {
getType2Charstrings : function Type1Font _getType2Charstrings (
type1Charstrings ) {
var type2Charstrings = [ ] ;
var type2Charstrings = [ ] ;
var count = type1Charstrings . length ;
var count = type1Charstrings . length ;
for ( var i = 0 ; i < count ; i ++ ) {
for ( var i = 0 ; i < count ; i ++ ) {
@ -3221,7 +3237,7 @@ Type1Font.prototype = {
return type2Charstrings ;
return type2Charstrings ;
} ,
} ,
getType2Subrs : function getType2Subrs ( type1Subrs ) {
getType2Subrs : function Type1Font _ getType2Subrs( type1Subrs ) {
var bias = 0 ;
var bias = 0 ;
var count = type1Subrs . length ;
var count = type1Subrs . length ;
if ( count < 1240 )
if ( count < 1240 )
@ -3273,7 +3289,7 @@ Type1Font.prototype = {
'hvcurveto' : 31
'hvcurveto' : 31
} ,
} ,
flattenCharstring : function flattenCharstring ( charstring , map ) {
flattenCharstring : function Type1Font _ flattenCharstring( charstring , map ) {
// charstring changes size - can't cache .length in loop
// charstring changes size - can't cache .length in loop
for ( var i = 0 ; i < charstring . length ; i ++ ) {
for ( var i = 0 ; i < charstring . length ; i ++ ) {
var command = charstring [ i ] ;
var command = charstring [ i ] ;
@ -3300,7 +3316,7 @@ Type1Font.prototype = {
return charstring ;
return charstring ;
} ,
} ,
wrap : function wrap ( name , glyphs , charstrings , subrs , properties ) {
wrap : function Type1Font _ wrap( name , glyphs , charstrings , subrs , properties ) {
var fields = {
var fields = {
// major version, minor version, header size, offset size
// major version, minor version, header size, offset size
'header' : '\x01\x00\x04\x04' ,
'header' : '\x01\x00\x04\x04' ,
@ -3344,7 +3360,7 @@ Type1Font.prototype = {
dict += self . encodeNumber ( offset ) + '\x11' ; // Charstrings
dict += self . encodeNumber ( offset ) + '\x11' ; // Charstrings
offset = offset + fields . charstrings . length ;
offset = offset + fields . charstrings . length ;
dict += self . encodeNumber ( fields . private . length ) ;
dict += self . encodeNumber ( fields . privateData . length ) ;
dict += self . encodeNumber ( offset ) + '\x12' ; // Private
dict += self . encodeNumber ( offset ) + '\x12' ; // Private
return header + String . fromCharCode ( dict . length + 1 ) + dict ;
return header + String . fromCharCode ( dict . length + 1 ) + dict ;
@ -3385,7 +3401,7 @@ Type1Font.prototype = {
'charstrings' : this . createCFFIndexHeader ( [ [ 0x8B , 0x0E ] ] . concat ( glyphs ) ,
'charstrings' : this . createCFFIndexHeader ( [ [ 0x8B , 0x0E ] ] . concat ( glyphs ) ,
true ) ,
true ) ,
'private' : ( function cffWrapPrivate ( self ) {
'privateData ' : ( function cffWrapPrivate ( self ) {
var data =
var data =
'\x8b\x14' + // defaultWidth
'\x8b\x14' + // defaultWidth
'\x8b\x15' ; // nominalWidth
'\x8b\x15' ; // nominalWidth
@ -3403,9 +3419,9 @@ Type1Font.prototype = {
ExpansionFactor : '\x0c\x18'
ExpansionFactor : '\x0c\x18'
} ;
} ;
for ( var field in fieldMap ) {
for ( var field in fieldMap ) {
if ( ! properties . private . hasOwnProperty ( field ) )
if ( ! properties . privateData . hasOwnProperty ( field ) )
continue ;
continue ;
var value = properties . private [ field ] ;
var value = properties . privateData [ field ] ;
if ( isArray ( value ) ) {
if ( isArray ( value ) ) {
data += self . encodeNumber ( value [ 0 ] ) ;
data += self . encodeNumber ( value [ 0 ] ) ;
@ -3457,7 +3473,7 @@ var CFFFont = (function CFFFontClosure() {
}
}
CFFFont . prototype = {
CFFFont . prototype = {
readExtra : function readExtra ( cff ) {
readExtra : function CFFFont _ readExtra( cff ) {
// charstrings contains info about glyphs (one element per glyph
// charstrings contains info about glyphs (one element per glyph
// containing mappings for {unicode, width})
// containing mappings for {unicode, width})
var charset = cff . charset . charset ;
var charset = cff . charset . charset ;
@ -3472,7 +3488,7 @@ var CFFFont = (function CFFFontClosure() {
this . charstrings = charstrings ;
this . charstrings = charstrings ;
this . glyphIds = glyphIds ;
this . glyphIds = glyphIds ;
} ,
} ,
getCharStrings : function getCharStrings ( charsets , encoding ) {
getCharStrings : function CFFFont _ getCharStrings( charsets , encoding ) {
var charstrings = [ ] ;
var charstrings = [ ] ;
var unicodeUsed = [ ] ;
var unicodeUsed = [ ] ;
var unassignedUnicodeItems = [ ] ;
var unassignedUnicodeItems = [ ] ;
@ -3534,7 +3550,7 @@ var CFFParser = (function CFFParserClosure() {
this . properties = properties ;
this . properties = properties ;
}
}
CFFParser . prototype = {
CFFParser . prototype = {
parse : function parse ( ) {
parse : function CFFParser _ parse( ) {
var properties = this . properties ;
var properties = this . properties ;
var cff = new CFF ( ) ;
var cff = new CFF ( ) ;
this . cff = cff ;
this . cff = cff ;
@ -3591,7 +3607,7 @@ var CFFParser = (function CFFParserClosure() {
return cff ;
return cff ;
} ,
} ,
parseHeader : function parseHeader ( ) {
parseHeader : function CFFParser _ parseHeader( ) {
var bytes = this . bytes ;
var bytes = this . bytes ;
var offset = 0 ;
var offset = 0 ;
@ -3610,7 +3626,7 @@ var CFFParser = (function CFFParserClosure() {
var header = new CFFHeader ( major , minor , hdrSize , offSize ) ;
var header = new CFFHeader ( major , minor , hdrSize , offSize ) ;
return { obj : header , endPos : hdrSize } ;
return { obj : header , endPos : hdrSize } ;
} ,
} ,
parseDict : function parseDict ( dict ) {
parseDict : function CFFParser _ parseDict( dict ) {
var pos = 0 ;
var pos = 0 ;
function parseOperand ( ) {
function parseOperand ( ) {
@ -3680,7 +3696,7 @@ var CFFParser = (function CFFParserClosure() {
}
}
return entries ;
return entries ;
} ,
} ,
parseIndex : function parseIndex ( pos ) {
parseIndex : function CFFParser _ parseIndex( pos ) {
var cffIndex = new CFFIndex ( ) ;
var cffIndex = new CFFIndex ( ) ;
var bytes = this . bytes ;
var bytes = this . bytes ;
var count = ( bytes [ pos ++ ] << 8 ) | bytes [ pos ++ ] ;
var count = ( bytes [ pos ++ ] << 8 ) | bytes [ pos ++ ] ;
@ -3710,7 +3726,7 @@ var CFFParser = (function CFFParserClosure() {
}
}
return { obj : cffIndex , endPos : end } ;
return { obj : cffIndex , endPos : end } ;
} ,
} ,
parseNameIndex : function parseNameIndex ( index ) {
parseNameIndex : function CFFParser _ parseNameIndex( index ) {
var names = [ ] ;
var names = [ ] ;
for ( var i = 0 , ii = index . count ; i < ii ; ++ i ) {
for ( var i = 0 , ii = index . count ; i < ii ; ++ i ) {
var name = index . get ( i ) ;
var name = index . get ( i ) ;
@ -3737,7 +3753,7 @@ var CFFParser = (function CFFParserClosure() {
}
}
return names ;
return names ;
} ,
} ,
parseStringIndex : function parseStringIndex ( index ) {
parseStringIndex : function CFFParser _ parseStringIndex( index ) {
var strings = new CFFStrings ( ) ;
var strings = new CFFStrings ( ) ;
for ( var i = 0 , ii = index . count ; i < ii ; ++ i ) {
for ( var i = 0 , ii = index . count ; i < ii ; ++ i ) {
var data = index . get ( i ) ;
var data = index . get ( i ) ;
@ -3745,7 +3761,7 @@ var CFFParser = (function CFFParserClosure() {
}
}
return strings ;
return strings ;
} ,
} ,
createDict : function createDict ( type , dict , strings ) {
createDict : function CFFParser _ createDict( type , dict , strings ) {
var cffDict = new type ( strings ) ;
var cffDict = new type ( strings ) ;
var types = cffDict . types ;
var types = cffDict . types ;
@ -3757,7 +3773,7 @@ var CFFParser = (function CFFParserClosure() {
}
}
return cffDict ;
return cffDict ;
} ,
} ,
parseCharStrings : function parseCharStrings ( charStringOffset ) {
parseCharStrings : function CFFParser _ parseCharStrings( charStringOffset ) {
var charStrings = this . parseIndex ( charStringOffset ) . obj ;
var charStrings = this . parseIndex ( charStringOffset ) . obj ;
// The CFF specification state that the 'dotsection' command
// The CFF specification state that the 'dotsection' command
// (12, 0) is deprecated and treated as a no-op, but all Type2
// (12, 0) is deprecated and treated as a no-op, but all Type2
@ -3786,7 +3802,7 @@ var CFFParser = (function CFFParserClosure() {
}
}
return charStrings ;
return charStrings ;
} ,
} ,
parsePrivateDict : function parsePrivateDict ( parentDict ) {
parsePrivateDict : function CFFParser _ parsePrivateDict( parentDict ) {
// no private dict, do nothing
// no private dict, do nothing
if ( ! parentDict . hasName ( 'Private' ) )
if ( ! parentDict . hasName ( 'Private' ) )
return ;
return ;
@ -3824,7 +3840,7 @@ var CFFParser = (function CFFParserClosure() {
var subrsIndex = this . parseIndex ( relativeOffset ) ;
var subrsIndex = this . parseIndex ( relativeOffset ) ;
privateDict . subrsIndex = subrsIndex . obj ;
privateDict . subrsIndex = subrsIndex . obj ;
} ,
} ,
parseCharsets : function parsec harsets( pos , length , strings , cid ) {
parseCharsets : function CFFParser _parseC harsets( pos , length , strings , cid ) {
if ( pos == 0 ) {
if ( pos == 0 ) {
return new CFFCharset ( true , CFFCharsetPredefinedTypes . ISO _ADOBE ,
return new CFFCharset ( true , CFFCharsetPredefinedTypes . ISO _ADOBE ,
ISOAdobeCharset ) ;
ISOAdobeCharset ) ;
@ -3876,7 +3892,10 @@ var CFFParser = (function CFFParserClosure() {
return new CFFCharset ( false , format , charset , raw ) ;
return new CFFCharset ( false , format , charset , raw ) ;
} ,
} ,
parseEncoding : function parseEncoding ( pos , properties , strings , charset ) {
parseEncoding : function CFFParser _parseEncoding ( pos ,
properties ,
strings ,
charset ) {
var encoding = { } ;
var encoding = { } ;
var bytes = this . bytes ;
var bytes = this . bytes ;
var predefined = false ;
var predefined = false ;
@ -3945,7 +3964,7 @@ var CFFParser = (function CFFParserClosure() {
format = format & 0x7f ;
format = format & 0x7f ;
return new CFFEncoding ( predefined , format , encoding , raw ) ;
return new CFFEncoding ( predefined , format , encoding , raw ) ;
} ,
} ,
parseFDSelect : function parseFDSelect ( pos , length ) {
parseFDSelect : function CFFParser _ parseFDSelect( pos , length ) {
var start = pos ;
var start = pos ;
var bytes = this . bytes ;
var bytes = this . bytes ;
var format = bytes [ pos ++ ] ;
var format = bytes [ pos ++ ] ;
@ -4017,14 +4036,14 @@ var CFFStrings = (function CFFStringsClosure() {
this . strings = [ ] ;
this . strings = [ ] ;
}
}
CFFStrings . prototype = {
CFFStrings . prototype = {
get : function get ( index ) {
get : function CFFStrings _ get( index ) {
if ( index >= 0 && index <= 390 )
if ( index >= 0 && index <= 390 )
return CFFStandardStrings [ index ] ;
return CFFStandardStrings [ index ] ;
if ( index - 391 <= this . strings . length )
if ( index - 391 <= this . strings . length )
return this . strings [ index - 391 ] ;
return this . strings [ index - 391 ] ;
return CFFStandardStrings [ 0 ] ;
return CFFStandardStrings [ 0 ] ;
} ,
} ,
add : function add ( value ) {
add : function CFFStrings _ add( value ) {
this . strings . push ( value ) ;
this . strings . push ( value ) ;
} ,
} ,
get count ( ) {
get count ( ) {
@ -4040,11 +4059,11 @@ var CFFIndex = (function CFFIndexClosure() {
this . length = 0 ;
this . length = 0 ;
}
}
CFFIndex . prototype = {
CFFIndex . prototype = {
add : function add ( data ) {
add : function CFFIndex _ add( data ) {
this . length += data . length ;
this . length += data . length ;
this . objects . push ( data ) ;
this . objects . push ( data ) ;
} ,
} ,
get : function get ( index ) {
get : function CFFIndex _ get( index ) {
return this . objects [ index ] ;
return this . objects [ index ] ;
} ,
} ,
get count ( ) {
get count ( ) {
@ -4067,7 +4086,7 @@ var CFFDict = (function CFFDictClosure() {
}
}
CFFDict . prototype = {
CFFDict . prototype = {
// value should always be an array
// value should always be an array
setByKey : function setByKey ( key , value ) {
setByKey : function CFFDict _ setByKey( key , value ) {
if ( ! ( key in this . keyToNameMap ) )
if ( ! ( key in this . keyToNameMap ) )
return false ;
return false ;
// ignore empty values
// ignore empty values
@ -4080,10 +4099,10 @@ var CFFDict = (function CFFDictClosure() {
this . values [ key ] = value ;
this . values [ key ] = value ;
return true ;
return true ;
} ,
} ,
hasName : function hasName ( name ) {
hasName : function CFFDict _ hasName( name ) {
return this . nameToKeyMap [ name ] in this . values ;
return this . nameToKeyMap [ name ] in this . values ;
} ,
} ,
getByName : function getByName ( name ) {
getByName : function CFFDict _ getByName( name ) {
if ( ! ( name in this . nameToKeyMap ) )
if ( ! ( name in this . nameToKeyMap ) )
error ( 'Invalid dictionary name "' + name + '"' ) ;
error ( 'Invalid dictionary name "' + name + '"' ) ;
var key = this . nameToKeyMap [ name ] ;
var key = this . nameToKeyMap [ name ] ;
@ -4091,11 +4110,11 @@ var CFFDict = (function CFFDictClosure() {
return this . defaults [ key ] ;
return this . defaults [ key ] ;
return this . values [ key ] ;
return this . values [ key ] ;
} ,
} ,
removeByName : function removeByName ( name ) {
removeByName : function CFFDict _ removeByName( name ) {
delete this . values [ this . nameToKeyMap [ name ] ] ;
delete this . values [ this . nameToKeyMap [ name ] ] ;
}
}
} ;
} ;
CFFDict . createTables = function createTables ( layout ) {
CFFDict . createTables = function CFFDict _ createTables( layout ) {
var tables = {
var tables = {
keyToNameMap : { } ,
keyToNameMap : { } ,
nameToKeyMap : { } ,
nameToKeyMap : { } ,
@ -4252,20 +4271,22 @@ var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
this . offsets = { } ;
this . offsets = { } ;
}
}
CFFOffsetTracker . prototype = {
CFFOffsetTracker . prototype = {
isTracking : function isTracking ( key ) {
isTracking : function CFFOffsetTracker _ isTracking( key ) {
return key in this . offsets ;
return key in this . offsets ;
} ,
} ,
track : function track ( key , location ) {
track : function CFFOffsetTracker _ track( key , location ) {
if ( key in this . offsets )
if ( key in this . offsets )
error ( 'Already tracking location of ' + key ) ;
error ( 'Already tracking location of ' + key ) ;
this . offsets [ key ] = location ;
this . offsets [ key ] = location ;
} ,
} ,
offset : function offset ( value ) {
offset : function CFFOffsetTracker _ offset( value ) {
for ( var key in this . offsets ) {
for ( var key in this . offsets ) {
this . offsets [ key ] += value ;
this . offsets [ key ] += value ;
}
}
} ,
} ,
setEntryLocation : function setEntryLocation ( key , values , output ) {
setEntryLocation : function CFFOffsetTracker _setEntryLocation ( key ,
values ,
output ) {
if ( ! ( key in this . offsets ) )
if ( ! ( key in this . offsets ) )
error ( 'Not tracking location of ' + key ) ;
error ( 'Not tracking location of ' + key ) ;
var data = output . data ;
var data = output . data ;
@ -4306,12 +4327,12 @@ var CFFCompiler = (function CFFCompilerClosure() {
this . cff = cff ;
this . cff = cff ;
}
}
CFFCompiler . prototype = {
CFFCompiler . prototype = {
compile : function compile ( ) {
compile : function CFFCompiler _ compile( ) {
var cff = this . cff ;
var cff = this . cff ;
var output = {
var output = {
data : [ ] ,
data : [ ] ,
length : 0 ,
length : 0 ,
add : function add ( data ) {
add : function CFFCompiler _ add( data ) {
this . data = this . data . concat ( data ) ;
this . data = this . data . concat ( data ) ;
this . length = this . data . length ;
this . length = this . data . length ;
}
}
@ -4362,29 +4383,31 @@ var CFFCompiler = (function CFFCompilerClosure() {
output . add ( charStrings ) ;
output . add ( charStrings ) ;
if ( cff . isCIDFont ) {
if ( cff . isCIDFont ) {
// For some reason FDSelect must be in front of FDArray on windows. OSX
// and linux don't seem to care.
topDictTracker . setEntryLocation ( 'FDSelect' , [ output . length ] , output ) ;
var fdSelect = this . compileFDSelect ( cff . fdSelect . raw ) ;
output . add ( fdSelect ) ;
var compiled = this . compileTopDicts ( cff . fdArray , output . length ) ;
var compiled = this . compileTopDicts ( cff . fdArray , output . length ) ;
topDictTracker . setEntryLocation ( 'FDArray' , [ output . length ] , output ) ;
topDictTracker . setEntryLocation ( 'FDArray' , [ output . length ] , output ) ;
output . add ( compiled . output ) ;
output . add ( compiled . output ) ;
var fontDictTrackers = compiled . trackers ;
var fontDictTrackers = compiled . trackers ;
this . compilePrivateDicts ( cff . fdArray , fontDictTrackers , output ) ;
this . compilePrivateDicts ( cff . fdArray , fontDictTrackers , output ) ;
topDictTracker . setEntryLocation ( 'FDSelect' , [ output . length ] , output ) ;
var fdSelect = this . compileFDSelect ( cff . fdSelect . raw ) ;
output . add ( fdSelect ) ;
}
}
this . compilePrivateDicts ( [ cff . topDict ] , [ topDictTracker ] , output ) ;
this . compilePrivateDicts ( [ cff . topDict ] , [ topDictTracker ] , output ) ;
return output . data ;
return output . data ;
} ,
} ,
encodeNumber : function encodeNumber ( value ) {
encodeNumber : function CFFCompiler _ encodeNumber( value ) {
if ( parseFloat ( value ) == parseInt ( value ) && ! isNaN ( value ) ) // isInt
if ( parseFloat ( value ) == parseInt ( value ) && ! isNaN ( value ) ) // isInt
return this . encodeInteger ( value ) ;
return this . encodeInteger ( value ) ;
else
else
return this . encodeFloat ( value ) ;
return this . encodeFloat ( value ) ;
} ,
} ,
encodeFloat : function encodeFloat ( value ) {
encodeFloat : function CFFCompiler _ encodeFloat( value ) {
value = value . toString ( ) ;
value = value . toString ( ) ;
// Strip off the any leading zeros.
// Strip off the any leading zeros.
if ( value . substr ( 0 , 2 ) === '0.' )
if ( value . substr ( 0 , 2 ) === '0.' )
@ -4417,7 +4440,7 @@ var CFFCompiler = (function CFFCompilerClosure() {
out . push ( nibbles [ i ] << 4 | nibbles [ i + 1 ] ) ;
out . push ( nibbles [ i ] << 4 | nibbles [ i + 1 ] ) ;
return out ;
return out ;
} ,
} ,
encodeInteger : function encodeInteger ( value ) {
encodeInteger : function CFFCompiler _ encodeInteger( value ) {
var code ;
var code ;
if ( value >= - 107 && value <= 107 ) {
if ( value >= - 107 && value <= 107 ) {
code = [ value + 139 ] ;
code = [ value + 139 ] ;
@ -4438,7 +4461,7 @@ var CFFCompiler = (function CFFCompilerClosure() {
}
}
return code ;
return code ;
} ,
} ,
compileHeader : function compileHeader ( header ) {
compileHeader : function CFFCompiler _ compileHeader( header ) {
return [
return [
header . major ,
header . major ,
header . minor ,
header . minor ,
@ -4446,13 +4469,13 @@ var CFFCompiler = (function CFFCompilerClosure() {
header . offSize
header . offSize
] ;
] ;
} ,
} ,
compileNameIndex : function compileNameIndex ( names ) {
compileNameIndex : function CFFCompiler _ compileNameIndex( names ) {
var nameIndex = new CFFIndex ( ) ;
var nameIndex = new CFFIndex ( ) ;
for ( var i = 0 , ii = names . length ; i < ii ; ++ i )
for ( var i = 0 , ii = names . length ; i < ii ; ++ i )
nameIndex . add ( stringToArray ( names [ i ] ) ) ;
nameIndex . add ( stringToArray ( names [ i ] ) ) ;
return this . compileIndex ( nameIndex ) ;
return this . compileIndex ( nameIndex ) ;
} ,
} ,
compileTopDicts : function compileTopDicts ( dicts , length ) {
compileTopDicts : function CFFCompiler _ compileTopDicts( dicts , length ) {
var fontDictTrackers = [ ] ;
var fontDictTrackers = [ ] ;
var fdArrayIndex = new CFFIndex ( ) ;
var fdArrayIndex = new CFFIndex ( ) ;
for ( var i = 0 , ii = dicts . length ; i < ii ; ++ i ) {
for ( var i = 0 , ii = dicts . length ; i < ii ; ++ i ) {
@ -4469,7 +4492,9 @@ var CFFCompiler = (function CFFCompilerClosure() {
output : fdArrayIndex
output : fdArrayIndex
} ;
} ;
} ,
} ,
compilePrivateDicts : function compilePrivateDicts ( dicts , trackers , output ) {
compilePrivateDicts : function CFFCompiler _compilePrivateDicts ( dicts ,
trackers ,
output ) {
for ( var i = 0 , ii = dicts . length ; i < ii ; ++ i ) {
for ( var i = 0 , ii = dicts . length ; i < ii ; ++ i ) {
var fontDict = dicts [ i ] ;
var fontDict = dicts [ i ] ;
if ( ! fontDict . privateDict || ! fontDict . hasName ( 'Private' ) )
if ( ! fontDict . privateDict || ! fontDict . hasName ( 'Private' ) )
@ -4492,7 +4517,7 @@ var CFFCompiler = (function CFFCompilerClosure() {
}
}
}
}
} ,
} ,
compileDict : function compileDict ( dict , offsetTracker ) {
compileDict : function CFFCompiler _ compileDict( dict , offsetTracker ) {
var out = [ ] ;
var out = [ ] ;
// The dictionary keys must be in a certain order.
// The dictionary keys must be in a certain order.
var order = dict . order ;
var order = dict . order ;
@ -4543,35 +4568,35 @@ var CFFCompiler = (function CFFCompilerClosure() {
}
}
return out ;
return out ;
} ,
} ,
compileStringIndex : function compileStringIndex ( strings ) {
compileStringIndex : function CFFCompiler _ compileStringIndex( strings ) {
var stringIndex = new CFFIndex ( ) ;
var stringIndex = new CFFIndex ( ) ;
for ( var i = 0 , ii = strings . length ; i < ii ; ++ i )
for ( var i = 0 , ii = strings . length ; i < ii ; ++ i )
stringIndex . add ( stringToArray ( strings [ i ] ) ) ;
stringIndex . add ( stringToArray ( strings [ i ] ) ) ;
return this . compileIndex ( stringIndex ) ;
return this . compileIndex ( stringIndex ) ;
} ,
} ,
compileGlobalSubrIndex : function compileGlobalSubrIndex ( ) {
compileGlobalSubrIndex : function CFFCompiler _ compileGlobalSubrIndex( ) {
var globalSubrIndex = this . cff . globalSubrIndex ;
var globalSubrIndex = this . cff . globalSubrIndex ;
this . out . writeByteArray ( this . compileIndex ( globalSubrIndex ) ) ;
this . out . writeByteArray ( this . compileIndex ( globalSubrIndex ) ) ;
} ,
} ,
compileCharStrings : function compileCharStrings ( charStrings ) {
compileCharStrings : function CFFCompiler _ compileCharStrings( charStrings ) {
return this . compileIndex ( charStrings ) ;
return this . compileIndex ( charStrings ) ;
} ,
} ,
compileCharset : function compileCharset ( charset ) {
compileCharset : function CFFCompiler _ compileCharset( charset ) {
return this . compileTypedArray ( charset . raw ) ;
return this . compileTypedArray ( charset . raw ) ;
} ,
} ,
compileEncoding : function compileEncoding ( encoding ) {
compileEncoding : function CFFCompiler _ compileEncoding( encoding ) {
return this . compileTypedArray ( encoding . raw ) ;
return this . compileTypedArray ( encoding . raw ) ;
} ,
} ,
compileFDSelect : function compileFDSelect ( fdSelect ) {
compileFDSelect : function CFFCompiler _ compileFDSelect( fdSelect ) {
return this . compileTypedArray ( fdSelect ) ;
return this . compileTypedArray ( fdSelect ) ;
} ,
} ,
compileTypedArray : function compileTypedArray ( data ) {
compileTypedArray : function CFFCompiler _ compileTypedArray( data ) {
var out = [ ] ;
var out = [ ] ;
for ( var i = 0 , ii = data . length ; i < ii ; ++ i )
for ( var i = 0 , ii = data . length ; i < ii ; ++ i )
out [ i ] = data [ i ] ;
out [ i ] = data [ i ] ;
return out ;
return out ;
} ,
} ,
compileIndex : function compileIndex ( index , trackers ) {
compileIndex : function CFFCompiler _ compileIndex( index , trackers ) {
trackers = trackers || [ ] ;
trackers = trackers || [ ] ;
var objects = index . objects ;
var objects = index . objects ;
// First 2 bytes contains the number of objects contained into this index
// First 2 bytes contains the number of objects contained into this index