Skip to content

Commit

Permalink
Avoid full renderAll for exporting to a new canvas, dereference conte…
Browse files Browse the repository at this point in the history
…xtTop (#5736)
  • Loading branch information
asturur authored Jun 2, 2019
1 parent 51a8437 commit c7eaced
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 26 deletions.
11 changes: 5 additions & 6 deletions src/mixins/canvas_dataurl_exporter.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,28 +69,27 @@
translateX = (vp[4] - (cropping.left || 0)) * multiplier,
translateY = (vp[5] - (cropping.top || 0)) * multiplier,
originalInteractive = this.interactive,
originalContext = this.contextContainer,
newVp = [newZoom, 0, 0, newZoom, translateX, translateY],
originalRetina = this.enableRetinaScaling,
canvasEl = fabric.util.createCanvasElement();
canvasEl = fabric.util.createCanvasElement(),
originalContextTop = this.contextTop;
canvasEl.width = scaledWidth;
canvasEl.height = scaledHeight;
this.contextTop = null;
this.enableRetinaScaling = false;
this.interactive = false;
this.viewportTransform = newVp;
this.width = scaledWidth;
this.height = scaledHeight;
this.calcViewportBoundaries();
this.contextContainer = canvasEl.getContext('2d');
// will be renderAllExport();
this.renderAll();
this.renderCanvas(canvasEl.getContext('2d'), this._objects);
this.viewportTransform = vp;
this.width = originalWidth;
this.height = originalHeight;
this.calcViewportBoundaries();
this.contextContainer = originalContext;
this.interactive = originalInteractive;
this.enableRetinaScaling = originalRetina;
this.contextTop = originalContextTop;
return canvasEl;
},
});
Expand Down
33 changes: 13 additions & 20 deletions src/shapes/itext.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,36 +261,29 @@
* Prepare and clean the contextTop
*/
clearContextTop: function(skipRestore) {
if (!this.isEditing) {
if (!this.isEditing || !this.canvas || !this.canvas.contextTop) {
return;
}
if (this.canvas && this.canvas.contextTop) {
var ctx = this.canvas.contextTop, v = this.canvas.viewportTransform;
ctx.save();
ctx.transform(v[0], v[1], v[2], v[3], v[4], v[5]);
this.transform(ctx);
this.transformMatrix && ctx.transform.apply(ctx, this.transformMatrix);
this._clearTextArea(ctx);
skipRestore || ctx.restore();
}
var ctx = this.canvas.contextTop, v = this.canvas.viewportTransform;
ctx.save();
ctx.transform(v[0], v[1], v[2], v[3], v[4], v[5]);
this.transform(ctx);
this.transformMatrix && ctx.transform.apply(ctx, this.transformMatrix);
this._clearTextArea(ctx);
skipRestore || ctx.restore();
},

/**
* Renders cursor or selection (depending on what exists)
* it does on the contextTop. If contextTop is not available, do nothing.
*/
renderCursorOrSelection: function() {
if (!this.isEditing || !this.canvas) {
if (!this.isEditing || !this.canvas || !this.canvas.contextTop) {
return;
}
var boundaries = this._getCursorBoundaries(), ctx;
if (this.canvas && this.canvas.contextTop) {
ctx = this.canvas.contextTop;
this.clearContextTop(true);
}
else {
ctx = this.canvas.contextContainer;
ctx.save();
}
var boundaries = this._getCursorBoundaries(),
ctx = this.canvas.contextTop;
this.clearContextTop(true);
if (this.selectionStart === this.selectionEnd) {
this.renderCursor(boundaries, ctx);
}
Expand Down

0 comments on commit c7eaced

Please sign in to comment.