1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Merge pull request #17770 from Aditi-1400/fix-issue-16843

Add language attribute to canvas
This commit is contained in:
Jonas Jenwald 2024-05-21 21:35:43 +02:00 committed by GitHub
commit 2a52fda11b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 7 deletions

View file

@ -81,7 +81,7 @@ class TextLayer {
static #ascentCache = new Map();
static #canvasCtx = null;
static #canvasContexts = new Map();
static #pendingTextLayers = new Set();
@ -423,13 +423,15 @@ class TextLayer {
return;
}
this.#ascentCache.clear();
this.#canvasCtx?.canvas.remove();
this.#canvasCtx = null;
for (const { canvas } of this.#canvasContexts.values()) {
canvas.remove();
}
this.#canvasContexts.clear();
}
static #getCtx(lang = null) {
if (!this.#canvasCtx) {
let canvasContext = this.#canvasContexts.get((lang ||= ""));
if (!canvasContext) {
// We don't use an OffscreenCanvas here because we use serif/sans serif
// fonts with it and they depends on the locale.
// In Firefox, the <html> element get a lang attribute that depends on
@ -442,10 +444,12 @@ class TextLayer {
// OffscreenCanvas.
const canvas = document.createElement("canvas");
canvas.className = "hiddenCanvasElement";
canvas.lang = lang;
document.body.append(canvas);
this.#canvasCtx = canvas.getContext("2d", { alpha: false });
canvasContext = canvas.getContext("2d", { alpha: false });
this.#canvasContexts.set(lang, canvasContext);
}
return this.#canvasCtx;
return canvasContext;
}
static #getAscent(fontFamily, lang) {