Skip to content

Commit b792783

Browse files
committed
Merge pull request parallax#171 from diegocr/master
Various fixes and improvements.
2 parents 102103e + 53a89bf commit b792783

3 files changed

Lines changed: 21 additions & 10 deletions

File tree

jspdf.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,16 @@ PubSub implementation
326326
@private
327327
*/
328328
function jsPDF(orientation, unit, format, compressPdf) { /** String orientation, String unit, String format, Boolean compressed */
329+
var options = {};
330+
331+
if (typeof orientation === 'object') {
332+
options = orientation;
333+
334+
orientation = options.orientation;
335+
unit = options.unit;
336+
format = options.format;
337+
compressPdf = options.compress || options.compressPdf;
338+
}
329339

330340
// Default parameter values
331341
if (typeof orientation === 'undefined') {
@@ -338,7 +348,7 @@ PubSub implementation
338348
if (typeof compressPdf === 'undefined' && typeof zpipe === 'undefined') { compressPdf = false; }
339349

340350
var format_as_string = format.toString().toLowerCase(),
341-
version = '0.9.0rc2',
351+
version = '1.0.0-trunk',
342352
content = [],
343353
content_length = 0,
344354
compress = compressPdf,
@@ -389,14 +399,14 @@ PubSub implementation
389399
page = 0,
390400
pages = [],
391401
objectNumber = 2, // 'n' Current object number
392-
outToPages = false, // switches where out() prints. outToPages true = push to pages obj. outToPages false = doc builder content
402+
outToPages = !!options.outToPages, // switches where out() prints. outToPages true = push to pages obj. outToPages false = doc builder content
393403
offsets = [], // List of offsets. Activated and reset by buildDocument(). Pupulated by various calls buildDocument makes.
394404
fonts = {}, // collection of font objects, where key is fontKey - a dynamically created label for a given font.
395405
fontmap = {}, // mapping structure fontName > fontStyle > font key - performance layer. See addFont()
396406
activeFontSize = 16,
397407
activeFontKey, // will be string representing the KEY of the font as combination of fontName + fontStyle
398-
lineWidth = 0.200025, // 2mm
399-
lineHeightProportion = 1.15,
408+
lineWidth = options.lineWidth || 0.200025, // 2mm
409+
lineHeightProportion = options.lineHeight || 1.15,
400410
pageHeight,
401411
pageWidth,
402412
k, // Scale factor

jspdf.plugin.addimage.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,13 @@ var getJpegSize = function(imgData) {
140140

141141
jsPDFAPI.addImage = function(imageData, format, x, y, w, h) {
142142
'use strict'
143-
if(imageData.substr(11,4).indexOf('jpeg') < 0){
144-
imageData = imageData.substr(0,15).replace('jpg','jpeg')+imageData.substr(15);
143+
if(typeof imageData === 'string' && imageData.substr(0,14) === 'data:image/jpg') {
144+
imageData = imageData.replace('data:image/jpg','data:image/jpeg');
145145
}
146146
if (typeof imageData === 'object' && imageData.nodeType === 1) {
147147
var canvas = document.createElement('canvas');
148-
canvas.width = imageData.clientWidth;
149-
canvas.height = imageData.clientHeight;
148+
canvas.width = imageData.clientWidth || imageData.width;
149+
canvas.height = imageData.clientHeight || imageData.height;
150150

151151
var ctx = canvas.getContext('2d');
152152
if (!ctx) {
@@ -230,4 +230,4 @@ jsPDFAPI.addImage = function(imageData, format, x, y, w, h) {
230230

231231
return this
232232
}
233-
})(jsPDF.API)
233+
})(jsPDF.API);

wscript.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ def minifyfiles(context):
2424
(src - 'jspdf.js' + 'libs/Blob.js/BlobBuilder.js').text + \
2525
(src - 'jspdf.js' + 'libs/FileSaver.js/FileSaver.js').text + \
2626
(src - 'jspdf.js' + 'libs/Deflate/deflate.js').text + \
27-
(src - 'jspdf.js' + 'libs/Deflate/adler32cs.js').text
27+
(src - 'jspdf.js' + 'libs/Deflate/adler32cs.js').text + \
28+
(src - 'jspdf.js' + 'libs/async.js').text
2829
# (src - '.js' + '.plugin.from_html.js').text + \
2930
#
3031

0 commit comments

Comments
 (0)