Merge pull request #19475 from Snuffleupagus/injectLinkAnnotations-method-event
Move the auto-link handling into its own `PDFPageView` helper-method, and dispatch a "linkannotationsadded" event
This commit is contained in:
commit
c81a404138
@ -536,6 +536,28 @@ class PDFPageView {
|
|||||||
this._textHighlighter.enable();
|
this._textHighlighter.enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async #injectLinkAnnotations(textLayerPromise) {
|
||||||
|
let error = null;
|
||||||
|
try {
|
||||||
|
await textLayerPromise;
|
||||||
|
|
||||||
|
if (!this.annotationLayer) {
|
||||||
|
return; // Rendering was cancelled while the textLayerPromise resolved.
|
||||||
|
}
|
||||||
|
await this.annotationLayer.injectLinkAnnotations({
|
||||||
|
inferredLinks: Autolinker.processLinks(this),
|
||||||
|
viewport: this.viewport,
|
||||||
|
structTreeLayer: this.structTreeLayer,
|
||||||
|
});
|
||||||
|
} catch (ex) {
|
||||||
|
console.error("#injectLinkAnnotations:", ex);
|
||||||
|
error = ex;
|
||||||
|
}
|
||||||
|
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
|
||||||
|
this.#dispatchLayerRendered("linkannotationsadded", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#resetCanvas() {
|
#resetCanvas() {
|
||||||
const { canvas } = this;
|
const { canvas } = this;
|
||||||
if (!canvas) {
|
if (!canvas) {
|
||||||
@ -1122,18 +1144,8 @@ class PDFPageView {
|
|||||||
if (this.annotationLayer) {
|
if (this.annotationLayer) {
|
||||||
await this.#renderAnnotationLayer();
|
await this.#renderAnnotationLayer();
|
||||||
|
|
||||||
if (this.#enableAutoLinking) {
|
if (this.#enableAutoLinking && this.annotationLayer) {
|
||||||
try {
|
await this.#injectLinkAnnotations(textLayerPromise);
|
||||||
await textLayerPromise;
|
|
||||||
|
|
||||||
this.annotationLayer?.injectLinkAnnotations({
|
|
||||||
inferredLinks: Autolinker.processLinks(this),
|
|
||||||
viewport: this.viewport,
|
|
||||||
structTreeLayer: this.structTreeLayer,
|
|
||||||
});
|
|
||||||
} catch (ex) {
|
|
||||||
console.error("enableAutoLinking:", ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user