@@ -85,38 +85,49 @@ function fetchRemoteDest(action) {
85
85
}
86
86
87
87
class Catalog {
88
+ #actualNumPages = null ;
89
+
90
+ #catDict = null ;
91
+
92
+ builtInCMapCache = new Map ( ) ;
93
+
94
+ fontCache = new RefSetCache ( ) ;
95
+
96
+ globalColorSpaceCache = new GlobalColorSpaceCache ( ) ;
97
+
98
+ globalImageCache = new GlobalImageCache ( ) ;
99
+
100
+ nonBlendModesSet = new RefSet ( ) ;
101
+
102
+ pageDictCache = new RefSetCache ( ) ;
103
+
104
+ pageIndexCache = new RefSetCache ( ) ;
105
+
106
+ pageKidsCountCache = new RefSetCache ( ) ;
107
+
108
+ standardFontDataCache = new Map ( ) ;
109
+
110
+ systemFontCache = new Map ( ) ;
111
+
88
112
constructor ( pdfManager , xref ) {
89
113
this . pdfManager = pdfManager ;
90
114
this . xref = xref ;
91
115
92
- this . _catDict = xref . getCatalogObj ( ) ;
93
- if ( ! ( this . _catDict instanceof Dict ) ) {
116
+ this . #catDict = xref . getCatalogObj ( ) ;
117
+ if ( ! ( this . #catDict instanceof Dict ) ) {
94
118
throw new FormatError ( "Catalog object is not a dictionary." ) ;
95
119
}
96
120
// Given that `XRef.parse` will both fetch *and* validate the /Pages-entry,
97
121
// the following call must always succeed here:
98
122
this . toplevelPagesDict ; // eslint-disable-line no-unused-expressions
99
-
100
- this . _actualNumPages = null ;
101
-
102
- this . fontCache = new RefSetCache ( ) ;
103
- this . builtInCMapCache = new Map ( ) ;
104
- this . standardFontDataCache = new Map ( ) ;
105
- this . globalColorSpaceCache = new GlobalColorSpaceCache ( ) ;
106
- this . globalImageCache = new GlobalImageCache ( ) ;
107
- this . pageKidsCountCache = new RefSetCache ( ) ;
108
- this . pageIndexCache = new RefSetCache ( ) ;
109
- this . pageDictCache = new RefSetCache ( ) ;
110
- this . nonBlendModesSet = new RefSet ( ) ;
111
- this . systemFontCache = new Map ( ) ;
112
123
}
113
124
114
125
cloneDict ( ) {
115
- return this . _catDict . clone ( ) ;
126
+ return this . #catDict . clone ( ) ;
116
127
}
117
128
118
129
get version ( ) {
119
- const version = this . _catDict . get ( "Version" ) ;
130
+ const version = this . #catDict . get ( "Version" ) ;
120
131
if ( version instanceof Name ) {
121
132
if ( PDF_VERSION_REGEXP . test ( version . name ) ) {
122
133
return shadow ( this , "version" , version . name ) ;
@@ -127,7 +138,7 @@ class Catalog {
127
138
}
128
139
129
140
get lang ( ) {
130
- const lang = this . _catDict . get ( "Lang" ) ;
141
+ const lang = this . #catDict . get ( "Lang" ) ;
131
142
return shadow (
132
143
this ,
133
144
"lang" ,
@@ -140,7 +151,7 @@ class Catalog {
140
151
* `false` for XFA Foreground documents.
141
152
*/
142
153
get needsRendering ( ) {
143
- const needsRendering = this . _catDict . get ( "NeedsRendering" ) ;
154
+ const needsRendering = this . #catDict . get ( "NeedsRendering" ) ;
144
155
return shadow (
145
156
this ,
146
157
"needsRendering" ,
@@ -151,7 +162,7 @@ class Catalog {
151
162
get collection ( ) {
152
163
let collection = null ;
153
164
try {
154
- const obj = this . _catDict . get ( "Collection" ) ;
165
+ const obj = this . #catDict . get ( "Collection" ) ;
155
166
if ( obj instanceof Dict && obj . size > 0 ) {
156
167
collection = obj ;
157
168
}
@@ -167,7 +178,7 @@ class Catalog {
167
178
get acroForm ( ) {
168
179
let acroForm = null ;
169
180
try {
170
- const obj = this . _catDict . get ( "AcroForm" ) ;
181
+ const obj = this . #catDict . get ( "AcroForm" ) ;
171
182
if ( obj instanceof Dict && obj . size > 0 ) {
172
183
acroForm = obj ;
173
184
}
@@ -181,12 +192,12 @@ class Catalog {
181
192
}
182
193
183
194
get acroFormRef ( ) {
184
- const value = this . _catDict . getRaw ( "AcroForm" ) ;
195
+ const value = this . #catDict . getRaw ( "AcroForm" ) ;
185
196
return shadow ( this , "acroFormRef" , value instanceof Ref ? value : null ) ;
186
197
}
187
198
188
199
get metadata ( ) {
189
- const streamRef = this . _catDict . getRaw ( "Metadata" ) ;
200
+ const streamRef = this . #catDict . getRaw ( "Metadata" ) ;
190
201
if ( ! ( streamRef instanceof Ref ) ) {
191
202
return shadow ( this , "metadata" , null ) ;
192
203
}
@@ -225,7 +236,7 @@ class Catalog {
225
236
get markInfo ( ) {
226
237
let markInfo = null ;
227
238
try {
228
- markInfo = this . _readMarkInfo ( ) ;
239
+ markInfo = this . #readMarkInfo ( ) ;
229
240
} catch ( ex ) {
230
241
if ( ex instanceof MissingDataException ) {
231
242
throw ex ;
@@ -235,11 +246,8 @@ class Catalog {
235
246
return shadow ( this , "markInfo" , markInfo ) ;
236
247
}
237
248
238
- /**
239
- * @private
240
- */
241
- _readMarkInfo ( ) {
242
- const obj = this . _catDict . get ( "MarkInfo" ) ;
249
+ #readMarkInfo( ) {
250
+ const obj = this . #catDict. get ( "MarkInfo" ) ;
243
251
if ( ! ( obj instanceof Dict ) ) {
244
252
return null ;
245
253
}
@@ -273,7 +281,7 @@ class Catalog {
273
281
}
274
282
275
283
#readStructTreeRoot( ) {
276
- const rawObj = this . _catDict . getRaw ( "StructTreeRoot" ) ;
284
+ const rawObj = this . #catDict . getRaw ( "StructTreeRoot" ) ;
277
285
const obj = this . xref . fetchIfRef ( rawObj ) ;
278
286
if ( ! ( obj instanceof Dict ) ) {
279
287
return null ;
@@ -285,7 +293,7 @@ class Catalog {
285
293
}
286
294
287
295
get toplevelPagesDict ( ) {
288
- const pagesObj = this . _catDict . get ( "Pages" ) ;
296
+ const pagesObj = this . #catDict . get ( "Pages" ) ;
289
297
if ( ! ( pagesObj instanceof Dict ) ) {
290
298
throw new FormatError ( "Invalid top-level pages dictionary." ) ;
291
299
}
@@ -295,7 +303,7 @@ class Catalog {
295
303
get documentOutline ( ) {
296
304
let obj = null ;
297
305
try {
298
- obj = this . _readDocumentOutline ( ) ;
306
+ obj = this . #readDocumentOutline ( ) ;
299
307
} catch ( ex ) {
300
308
if ( ex instanceof MissingDataException ) {
301
309
throw ex ;
@@ -305,11 +313,8 @@ class Catalog {
305
313
return shadow ( this , "documentOutline" , obj ) ;
306
314
}
307
315
308
- /**
309
- * @private
310
- */
311
- _readDocumentOutline ( ) {
312
- let obj = this . _catDict . get ( "Outlines" ) ;
316
+ #readDocumentOutline( ) {
317
+ let obj = this . #catDict. get ( "Outlines" ) ;
313
318
if ( ! ( obj instanceof Dict ) ) {
314
319
return null ;
315
320
}
@@ -391,7 +396,7 @@ class Catalog {
391
396
get permissions ( ) {
392
397
let permissions = null ;
393
398
try {
394
- permissions = this . _readPermissions ( ) ;
399
+ permissions = this . #readPermissions ( ) ;
395
400
} catch ( ex ) {
396
401
if ( ex instanceof MissingDataException ) {
397
402
throw ex ;
@@ -401,10 +406,7 @@ class Catalog {
401
406
return shadow ( this , "permissions" , permissions ) ;
402
407
}
403
408
404
- /**
405
- * @private
406
- */
407
- _readPermissions ( ) {
409
+ #readPermissions( ) {
408
410
const encrypt = this . xref . trailer . get ( "Encrypt" ) ;
409
411
if ( ! ( encrypt instanceof Dict ) ) {
410
412
return null ;
@@ -433,7 +435,7 @@ class Catalog {
433
435
get optionalContentConfig ( ) {
434
436
let config = null ;
435
437
try {
436
- const properties = this . _catDict . get ( "OCProperties" ) ;
438
+ const properties = this . #catDict . get ( "OCProperties" ) ;
437
439
if ( ! properties ) {
438
440
return shadow ( this , "optionalContentConfig" , null ) ;
439
441
}
@@ -645,11 +647,11 @@ class Catalog {
645
647
}
646
648
647
649
setActualNumPages ( num = null ) {
648
- this . _actualNumPages = num ;
650
+ this . #actualNumPages = num ;
649
651
}
650
652
651
653
get hasActualNumPages ( ) {
652
- return this . _actualNumPages !== null ;
654
+ return this . #actualNumPages !== null ;
653
655
}
654
656
655
657
get _pagesCount ( ) {
@@ -663,7 +665,7 @@ class Catalog {
663
665
}
664
666
665
667
get numPages ( ) {
666
- return this . hasActualNumPages ? this . _actualNumPages : this . _pagesCount ;
668
+ return this . #actualNumPages ?? this . _pagesCount ;
667
669
}
668
670
669
671
get destinations ( ) {
@@ -721,22 +723,22 @@ class Catalog {
721
723
}
722
724
723
725
#readDests( ) {
724
- const obj = this . _catDict . get ( "Names" ) ;
726
+ const obj = this . #catDict . get ( "Names" ) ;
725
727
const rawDests = [ ] ;
726
728
if ( obj ?. has ( "Dests" ) ) {
727
729
rawDests . push ( new NameTree ( obj . getRaw ( "Dests" ) , this . xref ) ) ;
728
730
}
729
- if ( this . _catDict . has ( "Dests" ) ) {
731
+ if ( this . #catDict . has ( "Dests" ) ) {
730
732
// Simple destination dictionary.
731
- rawDests . push ( this . _catDict . get ( "Dests" ) ) ;
733
+ rawDests . push ( this . #catDict . get ( "Dests" ) ) ;
732
734
}
733
735
return rawDests ;
734
736
}
735
737
736
738
get pageLabels ( ) {
737
739
let obj = null ;
738
740
try {
739
- obj = this . _readPageLabels ( ) ;
741
+ obj = this . #readPageLabels ( ) ;
740
742
} catch ( ex ) {
741
743
if ( ex instanceof MissingDataException ) {
742
744
throw ex ;
@@ -746,11 +748,8 @@ class Catalog {
746
748
return shadow ( this , "pageLabels" , obj ) ;
747
749
}
748
750
749
- /**
750
- * @private
751
- */
752
- _readPageLabels ( ) {
753
- const obj = this . _catDict . getRaw ( "PageLabels" ) ;
751
+ #readPageLabels( ) {
752
+ const obj = this . #catDict. getRaw ( "PageLabels" ) ;
754
753
if ( ! obj ) {
755
754
return null ;
756
755
}
@@ -847,7 +846,7 @@ class Catalog {
847
846
}
848
847
849
848
get pageLayout ( ) {
850
- const obj = this . _catDict . get ( "PageLayout" ) ;
849
+ const obj = this . #catDict . get ( "PageLayout" ) ;
851
850
// Purposely use a non-standard default value, rather than 'SinglePage', to
852
851
// allow differentiating between `undefined` and /SinglePage since that does
853
852
// affect the Scroll mode (continuous/non-continuous) used in Adobe Reader.
@@ -868,7 +867,7 @@ class Catalog {
868
867
}
869
868
870
869
get pageMode ( ) {
871
- const obj = this . _catDict . get ( "PageMode" ) ;
870
+ const obj = this . #catDict . get ( "PageMode" ) ;
872
871
let pageMode = "UseNone" ; // Default value.
873
872
874
873
if ( obj instanceof Name ) {
@@ -886,7 +885,7 @@ class Catalog {
886
885
}
887
886
888
887
get viewerPreferences ( ) {
889
- const obj = this . _catDict . get ( "ViewerPreferences" ) ;
888
+ const obj = this . #catDict . get ( "ViewerPreferences" ) ;
890
889
if ( ! ( obj instanceof Dict ) ) {
891
890
return shadow ( this , "viewerPreferences" , null ) ;
892
891
}
@@ -1012,7 +1011,7 @@ class Catalog {
1012
1011
}
1013
1012
1014
1013
get openAction ( ) {
1015
- const obj = this . _catDict . get ( "OpenAction" ) ;
1014
+ const obj = this . #catDict . get ( "OpenAction" ) ;
1016
1015
const openAction = Object . create ( null ) ;
1017
1016
1018
1017
if ( obj instanceof Dict ) {
@@ -1040,7 +1039,7 @@ class Catalog {
1040
1039
}
1041
1040
1042
1041
get attachments ( ) {
1043
- const obj = this . _catDict . get ( "Names" ) ;
1042
+ const obj = this . #catDict . get ( "Names" ) ;
1044
1043
let attachments = null ;
1045
1044
1046
1045
if ( obj instanceof Dict && obj . has ( "EmbeddedFiles" ) ) {
@@ -1056,7 +1055,7 @@ class Catalog {
1056
1055
}
1057
1056
1058
1057
get xfaImages ( ) {
1059
- const obj = this . _catDict . get ( "Names" ) ;
1058
+ const obj = this . #catDict . get ( "Names" ) ;
1060
1059
let xfaImages = null ;
1061
1060
1062
1061
if ( obj instanceof Dict && obj . has ( "XFAImages" ) ) {
@@ -1074,8 +1073,8 @@ class Catalog {
1074
1073
return shadow ( this , "xfaImages" , xfaImages ) ;
1075
1074
}
1076
1075
1077
- _collectJavaScript ( ) {
1078
- const obj = this . _catDict . get ( "Names" ) ;
1076
+ #collectJavaScript ( ) {
1077
+ const obj = this . #catDict . get ( "Names" ) ;
1079
1078
let javaScript = null ;
1080
1079
1081
1080
function appendIfJavaScriptDict ( name , jsDict ) {
@@ -1112,7 +1111,7 @@ class Catalog {
1112
1111
}
1113
1112
}
1114
1113
// Append OpenAction "JavaScript" actions, if any, to the JavaScript map.
1115
- const openAction = this . _catDict . get ( "OpenAction" ) ;
1114
+ const openAction = this . #catDict . get ( "OpenAction" ) ;
1116
1115
if ( openAction ) {
1117
1116
appendIfJavaScriptDict ( "OpenAction" , openAction ) ;
1118
1117
}
@@ -1121,10 +1120,10 @@ class Catalog {
1121
1120
}
1122
1121
1123
1122
get jsActions ( ) {
1124
- const javaScript = this . _collectJavaScript ( ) ;
1123
+ const javaScript = this . #collectJavaScript ( ) ;
1125
1124
let actions = collectActions (
1126
1125
this . xref ,
1127
- this . _catDict ,
1126
+ this . #catDict ,
1128
1127
DocumentActionEventType
1129
1128
) ;
1130
1129
@@ -1164,7 +1163,7 @@ class Catalog {
1164
1163
const nodesToVisit = [ this . toplevelPagesDict ] ;
1165
1164
const visitedNodes = new RefSet ( ) ;
1166
1165
1167
- const pagesRef = this . _catDict . getRaw ( "Pages" ) ;
1166
+ const pagesRef = this . #catDict . getRaw ( "Pages" ) ;
1168
1167
if ( pagesRef instanceof Ref ) {
1169
1168
visitedNodes . put ( pagesRef ) ;
1170
1169
}
@@ -1301,7 +1300,7 @@ class Catalog {
1301
1300
const queue = [ { currentNode : this . toplevelPagesDict , posInKids : 0 } ] ;
1302
1301
const visitedNodes = new RefSet ( ) ;
1303
1302
1304
- const pagesRef = this . _catDict . getRaw ( "Pages" ) ;
1303
+ const pagesRef = this . #catDict . getRaw ( "Pages" ) ;
1305
1304
if ( pagesRef instanceof Ref ) {
1306
1305
visitedNodes . put ( pagesRef ) ;
1307
1306
}
@@ -1505,7 +1504,7 @@ class Catalog {
1505
1504
}
1506
1505
1507
1506
get baseUrl ( ) {
1508
- const uri = this . _catDict . get ( "URI" ) ;
1507
+ const uri = this . #catDict . get ( "URI" ) ;
1509
1508
if ( uri instanceof Dict ) {
1510
1509
const base = uri . get ( "Base" ) ;
1511
1510
if ( typeof base === "string" ) {
0 commit comments