Remove indexOf, using reverse map instead

This commit is contained in:
notmasteryet 2011-11-28 21:54:07 -06:00
parent 88310a09c2
commit 683a8f0de8

View File

@ -1700,12 +1700,19 @@ var Font = (function Font() {
tables.push(cmap); tables.push(cmap);
} }
var cidToGidMap = properties.cidToGidMap || [];
var gidToCidMap = [0];
for (var j = cidToGidMap.length - 1; j >= 0; j--) {
var gid = cidToGidMap[j];
if (gid)
gidToCidMap[gid] = j;
}
var glyphs = [], ids = []; var glyphs = [], ids = [];
var usedUnicodes = []; var usedUnicodes = [];
var cidToGidMap = properties.cidToGidMap;
var unassignedUnicodeItems = []; var unassignedUnicodeItems = [];
for (var i = 1; i < numGlyphs; i++) { for (var i = 1; i < numGlyphs; i++) {
var cid = cidToGidMap ? cidToGidMap.indexOf(i) : i; var cid = gidToCidMap[i] || i;
var unicode = this.toUnicode[cid]; var unicode = this.toUnicode[cid];
if (!unicode || isSpecialUnicode(unicode) || if (!unicode || isSpecialUnicode(unicode) ||
unicode in usedUnicodes) { unicode in usedUnicodes) {
@ -1716,21 +1723,21 @@ var Font = (function Font() {
glyphs.push({ unicode: unicode, code: cid }); glyphs.push({ unicode: unicode, code: cid });
ids.push(i); ids.push(i);
} }
// checking if unassigned symbols will fit the user defined symbols // trying to fit as many unassigned symbols as we can
// if those symbols too many, probably they will not be used anyway // in the range allocated for the user defined symbols
if (unassignedUnicodeItems.length <= kSizeOfGlyphArea) { var unusedUnicode = kCmapGlyphOffset;
var unusedUnicode = kCmapGlyphOffset; for (var j = 0, jj = unassignedUnicodeItems.length; j < jj; j++) {
for (var j = 0, jj = unassignedUnicodeItems.length; j < jj; j++) { var i = unassignedUnicodeItems[j];
var i = unassignedUnicodeItems[j]; var cid = gidToCidMap[i] || i;
var cid = cidToGidMap ? cidToGidMap.indexOf(i) : i; while (unusedUnicode in usedUnicodes)
while (unusedUnicode in usedUnicodes) unusedUnicode++;
unusedUnicode++; if (unusedUnicode >= kCmapGlyphOffset + kSizeOfGlyphArea)
var unicode = unusedUnicode++; break;
this.toUnicode[cid] = unicode; var unicode = unusedUnicode++;
usedUnicodes[unicode] = true; this.toUnicode[cid] = unicode;
glyphs.push({ unicode: unicode, code: cid }); usedUnicodes[unicode] = true;
ids.push(i); glyphs.push({ unicode: unicode, code: cid });
} ids.push(i);
} }
cmap.data = createCMapTable(glyphs, ids); cmap.data = createCMapTable(glyphs, ids);
} else { } else {