Merge pull request #13576 from calixteman/really_fix_text_stuff
XFA - When no fonts in the pdf just use font size as width when measuring text
This commit is contained in:
commit
3264d409dd
@ -59,15 +59,25 @@ class FontInfo {
|
|||||||
fonts.Arial ||
|
fonts.Arial ||
|
||||||
fonts.ArialMT ||
|
fonts.ArialMT ||
|
||||||
Object.values(fonts)[0];
|
Object.values(fonts)[0];
|
||||||
const pdfFont = font.regular;
|
if (font && font.regular) {
|
||||||
const info = pdfFont.cssFontInfo;
|
const pdfFont = font.regular;
|
||||||
|
const info = pdfFont.cssFontInfo;
|
||||||
|
const xfaFont = {
|
||||||
|
typeface: info.fontFamily,
|
||||||
|
posture: "normal",
|
||||||
|
weight: "normal",
|
||||||
|
size: 10,
|
||||||
|
};
|
||||||
|
return [pdfFont, xfaFont];
|
||||||
|
}
|
||||||
|
|
||||||
const xfaFont = {
|
const xfaFont = {
|
||||||
typeface: info.fontFamily,
|
typeface: "Courier",
|
||||||
posture: "normal",
|
posture: "normal",
|
||||||
weight: "normal",
|
weight: "normal",
|
||||||
size: 10,
|
size: 10,
|
||||||
};
|
};
|
||||||
return [pdfFont, xfaFont];
|
return [null, xfaFont];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,27 +134,39 @@ 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;
|
||||||
const lineHeight = Math.round(Math.max(1, pdfFont.lineHeight) * fontSize);
|
if (lastFont.pdfFont) {
|
||||||
const scale = fontSize / 1000;
|
const pdfFont = lastFont.pdfFont;
|
||||||
|
const lineHeight = Math.round(Math.max(1, pdfFont.lineHeight) * fontSize);
|
||||||
|
const scale = fontSize / 1000;
|
||||||
|
|
||||||
|
for (const line of str.split(/[\u2029\n]/)) {
|
||||||
|
const encodedLine = pdfFont.encodeString(line).join("");
|
||||||
|
const glyphs = pdfFont.charsToGlyphs(encodedLine);
|
||||||
|
|
||||||
|
for (const glyph of glyphs) {
|
||||||
|
this.glyphs.push([
|
||||||
|
glyph.width * scale,
|
||||||
|
lineHeight,
|
||||||
|
glyph.unicode === " ",
|
||||||
|
false,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 line of str.split(/[\u2029\n]/)) {
|
||||||
const encodedLine = pdfFont.encodeString(line).join("");
|
for (const char of line.split("")) {
|
||||||
const glyphs = pdfFont.charsToGlyphs(encodedLine);
|
this.glyphs.push([fontSize, fontSize, char === " ", false]);
|
||||||
|
|
||||||
for (const glyph of glyphs) {
|
|
||||||
this.glyphs.push([
|
|
||||||
glyph.width * scale,
|
|
||||||
lineHeight,
|
|
||||||
glyph.unicode === " ",
|
|
||||||
false,
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.glyphs.push([0, 0, false, true]);
|
this.glyphs.push([0, 0, false, true]);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.glyphs.pop();
|
this.glyphs.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user