Mark the catDict
member as private in the Catalog
class
Not only is `catDict` never accessed anymore outside of this file, it should also never happen since it's internal to the catalog. If data from it is needed elsewhere, the catalog should provide a getter for it that can do basic data integrity checks and abstract away any unnecessary details.
This commit is contained in:
parent
f20f0bcc78
commit
f0bf62ff54
@ -65,8 +65,8 @@ class Catalog {
|
|||||||
this.pdfManager = pdfManager;
|
this.pdfManager = pdfManager;
|
||||||
this.xref = xref;
|
this.xref = xref;
|
||||||
|
|
||||||
this.catDict = xref.getCatalogObj();
|
this._catDict = xref.getCatalogObj();
|
||||||
if (!isDict(this.catDict)) {
|
if (!isDict(this._catDict)) {
|
||||||
throw new FormatError("Catalog object is not a dictionary.");
|
throw new FormatError("Catalog object is not a dictionary.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ class Catalog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get version() {
|
get version() {
|
||||||
const version = this.catDict.get("Version");
|
const version = this._catDict.get("Version");
|
||||||
if (!isName(version)) {
|
if (!isName(version)) {
|
||||||
return shadow(this, "version", null);
|
return shadow(this, "version", null);
|
||||||
}
|
}
|
||||||
@ -87,7 +87,7 @@ class Catalog {
|
|||||||
get collection() {
|
get collection() {
|
||||||
let collection = null;
|
let collection = null;
|
||||||
try {
|
try {
|
||||||
const obj = this.catDict.get("Collection");
|
const obj = this._catDict.get("Collection");
|
||||||
if (isDict(obj) && obj.size > 0) {
|
if (isDict(obj) && obj.size > 0) {
|
||||||
collection = obj;
|
collection = obj;
|
||||||
}
|
}
|
||||||
@ -103,7 +103,7 @@ class Catalog {
|
|||||||
get acroForm() {
|
get acroForm() {
|
||||||
let acroForm = null;
|
let acroForm = null;
|
||||||
try {
|
try {
|
||||||
const obj = this.catDict.get("AcroForm");
|
const obj = this._catDict.get("AcroForm");
|
||||||
if (isDict(obj) && obj.size > 0) {
|
if (isDict(obj) && obj.size > 0) {
|
||||||
acroForm = obj;
|
acroForm = obj;
|
||||||
}
|
}
|
||||||
@ -117,7 +117,7 @@ class Catalog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get metadata() {
|
get metadata() {
|
||||||
const streamRef = this.catDict.getRaw("Metadata");
|
const streamRef = this._catDict.getRaw("Metadata");
|
||||||
if (!isRef(streamRef)) {
|
if (!isRef(streamRef)) {
|
||||||
return shadow(this, "metadata", null);
|
return shadow(this, "metadata", null);
|
||||||
}
|
}
|
||||||
@ -152,7 +152,7 @@ class Catalog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get toplevelPagesDict() {
|
get toplevelPagesDict() {
|
||||||
const pagesObj = this.catDict.get("Pages");
|
const pagesObj = this._catDict.get("Pages");
|
||||||
if (!isDict(pagesObj)) {
|
if (!isDict(pagesObj)) {
|
||||||
throw new FormatError("Invalid top-level pages dictionary.");
|
throw new FormatError("Invalid top-level pages dictionary.");
|
||||||
}
|
}
|
||||||
@ -176,7 +176,7 @@ class Catalog {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_readDocumentOutline() {
|
_readDocumentOutline() {
|
||||||
let obj = this.catDict.get("Outlines");
|
let obj = this._catDict.get("Outlines");
|
||||||
if (!isDict(obj)) {
|
if (!isDict(obj)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -297,7 +297,7 @@ class Catalog {
|
|||||||
get optionalContentConfig() {
|
get optionalContentConfig() {
|
||||||
let config = null;
|
let config = null;
|
||||||
try {
|
try {
|
||||||
const properties = this.catDict.get("OCProperties");
|
const properties = this._catDict.get("OCProperties");
|
||||||
if (!properties) {
|
if (!properties) {
|
||||||
return shadow(this, "optionalContentConfig", null);
|
return shadow(this, "optionalContentConfig", null);
|
||||||
}
|
}
|
||||||
@ -410,12 +410,12 @@ class Catalog {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_readDests() {
|
_readDests() {
|
||||||
const obj = this.catDict.get("Names");
|
const obj = this._catDict.get("Names");
|
||||||
if (obj && obj.has("Dests")) {
|
if (obj && obj.has("Dests")) {
|
||||||
return new NameTree(obj.getRaw("Dests"), this.xref);
|
return new NameTree(obj.getRaw("Dests"), this.xref);
|
||||||
} else if (this.catDict.has("Dests")) {
|
} else if (this._catDict.has("Dests")) {
|
||||||
// Simple destination dictionary.
|
// Simple destination dictionary.
|
||||||
return this.catDict.get("Dests");
|
return this._catDict.get("Dests");
|
||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
@ -437,7 +437,7 @@ class Catalog {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_readPageLabels() {
|
_readPageLabels() {
|
||||||
const obj = this.catDict.getRaw("PageLabels");
|
const obj = this._catDict.getRaw("PageLabels");
|
||||||
if (!obj) {
|
if (!obj) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -537,7 +537,7 @@ class Catalog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get pageLayout() {
|
get pageLayout() {
|
||||||
const obj = this.catDict.get("PageLayout");
|
const obj = this._catDict.get("PageLayout");
|
||||||
// Purposely use a non-standard default value, rather than 'SinglePage', to
|
// Purposely use a non-standard default value, rather than 'SinglePage', to
|
||||||
// allow differentiating between `undefined` and /SinglePage since that does
|
// allow differentiating between `undefined` and /SinglePage since that does
|
||||||
// affect the Scroll mode (continuous/non-continuous) used in Adobe Reader.
|
// affect the Scroll mode (continuous/non-continuous) used in Adobe Reader.
|
||||||
@ -558,7 +558,7 @@ class Catalog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get pageMode() {
|
get pageMode() {
|
||||||
const obj = this.catDict.get("PageMode");
|
const obj = this._catDict.get("PageMode");
|
||||||
let pageMode = "UseNone"; // Default value.
|
let pageMode = "UseNone"; // Default value.
|
||||||
|
|
||||||
if (isName(obj)) {
|
if (isName(obj)) {
|
||||||
@ -596,7 +596,7 @@ class Catalog {
|
|||||||
NumCopies: Number.isInteger,
|
NumCopies: Number.isInteger,
|
||||||
};
|
};
|
||||||
|
|
||||||
const obj = this.catDict.get("ViewerPreferences");
|
const obj = this._catDict.get("ViewerPreferences");
|
||||||
let prefs = null;
|
let prefs = null;
|
||||||
|
|
||||||
if (isDict(obj)) {
|
if (isDict(obj)) {
|
||||||
@ -721,7 +721,7 @@ class Catalog {
|
|||||||
* NOTE: "JavaScript" actions are, for now, handled by `get javaScript` below.
|
* NOTE: "JavaScript" actions are, for now, handled by `get javaScript` below.
|
||||||
*/
|
*/
|
||||||
get openAction() {
|
get openAction() {
|
||||||
const obj = this.catDict.get("OpenAction");
|
const obj = this._catDict.get("OpenAction");
|
||||||
let openAction = null;
|
let openAction = null;
|
||||||
|
|
||||||
if (isDict(obj)) {
|
if (isDict(obj)) {
|
||||||
@ -754,7 +754,7 @@ class Catalog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get attachments() {
|
get attachments() {
|
||||||
const obj = this.catDict.get("Names");
|
const obj = this._catDict.get("Names");
|
||||||
let attachments = null;
|
let attachments = null;
|
||||||
|
|
||||||
if (obj && obj.has("EmbeddedFiles")) {
|
if (obj && obj.has("EmbeddedFiles")) {
|
||||||
@ -772,7 +772,7 @@ class Catalog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get javaScript() {
|
get javaScript() {
|
||||||
const obj = this.catDict.get("Names");
|
const obj = this._catDict.get("Names");
|
||||||
|
|
||||||
let javaScript = null;
|
let javaScript = null;
|
||||||
function appendIfJavaScriptDict(jsDict) {
|
function appendIfJavaScriptDict(jsDict) {
|
||||||
@ -808,7 +808,7 @@ class Catalog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Append OpenAction "JavaScript" actions to the JavaScript array.
|
// Append OpenAction "JavaScript" actions to the JavaScript array.
|
||||||
const openAction = this.catDict.get("OpenAction");
|
const openAction = this._catDict.get("OpenAction");
|
||||||
if (isDict(openAction) && isName(openAction.get("S"), "JavaScript")) {
|
if (isDict(openAction) && isName(openAction.get("S"), "JavaScript")) {
|
||||||
appendIfJavaScriptDict(openAction);
|
appendIfJavaScriptDict(openAction);
|
||||||
}
|
}
|
||||||
@ -853,7 +853,7 @@ class Catalog {
|
|||||||
|
|
||||||
getPageDict(pageIndex) {
|
getPageDict(pageIndex) {
|
||||||
const capability = createPromiseCapability();
|
const capability = createPromiseCapability();
|
||||||
const nodesToVisit = [this.catDict.getRaw("Pages")];
|
const nodesToVisit = [this._catDict.getRaw("Pages")];
|
||||||
const visitedNodes = new RefSet();
|
const visitedNodes = new RefSet();
|
||||||
const xref = this.xref,
|
const xref = this.xref,
|
||||||
pageKidsCountCache = this.pageKidsCountCache;
|
pageKidsCountCache = this.pageKidsCountCache;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user