Browse Source

Simplify the cmap format 6 conversion - fix #449

Vivien Nicolas 14 years ago
parent
commit
6329f89982
  1. 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)
min = charcode;
if (charcode > max)
max = charcode;
}
// Since Format 6 is a dense array, check for gaps var mapping = encoding[j] || {};
for (var j = min; j < max; j++) { mapping.unicode = glyphs[j].unicode;
if (glyphs.indexOf(j) == -1) encoding[j] = mapping;
glyphs.push(j);
} }
return cmap.data = createCMapTable(glyphs, ids);
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…
Cancel
Save