diff --git a/src/display/text_layer.js b/src/display/text_layer.js index d692794673d76c..ef9a71445cf868 100644 --- a/src/display/text_layer.js +++ b/src/display/text_layer.js @@ -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. @@ -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 }); }