From 5dc7220425659f352ecd0c1d3ab61b166b8866eb Mon Sep 17 00:00:00 2001 From: kangax Date: Wed, 7 Sep 2011 16:30:25 -0400 Subject: [PATCH] Closes #51 again. Fix background scaling in `toDataURLWithMultiplier`. --- HEADER.js | 2 +- dist/all.js | 27 ++++++++++++--------------- package.json | 2 +- src/canvas.class.js | 25 +++++++++++-------------- 4 files changed, 25 insertions(+), 31 deletions(-) diff --git a/HEADER.js b/HEADER.js index 72d953fa..4a86b150 100644 --- a/HEADER.js +++ b/HEADER.js @@ -1,6 +1,6 @@ /*! Fabric.js Copyright 2008-2011, Bitsonnet (Juriy Zaytsev, Maxim Chernyak) */ -var fabric = fabric || { version: "0.5.8" }; +var fabric = fabric || { version: "0.5.9" }; if (typeof exports != 'undefined') { exports.fabric = fabric; diff --git a/dist/all.js b/dist/all.js index b3c74a36..396cf70d 100644 --- a/dist/all.js +++ b/dist/all.js @@ -1,6 +1,6 @@ /*! Fabric.js Copyright 2008-2011, Bitsonnet (Juriy Zaytsev, Maxim Chernyak) */ -var fabric = fabric || { version: "0.5.8" }; +var fabric = fabric || { version: "0.5.9" }; if (typeof exports != 'undefined') { exports.fabric = fabric; @@ -5695,27 +5695,24 @@ fabric.util.string = { scaledHeight = origHeight * multiplier, activeObject = this.getActiveObject(); - if (multiplier > 1) { - // we're only changing canvas dimensions when retrieving _enlarged_ version of data url, - // since canvas element needs to accomodate increased dimensions - // when multiplier is <=1 canvas dimensions stay the same (and only context scaling changes) - this.setWidth(scaledWidth).setHeight(scaledHeight); - } - + this.setWidth(scaledWidth).setHeight(scaledHeight); this.contextTop.scale(multiplier, multiplier); - this.renderAll(true); if (activeObject) { - this.deactivateAll().renderAll(); + this.deactivateAll(); } + // restoring width, height for `renderAll` to draw + // background properly (while context is scaled) + this.width = origWidth; + this.height = origHeight; + + this.renderAll(true); + var dataURL = this.toDataURL(format); - this.contextTop.scale( 1 / multiplier, 1 / multiplier); - - if (multiplier > 1) { - this.setWidth(origWidth).setHeight(origHeight); - } + this.contextTop.scale(1 / multiplier, 1 / multiplier); + this.setWidth(origWidth).setHeight(origHeight); if (activeObject) { this.setActiveObject(activeObject); diff --git a/package.json b/package.json index c9eb085d..1aa91090 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "fabric", "description": "Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.", - "version": "0.5.8", + "version": "0.5.9", "author": "Juriy Zaytsev ", "keywords": ["canvas", "graphic", "graphics", "SVG", "node-canvas", "parser", "HTML5", "object model"], "repository": "git://github.com/kangax/fabric.js", diff --git a/src/canvas.class.js b/src/canvas.class.js index 5c54b8c6..b7afd6af 100644 --- a/src/canvas.class.js +++ b/src/canvas.class.js @@ -1440,27 +1440,24 @@ scaledHeight = origHeight * multiplier, activeObject = this.getActiveObject(); - if (multiplier > 1) { - // we're only changing canvas dimensions when retrieving _enlarged_ version of data url, - // since canvas element needs to accomodate increased dimensions - // when multiplier is <=1 canvas dimensions stay the same (and only context scaling changes) - this.setWidth(scaledWidth).setHeight(scaledHeight); - } - + this.setWidth(scaledWidth).setHeight(scaledHeight); this.contextTop.scale(multiplier, multiplier); - this.renderAll(true); if (activeObject) { - this.deactivateAll().renderAll(); + this.deactivateAll(); } + // restoring width, height for `renderAll` to draw + // background properly (while context is scaled) + this.width = origWidth; + this.height = origHeight; + + this.renderAll(true); + var dataURL = this.toDataURL(format); - this.contextTop.scale( 1 / multiplier, 1 / multiplier); - - if (multiplier > 1) { - this.setWidth(origWidth).setHeight(origHeight); - } + this.contextTop.scale(1 / multiplier, 1 / multiplier); + this.setWidth(origWidth).setHeight(origHeight); if (activeObject) { this.setActiveObject(activeObject);