From a0b968c8e08afc42b96930871410cbddce6ab748 Mon Sep 17 00:00:00 2001 From: Aakansha Doshi Date: Mon, 3 Apr 2023 17:15:29 +0530 Subject: [PATCH] fix for safari --- src/element/textElement.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/element/textElement.ts b/src/element/textElement.ts index f9bd01f3d6..1b391b38bb 100644 --- a/src/element/textElement.ts +++ b/src/element/textElement.ts @@ -329,13 +329,19 @@ export const measureBaseline = ( let baseline = span.offsetTop + span.offsetHeight; const domHeight = container.offsetHeight; - // In Safari sometimes DOM height could be less than canvas height due to - // which text could go out of the bounding box hence shifting the baseline - // to make sure text is rendered correctly if (isSafari) { + // In Safari sometimes DOM height could be less than canvas height due to + // which text could go out of the bounding box hence shifting the baseline + // to make sure text is rendered correctly if (canvasHeight > domHeight) { baseline += canvasHeight - domHeight; } + // In Safari sometimes DOM height could be more than canvas height due to + // which text could go out of the bounding box hence shifting the baseline + // to make sure text is rendered correctly + if (domHeight > canvasHeight) { + baseline -= domHeight - canvasHeight; + } } document.body.removeChild(container); return baseline;