1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 10:08:06 +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

@ -46,6 +46,8 @@ import {
$nodeName,
$onChild,
$onText,
$popPara,
$pushPara,
$removeChild,
$searchNode,
$setSetAttributes,
@ -1062,8 +1064,11 @@ class Caption extends XFAObject {
return HTMLResult.EMPTY;
}
this[$pushPara]();
const value = this.value[$toHTML](availableSpace).html;
if (!value) {
this[$popPara]();
return HTMLResult.EMPTY;
}
@ -1110,6 +1115,7 @@ class Caption extends XFAObject {
}
setPara(this, null, value);
this[$popPara]();
this.reserve = savedReserve;
@ -1730,6 +1736,7 @@ class Draw extends XFAObject {
}
fixDimensions(this);
this[$pushPara]();
// If at least one dimension is missing and we've a text
// then we can guess it in laying out the text.
@ -1744,6 +1751,7 @@ class Draw extends XFAObject {
// So if we've potentially more width to provide in some parent containers
// let's increase it to give a chance to have a better rendering.
if (isBroken && this[$getSubformParent]()[$isThereMoreWidth]()) {
this[$popPara]();
return HTMLResult.FAILURE;
}
@ -1757,6 +1765,7 @@ class Draw extends XFAObject {
if (!checkDimensions(this, availableSpace)) {
this.w = savedW;
this.h = savedH;
this[$popPara]();
return HTMLResult.FAILURE;
}
unsetFirstUnsplittable(this);
@ -1816,6 +1825,7 @@ class Draw extends XFAObject {
if (value === null) {
this.w = savedW;
this.h = savedH;
this[$popPara]();
return HTMLResult.success(createWrapper(this, html), bbox);
}
@ -1825,6 +1835,7 @@ class Draw extends XFAObject {
this.w = savedW;
this.h = savedH;
this[$popPara]();
return HTMLResult.success(createWrapper(this, html), bbox);
}
}
@ -2364,6 +2375,7 @@ class ExclGroup extends XFAObject {
attributes.xfaName = this.name;
}
this[$pushPara]();
const isLrTb = this.layout === "lr-tb" || this.layout === "rl-tb";
const maxRun = isLrTb ? MAX_ATTEMPTS_FOR_LRTB_LAYOUT : 1;
for (; this[$extra].attempt < maxRun; this[$extra].attempt++) {
@ -2381,6 +2393,7 @@ class ExclGroup extends XFAObject {
break;
}
if (result.isBreak()) {
this[$popPara]();
return result;
}
if (
@ -2395,6 +2408,8 @@ class ExclGroup extends XFAObject {
}
}
this[$popPara]();
if (!isSplittable) {
unsetFirstUnsplittable(this);
}
@ -2627,6 +2642,8 @@ class Field extends XFAObject {
delete this.caption[$extra];
}
this[$pushPara]();
const caption = this.caption
? this.caption[$toHTML](availableSpace).html
: null;
@ -2667,6 +2684,7 @@ class Field extends XFAObject {
// See comment in Draw::[$toHTML] to have an explanation
// about this line.
if (isBroken && this[$getSubformParent]()[$isThereMoreWidth]()) {
this[$popPara]();
return HTMLResult.FAILURE;
}
@ -2706,12 +2724,15 @@ class Field extends XFAObject {
}
}
this[$popPara]();
fixDimensions(this);
setFirstUnsplittable(this);
if (!checkDimensions(this, availableSpace)) {
this.w = savedW;
this.h = savedH;
this[$popPara]();
return HTMLResult.FAILURE;
}
unsetFirstUnsplittable(this);
@ -3131,7 +3152,7 @@ class Font extends XFAObject {
style.fontStyle = this.posture;
style.fontSize = measureToString(0.99 * this.size);
setFontFamily(this, this[$globalData].fontFinder, style);
setFontFamily(this, this, this[$globalData].fontFinder, style);
if (this.underline !== 0) {
style.textDecoration = "underline";
@ -4957,6 +4978,7 @@ class Subform extends XFAObject {
}
}
this[$pushPara]();
const isLrTb = this.layout === "lr-tb" || this.layout === "rl-tb";
const maxRun = isLrTb ? MAX_ATTEMPTS_FOR_LRTB_LAYOUT : 1;
for (; this[$extra].attempt < maxRun; this[$extra].attempt++) {
@ -4974,6 +4996,7 @@ class Subform extends XFAObject {
break;
}
if (result.isBreak()) {
this[$popPara]();
return result;
}
if (
@ -4995,6 +5018,7 @@ class Subform extends XFAObject {
}
}
this[$popPara]();
if (!isSplittable) {
unsetFirstUnsplittable(this);
}
@ -5242,6 +5266,7 @@ class Template extends XFAObject {
pagePosition: "first",
oddOrEven: "odd",
blankOrNotBlank: "nonBlank",
paraStack: [],
};
const root = this.subform.children[0];