Skip to content

Commit

Permalink
Merge pull request #16513 from Snuffleupagus/issue-7454
Browse files Browse the repository at this point in the history
Improve handling of mismatching /BaseFont and /FontName entries for non-embedded fonts (issue 7454)
  • Loading branch information
Snuffleupagus committed Jun 2, 2023
2 parents 666e353 + 459d26e commit cccdc8d
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 20 deletions.
44 changes: 24 additions & 20 deletions src/core/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import {
getStandardFontName,
getStdFontMap,
getSymbolsFonts,
isKnownFontName,
} from "./standard_fonts.js";
import { getTilingPatternIR, Pattern } from "./pattern.js";
import { getXfaFontDict, getXfaFontName } from "./xfa_fonts.js";
Expand Down Expand Up @@ -3487,14 +3488,11 @@ class PartialEvaluator {
}
}

const nonEmbeddedFont = !properties.file || properties.isInternalFont;
const nonEmbeddedFont = !properties.file || properties.isInternalFont,
isSymbolsFontName = getSymbolsFonts()[properties.name];
// Ignore an incorrectly specified named encoding for non-embedded
// symbol fonts (fixes issue16464.pdf).
if (
baseEncodingName &&
nonEmbeddedFont &&
getSymbolsFonts()[properties.name]
) {
if (baseEncodingName && nonEmbeddedFont && isSymbolsFontName) {
baseEncodingName = null;
}

Expand All @@ -3512,7 +3510,7 @@ class PartialEvaluator {
}
// The Symbolic attribute can be misused for regular fonts
// Heuristic: we have to check if the font is a standard one also
if (isSymbolicFont) {
if (isSymbolicFont || isSymbolsFontName) {
encoding = MacRomanEncoding;
if (nonEmbeddedFont) {
if (/Symbol/i.test(properties.name)) {
Expand Down Expand Up @@ -4249,19 +4247,25 @@ class PartialEvaluator {
baseFont = Name.get(baseFont);
}

if (!isType3Font) {
const fontNameStr = fontName?.name;
const baseFontStr = baseFont?.name;
if (fontNameStr !== baseFontStr) {
info(
`The FontDescriptor's FontName is "${fontNameStr}" but ` +
`should be the same as the Font's BaseFont "${baseFontStr}".`
);
// Workaround for cases where e.g. fontNameStr = 'Arial' and
// baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
if (fontNameStr && baseFontStr?.startsWith(fontNameStr)) {
fontName = baseFont;
}
const fontNameStr = fontName?.name;
const baseFontStr = baseFont?.name;
if (!isType3Font && fontNameStr !== baseFontStr) {
info(
`The FontDescriptor's FontName is "${fontNameStr}" but ` +
`should be the same as the Font's BaseFont "${baseFontStr}".`
);
// - Workaround for cases where e.g. fontNameStr = 'Arial' and
// baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
//
// - Workaround for cases where e.g. fontNameStr = 'wg09np' and
// baseFontStr = 'Wingdings-Regular' (fixes issue7454.pdf).
if (
fontNameStr &&
baseFontStr &&
(baseFontStr.startsWith(fontNameStr) ||
(!isKnownFontName(fontNameStr) && isKnownFontName(baseFontStr)))
) {
fontName = null;
}
}
fontName ||= baseFont;
Expand Down
14 changes: 14 additions & 0 deletions src/core/standard_fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,9 @@ const getSymbolsFonts = getLookupTableFactory(function (t) {
t.Dingbats = true;
t.Symbol = true;
t.ZapfDingbats = true;
t.Wingdings = true;
t["Wingdings-Bold"] = true;
t["Wingdings-Regular"] = true;
});

// Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID
Expand Down Expand Up @@ -888,6 +891,16 @@ function getStandardFontName(name) {
return stdFontMap[fontName];
}

function isKnownFontName(name) {
const fontName = normalizeFontName(name);
return !!(
getStdFontMap()[fontName] ||
getNonStdFontMap()[fontName] ||
getSerifFonts()[fontName] ||
getSymbolsFonts()[fontName]
);
}

export {
getFontNameToFileMap,
getGlyphMapForStandardFonts,
Expand All @@ -898,4 +911,5 @@ export {
getSupplementalGlyphMapForArialBlack,
getSupplementalGlyphMapForCalibri,
getSymbolsFonts,
isKnownFontName,
};
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@
!issue11656.pdf
!annotation-fileattachment.pdf
!annotation-text-widget.pdf
!issue7454.pdf
!issue15443.pdf
!annotation-choice-widget.pdf
!issue10900.pdf
Expand Down
Binary file added test/pdfs/issue7454.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 @@ -5042,6 +5042,12 @@
"link": true,
"type": "load"
},
{ "id": "issue7454",
"file": "pdfs/issue7454.pdf",
"md5": "45889bf6a9d3e2eccd01dc48668b21e5",
"rounds": 1,
"type": "eq"
},
{ "id": "bigboundingbox",
"file": "pdfs/bigboundingbox.pdf",
"md5": "e5c5e2cb80826d6ebf535413865270cd",
Expand Down

0 comments on commit cccdc8d

Please sign in to comment.