mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-28 23:28:16 +02:00
XFA - Match font family correctly
- partial fix for https://bugzilla.mozilla.org/show_bug.cgi?id=1716980; - some pdf can contain an invalid font family (e.g. 'Windings 3') so in this case remove the space; - the font family in typeface attribute doesn't always match the one defined in the FontDescriptor dictionary.
This commit is contained in:
parent
248efb16a7
commit
7cdbc98716
13 changed files with 221 additions and 57 deletions
|
@ -190,8 +190,8 @@ function setMinMaxDimensions(node, style) {
|
|||
}
|
||||
}
|
||||
|
||||
function layoutText(text, xfaFont, fonts, width) {
|
||||
const measure = new TextMeasure(xfaFont, fonts);
|
||||
function layoutText(text, xfaFont, fontFinder, width) {
|
||||
const measure = new TextMeasure(xfaFont, fontFinder);
|
||||
if (typeof text === "string") {
|
||||
measure.addString(text);
|
||||
} else {
|
||||
|
@ -448,13 +448,20 @@ function fixTextIndent(styles) {
|
|||
}
|
||||
}
|
||||
|
||||
function getFonts(family) {
|
||||
function getFonts(family, fontFinder) {
|
||||
if (family.startsWith("'") || family.startsWith('"')) {
|
||||
family = family.slice(1, family.length - 1);
|
||||
}
|
||||
|
||||
const fonts = [`"${family}"`, `"${family}-PdfJS-XFA"`];
|
||||
return fonts.join(",");
|
||||
const pdfFont = fontFinder.find(family);
|
||||
if (pdfFont) {
|
||||
const { fontFamily } = pdfFont.regular.cssFontInfo;
|
||||
if (fontFamily !== family) {
|
||||
return `"${family}","${fontFamily}"`;
|
||||
}
|
||||
}
|
||||
|
||||
return `"${family}"`;
|
||||
}
|
||||
|
||||
export {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue