From 7ec5cbffe9524287c764fd7b7ad0aafd39f4d860 Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Wed, 14 Apr 2021 17:09:52 +0200 Subject: [PATCH] Set block layout for text measurement --- src/ol/render/canvas.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/ol/render/canvas.js b/src/ol/render/canvas.js index 61780050a9..2ad12b8033 100644 --- a/src/ol/render/canvas.js +++ b/src/ol/render/canvas.js @@ -289,7 +289,7 @@ export const measureTextHeight = (function () { /** * @type {HTMLDivElement} */ - let div; + let measureElement; return function (fontSpec) { let height = textHeights[fontSpec]; if (height == undefined) { @@ -303,18 +303,22 @@ export const measureTextHeight = (function () { lineHeight * (metrics.actualBoundingBoxAscent + metrics.actualBoundingBoxDescent); } else { - if (!div) { - div = document.createElement('div'); - div.innerHTML = 'M'; - div.style.margin = '0 !important'; - div.style.padding = '0 !important'; - div.style.position = 'absolute !important'; - div.style.left = '-99999px !important'; + if (!measureElement) { + measureElement = document.createElement('div'); + measureElement.innerHTML = 'M'; + measureElement.style.minHeight = '0'; + measureElement.style.maxHeight = 'none'; + measureElement.style.height = 'auto'; + measureElement.style.padding = '0'; + measureElement.style.border = 'none'; + measureElement.style.position = 'absolute'; + measureElement.style.display = 'block'; + measureElement.style.left = '-99999px'; } - div.style.font = fontSpec; - document.body.appendChild(div); - height = div.offsetHeight; - document.body.removeChild(div); + measureElement.style.font = fontSpec; + document.body.appendChild(measureElement); + height = measureElement.offsetHeight; + document.body.removeChild(measureElement); } textHeights[fontSpec] = height; }