Skip to content

Commit

Permalink
Delegate dataURL multiplier to viewport zooming (#2940)
Browse files Browse the repository at this point in the history
This temporary viewport change allow correct zooming and scaling of shadow.
  • Loading branch information
asturur committed May 4, 2016
1 parent d7ea78b commit 27fd548
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/mixins/canvas_dataurl_exporter.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,14 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
scaledHeight = origHeight * multiplier,
activeObject = this.getActiveObject(),
activeGroup = this.getActiveGroup(),
ctx = this.contextContainer;
zoom = this.getZoom(),
newZoom = zoom * multiplier / fabric.devicePixelRatio;

if (multiplier > 1) {
this.setDimensions({ width: scaledWidth, height: scaledHeight });
}
ctx.save();
ctx.scale(multiplier / fabric.devicePixelRatio, multiplier / fabric.devicePixelRatio);

this.setZoom(newZoom);

if (cropping.left) {
cropping.left *= multiplier;
Expand Down Expand Up @@ -155,22 +156,16 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
}

var data = this.__toDataURL(format, quality, cropping);

// restoring width, height for `renderAll` to draw
// background properly (while context is scaled)
this.width = origWidth;
this.height = origHeight;
this.setDimensions({ width: origWidth, height: origHeight });

if (activeGroup) {
this._restoreBordersControlsOnGroup(activeGroup);
}
else if (activeObject && this.setActiveObject) {
this.setActiveObject(activeObject);
}

this.contextTop && this.clearContext(this.contextTop);
this.renderAll();
this.setZoom(zoom);
//setDimensions with no option object is taking care of:
//this.width, this.height, this.renderAll()
this.setDimensions({ width: origWidth, height: origHeight });

return data;
},
Expand Down

0 comments on commit 27fd548

Please sign in to comment.