mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
Fix background rendering regression #496
This commit is contained in:
parent
9b372a4399
commit
7a58ad019f
4
dist/html2canvas.js
vendored
4
dist/html2canvas.js
vendored
@ -949,6 +949,8 @@ Color.prototype.namedColor = function(value) {
|
|||||||
return !!color;
|
return !!color;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Color.prototype.isColor = true;
|
||||||
|
|
||||||
// JSON.stringify([].slice.call($$('.named-color-table tr'), 1).map(function(row) { return [row.childNodes[3].textContent, row.childNodes[5].textContent.trim().split(",").map(Number)] }).reduce(function(data, row) {data[row[0]] = row[1]; return data}, {}))
|
// JSON.stringify([].slice.call($$('.named-color-table tr'), 1).map(function(row) { return [row.childNodes[3].textContent, row.childNodes[5].textContent.trim().split(",").map(Number)] }).reduce(function(data, row) {data[row[0]] = row[1]; return data}, {}))
|
||||||
var colors = {
|
var colors = {
|
||||||
"aliceblue": [240, 248, 255],
|
"aliceblue": [240, 248, 255],
|
||||||
@ -3182,7 +3184,7 @@ function CanvasRenderer(width, height) {
|
|||||||
CanvasRenderer.prototype = Object.create(Renderer.prototype);
|
CanvasRenderer.prototype = Object.create(Renderer.prototype);
|
||||||
|
|
||||||
CanvasRenderer.prototype.setFillStyle = function(fillStyle) {
|
CanvasRenderer.prototype.setFillStyle = function(fillStyle) {
|
||||||
this.ctx.fillStyle = typeof(fillStyle) === "object" ? fillStyle.toString() : fillStyle;
|
this.ctx.fillStyle = typeof(fillStyle) === "object" && !!fillStyle.isColor ? fillStyle.toString() : fillStyle;
|
||||||
return this.ctx;
|
return this.ctx;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
4
dist/html2canvas.min.js
vendored
4
dist/html2canvas.min.js
vendored
File diff suppressed because one or more lines are too long
@ -114,6 +114,8 @@ Color.prototype.namedColor = function(value) {
|
|||||||
return !!color;
|
return !!color;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Color.prototype.isColor = true;
|
||||||
|
|
||||||
// JSON.stringify([].slice.call($$('.named-color-table tr'), 1).map(function(row) { return [row.childNodes[3].textContent, row.childNodes[5].textContent.trim().split(",").map(Number)] }).reduce(function(data, row) {data[row[0]] = row[1]; return data}, {}))
|
// JSON.stringify([].slice.call($$('.named-color-table tr'), 1).map(function(row) { return [row.childNodes[3].textContent, row.childNodes[5].textContent.trim().split(",").map(Number)] }).reduce(function(data, row) {data[row[0]] = row[1]; return data}, {}))
|
||||||
var colors = {
|
var colors = {
|
||||||
"aliceblue": [240, 248, 255],
|
"aliceblue": [240, 248, 255],
|
||||||
|
@ -15,7 +15,7 @@ function CanvasRenderer(width, height) {
|
|||||||
CanvasRenderer.prototype = Object.create(Renderer.prototype);
|
CanvasRenderer.prototype = Object.create(Renderer.prototype);
|
||||||
|
|
||||||
CanvasRenderer.prototype.setFillStyle = function(fillStyle) {
|
CanvasRenderer.prototype.setFillStyle = function(fillStyle) {
|
||||||
this.ctx.fillStyle = typeof(fillStyle) === "object" ? fillStyle.toString() : fillStyle;
|
this.ctx.fillStyle = typeof(fillStyle) === "object" && !!fillStyle.isColor ? fillStyle.toString() : fillStyle;
|
||||||
return this.ctx;
|
return this.ctx;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -17,6 +17,17 @@
|
|||||||
height: 200px;
|
height: 200px;
|
||||||
background: green;
|
background: green;
|
||||||
}
|
}
|
||||||
|
#background-block {
|
||||||
|
width: 200px;
|
||||||
|
height: 200px;
|
||||||
|
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNgaGD4DwAChAGAJVtEDQAAAABJRU5ErkJggg==) red;
|
||||||
|
}
|
||||||
|
#gradient-block {
|
||||||
|
width: 200px;
|
||||||
|
height: 200px;
|
||||||
|
background-image: -webkit-linear-gradient(top, #008000, #008000);
|
||||||
|
background-image: linear-gradient(to bottom, #008000, #008000);
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@ -24,6 +35,8 @@
|
|||||||
<script>mocha.setup('bdd')</script>
|
<script>mocha.setup('bdd')</script>
|
||||||
<div id="block"></div>
|
<div id="block"></div>
|
||||||
<div id="green-block"></div>
|
<div id="green-block"></div>
|
||||||
|
<div id="background-block"></div>
|
||||||
|
<div id="gradient-block"></div>
|
||||||
<script>
|
<script>
|
||||||
describe("options.background", function() {
|
describe("options.background", function() {
|
||||||
it("with hexcolor", function(done) {
|
it("with hexcolor", function(done) {
|
||||||
@ -60,11 +73,47 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('element background', function() {
|
||||||
|
it('with background-color', function(done) {
|
||||||
|
html2canvas(document.querySelector("#green-block")).then(function(canvas) {
|
||||||
|
expect(canvas.width).to.equal(200);
|
||||||
|
expect(canvas.height).to.equal(200);
|
||||||
|
validCanvasPixels(canvas);
|
||||||
|
done();
|
||||||
|
}).catch(function(error) {
|
||||||
|
done(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('with background-image', function(done) {
|
||||||
|
html2canvas(document.querySelector("#background-block")).then(function(canvas) {
|
||||||
|
expect(canvas.width).to.equal(200);
|
||||||
|
expect(canvas.height).to.equal(200);
|
||||||
|
validCanvasPixels(canvas);
|
||||||
|
done();
|
||||||
|
}).catch(function(error) {
|
||||||
|
done(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('with gradient background-image', function(done) {
|
||||||
|
html2canvas(document.querySelector("#gradient-block")).then(function(canvas) {
|
||||||
|
expect(canvas.width).to.equal(200);
|
||||||
|
expect(canvas.height).to.equal(200);
|
||||||
|
validCanvasPixels(canvas);
|
||||||
|
done();
|
||||||
|
}).catch(function(error) {
|
||||||
|
done(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
function validCanvasPixels(canvas) {
|
function validCanvasPixels(canvas) {
|
||||||
var ctx = canvas.getContext("2d");
|
var ctx = canvas.getContext("2d");
|
||||||
var data = ctx.getImageData(0, 0, canvas.width, canvas.height).data;
|
var data = ctx.getImageData(0, 0, canvas.width, canvas.height).data;
|
||||||
for (var i = 0, len = data.length; i < len; i+=4) {
|
for (var i = 0, len = data.length; i < len; i+=4) {
|
||||||
if (data[i] !== 0 || data[i+1] !== 128 || data[i+2] !== 0 || data[i+3] !== 255) {
|
if (data[i] !== 0 || data[i+1] !== 128 || data[i+2] !== 0 || data[i+3] !== 255) {
|
||||||
|
console.log(i,data[i], data[i+1], data[i+2], data[i+3]);
|
||||||
expect().fail("Invalid canvas data");
|
expect().fail("Invalid canvas data");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user