Skip to content

Commit 8ab0604

Browse files
committed
Move toPx into utils and update unitConvert
1 parent bb5f0f9 commit 8ab0604

2 files changed

Lines changed: 15 additions & 10 deletions

File tree

src/utils.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,20 @@ export const cloneNode = function(node, javascriptEnabled) {
5959
return clone;
6060
}
6161

62-
// Convert units using the conversion value 'k' from jsPDF.
62+
// Convert units from px using the conversion value 'k' from jsPDF.
6363
export const unitConvert = function(obj, k) {
64-
var newObj = {};
65-
for (var key in obj) {
66-
newObj[key] = obj[key] * 72 / 96 / k;
64+
if (objType(obj) === 'number') {
65+
return obj * 72 / 96 / k;
66+
} else {
67+
var newObj = {};
68+
for (var key in obj) {
69+
newObj[key] = obj[key] * 72 / 96 / k;
70+
}
71+
return newObj;
6772
}
68-
return newObj;
6973
};
74+
75+
// Convert units to px using the conversion value 'k' from jsPDF.
76+
export const toPx = function toPx(val, k) {
77+
return Math.floor(val * k / 72 * 96);
78+
}

src/worker.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import jsPDF from 'jspdf';
22
import html2canvas from 'html2canvas';
3-
import { objType, createElement, cloneNode, unitConvert } from './utils.js';
3+
import { objType, createElement, cloneNode, toPx } from './utils.js';
44

55
/* ----- CONSTRUCTOR ----- */
66

@@ -351,10 +351,6 @@ Worker.prototype.setMargin = function setMargin(margin) {
351351
}
352352

353353
Worker.prototype.setPageSize = function setPageSize(pageSize) {
354-
function toPx(val, k) {
355-
return Math.floor(val * k / 72 * 96);
356-
}
357-
358354
return this.then(function setPageSize_main() {
359355
// Retrieve page-size based on jsPDF settings, if not explicitly provided.
360356
pageSize = pageSize || jsPDF.getPageSize(this.opt.jsPDF);

0 commit comments

Comments
 (0)