Merge pull request #20637 from Snuffleupagus/issue-20246

Normalize the font name in `getBaseFontMetrics` (issue 20246)
This commit is contained in:
Tim van der Meij 2026-02-08 19:48:16 +01:00 committed by GitHub
commit 2a2806dc07
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 24 additions and 8 deletions

View File

@ -31,7 +31,11 @@ import {
} from "../shared/util.js"; } from "../shared/util.js";
import { CMapFactory, IdentityCMap } from "./cmap.js"; import { CMapFactory, IdentityCMap } from "./cmap.js";
import { Cmd, Dict, EOF, isName, Name, Ref, RefSet } from "./primitives.js"; import { Cmd, Dict, EOF, isName, Name, Ref, RefSet } from "./primitives.js";
import { compileType3Glyph, FontFlags } from "./fonts_utils.js"; import {
compileType3Glyph,
FontFlags,
normalizeFontName,
} from "./fonts_utils.js";
import { ErrorFont, Font } from "./fonts.js"; import { ErrorFont, Font } from "./fonts.js";
import { import {
fetchBinaryData, fetchBinaryData,
@ -4238,16 +4242,17 @@ class PartialEvaluator {
let defaultWidth = 0; let defaultWidth = 0;
let widths = Object.create(null); let widths = Object.create(null);
let monospace = false; let monospace = false;
let fontName = normalizeFontName(name);
const stdFontMap = getStdFontMap(); const stdFontMap = getStdFontMap();
let lookupName = stdFontMap[name] || name; fontName = stdFontMap[fontName] || fontName;
const Metrics = getMetrics(); const Metrics = getMetrics();
if (!(lookupName in Metrics)) { const glyphWidths =
Metrics[fontName] ??
// Use default fonts for looking up font metrics if the passed // Use default fonts for looking up font metrics if the passed
// font is not a base font // font is not a base font
lookupName = this.isSerifFont(name) ? "Times-Roman" : "Helvetica"; Metrics[this.isSerifFont(name) ? "Times-Roman" : "Helvetica"];
}
const glyphWidths = Metrics[lookupName];
if (typeof glyphWidths === "number") { if (typeof glyphWidths === "number") {
defaultWidth = glyphWidths; defaultWidth = glyphWidths;
@ -4458,7 +4463,7 @@ class PartialEvaluator {
} }
// Using base font name as a font name. // Using base font name as a font name.
baseFontName = baseFontName.name.replaceAll(/[,_]/g, "-"); baseFontName = normalizeFontName(baseFontName.name);
const metrics = this.getBaseFontMetrics(baseFontName); const metrics = this.getBaseFontMetrics(baseFontName);
// Simulating descriptor flags attribute // Simulating descriptor flags attribute

View File

@ -992,7 +992,7 @@ class Font {
nonStdFontMap = getNonStdFontMap(), nonStdFontMap = getNonStdFontMap(),
serifFonts = getSerifFonts(); serifFonts = getSerifFonts();
for (const namePart of name.split("+")) { for (const namePart of name.split("+")) {
let fontName = namePart.replaceAll(/[,_]/g, "-"); let fontName = normalizeFontName(namePart);
fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName; fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
fontName = fontName.split("-", 1)[0]; fontName = fontName.split("-", 1)[0];
if (serifFonts[fontName]) { if (serifFonts[fontName]) {

View File

@ -873,3 +873,4 @@
!Brotli-Prototype-FileA.pdf !Brotli-Prototype-FileA.pdf
!bug2013793.pdf !bug2013793.pdf
!bug2014080.pdf !bug2014080.pdf
!issue20246.pdf

View File

@ -0,0 +1 @@
https://github.com/user-attachments/files/22213611/SFM305474INV1574654.PDF

View File

@ -13936,5 +13936,14 @@
"md5": "9113370932798776ba91c807ce95082e", "md5": "9113370932798776ba91c807ce95082e",
"rounds": 1, "rounds": 1,
"type": "eq" "type": "eq"
},
{
"id": "issue20246",
"file": "pdfs/issue20246.pdf",
"md5": "4ec1d6b41c7a919ca2de8174ba300233",
"rounds": 1,
"link": true,
"lastPage": 1,
"type": "eq"
} }
] ]