Optimize scale calculation in text_layer.js
This patch avoids having to calculate the scale twice by saving it in the properties object. Moreover, we remove a temporary variable and place parentheses around a calculation inside a string concatenation.
This commit is contained in:
parent
b3818d5c36
commit
96593571eb
@ -67,11 +67,11 @@ var renderTextLayer = (function renderTextLayerClosure() {
|
|||||||
canvasWidth: 0,
|
canvasWidth: 0,
|
||||||
isWhitespace: false,
|
isWhitespace: false,
|
||||||
originalTransform: '',
|
originalTransform: '',
|
||||||
originalWidth: 0,
|
|
||||||
paddingBottom: 0,
|
paddingBottom: 0,
|
||||||
paddingLeft: 0,
|
paddingLeft: 0,
|
||||||
paddingRight: 0,
|
paddingRight: 0,
|
||||||
paddingTop: 0,
|
paddingTop: 0,
|
||||||
|
scale: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
task._textDivs.push(textDiv);
|
task._textDivs.push(textDiv);
|
||||||
@ -205,17 +205,15 @@ var renderTextLayer = (function renderTextLayerClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var width = ctx.measureText(textDiv.textContent).width;
|
var width = ctx.measureText(textDiv.textContent).width;
|
||||||
textDivProperties.originalWidth = width;
|
|
||||||
textLayerFrag.appendChild(textDiv);
|
textLayerFrag.appendChild(textDiv);
|
||||||
|
|
||||||
var transform = '';
|
var transform = '';
|
||||||
if (textDivProperties.canvasWidth !== 0 && width > 0) {
|
if (textDivProperties.canvasWidth !== 0 && width > 0) {
|
||||||
var scale = textDivProperties.canvasWidth / width;
|
textDivProperties.scale = textDivProperties.canvasWidth / width;
|
||||||
transform = 'scaleX(' + scale + ')';
|
transform = 'scaleX(' + textDivProperties.scale + ')';
|
||||||
}
|
}
|
||||||
var rotation = textDivProperties.angle;
|
if (textDivProperties.angle !== 0) {
|
||||||
if (rotation !== 0) {
|
transform = 'rotate(' + textDivProperties.angle + 'deg) ' + transform;
|
||||||
transform = 'rotate(' + rotation + 'deg) ' + transform;
|
|
||||||
}
|
}
|
||||||
if (transform !== '') {
|
if (transform !== '') {
|
||||||
textDivProperties.originalTransform = transform;
|
textDivProperties.originalTransform = transform;
|
||||||
@ -569,21 +567,18 @@ var renderTextLayer = (function renderTextLayerClosure() {
|
|||||||
|
|
||||||
if (expandDivs) {
|
if (expandDivs) {
|
||||||
var transform = '';
|
var transform = '';
|
||||||
var scale = 1;
|
|
||||||
|
|
||||||
if (divProperties.canvasWidth !== 0 &&
|
if (divProperties.scale !== 1) {
|
||||||
divProperties.originalWidth > 0) {
|
transform = 'scaleX(' + divProperties.scale + ')';
|
||||||
scale = divProperties.canvasWidth / divProperties.originalWidth;
|
|
||||||
transform = 'scaleX(' + scale + ')';
|
|
||||||
}
|
}
|
||||||
if (divProperties.angle !== 0) {
|
if (divProperties.angle !== 0) {
|
||||||
transform = 'rotate(' + divProperties.angle + 'deg) ' + transform;
|
transform = 'rotate(' + divProperties.angle + 'deg) ' + transform;
|
||||||
}
|
}
|
||||||
if (divProperties.paddingLeft !== 0) {
|
if (divProperties.paddingLeft !== 0) {
|
||||||
div.style.paddingLeft =
|
div.style.paddingLeft =
|
||||||
(divProperties.paddingLeft / scale) + 'px';
|
(divProperties.paddingLeft / divProperties.scale) + 'px';
|
||||||
transform += ' translateX(' +
|
transform += ' translateX(' +
|
||||||
(-divProperties.paddingLeft / scale) + 'px)';
|
(-divProperties.paddingLeft / divProperties.scale) + 'px)';
|
||||||
}
|
}
|
||||||
if (divProperties.paddingTop !== 0) {
|
if (divProperties.paddingTop !== 0) {
|
||||||
div.style.paddingTop = divProperties.paddingTop + 'px';
|
div.style.paddingTop = divProperties.paddingTop + 'px';
|
||||||
@ -591,7 +586,7 @@ var renderTextLayer = (function renderTextLayerClosure() {
|
|||||||
}
|
}
|
||||||
if (divProperties.paddingRight !== 0) {
|
if (divProperties.paddingRight !== 0) {
|
||||||
div.style.paddingRight =
|
div.style.paddingRight =
|
||||||
divProperties.paddingRight / scale + 'px';
|
(divProperties.paddingRight / divProperties.scale) + 'px';
|
||||||
}
|
}
|
||||||
if (divProperties.paddingBottom !== 0) {
|
if (divProperties.paddingBottom !== 0) {
|
||||||
div.style.paddingBottom = divProperties.paddingBottom + 'px';
|
div.style.paddingBottom = divProperties.paddingBottom + 'px';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user