Merge pull request #11079 from Snuffleupagus/textLayer-memory

[TextLayer] Only cache the current `textDiv` style when `enhanceTextSelection` is enabled and use template strings in `expandTextDivs``
This commit is contained in:
Tim van der Meij 2019-08-20 22:48:10 +02:00 committed by GitHub
commit 52c6b3c138
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -90,8 +90,7 @@ var renderTextLayer = (function renderTextLayerClosure() {
fontAscent = (1 + style.descent) * fontAscent; fontAscent = (1 + style.descent) * fontAscent;
} }
var left; let left, top;
var top;
if (angle === 0) { if (angle === 0) {
left = tx[4]; left = tx[4];
top = tx[5] - fontAscent; top = tx[5] - fontAscent;
@ -103,8 +102,12 @@ var renderTextLayer = (function renderTextLayerClosure() {
styleBuf[3] = top; styleBuf[3] = top;
styleBuf[5] = fontHeight; styleBuf[5] = fontHeight;
styleBuf[7] = style.fontFamily; styleBuf[7] = style.fontFamily;
textDivProperties.style = styleBuf.join(''); const styleStr = styleBuf.join('');
textDiv.setAttribute('style', textDivProperties.style);
if (task._enhanceTextSelection) {
textDivProperties.style = styleStr;
}
textDiv.setAttribute('style', styleStr);
textDiv.textContent = geom.str; textDiv.textContent = geom.str;
// `fontName` is only used by the FontInspector, and we only use `dataset` // `fontName` is only used by the FontInspector, and we only use `dataset`
@ -625,49 +628,48 @@ var renderTextLayer = (function renderTextLayerClosure() {
} }
for (var i = 0, ii = this._textDivs.length; i < ii; i++) { for (var i = 0, ii = this._textDivs.length; i < ii; i++) {
var div = this._textDivs[i]; const div = this._textDivs[i];
var divProperties = this._textDivProperties.get(div); const divProps = this._textDivProperties.get(div);
if (divProperties.isWhitespace) { if (divProps.isWhitespace) {
continue; continue;
} }
if (expandDivs) { if (expandDivs) {
var transform = '', padding = ''; let transform = '', padding = '';
if (divProperties.scale !== 1) { if (divProps.scale !== 1) {
transform = 'scaleX(' + divProperties.scale + ')'; transform = `scaleX(${divProps.scale})`;
} }
if (divProperties.angle !== 0) { if (divProps.angle !== 0) {
transform = 'rotate(' + divProperties.angle + 'deg) ' + transform; transform = `rotate(${divProps.angle}deg) ${transform}`;
} }
if (divProperties.paddingLeft !== 0) { if (divProps.paddingLeft !== 0) {
padding += ' padding-left: ' + padding +=
(divProperties.paddingLeft / divProperties.scale) + 'px;'; ` padding-left: ${divProps.paddingLeft / divProps.scale}px;`;
transform += ' translateX(' + transform +=
(-divProperties.paddingLeft / divProperties.scale) + 'px)'; ` translateX(${-divProps.paddingLeft / divProps.scale}px)`;
} }
if (divProperties.paddingTop !== 0) { if (divProps.paddingTop !== 0) {
padding += ' padding-top: ' + divProperties.paddingTop + 'px;'; padding += ` padding-top: ${divProps.paddingTop}px;`;
transform += ' translateY(' + (-divProperties.paddingTop) + 'px)'; transform += ` translateY(${-divProps.paddingTop}px)`;
} }
if (divProperties.paddingRight !== 0) { if (divProps.paddingRight !== 0) {
padding += ' padding-right: ' + padding +=
(divProperties.paddingRight / divProperties.scale) + 'px;'; ` padding-right: ${divProps.paddingRight / divProps.scale}px;`;
} }
if (divProperties.paddingBottom !== 0) { if (divProps.paddingBottom !== 0) {
padding += ' padding-bottom: ' + padding += ` padding-bottom: ${divProps.paddingBottom}px;`;
divProperties.paddingBottom + 'px;';
} }
if (padding !== '') { if (padding !== '') {
div.setAttribute('style', divProperties.style + padding); div.setAttribute('style', divProps.style + padding);
} }
if (transform !== '') { if (transform !== '') {
div.style.transform = transform; div.style.transform = transform;
} }
} else { } else {
div.style.padding = 0; div.style.padding = 0;
div.style.transform = divProperties.originalTransform || ''; div.style.transform = divProps.originalTransform || '';
} }
} }
}, },