Simplify the cmap format 6 conversion - fix #449
This commit is contained in:
parent
5cb2a07b3d
commit
6329f89982
44
fonts.js
44
fonts.js
@ -1001,43 +1001,17 @@ var Font = (function Font() {
|
|||||||
var entryCount = int16(font.getBytes(2));
|
var entryCount = int16(font.getBytes(2));
|
||||||
|
|
||||||
var glyphs = [];
|
var glyphs = [];
|
||||||
var min = 0xffff, max = 0;
|
var ids = [];
|
||||||
for (var j = 0; j < entryCount; j++) {
|
for (var j = 0; j < firstCode + entryCount; j++) {
|
||||||
var charcode = int16(font.getBytes(2));
|
var code = (j >= firstCode) ? int16(font.getBytes(2)) : j;
|
||||||
if (!charcode)
|
glyphs.push({ unicode: j + kCmapGlyphOffset });
|
||||||
continue;
|
ids.push(code);
|
||||||
glyphs.push(charcode);
|
|
||||||
|
|
||||||
if (charcode < min)
|
var mapping = encoding[j] || {};
|
||||||
min = charcode;
|
mapping.unicode = glyphs[j].unicode;
|
||||||
if (charcode > max)
|
encoding[j] = mapping;
|
||||||
max = charcode;
|
|
||||||
}
|
}
|
||||||
|
return cmap.data = createCMapTable(glyphs, ids);
|
||||||
// Since Format 6 is a dense array, check for gaps
|
|
||||||
for (var j = min; j < max; j++) {
|
|
||||||
if (glyphs.indexOf(j) == -1)
|
|
||||||
glyphs.push(j);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var j = 0; j < glyphs.length; j++)
|
|
||||||
glyphs[j] = { unicode: glyphs[j] + firstCode };
|
|
||||||
|
|
||||||
var ranges = getRanges(glyphs);
|
|
||||||
assert(ranges.length == 1, 'Got ' + ranges.length +
|
|
||||||
' ranges in a dense array');
|
|
||||||
|
|
||||||
var denseRange = ranges[0];
|
|
||||||
var start = denseRange[0];
|
|
||||||
var end = denseRange[1];
|
|
||||||
var index = firstCode;
|
|
||||||
for (var j = start; j <= end; j++) {
|
|
||||||
var code = glyphs[j - start];
|
|
||||||
var mapping = encoding[index] || {};
|
|
||||||
mapping.unicode = code.unicode;
|
|
||||||
encoding[index++] = mapping;
|
|
||||||
}
|
|
||||||
return cmap.data = createCMapTable(glyphs);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return cmap.data;
|
return cmap.data;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user