@@ -5712,9 +5712,9 @@ var CFFFont = (function CFFFontClosure() {
5712
5712
this .properties = properties ;
5713
5713
5714
5714
var parser = new CFFParser (file , properties );
5715
- var cff = parser .parse ();
5716
- var compiler = new CFFCompiler (cff );
5717
- this .readExtra (cff );
5715
+ this . cff = parser .parse ();
5716
+ var compiler = new CFFCompiler (this . cff );
5717
+ this .readExtra ();
5718
5718
try {
5719
5719
this .data = compiler .compile ();
5720
5720
} catch (e ) {
@@ -5726,12 +5726,10 @@ var CFFFont = (function CFFFontClosure() {
5726
5726
}
5727
5727
5728
5728
CFFFont .prototype = {
5729
- readExtra : function CFFFont_readExtra (cff ) {
5729
+ readExtra : function CFFFont_readExtra () {
5730
5730
// charstrings contains info about glyphs (one element per glyph
5731
5731
// containing mappings for {unicode, width})
5732
- var charset = cff .charset .charset ;
5733
- var encoding = cff .encoding ? cff .encoding .encoding : null ;
5734
- var charstrings = this .getCharStrings (charset , encoding );
5732
+ var charstrings = this .getCharStrings ();
5735
5733
5736
5734
// create the mapping between charstring and glyph id
5737
5735
var glyphIds = [];
@@ -5740,21 +5738,39 @@ var CFFFont = (function CFFFontClosure() {
5740
5738
5741
5739
this .charstrings = charstrings ;
5742
5740
this .glyphIds = glyphIds ;
5743
- this .seacs = cff .seacs ;
5741
+ this .seacs = this . cff .seacs ;
5744
5742
},
5745
- getCharStrings : function CFFFont_getCharStrings (charsets , encoding ) {
5743
+ getCharStrings : function CFFFont_getCharStrings () {
5744
+ var cff = this .cff ;
5745
+ var charsets = cff .charset .charset ;
5746
+ var encoding = cff .encoding ? cff .encoding .encoding : null ;
5746
5747
var charstrings = [];
5747
5748
var unicodeUsed = [];
5748
5749
var unassignedUnicodeItems = [];
5749
5750
var inverseEncoding = [];
5750
- // CID fonts don't have an encoding.
5751
- if (encoding !== null )
5751
+ var gidStart = 0 ;
5752
+ // Even though the CFF font may not actually be a CID font is could have
5753
+ // CID information in the font descriptor.
5754
+ if (this .properties .cidSystemInfo ) {
5755
+ // According to section 9.7.4.2 if the font is actually a CID font then
5756
+ // we should use the charset to map CIDs to GIDs. If it is not actually
5757
+ // a CID font then CIDs can be mapped directly to GIDs.
5758
+ if (this .cff .isCIDFont ) {
5759
+ inverseEncoding = charsets ;
5760
+ } else {
5761
+ for (var i = 0 , ii = charsets .length ; i < charsets .length ; i ++) {
5762
+ inverseEncoding .push (i );
5763
+ }
5764
+ }
5765
+ } else {
5752
5766
for (var charcode in encoding )
5753
5767
inverseEncoding [encoding [charcode ]] = charcode | 0 ;
5754
- else
5755
- inverseEncoding = charsets ;
5756
- var i = charsets [0 ] == '.notdef' ? 1 : 0 ;
5757
- for (var ii = charsets .length ; i < ii ; i ++) {
5768
+ if (charsets [0 ] === '.notedef' ) {
5769
+ gidStart = 1 ;
5770
+ }
5771
+ }
5772
+
5773
+ for (var i = gidStart , ii = charsets .length ; i < ii ; i ++) {
5758
5774
var glyph = charsets [i ];
5759
5775
5760
5776
var code = inverseEncoding [i ];
0 commit comments