Skip to content

Commit

Permalink
Merge pull request #11097 from Snuffleupagus/textLayer-measure-width
Browse files Browse the repository at this point in the history
[TextLayer] Only measure the width of the text, in `_layoutText`, for multi-char text divs
  • Loading branch information
timvandermeij authored Aug 25, 2019
2 parents d64b498 + a139804 commit 184d416
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/display/text_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand Down Expand Up @@ -634,11 +636,8 @@ var renderTextLayer = (function renderTextLayerClosure() {
transformBuf.length = 0;
paddingBuf.length = 0;

if (divProps.angle !== 0) {
transformBuf.push(`rotate(${divProps.angle}deg)`);
}
if (divProps.scale !== 1) {
transformBuf.push(`scaleX(${divProps.scale})`);
if (divProps.originalTransform) {
transformBuf.push(divProps.originalTransform);
}
if (divProps.paddingTop > 0) {
paddingBuf.push(`${divProps.paddingTop}px`);
Expand Down

0 comments on commit 184d416

Please sign in to comment.