1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-28 23:28:16 +02:00

XFA - Fix font scale factors (bug 1720888)

- All the scale factors in for the substitution font were wrong because of different glyph positions between Liberation and the other ones:
    - regenerate all the factors
  - Text may have polish chars for example and in this case the glyph widths were wrong:
    - treat substitution font as a composite one
    - add a map glyphIndex to unicode for Liberation in order to generate width array for cid font
This commit is contained in:
Calixte Denizet 2021-07-28 18:30:22 +02:00
parent ac5c4b7fd0
commit 4a4591bd2c
17 changed files with 1614 additions and 1248 deletions

View file

@ -15,7 +15,7 @@
import { selectFont } from "./fonts.js";
const WIDTH_FACTOR = 1.01;
const WIDTH_FACTOR = 1.02;
class FontInfo {
constructor(xfaFont, margin, lineHeight, fontFinder) {
@ -188,22 +188,25 @@ class TextMeasure {
const noGap = fontLineHeight - lineGap;
const firstLineHeight = Math.max(1, noGap) * fontSize;
const scale = fontSize / 1000;
const fallbackWidth =
pdfFont.defaultWidth || pdfFont.charsToGlyphs(" ")[0].width;
for (const line of str.split(/[\u2029\n]/)) {
const encodedLine = pdfFont.encodeString(line).join("");
const glyphs = pdfFont.charsToGlyphs(encodedLine);
for (const glyph of glyphs) {
const width = glyph.width || fallbackWidth;
this.glyphs.push([
glyph.width * scale + letterSpacing,
width * scale + letterSpacing,
lineHeight,
firstLineHeight,
glyph.unicode === " ",
glyph.unicode,
false,
]);
}
this.glyphs.push([0, 0, 0, false, true]);
this.glyphs.push([0, 0, 0, "\n", true]);
}
this.glyphs.pop();
return;
@ -212,16 +215,10 @@ class TextMeasure {
// 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,
1.2 * fontSize,
fontSize,
char === " ",
false,
]);
this.glyphs.push([fontSize, 1.2 * fontSize, fontSize, char, false]);
}
this.glyphs.push([0, 0, 0, false, true]);
this.glyphs.push([0, 0, 0, "\n", true]);
}
this.glyphs.pop();
}
@ -237,8 +234,9 @@ class TextMeasure {
let isFirstLine = true;
for (let i = 0, ii = this.glyphs.length; i < ii; i++) {
const [glyphWidth, lineHeight, firstLineHeight, isSpace, isEOL] =
const [glyphWidth, lineHeight, firstLineHeight, char, isEOL] =
this.glyphs[i];
const isSpace = char === " ";
const glyphHeight = isFirstLine ? firstLineHeight : lineHeight;
if (isEOL) {
width = Math.max(width, currentLineWidth);