mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-09 09:45:42 +02:00
Ensure that the textLayer styleCache
is always cleared, even on failure
By also moving it to the `TextLayerRenderTask`-instance, we can avoid a bit of manual parameter passing.
This commit is contained in:
parent
049848ba00
commit
30840e411e
1 changed files with 8 additions and 7 deletions
|
@ -162,7 +162,7 @@ function getAscent(fontFamily) {
|
||||||
return DEFAULT_FONT_ASCENT;
|
return DEFAULT_FONT_ASCENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
function appendText(task, geom, styles) {
|
function appendText(task, geom) {
|
||||||
// Initialize all used properties to keep the caches monomorphic.
|
// Initialize all used properties to keep the caches monomorphic.
|
||||||
const textDiv = document.createElement("span");
|
const textDiv = document.createElement("span");
|
||||||
const textDivProperties = {
|
const textDivProperties = {
|
||||||
|
@ -176,7 +176,7 @@ function appendText(task, geom, styles) {
|
||||||
|
|
||||||
const tx = Util.transform(task._transform, geom.transform);
|
const tx = Util.transform(task._transform, geom.transform);
|
||||||
let angle = Math.atan2(tx[1], tx[0]);
|
let angle = Math.atan2(tx[1], tx[0]);
|
||||||
const style = styles[geom.fontName];
|
const style = task._styleCache[geom.fontName];
|
||||||
if (style.vertical) {
|
if (style.vertical) {
|
||||||
angle += Math.PI / 2;
|
angle += Math.PI / 2;
|
||||||
}
|
}
|
||||||
|
@ -343,6 +343,7 @@ class TextLayerRenderTask {
|
||||||
properties: null,
|
properties: null,
|
||||||
ctx: getCtx(),
|
ctx: getCtx(),
|
||||||
};
|
};
|
||||||
|
this._styleCache = Object.create(null);
|
||||||
const { pageWidth, pageHeight, pageX, pageY } = viewport.rawDims;
|
const { pageWidth, pageHeight, pageX, pageY } = viewport.rawDims;
|
||||||
this._transform = [1, 0, 0, -1, -pageX, pageY + pageHeight];
|
this._transform = [1, 0, 0, -1, -pageX, pageY + pageHeight];
|
||||||
this._pageWidth = pageWidth;
|
this._pageWidth = pageWidth;
|
||||||
|
@ -354,6 +355,7 @@ class TextLayerRenderTask {
|
||||||
this._capability.promise
|
this._capability.promise
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
this._layoutTextParams = null;
|
this._layoutTextParams = null;
|
||||||
|
this._styleCache = null;
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
// Avoid "Uncaught promise" messages in the console.
|
// Avoid "Uncaught promise" messages in the console.
|
||||||
|
@ -386,7 +388,7 @@ class TextLayerRenderTask {
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_processItems(items, styleCache) {
|
_processItems(items) {
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
if (item.str === undefined) {
|
if (item.str === undefined) {
|
||||||
if (
|
if (
|
||||||
|
@ -406,7 +408,7 @@ class TextLayerRenderTask {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
this._textContentItemsStr.push(item.str);
|
this._textContentItemsStr.push(item.str);
|
||||||
appendText(this, item, styleCache);
|
appendText(this, item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -434,7 +436,7 @@ class TextLayerRenderTask {
|
||||||
*/
|
*/
|
||||||
_render() {
|
_render() {
|
||||||
const { promise, resolve, reject } = Promise.withResolvers();
|
const { promise, resolve, reject } = Promise.withResolvers();
|
||||||
let styleCache = Object.create(null);
|
const styleCache = this._styleCache;
|
||||||
|
|
||||||
const pump = () => {
|
const pump = () => {
|
||||||
this.#reader.read().then(({ value, done }) => {
|
this.#reader.read().then(({ value, done }) => {
|
||||||
|
@ -444,7 +446,7 @@ class TextLayerRenderTask {
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.assign(styleCache, value.styles);
|
Object.assign(styleCache, value.styles);
|
||||||
this._processItems(value.items, styleCache);
|
this._processItems(value.items);
|
||||||
pump();
|
pump();
|
||||||
}, reject);
|
}, reject);
|
||||||
};
|
};
|
||||||
|
@ -453,7 +455,6 @@ class TextLayerRenderTask {
|
||||||
pump();
|
pump();
|
||||||
|
|
||||||
promise.then(() => {
|
promise.then(() => {
|
||||||
styleCache = null;
|
|
||||||
render(this);
|
render(this);
|
||||||
}, this._capability.reject);
|
}, this._capability.reject);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue