mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-07-29 10:27:21 +02:00
Normalize the font name in getBaseFontMetrics (issue 20246)
We tried to lookup the font metrics using the font name as-is, which didn't work since the PDF file in question has non-embedded fonts with names that include commas. Hence the font names need to be normalized here as well, similar to elsewhere in the font code.
This commit is contained in:
parent
2b95a8eb38
commit
e9c509aca9
@ -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;
|
||||||
|
|||||||
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
@ -873,3 +873,4 @@
|
|||||||
!Brotli-Prototype-FileA.pdf
|
!Brotli-Prototype-FileA.pdf
|
||||||
!bug2013793.pdf
|
!bug2013793.pdf
|
||||||
!bug2014080.pdf
|
!bug2014080.pdf
|
||||||
|
!issue20246.pdf
|
||||||
|
|||||||
1
test/pdfs/issue20246.pdf.link
Normal file
1
test/pdfs/issue20246.pdf.link
Normal file
@ -0,0 +1 @@
|
|||||||
|
https://github.com/user-attachments/files/22213611/SFM305474INV1574654.PDF
|
||||||
@ -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"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user