Skip to content

Commit

Permalink
Merge pull request #12419 from Snuffleupagus/fallbackToSystemFont-cid…
Browse files Browse the repository at this point in the history
…ToGidMap

Use the `cidToGidMap`, if it exists, when building the glyph mapping for non-embedded composite fonts (issue 12418)
  • Loading branch information
timvandermeij authored Sep 30, 2020
2 parents d49b2f6 + bd3b15b commit 8e7a6e0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/core/fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ var Font = (function FontClosure() {
// attempting to recover by assuming that no file exists.
warn('Font file is empty in "' + name + '" (' + this.loadedName + ")");
}
this.fallbackToSystemFont();
this.fallbackToSystemFont(properties);
return;
}

Expand Down Expand Up @@ -679,7 +679,7 @@ var Font = (function FontClosure() {
}
} catch (e) {
warn(e);
this.fallbackToSystemFont();
this.fallbackToSystemFont(properties);
return;
}

Expand Down Expand Up @@ -1308,7 +1308,7 @@ var Font = (function FontClosure() {
return data;
},

fallbackToSystemFont: function Font_fallbackToSystemFont() {
fallbackToSystemFont(properties) {
this.missingFile = true;
// The file data is not specified. Trying to fix the font name
// to be used with the canvas.font.
Expand Down Expand Up @@ -1339,7 +1339,8 @@ var Font = (function FontClosure() {
type === "CIDFontType2" &&
this.cidEncoding.startsWith("Identity-")
) {
const GlyphMapForStandardFonts = getGlyphMapForStandardFonts();
const GlyphMapForStandardFonts = getGlyphMapForStandardFonts(),
cidToGidMap = properties.cidToGidMap;
// Standard fonts might be embedded as CID font without glyph mapping.
// Building one based on GlyphMapForStandardFonts.
const map = [];
Expand All @@ -1357,6 +1358,16 @@ var Font = (function FontClosure() {
map[+charCode] = SupplementalGlyphMapForCalibri[charCode];
}
}
// Always update the glyph mapping with the `cidToGidMap` when it exists
// (fixes issue12418_reduced.pdf).
if (cidToGidMap) {
for (const charCode in map) {
const cid = map[charCode];
if (cidToGidMap[cid] !== undefined) {
map[+charCode] = cidToGidMap[cid];
}
}
}

var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
if (!isIdentityUnicode) {
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@
!annotation-squiggly-without-appearance.pdf
!annotation-highlight.pdf
!annotation-highlight-without-appearance.pdf
!issue12418_reduced.pdf
!annotation-freetext.pdf
!annotation-line.pdf
!annotation-square-circle.pdf
Expand Down
Binary file added test/pdfs/issue12418_reduced.pdf
Binary file not shown.
6 changes: 6 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -1440,6 +1440,12 @@
"rounds": 1,
"type": "eq"
},
{ "id": "issue12418",
"file": "pdfs/issue12418_reduced.pdf",
"md5": "596b70f00a5f88ff58f4f4d06fcf75f1",
"rounds": 1,
"type": "eq"
},
{ "id": "issue6692",
"file": "pdfs/issue6692.pdf",
"md5": "ba078e0ddd59cda4b6c51ea10599f49a",
Expand Down

0 comments on commit 8e7a6e0

Please sign in to comment.