Skip to content

[Bugfix] Fix character encoding issue #1

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

Merged
merged 1 commit into from
Jan 21, 2022
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
4 changes: 4 additions & 0 deletions src/core/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2639,6 +2639,10 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
// NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
// to iterate over all keys.
cmap.forEach(function(charCode, token) {
if (typeof token === "number") {
map[charCode] = String.fromCodePoint(token);
return;
}
var str = [];
for (var k = 0; k < token.length; k += 2) {
var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
Expand Down
34 changes: 15 additions & 19 deletions src/core/fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,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 @@ -854,7 +854,7 @@ var Font = (function FontClosure() {
}
} catch (e) {
warn(e);
this.fallbackToSystemFont();
this.fallbackToSystemFont(properties);
return;
}

Expand Down Expand Up @@ -993,6 +993,12 @@ var Font = (function FontClosure() {
return [fileType, fileSubtype];
}

function applyStandardFontGlyphMap(map, glyphMap) {
for (const charCode in glyphMap) {
map[+charCode] = glyphMap[charCode];
}
}

function buildToFontChar(encoding, glyphsUnicodeMap, differences) {
var toFontChar = [],
unicode;
Expand Down Expand Up @@ -1482,7 +1488,7 @@ var Font = (function FontClosure() {
return data;
},

fallbackToSystemFont: function Font_fallbackToSystemFont() {
fallbackToSystemFont: function Font_fallbackToSystemFont(properties) {
this.missingFile = true;
var charCode, unicode;
// The file data is not specified. Trying to fix the font name
Expand Down Expand Up @@ -1514,23 +1520,16 @@ var Font = (function FontClosure() {
type === "CIDFontType2" &&
this.cidEncoding.startsWith("Identity-")
) {
const GlyphMapForStandardFonts = getGlyphMapForStandardFonts();
const cidToGidMap = properties.cidToGidMap;
// Standard fonts might be embedded as CID font without glyph mapping.
// Building one based on GlyphMapForStandardFonts.
const map = [];
for (charCode in GlyphMapForStandardFonts) {
map[+charCode] = GlyphMapForStandardFonts[charCode];
}
applyStandardFontGlyphMap(map, getGlyphMapForStandardFonts());

if (/Arial-?Black/i.test(name)) {
var SupplementalGlyphMapForArialBlack = getSupplementalGlyphMapForArialBlack();
for (charCode in SupplementalGlyphMapForArialBlack) {
map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
}
applyStandardFontGlyphMap(map, getSupplementalGlyphMapForArialBlack());
} else if (/Calibri/i.test(name)) {
let SupplementalGlyphMapForCalibri = getSupplementalGlyphMapForCalibri();
for (charCode in SupplementalGlyphMapForCalibri) {
map[+charCode] = SupplementalGlyphMapForCalibri[charCode];
}
applyStandardFontGlyphMap(map, getSupplementalGlyphMapForCalibri());
}

var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
Expand Down Expand Up @@ -1582,10 +1581,7 @@ var Font = (function FontClosure() {
if (this.composite && this.toUnicode instanceof IdentityToUnicodeMap) {
if (/Verdana/i.test(name)) {
// Fixes issue11242_reduced.pdf
const GlyphMapForStandardFonts = getGlyphMapForStandardFonts();
for (charCode in GlyphMapForStandardFonts) {
map[+charCode] = GlyphMapForStandardFonts[charCode];
}
applyStandardFontGlyphMap(map, getGlyphMapForStandardFonts());
}
}
this.toFontChar = map;
Expand Down