Remove indexOf, using reverse map instead
This commit is contained in:
parent
88310a09c2
commit
683a8f0de8
21
src/fonts.js
21
src/fonts.js
@ -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,22 +1723,22 @@ 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 = cidToGidMap ? cidToGidMap.indexOf(i) : i;
|
var cid = gidToCidMap[i] || i;
|
||||||
while (unusedUnicode in usedUnicodes)
|
while (unusedUnicode in usedUnicodes)
|
||||||
unusedUnicode++;
|
unusedUnicode++;
|
||||||
|
if (unusedUnicode >= kCmapGlyphOffset + kSizeOfGlyphArea)
|
||||||
|
break;
|
||||||
var unicode = unusedUnicode++;
|
var unicode = unusedUnicode++;
|
||||||
this.toUnicode[cid] = unicode;
|
this.toUnicode[cid] = unicode;
|
||||||
usedUnicodes[unicode] = true;
|
usedUnicodes[unicode] = true;
|
||||||
glyphs.push({ unicode: unicode, code: cid });
|
glyphs.push({ unicode: unicode, code: cid });
|
||||||
ids.push(i);
|
ids.push(i);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
cmap.data = createCMapTable(glyphs, ids);
|
cmap.data = createCMapTable(glyphs, ids);
|
||||||
} else {
|
} else {
|
||||||
var cmapTable = readCMapTable(cmap, font);
|
var cmapTable = readCMapTable(cmap, font);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user