From b68f7bb40473d8c5b63c1fb3e13a443756c3bbf5 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 25 Aug 2019 12:32:49 +0200 Subject: [PATCH] [TextLayer] Only measure the width of the text, in `_layoutText`, for multi-char text divs For performance reasons single-char text divs aren't being scaled, as outlined in a comment in `appendText`. Hence it doesn't seem necessary, or even a good idea, to unconditionally measuring the width of the text in `_layoutText`. --- src/display/text_layer.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/display/text_layer.js b/src/display/text_layer.js index 00fd7e46b..774129852 100644 --- a/src/display/text_layer.js +++ b/src/display/text_layer.js @@ -541,12 +541,14 @@ var renderTextLayer = (function renderTextLayerClosure() { this._layoutTextLastFontFamily = fontFamily; } - let width = this._layoutTextCtx.measureText(textDiv.textContent).width; - let transform = ''; - if (textDivProperties.canvasWidth !== 0 && width > 0) { - textDivProperties.scale = textDivProperties.canvasWidth / width; - transform = `scaleX(${textDivProperties.scale})`; + if (textDivProperties.canvasWidth !== 0) { + // Only measure the width for multi-char text divs, see `appendText`. + const { width, } = this._layoutTextCtx.measureText(textDiv.textContent); + if (width > 0) { + textDivProperties.scale = textDivProperties.canvasWidth / width; + transform = `scaleX(${textDivProperties.scale})`; + } } if (textDivProperties.angle !== 0) { transform = `rotate(${textDivProperties.angle}deg) ${transform}`;