Optimize CanvasGraphics.setFont
to avoid intermediate string creation
This method creates quite a few intermediate strings on each call and it's called often, even for smaller documents like the Tracemonkey document. Scrolling from top to bottom in that document resulted in 14126 strings being created in this method. With this commit applied, this is reduced to 2018 strings.
This commit is contained in:
parent
95f9075565
commit
5b57e69da2
@ -1317,7 +1317,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
||||
var name = fontObj.loadedName || 'sans-serif';
|
||||
var bold = fontObj.black ? '900' : (fontObj.bold ? 'bold' : '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.
|
||||
// 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;
|
||||
this.current.fontSizeScale = size / browserFontSize;
|
||||
|
||||
var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface;
|
||||
this.ctx.font = rule;
|
||||
this.ctx.font = `${italic} ${bold} ${browserFontSize}px ${typeface}`;
|
||||
},
|
||||
setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
|
||||
this.current.textRenderingMode = mode;
|
||||
|
Loading…
Reference in New Issue
Block a user