From 2feedbdbb7989e4c6ba4fd02c2c900fc75347a49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Gro=C3=9Fe?= Date: Sun, 5 Jan 2020 14:59:24 +0100 Subject: [PATCH] fallback if TextMeasure.actualBoundingBox* unavailable --- src/index.tsx | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index 1115a685..5d753269 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1335,15 +1335,17 @@ class App extends React.Component<{}, AppState> { if (text === null) { return; } + const fontSize = 20; element.text = text; - element.font = "20px Virgil"; + element.font = `${fontSize}px Virgil`; const font = context.font; context.font = element.font; - const { - actualBoundingBoxAscent, - actualBoundingBoxDescent, - width - } = context.measureText(element.text); + const textMeasure = context.measureText(element.text); + const width = textMeasure.width; + const actualBoundingBoxAscent = + textMeasure.actualBoundingBoxAscent || fontSize; + const actualBoundingBoxDescent = + textMeasure.actualBoundingBoxDescent || 0; element.actualBoundingBoxAscent = actualBoundingBoxAscent; context.font = font; const height = actualBoundingBoxAscent + actualBoundingBoxDescent;