Skip to content

Commit

Permalink
fix: Using canvas as a direct source (#701)
Browse files Browse the repository at this point in the history
  • Loading branch information
eKoopmans authored Jun 30, 2024
1 parent 4c55448 commit 5734d5e
Show file tree
Hide file tree
Showing 11 changed files with 8 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Worker.prototype.from = function from(src, type) {
function getType(src) {
switch (objType(src)) {
case 'string': return 'string';
case 'element': return src.nodeName.toLowerCase === 'canvas' ? 'canvas' : 'element';
case 'element': return src.nodeName.toLowerCase && src.nodeName.toLowerCase() === 'canvas' ? 'canvas' : 'element';
default: return 'unknown';
}
}
Expand Down Expand Up @@ -168,7 +168,8 @@ Worker.prototype.toImg = function toImg() {
Worker.prototype.toPdf = function toPdf() {
// Set up function prerequisites.
var prereqs = [
function checkCanvas() { return this.prop.canvas || this.toCanvas(); }
function checkCanvas() { return this.prop.canvas || this.toCanvas(); },
function checkPageSize() { return this.prop.pageSize || this.setPageSize(); }
];

// Fulfill prereqs then create the image.
Expand Down
Binary file modified test/reference/snapshot/all-tags.pdf
Binary file not shown.
Binary file added test/reference/snapshot/all-tags_canvas.pdf
Binary file not shown.
Binary file modified test/reference/snapshot/css-selectors.pdf
Binary file not shown.
Binary file modified test/reference/snapshot/lorem-ipsum.pdf
Binary file not shown.
Binary file modified test/reference/snapshot/lorem-ipsum_margin.pdf
Binary file not shown.
Binary file modified test/reference/snapshot/pagebreaks_avoid-all.pdf
Binary file not shown.
Binary file modified test/reference/snapshot/pagebreaks_css.pdf
Binary file not shown.
Binary file modified test/reference/snapshot/pagebreaks_legacy.pdf
Binary file not shown.
Binary file modified test/reference/snapshot/pagebreaks_specify.pdf
Binary file not shown.
6 changes: 5 additions & 1 deletion test/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ describe('snapshot', () => {
runner: window => defaultCondition(window, { margin: 1, jsPDF: { unit: 'in' } }),
name: file => `${file}_margin.pdf`,
},
selectCanvas: {
runner: window => defaultCondition(window, {}, window.document.getElementById('canvas')),
name: file => `${file}_canvas.pdf`,
},
selectMainId: {
runner: window => defaultCondition(window, {}, window.document.getElementById('main')),
name: file => `${file}.pdf`,
Expand All @@ -56,7 +60,7 @@ describe('snapshot', () => {
const filesToTest = {
'blank': [ 'default' ],
'lorem-ipsum': [ 'default', 'legacy', 'margin' ],
'all-tags': [ 'default' ],
'all-tags': [ 'default', 'selectCanvas' ],
'css-selectors': [ 'selectMainId' ],
'pagebreaks': [ 'pagebreakLegacy', 'pagebreakCss', 'pagebreakAvoidAll', 'pagebreakSpecify' ],
};
Expand Down

0 comments on commit 5734d5e

Please sign in to comment.