Skip to content

Commit

Permalink
Add language attribute to canvas
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditi-1400 committed May 17, 2024
1 parent 0603d1a commit 4e53e30
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/display/text_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ const ascentCache = new Map();
let _canvasContext = null;

function getCtx(lang = null) {
if (_canvasContext && _canvasContext.canvas.lang !== (lang || "")) {
cleanupTextLayer();
}
if (!_canvasContext) {
// We don't use an OffscreenCanvas here because we use serif/sans serif
// fonts with it and they depends on the locale.
Expand All @@ -77,6 +80,9 @@ function getCtx(lang = null) {
// OffscreenCanvas.
const canvas = document.createElement("canvas");
canvas.className = "hiddenCanvasElement";
if (lang) {
canvas.lang = lang;
}
document.body.append(canvas);
_canvasContext = canvas.getContext("2d", { alpha: false });
}
Expand Down

0 comments on commit 4e53e30

Please sign in to comment.