Browse Source

Fixing duplicates in cmap

notmasteryet 14 years ago
parent
commit
aaad824f77
  1. 24
      src/fonts.js

24
src/fonts.js

@ -1432,7 +1432,7 @@ var Font = (function Font() {
var glyphCode = offsetIndex < 0 ? j : var glyphCode = offsetIndex < 0 ? j :
offsets[offsetIndex + j - start]; offsets[offsetIndex + j - start];
glyphCode = (glyphCode + delta) & 0xFFFF; glyphCode = (glyphCode + delta) & 0xFFFF;
if (glyphCode == 0) if (glyphCode == 0 || isAdaptedUnicode(j))
continue; continue;
var unicode = adaptUnicode(j); var unicode = adaptUnicode(j);
@ -1457,6 +1457,9 @@ var Font = (function Font() {
for (var j = 0; j < entryCount; j++) { for (var j = 0; j < entryCount; j++) {
var glyphCode = int16(font.getBytes(2)); var glyphCode = int16(font.getBytes(2));
var code = firstCode + j; var code = firstCode + j;
if (isAdaptedUnicode(glyphCode))
continue;
var unicode = adaptUnicode(code); var unicode = adaptUnicode(code);
glyphs.push({ unicode: unicode, code: code }); glyphs.push({ unicode: unicode, code: code });
ids.push(glyphCode); ids.push(glyphCode);
@ -2754,14 +2757,23 @@ CFF.prototype = {
var reverseMapping = {}; var reverseMapping = {};
var encoding = properties.baseEncoding; var encoding = properties.baseEncoding;
var differences = properties.differences; var differences = properties.differences;
var i, length; var usedIn = [];
var i, length, glyphName;
for (i = 0, length = encoding.length; i < length; ++i) { for (i = 0, length = encoding.length; i < length; ++i) {
if (encoding[i] && !isSpecialUnicode(i)) glyphName = encoding[i];
reverseMapping[encoding[i]] = i; if (!glyphName || isSpecialUnicode(i))
continue;
reverseMapping[glyphName] = i;
usedIn[i] = glyphName;
} }
for (i = 0, length = differences.length; i < length; ++i) { for (i = 0, length = differences.length; i < length; ++i) {
if (differences[i] && !isSpecialUnicode(i)) glyphName = differences[i];
reverseMapping[differences[i]] = i; if (!glyphName || isSpecialUnicode(i))
continue;
if (usedIn[i])
delete reverseMapping[usedIn[i]];
reverseMapping[glyphName] = i;
usedIn[i] = glyphName;
} }
reverseMapping['.notdef'] = 0; reverseMapping['.notdef'] = 0;
var unusedUnicode = kCmapGlyphOffset; var unusedUnicode = kCmapGlyphOffset;

Loading…
Cancel
Save