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

@ -560,6 +560,11 @@ function isPrintOnly(node) {
);
}
function getCurrentPara(node) {
const stack = node[$getTemplateRoot]()[$extra].paraStack;
return stack.length ? stack[stack.length - 1] : null;
}
function setPara(node, nodeStyle, value) {
if (value.attributes.class && value.attributes.class.includes("xfaRich")) {
if (nodeStyle) {
@ -570,13 +575,15 @@ function setPara(node, nodeStyle, value) {
nodeStyle.width = "auto";
}
}
if (node.para) {
const para = getCurrentPara(node);
if (para) {
// By definition exData are external data so para
// has no effect on it.
const valueStyle = value.attributes.style;
valueStyle.display = "flex";
valueStyle.flexDirection = "column";
switch (node.para.vAlign) {
switch (para.vAlign) {
case "top":
valueStyle.justifyContent = "start";
break;
@ -588,7 +595,7 @@ function setPara(node, nodeStyle, value) {
break;
}
const paraStyle = node.para[$toStyle]();
const paraStyle = para[$toStyle]();
for (const [key, val] of Object.entries(paraStyle)) {
if (!(key in valueStyle)) {
valueStyle[key] = val;
@ -598,7 +605,7 @@ function setPara(node, nodeStyle, value) {
}
}
function setFontFamily(xfaFont, fontFinder, style) {
function setFontFamily(xfaFont, node, fontFinder, style) {
const name = stripQuotes(xfaFont.typeface);
const typeface = fontFinder.find(name);
@ -608,6 +615,12 @@ function setFontFamily(xfaFont, fontFinder, style) {
if (fontFamily !== name) {
style.fontFamily = `"${fontFamily}"`;
}
const para = getCurrentPara(node);
if (para && para.lineHeight !== "") {
return;
}
if (style.lineHeight) {
// Already something so don't overwrite.
return;