Merge pull request #11090 from Snuffleupagus/textLayer-expandTextDivs-transform

[TextLayer] Use an Array to build the total `transform`, rather than concatenating Strings, in `expandTextDivs`
This commit is contained in:
Tim van der Meij 2019-08-23 23:12:42 +02:00 committed by GitHub
commit edbebb8bf7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -626,6 +626,7 @@ var renderTextLayer = (function renderTextLayerClosure() {
expand(this); expand(this);
this._bounds = null; this._bounds = null;
} }
const transformBuf = [];
for (var i = 0, ii = this._textDivs.length; i < ii; i++) { for (var i = 0, ii = this._textDivs.length; i < ii; i++) {
const div = this._textDivs[i]; const div = this._textDivs[i];
@ -635,23 +636,24 @@ var renderTextLayer = (function renderTextLayerClosure() {
continue; continue;
} }
if (expandDivs) { if (expandDivs) {
let transform = '', padding = ''; transformBuf.length = 0;
let padding = '';
if (divProps.scale !== 1) {
transform = `scaleX(${divProps.scale})`;
}
if (divProps.angle !== 0) { 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) { if (divProps.paddingLeft > 0) {
padding += padding +=
` padding-left: ${divProps.paddingLeft / divProps.scale}px;`; ` padding-left: ${divProps.paddingLeft / divProps.scale}px;`;
transform += transformBuf.push(
` translateX(${-divProps.paddingLeft / divProps.scale}px)`; `translateX(${-divProps.paddingLeft / divProps.scale}px)`);
} }
if (divProps.paddingTop > 0) { if (divProps.paddingTop > 0) {
padding += ` padding-top: ${divProps.paddingTop}px;`; padding += ` padding-top: ${divProps.paddingTop}px;`;
transform += ` translateY(${-divProps.paddingTop}px)`; transformBuf.push(`translateY(${-divProps.paddingTop}px)`);
} }
if (divProps.paddingRight > 0) { if (divProps.paddingRight > 0) {
padding += padding +=
@ -664,8 +666,8 @@ var renderTextLayer = (function renderTextLayerClosure() {
if (padding !== '') { if (padding !== '') {
div.setAttribute('style', divProps.style + padding); div.setAttribute('style', divProps.style + padding);
} }
if (transform !== '') { if (transformBuf.length) {
div.style.transform = transform; div.style.transform = transformBuf.join(' ');
} }
} else { } else {
div.style.padding = null; div.style.padding = null;