mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 10:08:06 +02:00
Merge pull request #5651 from Snuffleupagus/missing-glyphs
Try to skip mapping of missing TrueType and CIDFontType2 glyphs
This commit is contained in:
commit
394b38b22f
7 changed files with 77 additions and 21 deletions
|
@ -2203,6 +2203,10 @@ var ToUnicodeMap = (function ToUnicodeMapClosure() {
|
|||
}
|
||||
},
|
||||
|
||||
has: function(i) {
|
||||
return this._map[i] !== undefined;
|
||||
},
|
||||
|
||||
get: function(i) {
|
||||
return this._map[i];
|
||||
},
|
||||
|
@ -2232,6 +2236,10 @@ var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
|
|||
}
|
||||
},
|
||||
|
||||
has: function (i) {
|
||||
return this.firstChar <= i && i <= this.lastChar;
|
||||
},
|
||||
|
||||
get: function (i) {
|
||||
if (this.firstChar <= i && i <= this.lastChar) {
|
||||
return String.fromCharCode(i);
|
||||
|
@ -2664,7 +2672,6 @@ var Font = (function FontClosure() {
|
|||
var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
|
||||
var isIdentityUnicode =
|
||||
properties.toUnicode instanceof IdentityToUnicodeMap;
|
||||
var isCidFontType2 = (properties.type === 'CIDFontType2');
|
||||
var newMap = Object.create(null);
|
||||
var toFontChar = [];
|
||||
var usedFontCharCodes = [];
|
||||
|
@ -2675,17 +2682,11 @@ var Font = (function FontClosure() {
|
|||
var fontCharCode = originalCharCode;
|
||||
// First try to map the value to a unicode position if a non identity map
|
||||
// was created.
|
||||
if (!isIdentityUnicode) {
|
||||
if (toUnicode.get(originalCharCode) !== undefined) {
|
||||
var unicode = toUnicode.get(fontCharCode);
|
||||
// TODO: Try to map ligatures to the correct spot.
|
||||
if (unicode.length === 1) {
|
||||
fontCharCode = unicode.charCodeAt(0);
|
||||
}
|
||||
} else if (isCidFontType2) {
|
||||
// For CIDFontType2, move characters not present in toUnicode
|
||||
// to the private use area (fixes bug 1028735 and issue 4881).
|
||||
fontCharCode = nextAvailableFontCharCode;
|
||||
if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
|
||||
var unicode = toUnicode.get(fontCharCode);
|
||||
// TODO: Try to map ligatures to the correct spot.
|
||||
if (unicode.length === 1) {
|
||||
fontCharCode = unicode.charCodeAt(0);
|
||||
}
|
||||
}
|
||||
// Try to move control characters, special characters and already mapped
|
||||
|
@ -3530,6 +3531,7 @@ var Font = (function FontClosure() {
|
|||
var newGlyfData = new Uint8Array(oldGlyfDataLength);
|
||||
var startOffset = itemDecode(locaData, 0);
|
||||
var writeOffset = 0;
|
||||
var missingGlyphData = {};
|
||||
itemEncode(locaData, 0, writeOffset);
|
||||
var i, j;
|
||||
for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
|
||||
|
@ -3547,6 +3549,10 @@ var Font = (function FontClosure() {
|
|||
continue;
|
||||
}
|
||||
|
||||
if (startOffset === endOffset) {
|
||||
missingGlyphData[i] = true;
|
||||
}
|
||||
|
||||
var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
|
||||
newGlyfData, writeOffset, hintsValid);
|
||||
writeOffset += newLength;
|
||||
|
@ -3563,7 +3569,7 @@ var Font = (function FontClosure() {
|
|||
itemEncode(locaData, j, simpleGlyph.length);
|
||||
}
|
||||
glyf.data = simpleGlyph;
|
||||
return;
|
||||
return missingGlyphData;
|
||||
}
|
||||
|
||||
if (dupFirstEntry) {
|
||||
|
@ -3580,6 +3586,7 @@ var Font = (function FontClosure() {
|
|||
} else {
|
||||
glyf.data = newGlyfData.subarray(0, writeOffset);
|
||||
}
|
||||
return missingGlyphData;
|
||||
}
|
||||
|
||||
function readPostScriptTable(post, properties, maxpNumGlyphs) {
|
||||
|
@ -4039,11 +4046,13 @@ var Font = (function FontClosure() {
|
|||
|
||||
sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
|
||||
|
||||
var missingGlyphs = {};
|
||||
if (isTrueType) {
|
||||
var isGlyphLocationsLong = int16(tables.head.data[50],
|
||||
tables.head.data[51]);
|
||||
sanitizeGlyphLocations(tables.loca, tables.glyf, numGlyphs,
|
||||
isGlyphLocationsLong, hintsValid, dupFirstEntry);
|
||||
missingGlyphs = sanitizeGlyphLocations(tables.loca, tables.glyf,
|
||||
numGlyphs, isGlyphLocationsLong,
|
||||
hintsValid, dupFirstEntry);
|
||||
}
|
||||
|
||||
if (!tables.hhea) {
|
||||
|
@ -4065,19 +4074,33 @@ var Font = (function FontClosure() {
|
|||
}
|
||||
}
|
||||
|
||||
var charCodeToGlyphId = [], charCode;
|
||||
var charCodeToGlyphId = [], charCode, toUnicode = properties.toUnicode;
|
||||
|
||||
function hasGlyph(glyphId, charCode) {
|
||||
if (!missingGlyphs[glyphId]) {
|
||||
return true;
|
||||
}
|
||||
if (charCode >= 0 && toUnicode.has(charCode)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (properties.type === 'CIDFontType2') {
|
||||
var cidToGidMap = properties.cidToGidMap || [];
|
||||
var cidToGidMapLength = cidToGidMap.length;
|
||||
var isCidToGidMapEmpty = cidToGidMap.length === 0;
|
||||
|
||||
properties.cMap.forEach(function(charCode, cid) {
|
||||
assert(cid <= 0xffff, 'Max size of CID is 65,535');
|
||||
var glyphId = -1;
|
||||
if (cidToGidMapLength === 0) {
|
||||
if (isCidToGidMapEmpty) {
|
||||
glyphId = charCode;
|
||||
} else if (cidToGidMap[cid] !== undefined) {
|
||||
glyphId = cidToGidMap[cid];
|
||||
}
|
||||
if (glyphId >= 0 && glyphId < numGlyphs) {
|
||||
|
||||
if (glyphId >= 0 && glyphId < numGlyphs &&
|
||||
hasGlyph(glyphId, charCode)) {
|
||||
charCodeToGlyphId[charCode] = glyphId;
|
||||
}
|
||||
});
|
||||
|
@ -4137,7 +4160,8 @@ var Font = (function FontClosure() {
|
|||
|
||||
var found = false;
|
||||
for (i = 0; i < cmapMappingsLength; ++i) {
|
||||
if (cmapMappings[i].charCode === unicodeOrCharCode) {
|
||||
if (cmapMappings[i].charCode === unicodeOrCharCode &&
|
||||
hasGlyph(cmapMappings[i].glyphId, unicodeOrCharCode)) {
|
||||
charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
|
||||
found = true;
|
||||
break;
|
||||
|
@ -4147,7 +4171,7 @@ var Font = (function FontClosure() {
|
|||
// Try to map using the post table. There are currently no known
|
||||
// pdfs that this fixes.
|
||||
var glyphId = properties.glyphNames.indexOf(glyphName);
|
||||
if (glyphId > 0) {
|
||||
if (glyphId > 0 && hasGlyph(glyphId, -1)) {
|
||||
charCodeToGlyphId[charCode] = glyphId;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue