Skip to content

Commit e4e8647

Browse files
committed
Fix CIDFontType2 large cmap tables
1 parent 08e3fd8 commit e4e8647

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

src/fonts.js

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,27 +1701,37 @@ var Font = (function Font() {
17011701
}
17021702

17031703
var glyphs = [], ids = [];
1704-
var usedUnicodes = [], unusedUnicode = kCmapGlyphOffset;
1704+
var usedUnicodes = [];
17051705
var cidToGidMap = properties.cidToGidMap;
1706-
for (i = 1; i < numGlyphs; i++) {
1706+
var unassignedUnicodeItems = [];
1707+
for (var i = 1; i < numGlyphs; i++) {
17071708
var cid = cidToGidMap ? cidToGidMap.indexOf(i) : i;
17081709
var unicode = this.toUnicode[cid];
17091710
if (!unicode || isSpecialUnicode(unicode) ||
17101711
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;
17201714
}
17211715
usedUnicodes[unicode] = true;
17221716
glyphs.push({ unicode: unicode, code: cid });
17231717
ids.push(i);
17241718
}
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+
}
17251735
cmap.data = createCMapTable(glyphs, ids);
17261736
} else {
17271737
var cmapTable = readCMapTable(cmap, font);

0 commit comments

Comments
 (0)