Take the /CIDToGIDMap into account when getting the glyph mapping for CFF fonts (issue 15559)
*Please note:* I don't really know what I'm doing here, however the patch appears to fix the referenced issue when comparing the rendering with Adobe Reader (with the caveat that I don't speak the language in question).
This commit is contained in:
parent
c6cc7c6e6a
commit
858d941ff8
@ -48,11 +48,23 @@ class CFFFont {
|
|||||||
getGlyphMapping() {
|
getGlyphMapping() {
|
||||||
const cff = this.cff;
|
const cff = this.cff;
|
||||||
const properties = this.properties;
|
const properties = this.properties;
|
||||||
|
const { cidToGidMap, cMap } = properties;
|
||||||
const charsets = cff.charset.charset;
|
const charsets = cff.charset.charset;
|
||||||
let charCodeToGlyphId;
|
let charCodeToGlyphId;
|
||||||
let glyphId;
|
let glyphId;
|
||||||
|
|
||||||
if (properties.composite) {
|
if (properties.composite) {
|
||||||
|
let invCidToGidMap;
|
||||||
|
if (cidToGidMap && cidToGidMap.length > 0) {
|
||||||
|
invCidToGidMap = Object.create(null);
|
||||||
|
for (let i = 0, ii = cidToGidMap.length; i < ii; i++) {
|
||||||
|
const gid = cidToGidMap[i];
|
||||||
|
if (gid !== undefined) {
|
||||||
|
invCidToGidMap[gid] = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
charCodeToGlyphId = Object.create(null);
|
charCodeToGlyphId = Object.create(null);
|
||||||
let charCode;
|
let charCode;
|
||||||
if (cff.isCIDFont) {
|
if (cff.isCIDFont) {
|
||||||
@ -60,14 +72,25 @@ class CFFFont {
|
|||||||
// to map CIDs to GIDs.
|
// to map CIDs to GIDs.
|
||||||
for (glyphId = 0; glyphId < charsets.length; glyphId++) {
|
for (glyphId = 0; glyphId < charsets.length; glyphId++) {
|
||||||
const cid = charsets[glyphId];
|
const cid = charsets[glyphId];
|
||||||
charCode = properties.cMap.charCodeOf(cid);
|
charCode = cMap.charCodeOf(cid);
|
||||||
|
|
||||||
|
if (invCidToGidMap && invCidToGidMap[charCode] !== undefined) {
|
||||||
|
// According to the PDF specification, see Table 117, it's not clear
|
||||||
|
// that a /CIDToGIDMap should be used with any non-TrueType fonts,
|
||||||
|
// however it's necessary to do so in order to fix issue 15559.
|
||||||
|
//
|
||||||
|
// It seems, in the CFF-case, that the /CIDToGIDMap needs to be used
|
||||||
|
// "inverted" compared to the TrueType-case. Here it thus seem to be
|
||||||
|
// a charCode mapping, rather than the normal CID to GID mapping.
|
||||||
|
charCode = invCidToGidMap[charCode];
|
||||||
|
}
|
||||||
charCodeToGlyphId[charCode] = glyphId;
|
charCodeToGlyphId[charCode] = glyphId;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// If it is NOT actually a CID font then CIDs should be mapped
|
// If it is NOT actually a CID font then CIDs should be mapped
|
||||||
// directly to GIDs.
|
// directly to GIDs.
|
||||||
for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
|
for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
|
||||||
charCode = properties.cMap.charCodeOf(glyphId);
|
charCode = cMap.charCodeOf(glyphId);
|
||||||
charCodeToGlyphId[charCode] = glyphId;
|
charCodeToGlyphId[charCode] = glyphId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1
test/pdfs/issue15559.pdf.link
Normal file
1
test/pdfs/issue15559.pdf.link
Normal file
@ -0,0 +1 @@
|
|||||||
|
https://github.com/mozilla/pdf.js/files/9745330/FutureABC.L3.-1.pdf
|
@ -653,6 +653,14 @@
|
|||||||
"type": "eq",
|
"type": "eq",
|
||||||
"annotations": true
|
"annotations": true
|
||||||
},
|
},
|
||||||
|
{ "id": "issue15559",
|
||||||
|
"file": "pdfs/issue15559.pdf",
|
||||||
|
"md5": "b937f2e32925aef8c1740f357f2a6282",
|
||||||
|
"link": true,
|
||||||
|
"rounds": 1,
|
||||||
|
"lastPage": 1,
|
||||||
|
"type": "eq"
|
||||||
|
},
|
||||||
{ "id": "hmm-pdf",
|
{ "id": "hmm-pdf",
|
||||||
"file": "pdfs/hmm.pdf",
|
"file": "pdfs/hmm.pdf",
|
||||||
"md5": "e08467e60101ee5f4a59716e86db6dc9",
|
"md5": "e08467e60101ee5f4a59716e86db6dc9",
|
||||||
|
Loading…
Reference in New Issue
Block a user