Add a Page helper method to create a PartialEvaluator-instance
Currently we repeat the same identical code five times in the `Page`-class when creating a `PartialEvaluator`-instance, which given the number of parameters it needs seems like unnecessary duplication.
This commit is contained in:
parent
6f052312d6
commit
0ded85e9b3
@ -125,6 +125,22 @@ class Page {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#createPartialEvaluator(handler) {
|
||||||
|
return new PartialEvaluator({
|
||||||
|
xref: this.xref,
|
||||||
|
handler,
|
||||||
|
pageIndex: this.pageIndex,
|
||||||
|
idFactory: this._localIdFactory,
|
||||||
|
fontCache: this.fontCache,
|
||||||
|
builtInCMapCache: this.builtInCMapCache,
|
||||||
|
standardFontDataCache: this.standardFontDataCache,
|
||||||
|
globalColorSpaceCache: this.globalColorSpaceCache,
|
||||||
|
globalImageCache: this.globalImageCache,
|
||||||
|
systemFontCache: this.systemFontCache,
|
||||||
|
options: this.evaluatorOptions,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
@ -322,20 +338,7 @@ class Page {
|
|||||||
if (this.xfaFactory) {
|
if (this.xfaFactory) {
|
||||||
throw new Error("XFA: Cannot save new annotations.");
|
throw new Error("XFA: Cannot save new annotations.");
|
||||||
}
|
}
|
||||||
|
const partialEvaluator = this.#createPartialEvaluator(handler);
|
||||||
const partialEvaluator = new PartialEvaluator({
|
|
||||||
xref: this.xref,
|
|
||||||
handler,
|
|
||||||
pageIndex: this.pageIndex,
|
|
||||||
idFactory: this._localIdFactory,
|
|
||||||
fontCache: this.fontCache,
|
|
||||||
builtInCMapCache: this.builtInCMapCache,
|
|
||||||
standardFontDataCache: this.standardFontDataCache,
|
|
||||||
globalColorSpaceCache: this.globalColorSpaceCache,
|
|
||||||
globalImageCache: this.globalImageCache,
|
|
||||||
systemFontCache: this.systemFontCache,
|
|
||||||
options: this.evaluatorOptions,
|
|
||||||
});
|
|
||||||
|
|
||||||
const deletedAnnotations = new RefSetCache();
|
const deletedAnnotations = new RefSetCache();
|
||||||
const existingAnnotations = new RefSet();
|
const existingAnnotations = new RefSet();
|
||||||
@ -378,19 +381,7 @@ class Page {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async save(handler, task, annotationStorage, changes) {
|
async save(handler, task, annotationStorage, changes) {
|
||||||
const partialEvaluator = new PartialEvaluator({
|
const partialEvaluator = this.#createPartialEvaluator(handler);
|
||||||
xref: this.xref,
|
|
||||||
handler,
|
|
||||||
pageIndex: this.pageIndex,
|
|
||||||
idFactory: this._localIdFactory,
|
|
||||||
fontCache: this.fontCache,
|
|
||||||
builtInCMapCache: this.builtInCMapCache,
|
|
||||||
standardFontDataCache: this.standardFontDataCache,
|
|
||||||
globalColorSpaceCache: this.globalColorSpaceCache,
|
|
||||||
globalImageCache: this.globalImageCache,
|
|
||||||
systemFontCache: this.systemFontCache,
|
|
||||||
options: this.evaluatorOptions,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Fetch the page's annotations and save the content
|
// Fetch the page's annotations and save the content
|
||||||
// in case of interactive form fields.
|
// in case of interactive form fields.
|
||||||
@ -450,19 +441,7 @@ class Page {
|
|||||||
const contentStreamPromise = this.getContentStream();
|
const contentStreamPromise = this.getContentStream();
|
||||||
const resourcesPromise = this.loadResources(RESOURCES_KEYS_OPERATOR_LIST);
|
const resourcesPromise = this.loadResources(RESOURCES_KEYS_OPERATOR_LIST);
|
||||||
|
|
||||||
const partialEvaluator = new PartialEvaluator({
|
const partialEvaluator = this.#createPartialEvaluator(handler);
|
||||||
xref: this.xref,
|
|
||||||
handler,
|
|
||||||
pageIndex: this.pageIndex,
|
|
||||||
idFactory: this._localIdFactory,
|
|
||||||
fontCache: this.fontCache,
|
|
||||||
builtInCMapCache: this.builtInCMapCache,
|
|
||||||
standardFontDataCache: this.standardFontDataCache,
|
|
||||||
globalColorSpaceCache: this.globalColorSpaceCache,
|
|
||||||
globalImageCache: this.globalImageCache,
|
|
||||||
systemFontCache: this.systemFontCache,
|
|
||||||
options: this.evaluatorOptions,
|
|
||||||
});
|
|
||||||
|
|
||||||
const newAnnotsByPage = !this.xfaFactory
|
const newAnnotsByPage = !this.xfaFactory
|
||||||
? getNewAnnotationsMap(annotationStorage)
|
? getNewAnnotationsMap(annotationStorage)
|
||||||
@ -670,19 +649,7 @@ class Page {
|
|||||||
RESOURCES_KEYS_TEXT_CONTENT
|
RESOURCES_KEYS_TEXT_CONTENT
|
||||||
);
|
);
|
||||||
|
|
||||||
const partialEvaluator = new PartialEvaluator({
|
const partialEvaluator = this.#createPartialEvaluator(handler);
|
||||||
xref: this.xref,
|
|
||||||
handler,
|
|
||||||
pageIndex: this.pageIndex,
|
|
||||||
idFactory: this._localIdFactory,
|
|
||||||
fontCache: this.fontCache,
|
|
||||||
builtInCMapCache: this.builtInCMapCache,
|
|
||||||
standardFontDataCache: this.standardFontDataCache,
|
|
||||||
globalColorSpaceCache: this.globalColorSpaceCache,
|
|
||||||
globalImageCache: this.globalImageCache,
|
|
||||||
systemFontCache: this.systemFontCache,
|
|
||||||
options: this.evaluatorOptions,
|
|
||||||
});
|
|
||||||
|
|
||||||
return partialEvaluator.getTextContent({
|
return partialEvaluator.getTextContent({
|
||||||
stream: contentStream,
|
stream: contentStream,
|
||||||
@ -751,19 +718,7 @@ class Page {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (annotation.hasTextContent && isVisible) {
|
if (annotation.hasTextContent && isVisible) {
|
||||||
partialEvaluator ||= new PartialEvaluator({
|
partialEvaluator ??= this.#createPartialEvaluator(handler);
|
||||||
xref: this.xref,
|
|
||||||
handler,
|
|
||||||
pageIndex: this.pageIndex,
|
|
||||||
idFactory: this._localIdFactory,
|
|
||||||
fontCache: this.fontCache,
|
|
||||||
builtInCMapCache: this.builtInCMapCache,
|
|
||||||
standardFontDataCache: this.standardFontDataCache,
|
|
||||||
globalColorSpaceCache: this.globalColorSpaceCache,
|
|
||||||
globalImageCache: this.globalImageCache,
|
|
||||||
systemFontCache: this.systemFontCache,
|
|
||||||
options: this.evaluatorOptions,
|
|
||||||
});
|
|
||||||
|
|
||||||
textContentPromises.push(
|
textContentPromises.push(
|
||||||
annotation
|
annotation
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user