Always prefer the post-table for TrueType fonts with (0, x) cmap-tables (issue 13433)

While I don't know if this is necessarily the "correct" solution, it does fix issue 13433 without breaking any of the existing reference-tests.
This commit is contained in:
Jonas Jenwald 2021-09-01 12:22:49 +02:00
parent 07e233d08b
commit b7b6076294
3 changed files with 17 additions and 5 deletions

View File

@ -2606,7 +2606,8 @@ class Font {
const cmapEncodingId = cmapTable.encodingId;
const cmapMappings = cmapTable.mappings;
const cmapMappingsLength = cmapMappings.length;
let baseEncoding = [];
let baseEncoding = [],
forcePostTable = false;
if (
properties.hasEncoding &&
(properties.baseEncodingName === "MacRomanEncoding" ||
@ -2615,9 +2616,8 @@ class Font {
baseEncoding = getEncoding(properties.baseEncodingName);
}
// If the font has an encoding and is not symbolic then follow the
// rules in section 9.6.6.4 of the spec on how to map 3,1 and 1,0
// cmaps.
// If the font has an encoding and is not symbolic then follow the rules
// in section 9.6.6.4 of the spec on how to map 3,1 and 1,0 cmaps.
if (
properties.hasEncoding &&
!this.isSymbolicFont &&
@ -2664,6 +2664,9 @@ class Font {
for (let i = 0; i < cmapMappingsLength; ++i) {
charCodeToGlyphId[cmapMappings[i].charCode] = cmapMappings[i].glyphId;
}
// Always prefer the BaseEncoding/Differences arrays, when they exist
// (fixes issue13433.pdf).
forcePostTable = true;
} else {
// When there is only a (1, 0) cmap table, the char code is a single
// byte and it is used directly as the char code.
@ -2695,7 +2698,7 @@ class Font {
(baseEncoding.length || this.differences.length)
) {
for (let i = 0; i < 256; ++i) {
if (charCodeToGlyphId[i] !== undefined) {
if (!forcePostTable && charCodeToGlyphId[i] !== undefined) {
continue;
}
const glyphName = this.differences[i] || baseEncoding[i];

View File

@ -0,0 +1 @@
https://github.com/mozilla/pdf.js/files/6537699/pos36.pdf

View File

@ -1294,6 +1294,14 @@
"enableXfa": true,
"type": "eq"
},
{ "id": "issue13433",
"file": "pdfs/issue13433.pdf",
"md5": "4038cd87ff48fd54b3c4a36593d2ba03",
"link": true,
"rounds": 1,
"lastPage": 1,
"type": "eq"
},
{ "id": "xfa_issue13668",
"file": "pdfs/xfa_issue13668.pdf",
"md5": "8a5ed3c8a58b425b1ec53329334a0f5b",