@ -80,6 +80,7 @@ var getSupplementalGlyphMapForArialBlack =
@@ -80,6 +80,7 @@ var getSupplementalGlyphMapForArialBlack =
coreStandardFonts . getSupplementalGlyphMapForArialBlack ;
var getUnicodeRangeFor = coreUnicode . getUnicodeRangeFor ;
var mapSpecialUnicodeValues = coreUnicode . mapSpecialUnicodeValues ;
var getUnicodeForGlyph = coreUnicode . getUnicodeForGlyph ;
// Unicode Private Use Area
var PRIVATE _USE _OFFSET _START = 0xE000 ;
@ -465,7 +466,7 @@ var ProblematicCharRanges = new Int32Array([
@@ -465,7 +466,7 @@ var ProblematicCharRanges = new Int32Array([
* /
var Font = ( function FontClosure ( ) {
function Font ( name , file , properties ) {
var charCode , glyphName , fontChar ;
var charCode , glyphName , unicode , fontChar ;
this . name = name ;
this . loadedName = properties . loadedName ;
@ -609,21 +610,25 @@ var Font = (function FontClosure() {
@@ -609,21 +610,25 @@ var Font = (function FontClosure() {
this . toFontChar [ charCode ] = fontChar ;
}
} else if ( isStandardFont ) {
this . toFontChar = [ ] ;
glyphsUnicodeMap = getGlyphsUnicode ( ) ;
for ( charCode in properties . defaultEncoding ) {
glyphName = ( properties . differences [ charCode ] ||
properties . defaultEncoding [ charCode ] ) ;
this . toFontChar [ charCode ] = glyphsUnicodeMap [ glyphName ] ;
unicode = getUnicodeForGlyph ( glyphName , glyphsUnicodeMap ) ;
if ( unicode !== - 1 ) {
this . toFontChar [ charCode ] = unicode ;
}
}
} else {
var unicodeCharCode , notCidFont = ( type . indexOf ( 'CIDFontType' ) === - 1 ) ;
glyphsUnicodeMap = getGlyphsUnicode ( ) ;
this . toUnicode . forEach ( function ( charCode , unicodeCharCode ) {
if ( notCidFont ) {
if ( ! this . composite ) {
glyphName = ( properties . differences [ charCode ] ||
properties . defaultEncoding [ charCode ] ) ;
unicodeCharCode = ( glyphsUnicodeMap [ glyphName ] || unicodeCharCode ) ;
unicode = getUnicodeForGlyph ( glyphName , glyphsUnicodeMap ) ;
if ( unicode !== - 1 ) {
unicodeCharCode = unicode ;
}
}
this . toFontChar [ charCode ] = unicodeCharCode ;
} . bind ( this ) ) ;
@ -2283,6 +2288,26 @@ var Font = (function FontClosure() {
@@ -2283,6 +2288,26 @@ var Font = (function FontClosure() {
return false ;
}
// Some bad PDF generators, e.g. Scribus PDF, include glyph names
// in a 'uniXXXX' format -- attempting to recover proper ones.
function recoverGlyphName ( name , glyphsUnicodeMap ) {
if ( glyphsUnicodeMap [ name ] !== undefined ) {
return name ;
}
// The glyph name is non-standard, trying to recover.
var unicode = getUnicodeForGlyph ( name , glyphsUnicodeMap ) ;
if ( unicode !== - 1 ) {
for ( var key in glyphsUnicodeMap ) {
if ( glyphsUnicodeMap [ key ] === unicode ) {
return key ;
}
}
}
warn ( 'Unable to recover a standard glyph name for: ' + name ) ;
return name ;
}
if ( properties . type === 'CIDFontType2' ) {
var cidToGidMap = properties . cidToGidMap || [ ] ;
var isCidToGidMapEmpty = cidToGidMap . length === 0 ;
@ -2337,7 +2362,7 @@ var Font = (function FontClosure() {
@@ -2337,7 +2362,7 @@ var Font = (function FontClosure() {
}
var glyphsUnicodeMap = getGlyphsUnicode ( ) ;
for ( charCode = 0 ; charCode < 256 ; charCode ++ ) {
var glyphName ;
var glyphName , standardGlyphName ;
if ( this . differences && charCode in this . differences ) {
glyphName = this . differences [ charCode ] ;
} else if ( charCode in baseEncoding &&
@ -2349,13 +2374,16 @@ var Font = (function FontClosure() {
@@ -2349,13 +2374,16 @@ var Font = (function FontClosure() {
if ( ! glyphName ) {
continue ;
}
// Ensure that non-standard glyph names are resolved to valid ones.
standardGlyphName = recoverGlyphName ( glyphName , glyphsUnicodeMap ) ;
var unicodeOrCharCode , isUnicode = false ;
if ( cmapPlatformId === 3 && cmapEncodingId === 1 ) {
unicodeOrCharCode = glyphsUnicodeMap [ glyphName ] ;
unicodeOrCharCode = glyphsUnicodeMap [ standardG lyphName] ;
isUnicode = true ;
} else if ( cmapPlatformId === 1 && cmapEncodingId === 0 ) {
// TODO: the encoding needs to be updated with mac os table.
unicodeOrCharCode = MacRomanEncoding . indexOf ( g lyphName) ;
unicodeOrCharCode = MacRomanEncoding . indexOf ( standardG lyphName) ;
}
var found = false ;
@ -2373,6 +2401,11 @@ var Font = (function FontClosure() {
@@ -2373,6 +2401,11 @@ var Font = (function FontClosure() {
if ( ! found && properties . glyphNames ) {
// Try to map using the post table.
var glyphId = properties . glyphNames . indexOf ( glyphName ) ;
// The post table ought to use the same kind of glyph names as the
// `differences` array, but check the standard ones as a fallback.
if ( glyphId === - 1 && standardGlyphName !== glyphName ) {
glyphId = properties . glyphNames . indexOf ( standardGlyphName ) ;
}
if ( glyphId > 0 && hasGlyph ( glyphId , - 1 , - 1 ) ) {
charCodeToGlyphId [ charCode ] = glyphId ;
found = true ;
@ -2686,6 +2719,12 @@ var Font = (function FontClosure() {
@@ -2686,6 +2719,12 @@ var Font = (function FontClosure() {
code = + glyphName . substr ( 1 ) ;
}
break ;
default :
// 'uniXXXX'/'uXXXX{XX}' glyphs
var unicode = getUnicodeForGlyph ( glyphName , glyphsUnicodeMap ) ;
if ( unicode !== - 1 ) {
code = unicode ;
}
}
if ( code ) {
// If |baseEncodingName| is one the predefined encodings,