1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Merge pull request #14041 from Snuffleupagus/issue-9367

Support cmaps with only CID characters, when building the ToUnicode-map (issue 9367)
This commit is contained in:
Tim van der Meij 2021-09-18 16:47:06 +02:00 committed by GitHub
commit 83d3bb43f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 19 deletions

View file

@ -3455,6 +3455,11 @@ class PartialEvaluator {
// NOTE: cmap can be a sparse array, so use forEach instead of
// `for(;;)` to iterate over all keys.
cmap.forEach(function (charCode, token) {
// Some cmaps contain *only* CID characters (fixes issue9367.pdf).
if (typeof token === "number") {
map[charCode] = String.fromCodePoint(token);
return;
}
const str = [];
for (let k = 0; k < token.length; k += 2) {
const w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);

View file

@ -376,6 +376,12 @@ function getFontFileType(file, { type, subtype, composite }) {
return [fileType, fileSubtype];
}
function applyStandardFontGlyphMap(map, glyphMap) {
for (const charCode in glyphMap) {
map[+charCode] = glyphMap[charCode];
}
}
function buildToFontChar(encoding, glyphsUnicodeMap, differences) {
const toFontChar = [];
let unicode;
@ -1052,26 +1058,16 @@ class Font {
type === "CIDFontType2" &&
this.cidEncoding.startsWith("Identity-")
) {
const GlyphMapForStandardFonts = getGlyphMapForStandardFonts(),
cidToGidMap = properties.cidToGidMap;
const cidToGidMap = properties.cidToGidMap;
// Standard fonts might be embedded as CID font without glyph mapping.
// Building one based on GlyphMapForStandardFonts.
const map = [];
for (const charCode in GlyphMapForStandardFonts) {
map[+charCode] = GlyphMapForStandardFonts[charCode];
}
applyStandardFontGlyphMap(map, getGlyphMapForStandardFonts());
if (/Arial-?Black/i.test(name)) {
const SupplementalGlyphMapForArialBlack =
getSupplementalGlyphMapForArialBlack();
for (const charCode in SupplementalGlyphMapForArialBlack) {
map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
}
applyStandardFontGlyphMap(map, getSupplementalGlyphMapForArialBlack());
} else if (/Calibri/i.test(name)) {
const SupplementalGlyphMapForCalibri =
getSupplementalGlyphMapForCalibri();
for (const charCode in SupplementalGlyphMapForCalibri) {
map[+charCode] = SupplementalGlyphMapForCalibri[charCode];
}
applyStandardFontGlyphMap(map, getSupplementalGlyphMapForCalibri());
}
// Always update the glyph mapping with the `cidToGidMap` when it exists
@ -1158,10 +1154,7 @@ class Font {
if (this.composite && this.toUnicode instanceof IdentityToUnicodeMap) {
if (/Verdana/i.test(name)) {
// Fixes issue11242_reduced.pdf
const GlyphMapForStandardFonts = getGlyphMapForStandardFonts();
for (const charCode in GlyphMapForStandardFonts) {
map[+charCode] = GlyphMapForStandardFonts[charCode];
}
applyStandardFontGlyphMap(map, getGlyphMapForStandardFonts());
}
}
this.toFontChar = map;