[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`.
This commit is contained in:
Jonas Jenwald 2019-08-25 12:32:49 +02:00
parent 56ae7a6690
commit b68f7bb404

View File

@ -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}`;