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
|
@ -17,19 +17,16 @@ const WIDTH_FACTOR = 1.2;
|
|||
const HEIGHT_FACTOR = 1.2;
|
||||
|
||||
class FontInfo {
|
||||
constructor(xfaFont, fonts) {
|
||||
constructor(xfaFont, fontFinder) {
|
||||
if (!xfaFont) {
|
||||
[this.pdfFont, this.xfaFont] = this.defaultFont(fonts);
|
||||
[this.pdfFont, this.xfaFont] = this.defaultFont(fontFinder);
|
||||
return;
|
||||
}
|
||||
|
||||
this.xfaFont = xfaFont;
|
||||
let typeface = fonts[xfaFont.typeface];
|
||||
const typeface = fontFinder.find(xfaFont.typeface);
|
||||
if (!typeface) {
|
||||
typeface = fonts[`${xfaFont.typeface}-PdfJS-XFA`];
|
||||
}
|
||||
if (!typeface) {
|
||||
[this.pdfFont, this.xfaFont] = this.defaultFont(fonts);
|
||||
[this.pdfFont, this.xfaFont] = this.defaultFont(fontFinder);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -47,18 +44,17 @@ class FontInfo {
|
|||
}
|
||||
|
||||
if (!this.pdfFont) {
|
||||
[this.pdfFont, this.xfaFont] = this.defaultFont(fonts);
|
||||
[this.pdfFont, this.xfaFont] = this.defaultFont(fontFinder);
|
||||
}
|
||||
}
|
||||
|
||||
defaultFont(fonts) {
|
||||
defaultFont(fontFinder) {
|
||||
// TODO: Add a default font based on Liberation.
|
||||
const font =
|
||||
fonts.Helvetica ||
|
||||
fonts["Myriad Pro"] ||
|
||||
fonts.Arial ||
|
||||
fonts.ArialMT ||
|
||||
Object.values(fonts)[0];
|
||||
fontFinder.find("Helvetica", false) ||
|
||||
fontFinder.find("Myriad Pro", false) ||
|
||||
fontFinder.find("Arial", false) ||
|
||||
fontFinder.getDefault();
|
||||
if (font && font.regular) {
|
||||
const pdfFont = font.regular;
|
||||
const info = pdfFont.cssFontInfo;
|
||||
|
@ -82,9 +78,9 @@ class FontInfo {
|
|||
}
|
||||
|
||||
class FontSelector {
|
||||
constructor(defaultXfaFont, fonts) {
|
||||
this.fonts = fonts;
|
||||
this.stack = [new FontInfo(defaultXfaFont, fonts)];
|
||||
constructor(defaultXfaFont, fontFinder) {
|
||||
this.fontFinder = fontFinder;
|
||||
this.stack = [new FontInfo(defaultXfaFont, fontFinder)];
|
||||
}
|
||||
|
||||
pushFont(xfaFont) {
|
||||
|
@ -95,7 +91,7 @@ class FontSelector {
|
|||
}
|
||||
}
|
||||
|
||||
const fontInfo = new FontInfo(xfaFont, this.fonts);
|
||||
const fontInfo = new FontInfo(xfaFont, this.fontFinder);
|
||||
if (!fontInfo.pdfFont) {
|
||||
fontInfo.pdfFont = lastFont.pdfFont;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue