mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
Add options.background option
This commit is contained in:
parent
fc800bff9d
commit
657eb983cf
3
dist/html2canvas.js
vendored
3
dist/html2canvas.js
vendored
@ -2807,6 +2807,9 @@ function CanvasRenderer(width, height) {
|
|||||||
this.canvas.height = height;
|
this.canvas.height = height;
|
||||||
}
|
}
|
||||||
this.ctx = this.canvas.getContext("2d");
|
this.ctx = this.canvas.getContext("2d");
|
||||||
|
if (this.options.background) {
|
||||||
|
this.rectangle(0, 0, width, height, this.options.background);
|
||||||
|
}
|
||||||
this.taintCtx = this.document.createElement("canvas").getContext("2d");
|
this.taintCtx = this.document.createElement("canvas").getContext("2d");
|
||||||
this.ctx.textBaseline = "bottom";
|
this.ctx.textBaseline = "bottom";
|
||||||
this.variables = {};
|
this.variables = {};
|
||||||
|
4
dist/html2canvas.min.js
vendored
4
dist/html2canvas.min.js
vendored
File diff suppressed because one or more lines are too long
@ -6,6 +6,9 @@ function CanvasRenderer(width, height) {
|
|||||||
this.canvas.height = height;
|
this.canvas.height = height;
|
||||||
}
|
}
|
||||||
this.ctx = this.canvas.getContext("2d");
|
this.ctx = this.canvas.getContext("2d");
|
||||||
|
if (this.options.background) {
|
||||||
|
this.rectangle(0, 0, width, height, this.options.background);
|
||||||
|
}
|
||||||
this.taintCtx = this.document.createElement("canvas").getContext("2d");
|
this.taintCtx = this.document.createElement("canvas").getContext("2d");
|
||||||
this.ctx.textBaseline = "bottom";
|
this.ctx.textBaseline = "bottom";
|
||||||
this.variables = {};
|
this.variables = {};
|
||||||
|
83
tests/mocha/background.html
Normal file
83
tests/mocha/background.html
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Mocha Tests</title>
|
||||||
|
<link rel="stylesheet" href="lib/mocha.css" />
|
||||||
|
<script src="../../dist/html2canvas.js"></script>
|
||||||
|
<script src="../assets/jquery-1.6.2.js"></script>
|
||||||
|
<script src="lib/expect.js"></script>
|
||||||
|
<script src="lib/mocha.js"></script>
|
||||||
|
<style>
|
||||||
|
#block {
|
||||||
|
width: 200px;
|
||||||
|
height: 200px;
|
||||||
|
}
|
||||||
|
#green-block {
|
||||||
|
width: 200px;
|
||||||
|
height: 200px;
|
||||||
|
background: green;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="mocha"></div>
|
||||||
|
<script>mocha.setup('bdd')</script>
|
||||||
|
<div id="block"></div>
|
||||||
|
<div id="green-block"></div>
|
||||||
|
<script>
|
||||||
|
describe("options.background", function() {
|
||||||
|
it("with hexcolor", function(done) {
|
||||||
|
html2canvas(document.querySelector("#block"), {background: '#008000'}).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 named color", function(done) {
|
||||||
|
html2canvas(document.querySelector("#block"), {background: 'green'}).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 element background", function(done) {
|
||||||
|
html2canvas(document.querySelector("#green-block"), {background: 'red'}).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) {
|
||||||
|
var ctx = canvas.getContext("2d");
|
||||||
|
var data = ctx.getImageData(0, 0, canvas.width, canvas.height).data;
|
||||||
|
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) {
|
||||||
|
expect().fail("Invalid canvas data");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mocha.checkLeaks();
|
||||||
|
mocha.globals(['jQuery']);
|
||||||
|
if (window.mochaPhantomJS) {
|
||||||
|
mochaPhantomJS.run();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
mocha.run();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue
Block a user