mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-09 17:55:37 +02:00
Don't invoke cleanupTextLayer
when there are pending textLayers
*Please note:* This doesn't really affect the viewer, but may affect the library API if multiple PDF documents are opened in parallel. Since we clean-up "global" textLayer-data when destroying a PDF document, this means that other active PDFs could potentially break by invoking `cleanupTextLayer` unconditionally. Note that textLayer rendering is an asynchronous task, and we thus need to ensure those are all finished before running clean-up.
This commit is contained in:
parent
e8e9a3e29f
commit
d8e0fca609
1 changed files with 6 additions and 0 deletions
|
@ -63,6 +63,7 @@ const DEFAULT_FONT_SIZE = 30;
|
||||||
const DEFAULT_FONT_ASCENT = 0.8;
|
const DEFAULT_FONT_ASCENT = 0.8;
|
||||||
const ascentCache = new Map();
|
const ascentCache = new Map();
|
||||||
let _canvasContext = null;
|
let _canvasContext = null;
|
||||||
|
const pendingTextLayers = new Set();
|
||||||
|
|
||||||
function getCtx(lang = null) {
|
function getCtx(lang = null) {
|
||||||
if (!_canvasContext) {
|
if (!_canvasContext) {
|
||||||
|
@ -85,6 +86,9 @@ function getCtx(lang = null) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function cleanupTextLayer() {
|
function cleanupTextLayer() {
|
||||||
|
if (pendingTextLayers.size > 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
_canvasContext?.canvas.remove();
|
_canvasContext?.canvas.remove();
|
||||||
_canvasContext = null;
|
_canvasContext = null;
|
||||||
}
|
}
|
||||||
|
@ -245,9 +249,11 @@ class TextLayerRenderTask {
|
||||||
|
|
||||||
setLayerDimensions(container, viewport);
|
setLayerDimensions(container, viewport);
|
||||||
|
|
||||||
|
pendingTextLayers.add(this);
|
||||||
// Always clean-up the temporary canvas once rendering is no longer pending.
|
// Always clean-up the temporary canvas once rendering is no longer pending.
|
||||||
this._capability.promise
|
this._capability.promise
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
|
pendingTextLayers.delete(this);
|
||||||
this._layoutTextParams = null;
|
this._layoutTextParams = null;
|
||||||
this._styleCache = null;
|
this._styleCache = null;
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue