XFA - Fix the way to select page on breaking
- it aims to fix https://bugzilla.mozilla.org/show_bug.cgi?id=1716838. - some fonts in the pdf in the bug where bold when they shouldn't so write the font properties in the html to avoid to use some wrong inherited ones.
This commit is contained in:
parent
223b60f4e8
commit
7aea8faa34
@ -19,6 +19,7 @@ import {
|
|||||||
$appendChild,
|
$appendChild,
|
||||||
$childrenToHTML,
|
$childrenToHTML,
|
||||||
$clean,
|
$clean,
|
||||||
|
$cleanPage,
|
||||||
$content,
|
$content,
|
||||||
$extra,
|
$extra,
|
||||||
$finalize,
|
$finalize,
|
||||||
@ -37,6 +38,7 @@ import {
|
|||||||
$isCDATAXml,
|
$isCDATAXml,
|
||||||
$isSplittable,
|
$isSplittable,
|
||||||
$isTransparent,
|
$isTransparent,
|
||||||
|
$isUsable,
|
||||||
$namespaceId,
|
$namespaceId,
|
||||||
$nodeName,
|
$nodeName,
|
||||||
$onChild,
|
$onChild,
|
||||||
@ -2396,8 +2398,10 @@ class Field extends XFAObject {
|
|||||||
|
|
||||||
const caption = this.caption ? this.caption[$toHTML]().html : null;
|
const caption = this.caption ? this.caption[$toHTML]().html : null;
|
||||||
if (!caption) {
|
if (!caption) {
|
||||||
// Even if no caption this class will help to center the ui.
|
if (ui.attributes.class) {
|
||||||
ui.attributes.class.push("xfaLeft");
|
// Even if no caption this class will help to center the ui.
|
||||||
|
ui.attributes.class.push("xfaLeft");
|
||||||
|
}
|
||||||
return HTMLResult.success(createWrapper(this, html), bbox);
|
return HTMLResult.success(createWrapper(this, html), bbox);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2631,13 +2635,8 @@ class Font extends XFAObject {
|
|||||||
// TODO: fontHorizontalScale
|
// TODO: fontHorizontalScale
|
||||||
// TODO: fontVerticalScale
|
// TODO: fontVerticalScale
|
||||||
|
|
||||||
if (this.kerningMode !== "none") {
|
style.fontKerning = this.kerningMode === "none" ? "none" : "normal";
|
||||||
style.fontKerning = "normal";
|
style.letterSpacing = measureToString(this.letterSpacing);
|
||||||
}
|
|
||||||
|
|
||||||
if (this.letterSpacing) {
|
|
||||||
style.letterSpacing = measureToString(this.letterSpacing);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.lineThrough !== 0) {
|
if (this.lineThrough !== 0) {
|
||||||
style.textDecoration = "line-through";
|
style.textDecoration = "line-through";
|
||||||
@ -2657,9 +2656,7 @@ class Font extends XFAObject {
|
|||||||
|
|
||||||
// TODO: overlinePeriod
|
// TODO: overlinePeriod
|
||||||
|
|
||||||
if (this.posture !== "normal") {
|
style.fontStyle = this.posture;
|
||||||
style.fontStyle = this.posture;
|
|
||||||
}
|
|
||||||
|
|
||||||
const fontSize = measureToString(0.99 * this.size);
|
const fontSize = measureToString(0.99 * this.size);
|
||||||
if (fontSize !== "10px") {
|
if (fontSize !== "10px") {
|
||||||
@ -2677,9 +2674,7 @@ class Font extends XFAObject {
|
|||||||
|
|
||||||
// TODO: underlinePeriod
|
// TODO: underlinePeriod
|
||||||
|
|
||||||
if (this.weight !== "normal") {
|
style.fontWeight = this.weight;
|
||||||
style.fontWeight = this.weight;
|
|
||||||
}
|
|
||||||
|
|
||||||
return style;
|
return style;
|
||||||
}
|
}
|
||||||
@ -3282,24 +3277,39 @@ class PageArea extends XFAObject {
|
|||||||
this.subform = new XFAObjectArray();
|
this.subform = new XFAObjectArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[$isUsable]() {
|
||||||
|
if (!this[$extra]) {
|
||||||
|
this[$extra] = {
|
||||||
|
numberOfUse: 0,
|
||||||
|
};
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
!this.occur ||
|
||||||
|
this.occur.max === -1 ||
|
||||||
|
this[$extra].numberOfUse < this.occur.max
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
[$cleanPage]() {
|
||||||
|
delete this[$extra];
|
||||||
|
}
|
||||||
|
|
||||||
[$getNextPage]() {
|
[$getNextPage]() {
|
||||||
if (!this[$extra]) {
|
if (!this[$extra]) {
|
||||||
this[$extra] = {
|
this[$extra] = {
|
||||||
numberOfUse: 1,
|
numberOfUse: 0,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const parent = this[$getParent]();
|
const parent = this[$getParent]();
|
||||||
if (parent.relation === "orderedOccurrence") {
|
if (parent.relation === "orderedOccurrence") {
|
||||||
if (
|
if (this[$isUsable]()) {
|
||||||
this.occur &&
|
|
||||||
(this.occur.max === -1 || this[$extra].numberOfUse < this.occur.max)
|
|
||||||
) {
|
|
||||||
this[$extra].numberOfUse += 1;
|
this[$extra].numberOfUse += 1;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete this[$extra];
|
|
||||||
return parent[$getNextPage]();
|
return parent[$getNextPage]();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3309,12 +3319,6 @@ class PageArea extends XFAObject {
|
|||||||
|
|
||||||
[$toHTML]() {
|
[$toHTML]() {
|
||||||
// TODO: incomplete.
|
// TODO: incomplete.
|
||||||
if (!this[$extra]) {
|
|
||||||
this[$extra] = {
|
|
||||||
numberOfUse: 1,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const children = [];
|
const children = [];
|
||||||
this[$extra].children = children;
|
this[$extra].children = children;
|
||||||
|
|
||||||
@ -3385,43 +3389,57 @@ class PageSet extends XFAObject {
|
|||||||
this.pageSet = new XFAObjectArray();
|
this.pageSet = new XFAObjectArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[$cleanPage]() {
|
||||||
|
for (const page of this.pageArea.children) {
|
||||||
|
page[$cleanPage]();
|
||||||
|
}
|
||||||
|
for (const page of this.pageSet.children) {
|
||||||
|
page[$cleanPage]();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[$isUsable]() {
|
||||||
|
return (
|
||||||
|
!this.occur ||
|
||||||
|
this.occur.max === -1 ||
|
||||||
|
this[$extra].numberOfUse < this.occur.max
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
[$getNextPage]() {
|
[$getNextPage]() {
|
||||||
if (!this[$extra]) {
|
if (!this[$extra]) {
|
||||||
this[$extra] = {
|
this[$extra] = {
|
||||||
numberOfUse: 1,
|
numberOfUse: 1,
|
||||||
currentIndex: -1,
|
pageIndex: -1,
|
||||||
|
pageSetIndex: -1,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.relation === "orderedOccurrence") {
|
if (this.relation === "orderedOccurrence") {
|
||||||
if (this[$extra].currentIndex + 1 < this.pageArea.children.length) {
|
if (this[$extra].pageIndex + 1 < this.pageArea.children.length) {
|
||||||
this[$extra].currentIndex += 1;
|
this[$extra].pageIndex += 1;
|
||||||
return this.pageArea.children[this[$extra].currentIndex];
|
const pageArea = this.pageArea.children[this[$extra].pageIndex];
|
||||||
|
return pageArea[$getNextPage]();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this[$extra].currentIndex + 1 < this.pageSet.children.length) {
|
if (this[$extra].pageSetIndex + 1 < this.pageSet.children.length) {
|
||||||
this[$extra].currentIndex += 1;
|
this[$extra].pageSetIndex += 1;
|
||||||
return this.pageSet.children[this[$extra].currentIndex];
|
return this.pageSet.children[this[$extra].pageSetIndex][$getNextPage]();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (this[$isUsable]()) {
|
||||||
this.occur &&
|
|
||||||
(this.occur.max === -1 || this[$extra].numberOfUse < this.occur.max)
|
|
||||||
) {
|
|
||||||
this[$extra].numberOfUse += 1;
|
this[$extra].numberOfUse += 1;
|
||||||
this[$extra].currentIndex = 0;
|
this[$extra].pageIndex = -1;
|
||||||
if (this.pageArea.children.length > 0) {
|
this[$extra].pageSetIndex = -1;
|
||||||
return this.pageArea.children[0];
|
return this[$getNextPage]();
|
||||||
}
|
|
||||||
return this.pageSet.children[0][$getNextPage]();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
delete this[$extra];
|
|
||||||
const parent = this[$getParent]();
|
const parent = this[$getParent]();
|
||||||
if (parent instanceof PageSet) {
|
if (parent instanceof PageSet) {
|
||||||
return parent[$getNextPage]();
|
return parent[$getNextPage]();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this[$cleanPage]();
|
||||||
return this[$getNextPage]();
|
return this[$getNextPage]();
|
||||||
}
|
}
|
||||||
const pageNumber = this[$getTemplateRoot]()[$extra].pageNumber;
|
const pageNumber = this[$getTemplateRoot]()[$extra].pageNumber;
|
||||||
@ -4489,6 +4507,8 @@ class Template extends XFAObject {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const root = this.subform.children[0];
|
const root = this.subform.children[0];
|
||||||
|
root.pageSet[$cleanPage]();
|
||||||
|
|
||||||
const pageAreas = root.pageSet.pageArea.children;
|
const pageAreas = root.pageSet.pageArea.children;
|
||||||
const mainHtml = {
|
const mainHtml = {
|
||||||
name: "div",
|
name: "div",
|
||||||
@ -4535,10 +4555,15 @@ class Template extends XFAObject {
|
|||||||
pageArea = pageAreas[0];
|
pageArea = pageAreas[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pageArea[$extra] = {
|
||||||
|
numberOfUse: 1,
|
||||||
|
};
|
||||||
|
|
||||||
const pageAreaParent = pageArea[$getParent]();
|
const pageAreaParent = pageArea[$getParent]();
|
||||||
pageAreaParent[$extra] = {
|
pageAreaParent[$extra] = {
|
||||||
numberOfUse: 1,
|
numberOfUse: 1,
|
||||||
currentIndex: pageAreaParent.pageArea.children.indexOf(pageArea),
|
pageIndex: pageAreaParent.pageArea.children.indexOf(pageArea),
|
||||||
|
pageSetIndex: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
let targetPageArea;
|
let targetPageArea;
|
||||||
@ -4639,19 +4664,26 @@ class Template extends XFAObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (node.targetType === "pageArea") {
|
if (node.targetType === "pageArea") {
|
||||||
|
if (!(target instanceof PageArea)) {
|
||||||
|
target = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (startNew) {
|
if (startNew) {
|
||||||
|
targetPageArea = target || pageArea;
|
||||||
flush(i);
|
flush(i);
|
||||||
i = Infinity;
|
i = Infinity;
|
||||||
} else if (target === pageArea || !(target instanceof PageArea)) {
|
} else if (target && target !== pageArea) {
|
||||||
// Just ignore the break and do layout again.
|
|
||||||
i--;
|
|
||||||
} else {
|
|
||||||
// We must stop the contentAreas filling and go to the next page.
|
|
||||||
targetPageArea = target;
|
targetPageArea = target;
|
||||||
flush(i);
|
flush(i);
|
||||||
i = Infinity;
|
i = Infinity;
|
||||||
|
} else {
|
||||||
|
i--;
|
||||||
}
|
}
|
||||||
} else if (node.targetType === "contentArea") {
|
} else if (node.targetType === "contentArea") {
|
||||||
|
if (!(target instanceof ContentArea)) {
|
||||||
|
target = null;
|
||||||
|
}
|
||||||
|
|
||||||
const index = contentAreas.findIndex(e => e === target);
|
const index = contentAreas.findIndex(e => e === target);
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
flush(i);
|
flush(i);
|
||||||
@ -4705,6 +4737,13 @@ class Template extends XFAObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this[$extra].pageNumber += 1;
|
this[$extra].pageNumber += 1;
|
||||||
|
if (targetPageArea) {
|
||||||
|
if (targetPageArea[$isUsable]()) {
|
||||||
|
targetPageArea[$extra].numberOfUse += 1;
|
||||||
|
} else {
|
||||||
|
targetPageArea = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
pageArea = targetPageArea || pageArea[$getNextPage]();
|
pageArea = targetPageArea || pageArea[$getNextPage]();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ const $addHTML = Symbol();
|
|||||||
const $appendChild = Symbol();
|
const $appendChild = Symbol();
|
||||||
const $childrenToHTML = Symbol();
|
const $childrenToHTML = Symbol();
|
||||||
const $clean = Symbol();
|
const $clean = Symbol();
|
||||||
|
const $cleanPage = Symbol();
|
||||||
const $cleanup = Symbol();
|
const $cleanup = Symbol();
|
||||||
const $clone = Symbol();
|
const $clone = Symbol();
|
||||||
const $consumed = Symbol();
|
const $consumed = Symbol();
|
||||||
@ -59,6 +60,7 @@ const $isDataValue = Symbol();
|
|||||||
const $isDescendent = Symbol();
|
const $isDescendent = Symbol();
|
||||||
const $isSplittable = Symbol();
|
const $isSplittable = Symbol();
|
||||||
const $isTransparent = Symbol();
|
const $isTransparent = Symbol();
|
||||||
|
const $isUsable = Symbol();
|
||||||
const $lastAttribute = Symbol();
|
const $lastAttribute = Symbol();
|
||||||
const $namespaceId = Symbol("namespaceId");
|
const $namespaceId = Symbol("namespaceId");
|
||||||
const $nodeName = Symbol("nodeName");
|
const $nodeName = Symbol("nodeName");
|
||||||
@ -978,6 +980,7 @@ export {
|
|||||||
$appendChild,
|
$appendChild,
|
||||||
$childrenToHTML,
|
$childrenToHTML,
|
||||||
$clean,
|
$clean,
|
||||||
|
$cleanPage,
|
||||||
$cleanup,
|
$cleanup,
|
||||||
$clone,
|
$clone,
|
||||||
$consumed,
|
$consumed,
|
||||||
@ -1012,6 +1015,7 @@ export {
|
|||||||
$isDescendent,
|
$isDescendent,
|
||||||
$isSplittable,
|
$isSplittable,
|
||||||
$isTransparent,
|
$isTransparent,
|
||||||
|
$isUsable,
|
||||||
$namespaceId,
|
$namespaceId,
|
||||||
$nodeName,
|
$nodeName,
|
||||||
$nsAttributes,
|
$nsAttributes,
|
||||||
|
1
test/pdfs/xfa_bug1716838.pdf.link
Normal file
1
test/pdfs/xfa_bug1716838.pdf.link
Normal file
@ -0,0 +1 @@
|
|||||||
|
https://bugzilla.mozilla.org/attachment.cgi?id=9227473
|
@ -962,6 +962,14 @@
|
|||||||
"enableXfa": true,
|
"enableXfa": true,
|
||||||
"type": "eq"
|
"type": "eq"
|
||||||
},
|
},
|
||||||
|
{ "id": "xfa_bug1716838",
|
||||||
|
"file": "pdfs/xfa_bug1716838.pdf",
|
||||||
|
"md5": "564ecff67be690b43c2a144ae5967034",
|
||||||
|
"link": true,
|
||||||
|
"rounds": 1,
|
||||||
|
"enableXfa": true,
|
||||||
|
"type": "eq"
|
||||||
|
},
|
||||||
{ "id": "xfa_candidate_petitions",
|
{ "id": "xfa_candidate_petitions",
|
||||||
"file": "pdfs/xfa_candidate_petitions.pdf",
|
"file": "pdfs/xfa_candidate_petitions.pdf",
|
||||||
"md5": "0db96a00667f8f58f94cf81022e69341",
|
"md5": "0db96a00667f8f58f94cf81022e69341",
|
||||||
|
@ -118,6 +118,10 @@ describe("XFAFactory", function () {
|
|||||||
expect(draw.attributes.style).toEqual({
|
expect(draw.attributes.style).toEqual({
|
||||||
color: "#0c1722",
|
color: "#0c1722",
|
||||||
fontFamily: '"FooBar"',
|
fontFamily: '"FooBar"',
|
||||||
|
fontKerning: "none",
|
||||||
|
letterSpacing: "0px",
|
||||||
|
fontStyle: "normal",
|
||||||
|
fontWeight: "normal",
|
||||||
fontSize: "6.93px",
|
fontSize: "6.93px",
|
||||||
margin: "1px 4px 2px 3px",
|
margin: "1px 4px 2px 3px",
|
||||||
verticalAlign: "2px",
|
verticalAlign: "2px",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user