-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage.js
More file actions
110 lines (82 loc) · 2.81 KB
/
Copy pathpage.js
File metadata and controls
110 lines (82 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
const BaseContainerComponent = require('./base-container-component.js');
const { Alignment } = require('./enums/index.js');
module.exports = class Page extends BaseContainerComponent {
constructor(properties) {
super(properties);
this.firstPageHeader = properties.firstPageHeader;
this.header = properties.header;
this.footer = properties.footer;
this.size = properties.size;
this.width = this.size.width;
this.height = this.size.height;
}
initializeComponent(data) {
super.initializeComponent(data);
const dataBindingSource = this.getBinding(data);
for (let child of this.children) {
child.initializeComponent(dataBindingSource);
}
}
layoutComponent(document) {
const headerHeight = this._getHeaderHeight(document);
const footerHeight = this._getFooterHeight();
for (let child of this.children) {
child.width = this.width - this.margin.horizontalTotal;
child.height = this.height - this.margin.verticalTotal - headerHeight - footerHeight;
child._originX = this.margin.left;
child._originY = this.margin.top + headerHeight;
child.layoutComponent(document);
}
}
generateHeaderComponent(document, data) {
const headerTemplate = this._getHeader(document);
if (!headerTemplate) {
return;
}
const header = headerTemplate.clone();
header.width = this.width - this.margin.horizontalTotal;
header._originX = this.margin.left;
header._originY = this.margin.top;
header.initializeComponent(data);
header.layoutComponent(document);
header.generateComponent(document, data);
header.afterGenerateComponent(document);
}
generateFooterComponent(document, data) {
if (!this.footer) {
return;
}
const footerHeight = this._getFooterHeight();
const footer = this.footer.clone();
footer.width = this.size.width - this.margin.horizontalTotal;
footer._originX = this.margin.left;
footer._originY = this.size.height - this.margin.bottom - footerHeight;
footer.initializeComponent(data);
footer.layoutComponent(document);
footer.generateComponent(document, data);
footer.afterGenerateComponent(document);
}
generateComponent(document, data) {
super.generateComponent(document, data);
for (let child of this.children) {
child.generateComponent(document, data);
if (document.renderNextPage) {
return;
}
}
}
_getHeaderHeight(document) {
const header = this._getHeader(document);
return header && header.height || 0;
}
_getHeader(document) {
let headerComponent = this.header;
if (document.pageIndex === 0 && this.firstPageHeader) {
headerComponent = this.firstPageHeader;
}
return headerComponent;
}
_getFooterHeight() {
return this.footer && this.footer.height || 0;
}
}