Skip to content

Commit

Permalink
[TextLayer] Use an Array to build the total transform, rather than …
Browse files Browse the repository at this point in the history
…concatenating Strings, in `expandTextDivs`

Furthermore, it's possible to re-use the same Array for all `textDiv`s on the page.
  • Loading branch information
Snuffleupagus committed Aug 23, 2019
1 parent 490deb1 commit 0f3a7d3
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/display/text_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,7 @@ var renderTextLayer = (function renderTextLayerClosure() {
expand(this);
this._bounds = null;
}
const transformBuf = [];

for (var i = 0, ii = this._textDivs.length; i < ii; i++) {
const div = this._textDivs[i];
Expand All @@ -635,23 +636,24 @@ var renderTextLayer = (function renderTextLayerClosure() {
continue;
}
if (expandDivs) {
let transform = '', padding = '';
transformBuf.length = 0;
let padding = '';

if (divProps.scale !== 1) {
transform = `scaleX(${divProps.scale})`;
}
if (divProps.angle !== 0) {
transform = `rotate(${divProps.angle}deg) ${transform}`;
transformBuf.push(`rotate(${divProps.angle}deg)`);
}
if (divProps.scale !== 1) {
transformBuf.push(`scaleX(${divProps.scale})`);
}
if (divProps.paddingLeft !== 0) {
padding +=
` padding-left: ${divProps.paddingLeft / divProps.scale}px;`;
transform +=
` translateX(${-divProps.paddingLeft / divProps.scale}px)`;
transformBuf.push(
`translateX(${-divProps.paddingLeft / divProps.scale}px)`);
}
if (divProps.paddingTop !== 0) {
padding += ` padding-top: ${divProps.paddingTop}px;`;
transform += ` translateY(${-divProps.paddingTop}px)`;
transformBuf.push(`translateY(${-divProps.paddingTop}px)`);
}
if (divProps.paddingRight !== 0) {
padding +=
Expand All @@ -664,8 +666,8 @@ var renderTextLayer = (function renderTextLayerClosure() {
if (padding !== '') {
div.setAttribute('style', divProps.style + padding);
}
if (transform !== '') {
div.style.transform = transform;
if (transformBuf.length) {
div.style.transform = transformBuf.join(' ');
}
} else {
div.style.padding = null;
Expand Down

0 comments on commit 0f3a7d3

Please sign in to comment.