XFA - When no fonts in the pdf just use font size as width when measuring text
This commit is contained in:
parent
326226df45
commit
e65b41f891
@ -59,6 +59,7 @@ class FontInfo {
|
|||||||
fonts.Arial ||
|
fonts.Arial ||
|
||||||
fonts.ArialMT ||
|
fonts.ArialMT ||
|
||||||
Object.values(fonts)[0];
|
Object.values(fonts)[0];
|
||||||
|
if (font && font.regular) {
|
||||||
const pdfFont = font.regular;
|
const pdfFont = font.regular;
|
||||||
const info = pdfFont.cssFontInfo;
|
const info = pdfFont.cssFontInfo;
|
||||||
const xfaFont = {
|
const xfaFont = {
|
||||||
@ -69,6 +70,15 @@ class FontInfo {
|
|||||||
};
|
};
|
||||||
return [pdfFont, xfaFont];
|
return [pdfFont, xfaFont];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const xfaFont = {
|
||||||
|
typeface: "Courier",
|
||||||
|
posture: "normal",
|
||||||
|
weight: "normal",
|
||||||
|
size: 10,
|
||||||
|
};
|
||||||
|
return [null, xfaFont];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class FontSelector {
|
class FontSelector {
|
||||||
@ -124,8 +134,9 @@ class TextMeasure {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const lastFont = this.fontSelector.topFont();
|
const lastFont = this.fontSelector.topFont();
|
||||||
const pdfFont = lastFont.pdfFont;
|
|
||||||
const fontSize = lastFont.xfaFont.size;
|
const fontSize = lastFont.xfaFont.size;
|
||||||
|
if (lastFont.pdfFont) {
|
||||||
|
const pdfFont = lastFont.pdfFont;
|
||||||
const lineHeight = Math.round(Math.max(1, pdfFont.lineHeight) * fontSize);
|
const lineHeight = Math.round(Math.max(1, pdfFont.lineHeight) * fontSize);
|
||||||
const scale = fontSize / 1000;
|
const scale = fontSize / 1000;
|
||||||
|
|
||||||
@ -144,7 +155,18 @@ class TextMeasure {
|
|||||||
|
|
||||||
this.glyphs.push([0, 0, false, true]);
|
this.glyphs.push([0, 0, false, true]);
|
||||||
}
|
}
|
||||||
|
this.glyphs.pop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// When we have no font in the pdf, just use the font size as default width.
|
||||||
|
for (const line of str.split(/[\u2029\n]/)) {
|
||||||
|
for (const char of line.split("")) {
|
||||||
|
this.glyphs.push([fontSize, fontSize, char === " ", false]);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.glyphs.push([0, 0, false, true]);
|
||||||
|
}
|
||||||
this.glyphs.pop();
|
this.glyphs.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user