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:
commit
83d3bb43f4
@ -3455,6 +3455,11 @@ class PartialEvaluator {
|
|||||||
// NOTE: cmap can be a sparse array, so use forEach instead of
|
// NOTE: cmap can be a sparse array, so use forEach instead of
|
||||||
// `for(;;)` to iterate over all keys.
|
// `for(;;)` to iterate over all keys.
|
||||||
cmap.forEach(function (charCode, token) {
|
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 = [];
|
const str = [];
|
||||||
for (let k = 0; k < token.length; k += 2) {
|
for (let k = 0; k < token.length; k += 2) {
|
||||||
const w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
|
const w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
|
||||||
|
@ -376,6 +376,12 @@ function getFontFileType(file, { type, subtype, composite }) {
|
|||||||
return [fileType, fileSubtype];
|
return [fileType, fileSubtype];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function applyStandardFontGlyphMap(map, glyphMap) {
|
||||||
|
for (const charCode in glyphMap) {
|
||||||
|
map[+charCode] = glyphMap[charCode];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function buildToFontChar(encoding, glyphsUnicodeMap, differences) {
|
function buildToFontChar(encoding, glyphsUnicodeMap, differences) {
|
||||||
const toFontChar = [];
|
const toFontChar = [];
|
||||||
let unicode;
|
let unicode;
|
||||||
@ -1052,26 +1058,16 @@ class Font {
|
|||||||
type === "CIDFontType2" &&
|
type === "CIDFontType2" &&
|
||||||
this.cidEncoding.startsWith("Identity-")
|
this.cidEncoding.startsWith("Identity-")
|
||||||
) {
|
) {
|
||||||
const GlyphMapForStandardFonts = getGlyphMapForStandardFonts(),
|
const cidToGidMap = properties.cidToGidMap;
|
||||||
cidToGidMap = properties.cidToGidMap;
|
|
||||||
// Standard fonts might be embedded as CID font without glyph mapping.
|
// Standard fonts might be embedded as CID font without glyph mapping.
|
||||||
// Building one based on GlyphMapForStandardFonts.
|
// Building one based on GlyphMapForStandardFonts.
|
||||||
const map = [];
|
const map = [];
|
||||||
for (const charCode in GlyphMapForStandardFonts) {
|
applyStandardFontGlyphMap(map, getGlyphMapForStandardFonts());
|
||||||
map[+charCode] = GlyphMapForStandardFonts[charCode];
|
|
||||||
}
|
|
||||||
if (/Arial-?Black/i.test(name)) {
|
if (/Arial-?Black/i.test(name)) {
|
||||||
const SupplementalGlyphMapForArialBlack =
|
applyStandardFontGlyphMap(map, getSupplementalGlyphMapForArialBlack());
|
||||||
getSupplementalGlyphMapForArialBlack();
|
|
||||||
for (const charCode in SupplementalGlyphMapForArialBlack) {
|
|
||||||
map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
|
|
||||||
}
|
|
||||||
} else if (/Calibri/i.test(name)) {
|
} else if (/Calibri/i.test(name)) {
|
||||||
const SupplementalGlyphMapForCalibri =
|
applyStandardFontGlyphMap(map, getSupplementalGlyphMapForCalibri());
|
||||||
getSupplementalGlyphMapForCalibri();
|
|
||||||
for (const charCode in SupplementalGlyphMapForCalibri) {
|
|
||||||
map[+charCode] = SupplementalGlyphMapForCalibri[charCode];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always update the glyph mapping with the `cidToGidMap` when it exists
|
// 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 (this.composite && this.toUnicode instanceof IdentityToUnicodeMap) {
|
||||||
if (/Verdana/i.test(name)) {
|
if (/Verdana/i.test(name)) {
|
||||||
// Fixes issue11242_reduced.pdf
|
// Fixes issue11242_reduced.pdf
|
||||||
const GlyphMapForStandardFonts = getGlyphMapForStandardFonts();
|
applyStandardFontGlyphMap(map, getGlyphMapForStandardFonts());
|
||||||
for (const charCode in GlyphMapForStandardFonts) {
|
|
||||||
map[+charCode] = GlyphMapForStandardFonts[charCode];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.toFontChar = map;
|
this.toFontChar = map;
|
||||||
|
1
test/pdfs/issue9367.pdf.link
Normal file
1
test/pdfs/issue9367.pdf.link
Normal file
@ -0,0 +1 @@
|
|||||||
|
https://github.com/mozilla/pdf.js/files/1634833/E-WG18_105147.pdf
|
@ -2358,6 +2358,14 @@
|
|||||||
"lastPage": 2,
|
"lastPage": 2,
|
||||||
"type": "eq"
|
"type": "eq"
|
||||||
},
|
},
|
||||||
|
{ "id": "issue9367",
|
||||||
|
"file": "pdfs/issue9367.pdf",
|
||||||
|
"md5": "81a2c6f1fe5d1bb00ff0479aa6547155",
|
||||||
|
"rounds": 1,
|
||||||
|
"link": true,
|
||||||
|
"lastPage": 1,
|
||||||
|
"type": "eq"
|
||||||
|
},
|
||||||
{ "id": "issue10529",
|
{ "id": "issue10529",
|
||||||
"file": "pdfs/issue10529.pdf",
|
"file": "pdfs/issue10529.pdf",
|
||||||
"md5": "1a4d404a137c610ff0c747cbea3b8666",
|
"md5": "1a4d404a137c610ff0c747cbea3b8666",
|
||||||
|
Loading…
Reference in New Issue
Block a user