Skip to content

Commit 683a8f0

Browse files
committed
Remove indexOf, using reverse map instead
1 parent 88310a0 commit 683a8f0

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

src/fonts.js

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,12 +1700,19 @@ var Font = (function Font() {
17001700
tables.push(cmap);
17011701
}
17021702

1703+
var cidToGidMap = properties.cidToGidMap || [];
1704+
var gidToCidMap = [0];
1705+
for (var j = cidToGidMap.length - 1; j >= 0; j--) {
1706+
var gid = cidToGidMap[j];
1707+
if (gid)
1708+
gidToCidMap[gid] = j;
1709+
}
1710+
17031711
var glyphs = [], ids = [];
17041712
var usedUnicodes = [];
1705-
var cidToGidMap = properties.cidToGidMap;
17061713
var unassignedUnicodeItems = [];
17071714
for (var i = 1; i < numGlyphs; i++) {
1708-
var cid = cidToGidMap ? cidToGidMap.indexOf(i) : i;
1715+
var cid = gidToCidMap[i] || i;
17091716
var unicode = this.toUnicode[cid];
17101717
if (!unicode || isSpecialUnicode(unicode) ||
17111718
unicode in usedUnicodes) {
@@ -1716,21 +1723,21 @@ var Font = (function Font() {
17161723
glyphs.push({ unicode: unicode, code: cid });
17171724
ids.push(i);
17181725
}
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-
}
1726+
// trying to fit as many unassigned symbols as we can
1727+
// in the range allocated for the user defined symbols
1728+
var unusedUnicode = kCmapGlyphOffset;
1729+
for (var j = 0, jj = unassignedUnicodeItems.length; j < jj; j++) {
1730+
var i = unassignedUnicodeItems[j];
1731+
var cid = gidToCidMap[i] || i;
1732+
while (unusedUnicode in usedUnicodes)
1733+
unusedUnicode++;
1734+
if (unusedUnicode >= kCmapGlyphOffset + kSizeOfGlyphArea)
1735+
break;
1736+
var unicode = unusedUnicode++;
1737+
this.toUnicode[cid] = unicode;
1738+
usedUnicodes[unicode] = true;
1739+
glyphs.push({ unicode: unicode, code: cid });
1740+
ids.push(i);
17341741
}
17351742
cmap.data = createCMapTable(glyphs, ids);
17361743
} else {

0 commit comments

Comments
 (0)