From b1ea39db46b6e9699c6053c229721213d63474fe Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Tue, 8 Apr 2014 11:01:46 +0000 Subject: [PATCH] Provide values for px, pc, em, ex and utilize switch for divisor determination in jsPDF in order to utilize the user's current base unit type in PDF exports. Accurate conversion formulas? git-svn-id: http://svg-edit.googlecode.com/svn/trunk@2797 eee81c28-f429-11dd-99c0-75d572ba1ddd --- editor/jspdf/jspdf.js | 37 +++++++++++++++++++++++++++---------- editor/svg-editor.js | 3 ++- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/editor/jspdf/jspdf.js b/editor/jspdf/jspdf.js index de45a91c..e50eb857 100644 --- a/editor/jspdf/jspdf.js +++ b/editor/jspdf/jspdf.js @@ -990,16 +990,33 @@ PubSub implementation // @TODO: Add different output options }; - if (unit === 'pt') { - k = 1; - } else if (unit === 'mm') { - k = 72 / 25.4; - } else if (unit === 'cm') { - k = 72 / 2.54; - } else if (unit === 'in') { - k = 72; - } else { - throw ('Invalid unit: ' + unit); + switch (unit) { + case 'pt': + k = 1; + break; + case 'mm': + k = 72 / 25.4; + break; + case 'cm': + k = 72 / 2.54; + break; + case 'in': + k = 72; + break; + case 'px': + k = 96 / 72; + break; + case 'pc': + k = 12; + break; + case 'em': + k = 12; + break; + case 'ex': + k = 6; + break; + default: + throw ('Invalid unit: ' + unit); } // Dimensions are stored as user units and converted to points on output diff --git a/editor/svg-editor.js b/editor/svg-editor.js index a320cf05..8d5ff181 100644 --- a/editor/svg-editor.js +++ b/editor/svg-editor.js @@ -1111,7 +1111,8 @@ TODOS if (type === 'PDF') { var res = svgCanvas.getResolution(); var orientation = res.w > res.h ? 'landscape' : 'portrait'; - var doc = new jsPDF(orientation, 'pt', [res.w, res.h]); // Todo: Give options to use predefined jsPDF formats like "a4", etc. from pull-down (with option to keep customizable) + var units = curConfig.baseUnit; + var doc = new jsPDF(orientation, units, [res.w, res.h]); // Todo: Give options to use predefined jsPDF formats like "a4", etc. from pull-down (with option to keep customizable) var docTitle = svgCanvas.getDocumentTitle(); doc.setProperties({ title: docTitle/*,