Skip to content

Commit 2a2806d

Browse files
Merge pull request #20637 from Snuffleupagus/issue-20246
Normalize the font name in `getBaseFontMetrics` (issue 20246)
2 parents 2b95a8e + 6a3d5fe commit 2a2806d

5 files changed

Lines changed: 24 additions & 8 deletions

File tree

src/core/evaluator.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ import {
3131
} from "../shared/util.js";
3232
import { CMapFactory, IdentityCMap } from "./cmap.js";
3333
import { Cmd, Dict, EOF, isName, Name, Ref, RefSet } from "./primitives.js";
34-
import { compileType3Glyph, FontFlags } from "./fonts_utils.js";
34+
import {
35+
compileType3Glyph,
36+
FontFlags,
37+
normalizeFontName,
38+
} from "./fonts_utils.js";
3539
import { ErrorFont, Font } from "./fonts.js";
3640
import {
3741
fetchBinaryData,
@@ -4238,16 +4242,17 @@ class PartialEvaluator {
42384242
let defaultWidth = 0;
42394243
let widths = Object.create(null);
42404244
let monospace = false;
4245+
4246+
let fontName = normalizeFontName(name);
42414247
const stdFontMap = getStdFontMap();
4242-
let lookupName = stdFontMap[name] || name;
4248+
fontName = stdFontMap[fontName] || fontName;
42434249
const Metrics = getMetrics();
42444250

4245-
if (!(lookupName in Metrics)) {
4251+
const glyphWidths =
4252+
Metrics[fontName] ??
42464253
// Use default fonts for looking up font metrics if the passed
42474254
// font is not a base font
4248-
lookupName = this.isSerifFont(name) ? "Times-Roman" : "Helvetica";
4249-
}
4250-
const glyphWidths = Metrics[lookupName];
4255+
Metrics[this.isSerifFont(name) ? "Times-Roman" : "Helvetica"];
42514256

42524257
if (typeof glyphWidths === "number") {
42534258
defaultWidth = glyphWidths;
@@ -4458,7 +4463,7 @@ class PartialEvaluator {
44584463
}
44594464

44604465
// Using base font name as a font name.
4461-
baseFontName = baseFontName.name.replaceAll(/[,_]/g, "-");
4466+
baseFontName = normalizeFontName(baseFontName.name);
44624467
const metrics = this.getBaseFontMetrics(baseFontName);
44634468

44644469
// Simulating descriptor flags attribute

src/core/fonts.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ class Font {
992992
nonStdFontMap = getNonStdFontMap(),
993993
serifFonts = getSerifFonts();
994994
for (const namePart of name.split("+")) {
995-
let fontName = namePart.replaceAll(/[,_]/g, "-");
995+
let fontName = normalizeFontName(namePart);
996996
fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
997997
fontName = fontName.split("-", 1)[0];
998998
if (serifFonts[fontName]) {

test/pdfs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,3 +873,4 @@
873873
!Brotli-Prototype-FileA.pdf
874874
!bug2013793.pdf
875875
!bug2014080.pdf
876+
!issue20246.pdf

test/pdfs/issue20246.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/22213611/SFM305474INV1574654.PDF

test/test_manifest.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13936,5 +13936,14 @@
1393613936
"md5": "9113370932798776ba91c807ce95082e",
1393713937
"rounds": 1,
1393813938
"type": "eq"
13939+
},
13940+
{
13941+
"id": "issue20246",
13942+
"file": "pdfs/issue20246.pdf",
13943+
"md5": "4ec1d6b41c7a919ca2de8174ba300233",
13944+
"rounds": 1,
13945+
"link": true,
13946+
"lastPage": 1,
13947+
"type": "eq"
1393913948
}
1394013949
]

0 commit comments

Comments
 (0)