Skip to content
This repository was archived by the owner on Apr 12, 2021. It is now read-only.

Commit 52c3b45

Browse files
committed
Use property getter to define PDFPage lazy dictionaries
1 parent 56d4327 commit 52c3b45

1 file changed

Lines changed: 26 additions & 19 deletions

File tree

lib/page.js

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -95,25 +95,6 @@ class PDFPage {
9595
this.resources = this.document.ref({
9696
ProcSet: ['PDF', 'Text', 'ImageB', 'ImageC', 'ImageI']});
9797

98-
// Lazily create these dictionaries
99-
Object.defineProperties(this, {
100-
fonts: {
101-
get: () => this.resources.data.Font != null ? this.resources.data.Font : (this.resources.data.Font = {})
102-
},
103-
xobjects: {
104-
get: () => this.resources.data.XObject != null ? this.resources.data.XObject : (this.resources.data.XObject = {})
105-
},
106-
ext_gstates: {
107-
get: () => this.resources.data.ExtGState != null ? this.resources.data.ExtGState : (this.resources.data.ExtGState = {})
108-
},
109-
patterns: {
110-
get: () => this.resources.data.Pattern != null ? this.resources.data.Pattern : (this.resources.data.Pattern = {})
111-
},
112-
annotations: {
113-
get: () => this.dictionary.data.Annots != null ? this.dictionary.data.Annots : (this.dictionary.data.Annots = [])
114-
}
115-
});
116-
11798
// The page dictionary
11899
this.dictionary = this.document.ref({
119100
Type: 'Page',
@@ -123,6 +104,32 @@ class PDFPage {
123104
Resources: this.resources
124105
});
125106
}
107+
108+
// Lazily create these dictionaries
109+
get fonts() {
110+
const data = this.resources.data;
111+
return data.Font != null ? data.Font : (data.Font = {});
112+
}
113+
114+
get xobjects() {
115+
const data = this.resources.data;
116+
return data.XObject != null ? data.XObject : (data.XObject = {});
117+
}
118+
119+
get ext_gstates() {
120+
const data = this.resources.data;
121+
return data.ExtGState != null ? data.ExtGState : (data.ExtGState = {});
122+
}
123+
124+
get patterns() {
125+
const data = this.resources.data;
126+
return data.Pattern != null ? data.Pattern : (data.Pattern = {});
127+
}
128+
129+
get annotations() {
130+
const data = this.dictionary.data;
131+
return data.Annots != null ? data.Annots : (data.Annots = []);
132+
}
126133

127134
maxY() {
128135
return this.height - this.margins.bottom;

0 commit comments

Comments
 (0)