Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the cidToGidMap, if it exists, when building the glyph mapping for non-embedded composite fonts (issue 12418) #12419

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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