Skip to content

Commit

Permalink
Merge pull request #15563 from Snuffleupagus/issue-15559
Browse files Browse the repository at this point in the history
Take the /CIDToGIDMap into account when getting the glyph mapping for CFF fonts (issue 15559)
  • Loading branch information
Snuffleupagus authored Oct 14, 2022
2 parents d5036d7 + 858d941 commit 15d4d80
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/core/cff_font.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,49 @@ class CFFFont {
getGlyphMapping() {
const cff = this.cff;
const properties = this.properties;
const { cidToGidMap, cMap } = properties;
const charsets = cff.charset.charset;
let charCodeToGlyphId;
let glyphId;

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);
let charCode;
if (cff.isCIDFont) {
// If the font is actually a CID font then we should use the charset
// to map CIDs to GIDs.
for (glyphId = 0; glyphId < charsets.length; 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;
}
} else {
// If it is NOT actually a CID font then CIDs should be mapped
// directly to GIDs.
for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
charCode = properties.cMap.charCodeOf(glyphId);
charCode = cMap.charCodeOf(glyphId);
charCodeToGlyphId[charCode] = glyphId;
}
}
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/issue15559.pdf.link
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/mozilla/pdf.js/files/9745330/FutureABC.L3.-1.pdf
8 changes: 8 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,14 @@
"type": "eq",
"annotations": true
},
{ "id": "issue15559",
"file": "pdfs/issue15559.pdf",
"md5": "b937f2e32925aef8c1740f357f2a6282",
"link": true,
"rounds": 1,
"lastPage": 1,
"type": "eq"
},
{ "id": "hmm-pdf",
"file": "pdfs/hmm.pdf",
"md5": "e08467e60101ee5f4a59716e86db6dc9",
Expand Down

0 comments on commit 15d4d80

Please sign in to comment.