Don't re-create the structTreeLayer on zooming and rotation

Compared to the recent PR 15722 for the `textLayer` this one should be a (comparatively) much a smaller win overall, since most documents don't have any structTree-data and the required parsing should be cheaper. However, it seems to me that it cannot hurt to improve this nonetheless.

Note that by moving the `structTreeLayer` initialization we remove the need for the "textlayerrendered" event listener, which thus simplifies the code a little bit.

Also, removes the API-caching of the structTree-data since this was basically done to offset the lack of caching in the viewer.
This commit is contained in:
Jonas Jenwald 2022-12-04 00:27:44 +01:00
parent cd72818438
commit da0e6bc590
3 changed files with 43 additions and 42 deletions

View file

@ -72,8 +72,19 @@ const PDF_ROLE_TO_HTML_ROLE = {
const HEADING_PATTERN = /^H(\d+)$/;
class StructTreeLayerBuilder {
#treeDom = undefined;
get renderingDone() {
return this.#treeDom !== undefined;
}
render(structTree) {
return this.#walk(structTree);
if (this.#treeDom !== undefined) {
return this.#treeDom;
}
const treeDom = this.#walk(structTree);
treeDom?.classList.add("structTree");
return (this.#treeDom = treeDom);
}
#setAttributes(structElement, htmlElement) {