mirror of
https://github.com/konvajs/konva.git
synced 2025-06-28 06:31:15 +08:00
fixed multiple bugs related to toDataURL() when using hidden layers
This commit is contained in:
parent
432533ae4a
commit
f74955641a
14
dist/kinetic-core.js
vendored
14
dist/kinetic-core.js
vendored
@ -2937,7 +2937,7 @@ Kinetic.Stage.prototype = {
|
||||
|
||||
function drawLayer(n) {
|
||||
var layer = layers[n];
|
||||
var layerUrl = layer.getCanvas().toDataURL();
|
||||
var layerUrl = layer.toDataURL();
|
||||
var imageObj = new Image();
|
||||
imageObj.onload = function() {
|
||||
context.drawImage(imageObj, 0, 0);
|
||||
@ -3693,8 +3693,18 @@ Kinetic.Layer.prototype = {
|
||||
var mimeType = config && config.mimeType ? config.mimeType : null;
|
||||
var quality = config && config.quality ? config.quality : null;
|
||||
|
||||
if(config && config.width && config.height) {
|
||||
/*
|
||||
* if layer is hidden, return blank canvas
|
||||
* else if width and height are defined, create blank canvas and draw onto it
|
||||
* else return canvas as is
|
||||
*/
|
||||
if(!this.isVisible()) {
|
||||
var stage = this.getStage();
|
||||
canvas = new Kinetic.Canvas(stage.getWidth(), stage.getHeight());
|
||||
}
|
||||
else if(config && config.width && config.height) {
|
||||
canvas = new Kinetic.Canvas(config.width, config.height);
|
||||
this.draw(canvas);
|
||||
}
|
||||
else {
|
||||
canvas = this.getCanvas();
|
||||
|
6
dist/kinetic-core.min.js
vendored
6
dist/kinetic-core.min.js
vendored
File diff suppressed because one or more lines are too long
12
src/Layer.js
12
src/Layer.js
@ -240,8 +240,18 @@ Kinetic.Layer.prototype = {
|
||||
var mimeType = config && config.mimeType ? config.mimeType : null;
|
||||
var quality = config && config.quality ? config.quality : null;
|
||||
|
||||
if(config && config.width && config.height) {
|
||||
/*
|
||||
* if layer is hidden, return blank canvas
|
||||
* else if width and height are defined, create blank canvas and draw onto it
|
||||
* else return canvas as is
|
||||
*/
|
||||
if(!this.isVisible()) {
|
||||
var stage = this.getStage();
|
||||
canvas = new Kinetic.Canvas(stage.getWidth(), stage.getHeight());
|
||||
}
|
||||
else if(config && config.width && config.height) {
|
||||
canvas = new Kinetic.Canvas(config.width, config.height);
|
||||
this.draw(canvas);
|
||||
}
|
||||
else {
|
||||
canvas = this.getCanvas();
|
||||
|
@ -217,7 +217,7 @@ Kinetic.Stage.prototype = {
|
||||
|
||||
function drawLayer(n) {
|
||||
var layer = layers[n];
|
||||
var layerUrl = layer.getCanvas().toDataURL();
|
||||
var layerUrl = layer.toDataURL();
|
||||
var imageObj = new Image();
|
||||
imageObj.onload = function() {
|
||||
context.drawImage(imageObj, 0, 0);
|
||||
|
@ -937,18 +937,19 @@ Test.prototype.tests = {
|
||||
test(!layer2.isVisible(), 'layer2 should be invisible');
|
||||
test(layer2.canvas.element.style.display === 'none', 'layer canvas element display should be none');
|
||||
|
||||
//console.log(layer2.toDataURL());
|
||||
//console.log(layer1.toDataURL());
|
||||
|
||||
stage.toDataURL({
|
||||
callback: function(dataUrl) {
|
||||
//console.log(dataUrl);
|
||||
|
||||
layer2.show();
|
||||
//test(layer2.isVisible(), 'layer2 should be visible');
|
||||
//test(layer2.canvas.element.style.display === 'block', 'layer canvas element display should be block');
|
||||
test(layer2.isVisible(), 'layer2 should be visible');
|
||||
test(layer2.canvas.element.style.display === 'block', 'layer canvas element display should be block');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
},
|
||||
'LAYER - beforeDraw and afterDraw': function(containerId) {
|
||||
var stage = new Kinetic.Stage({
|
||||
|
Loading…
Reference in New Issue
Block a user