Merge pull request #10396 from timvandermeij/optimizations

Optimizations to avoid intermediate string creation
This commit is contained in:
Tim van der Meij 2018-12-31 12:50:00 +01:00 committed by GitHub
commit 2cdeb93b5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 6 deletions

View File

@ -1317,7 +1317,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var name = fontObj.loadedName || 'sans-serif'; var name = fontObj.loadedName || 'sans-serif';
var bold = fontObj.black ? '900' : (fontObj.bold ? 'bold' : 'normal'); var bold = fontObj.black ? '900' : (fontObj.bold ? 'bold' : 'normal');
var italic = fontObj.italic ? 'italic' : 'normal'; var italic = fontObj.italic ? 'italic' : 'normal';
var typeface = '"' + name + '", ' + fontObj.fallbackName; var typeface = `"${name}", ${fontObj.fallbackName}`;
// Some font backends cannot handle fonts below certain size. // Some font backends cannot handle fonts below certain size.
// Keeping the font at minimal size and using the fontSizeScale to change // Keeping the font at minimal size and using the fontSizeScale to change
@ -1327,8 +1327,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
size > MAX_FONT_SIZE ? MAX_FONT_SIZE : size; size > MAX_FONT_SIZE ? MAX_FONT_SIZE : size;
this.current.fontSizeScale = size / browserFontSize; this.current.fontSizeScale = size / browserFontSize;
var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface; this.ctx.font = `${italic} ${bold} ${browserFontSize}px ${typeface}`;
this.ctx.font = rule;
}, },
setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) { setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
this.current.textRenderingMode = mode; this.current.textRenderingMode = mode;

View File

@ -540,12 +540,12 @@ var renderTextLayer = (function renderTextLayerClosure() {
let transform = ''; let transform = '';
if (textDivProperties.canvasWidth !== 0 && width > 0) { if (textDivProperties.canvasWidth !== 0 && width > 0) {
textDivProperties.scale = textDivProperties.canvasWidth / width; textDivProperties.scale = textDivProperties.canvasWidth / width;
transform = 'scaleX(' + textDivProperties.scale + ')'; transform = `scaleX(${textDivProperties.scale})`;
} }
if (textDivProperties.angle !== 0) { if (textDivProperties.angle !== 0) {
transform = 'rotate(' + textDivProperties.angle + 'deg) ' + transform; transform = `rotate(${textDivProperties.angle}deg) ${transform}`;
} }
if (transform !== '') { if (transform.length > 0) {
textDivProperties.originalTransform = transform; textDivProperties.originalTransform = transform;
textDiv.style.transform = transform; textDiv.style.transform = transform;
} }