Fixing duplicate charstring selection
This commit is contained in:
parent
5ec177d88e
commit
01f026ce14
61
fonts.js
61
fonts.js
@ -2551,34 +2551,34 @@ var Type2CFF = (function type2CFF() {
|
|||||||
privateDict, properties) {
|
privateDict, properties) {
|
||||||
var defaultWidth = privateDict['defaultWidthX'];
|
var defaultWidth = privateDict['defaultWidthX'];
|
||||||
var charstrings = [];
|
var charstrings = [];
|
||||||
var differences = properties.differences;
|
var firstChar = properties.firstChar;
|
||||||
for (var i = 1; i < charsets.length; i++) {
|
var glyphMap = {};
|
||||||
var inDifferences;
|
for (var i = 0; i < charsets.length; i++) {
|
||||||
var glyph = charsets[i];
|
var glyph = charsets[i];
|
||||||
var code;
|
for (var charcode in encoding) {
|
||||||
for (var j = 0; j < differences.length; j++) {
|
if (encoding[charcode] == i)
|
||||||
if (differences[j] == glyph) {
|
glyphMap[glyph] = charcode | 0;
|
||||||
code = j;
|
|
||||||
inDifferences = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!inDifferences) {
|
|
||||||
var code = properties.firstChar + i;
|
|
||||||
for (var charcode in encoding) {
|
|
||||||
if (encoding[s] == i) {
|
|
||||||
code = charcode | 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (properties.encoding[code] &&
|
var differences = properties.differences;
|
||||||
properties.encoding[code].inDifferences)
|
for (var i = 0; i < differences.length; ++i) {
|
||||||
continue;
|
var glyph = differences[i];
|
||||||
|
if (!glyph)
|
||||||
|
continue;
|
||||||
|
var oldGlyph = charsets[i];
|
||||||
|
if (oldGlyph)
|
||||||
|
delete glyphMap[oldGlyph];
|
||||||
|
glyphMap[differences[i]] = i;
|
||||||
|
}
|
||||||
|
|
||||||
var mapping = properties.glyphs[code] || properties.glyphs[glyph] || {};
|
var glyphs = properties.glyphs;
|
||||||
var unicode = mapping.unicode || code;
|
for (var i = 1; i < charsets.length; i++) {
|
||||||
|
var glyph = charsets[i];
|
||||||
|
var code = glyphMap[glyph] || 0;
|
||||||
|
|
||||||
|
var mapping = glyphs[code] || glyphs[glyph] || {};
|
||||||
|
var unicode = mapping.unicode;
|
||||||
|
|
||||||
if (unicode <= 0x1f || (unicode >= 127 && unicode <= 255))
|
if (unicode <= 0x1f || (unicode >= 127 && unicode <= 255))
|
||||||
unicode += kCmapGlyphOffset;
|
unicode += kCmapGlyphOffset;
|
||||||
@ -2586,13 +2586,13 @@ var Type2CFF = (function type2CFF() {
|
|||||||
var width = isNum(mapping.width) ? mapping.width : defaultWidth;
|
var width = isNum(mapping.width) ? mapping.width : defaultWidth;
|
||||||
properties.encoding[code] = {
|
properties.encoding[code] = {
|
||||||
unicode: unicode,
|
unicode: unicode,
|
||||||
width: width,
|
width: width
|
||||||
inDifferences: inDifferences
|
|
||||||
};
|
};
|
||||||
|
|
||||||
charstrings.push({
|
charstrings.push({
|
||||||
unicode: unicode,
|
unicode: unicode,
|
||||||
width: width,
|
width: width,
|
||||||
|
code: code,
|
||||||
gid: i
|
gid: i
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -2604,7 +2604,6 @@ var Type2CFF = (function type2CFF() {
|
|||||||
|
|
||||||
// remove duplicates -- they might appear during selection:
|
// remove duplicates -- they might appear during selection:
|
||||||
// properties.glyphs[code] || properties.glyphs[glyph]
|
// properties.glyphs[code] || properties.glyphs[glyph]
|
||||||
// TODO make more deterministic
|
|
||||||
var nextUnusedUnicode = kCmapGlyphOffset + 0x0020;
|
var nextUnusedUnicode = kCmapGlyphOffset + 0x0020;
|
||||||
var lastUnicode = charstrings[0].unicode, wasModified = false;
|
var lastUnicode = charstrings[0].unicode, wasModified = false;
|
||||||
for (var i = 1; i < charstrings.length; ++i) {
|
for (var i = 1; i < charstrings.length; ++i) {
|
||||||
@ -2612,8 +2611,12 @@ var Type2CFF = (function type2CFF() {
|
|||||||
lastUnicode = charstrings[i].unicode;
|
lastUnicode = charstrings[i].unicode;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// duplicate found -- changing the unicode for previous one
|
// duplicate found -- keeping the item that has
|
||||||
charstrings[i - 1].unicode = nextUnusedUnicode++;
|
// different code and unicode, that one created
|
||||||
|
// as result of modification of the base encoding
|
||||||
|
var duplicateIndex =
|
||||||
|
charstrings[i].unicode == charstrings[i].code ? i : i - 1;
|
||||||
|
charstrings[duplicateIndex].unicode = nextUnusedUnicode++;
|
||||||
wasModified = true;
|
wasModified = true;
|
||||||
}
|
}
|
||||||
if (!wasModified)
|
if (!wasModified)
|
||||||
|
4
pdf.js
4
pdf.js
@ -4615,9 +4615,9 @@ var PartialEvaluator = (function partialEvaluator() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (replaceGlyph || !glyphs[glyph])
|
if (replaceGlyph || !glyphs[glyph])
|
||||||
glyphs[glyph] = map[i];
|
glyphs[glyph] = map[i];
|
||||||
if (replaceGlyph || !glyphs[index])
|
if (replaceGlyph || !glyphs[index])
|
||||||
glyphs[index] = map[i];
|
glyphs[index] = map[i];
|
||||||
|
|
||||||
// If there is no file, the character mapping can't be modified
|
// If there is no file, the character mapping can't be modified
|
||||||
// but this is unlikely that there is any standard encoding with
|
// but this is unlikely that there is any standard encoding with
|
||||||
|
Loading…
x
Reference in New Issue
Block a user