@@ -1701,27 +1701,37 @@ var Font = (function Font() {
1701
1701
}
1702
1702
1703
1703
var glyphs = [], ids = [];
1704
- var usedUnicodes = [], unusedUnicode = kCmapGlyphOffset ;
1704
+ var usedUnicodes = [];
1705
1705
var cidToGidMap = properties .cidToGidMap ;
1706
- for (i = 1 ; i < numGlyphs ; i ++) {
1706
+ var unassignedUnicodeItems = [];
1707
+ for (var i = 1 ; i < numGlyphs ; i ++) {
1707
1708
var cid = cidToGidMap ? cidToGidMap .indexOf (i ) : i ;
1708
1709
var unicode = this .toUnicode [cid ];
1709
1710
if (!unicode || isSpecialUnicode (unicode ) ||
1710
1711
unicode in usedUnicodes ) {
1711
- // overriding the special special symbols mapping
1712
- while (unusedUnicode in usedUnicodes )
1713
- unusedUnicode ++;
1714
- this .toUnicode [cid ] = unicode = unusedUnicode ++;
1715
- if (unusedUnicode >= kCmapGlyphOffset + kSizeOfGlyphArea ) {
1716
- // overflow of the user defined symblos range
1717
- // using symbols that a little bit lower than this range
1718
- unusedUnicode = kCmapGlyphOffset - numGlyphs ;
1719
- }
1712
+ unassignedUnicodeItems .push (i );
1713
+ continue ;
1720
1714
}
1721
1715
usedUnicodes [unicode ] = true ;
1722
1716
glyphs .push ({ unicode : unicode , code : cid });
1723
1717
ids .push (i );
1724
1718
}
1719
+ // checking if unassigned symbols will fit the user defined symbols
1720
+ // if those symbols too many, probably they will not be used anyway
1721
+ if (unassignedUnicodeItems .length <= kSizeOfGlyphArea ) {
1722
+ var unusedUnicode = kCmapGlyphOffset ;
1723
+ for (var j = 0 , jj = unassignedUnicodeItems .length ; j < jj ; j ++) {
1724
+ var i = unassignedUnicodeItems [j ];
1725
+ var cid = cidToGidMap ? cidToGidMap .indexOf (i ) : i ;
1726
+ while (unusedUnicode in usedUnicodes )
1727
+ unusedUnicode ++;
1728
+ var unicode = unusedUnicode ++;
1729
+ this .toUnicode [cid ] = unicode ;
1730
+ usedUnicodes [unicode ] = true ;
1731
+ glyphs .push ({ unicode : unicode , code : cid });
1732
+ ids .push (i );
1733
+ }
1734
+ }
1725
1735
cmap .data = createCMapTable (glyphs , ids );
1726
1736
} else {
1727
1737
var cmapTable = readCMapTable (cmap , font );
0 commit comments