Skip to content

Commit 36b40d9

Browse files
Merge pull request #19955 from Snuffleupagus/issue-19954
Support Type3 fonts with an incomplete /FontDescriptor dictionary (issue 19954)
2 parents 2b9f621 + c02ea0c commit 36b40d9

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

src/core/evaluator.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4313,12 +4313,9 @@ class PartialEvaluator {
43134313

43144314
if (!descriptor) {
43154315
if (isType3Font) {
4316-
const bbox = lookupNormalRect(dict.getArray("FontBBox"), [0, 0, 0, 0]);
43174316
// FontDescriptor is only required for Type3 fonts when the document
4318-
// is a tagged pdf. Create a barbebones one to get by.
4319-
descriptor = new Dict(null);
4320-
descriptor.set("FontName", Name.get(type));
4321-
descriptor.set("FontBBox", bbox);
4317+
// is a tagged pdf.
4318+
descriptor = Dict.empty;
43224319
} else {
43234320
// Before PDF 1.5 if the font was one of the base 14 fonts, having a
43244321
// FontDescriptor was not required.
@@ -4420,7 +4417,13 @@ class PartialEvaluator {
44204417

44214418
const fontNameStr = fontName?.name;
44224419
const baseFontStr = baseFont?.name;
4423-
if (!isType3Font && fontNameStr !== baseFontStr) {
4420+
if (isType3Font) {
4421+
if (!fontNameStr) {
4422+
// Since the /FontDescriptor is optional in Type3 fonts, ensure that we
4423+
// always have a "valid" /FontName (fixes issue19954.pdf).
4424+
fontName = Name.get(type);
4425+
}
4426+
} else if (fontNameStr !== baseFontStr) {
44244427
info(
44254428
`The FontDescriptor's FontName is "${fontNameStr}" but ` +
44264429
`should be the same as the Font's BaseFont "${baseFontStr}".`
@@ -4438,8 +4441,8 @@ class PartialEvaluator {
44384441
) {
44394442
fontName = null;
44404443
}
4444+
fontName ||= baseFont;
44414445
}
4442-
fontName ||= baseFont;
44434446

44444447
if (!(fontName instanceof Name)) {
44454448
throw new FormatError("invalid font name");
@@ -4517,7 +4520,7 @@ class PartialEvaluator {
45174520
);
45184521
const bbox = lookupNormalRect(
45194522
descriptor.getArray("FontBBox") || dict.getArray("FontBBox"),
4520-
undefined
4523+
isType3Font ? [0, 0, 0, 0] : undefined
45214524
);
45224525
let ascent = descriptor.get("Ascent");
45234526
if (typeof ascent !== "number") {
@@ -4705,9 +4708,9 @@ class TranslatedFont {
47054708
const fontResources = this.dict.get("Resources") || resources;
47064709
const charProcOperatorList = Object.create(null);
47074710

4708-
const fontBBox = Util.normalizeRect(font.bbox || [0, 0, 0, 0]),
4709-
width = fontBBox[2] - fontBBox[0],
4710-
height = fontBBox[3] - fontBBox[1];
4711+
const [x0, y0, x1, y1] = font.bbox,
4712+
width = x1 - x0,
4713+
height = y1 - y0;
47114714
const fontBBoxSize = Math.hypot(width, height);
47124715

47134716
for (const key of charProcs.getKeys()) {

test/pdfs/issue19954.pdf.link

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/user-attachments/files/20281525/Capital.Bancorp.Inc.Corporate.Responsibility.2025509.SD000000003063823863-1-2.pdf

test/test_manifest.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2859,6 +2859,15 @@
28592859
"rounds": 1,
28602860
"type": "eq"
28612861
},
2862+
{
2863+
"id": "issue19954",
2864+
"file": "pdfs/issue19954.pdf",
2865+
"md5": "9742309bb321691b53b96069dfc1099b",
2866+
"link": true,
2867+
"rounds": 1,
2868+
"lastPage": 1,
2869+
"type": "text"
2870+
},
28622871
{
28632872
"id": "IndexedCS_negative_and_high",
28642873
"file": "pdfs/IndexedCS_negative_and_high.pdf",

0 commit comments

Comments
 (0)