Skip to content

Commit ff6e93b

Browse files
authored
Merge branch 'master' into feature/custom-fonts
2 parents 20b0e80 + 94e0668 commit ff6e93b

File tree

14 files changed

+154
-110
lines changed

14 files changed

+154
-110
lines changed

docs/jspdf.js.html

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,18 +1153,17 @@ <h1 class="page-title">jspdf.js</h1>
11531153
return fonts[getFont.apply(API, arguments)];
11541154
},
11551155
'getTextColor': function() {
1156-
var colorEncoded = textColor.split(' ')
1157-
if (colorEncoded.length == 2 && colorEncoded[-1] == 'g') {
1158-
return '#000000'
1159-
} else {
1160-
var x;
1161-
var colorAsHex = '#'
1162-
for (var i = 0; i < 3; i++) {
1163-
x = Math.floor(parseFloat(colorEncoded[i]) * 255).toString(16);
1164-
colorAsHex += (x.length == 1) ? "0"+x : x;
1165-
}
1156+
var colorEncoded = textColor.split(' ');
1157+
if (colorEncoded.length === 2 && colorEncoded[1] === 'g') {
1158+
// convert grayscale value to rgb so that it can be converted to hex for consistency
1159+
var floatVal = parseFloat(colorEncoded[0]);
1160+
colorEncoded = [floatVal, floatVal, floatVal, 'r'];
1161+
}
1162+
var colorAsHex = '#';
1163+
for (var i = 0; i < 3; i++) {
1164+
colorAsHex += ('0' + Math.floor(parseFloat(colorEncoded[i]) * 255).toString(16)).slice(-2);
11661165
}
1167-
return colorAsHex
1166+
return colorAsHex;
11681167
},
11691168
'getFontSize': function() {
11701169
return activeFontSize;

jspdf.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,8 @@ var jsPDF = (function (global) {
410410
padd2 = function (number) {
411411
return ('0' + parseInt(number)).slice(-2);
412412
},
413-
out = function (string) {
413+
out = function(string) {
414+
string = (typeof string === "string") ? string : string.toString();
414415
if (outToPages) {
415416
/* set by beginPage */
416417
pages[currentPage].push(string);
@@ -1172,7 +1173,7 @@ var jsPDF = (function (global) {
11721173
case undefined:
11731174
return buildDocument();
11741175
case 'save':
1175-
if (navigator.getUserMedia) {
1176+
if (typeof navigator === "object" && navigator.getUserMedia) {
11761177
if (global.URL === undefined || global.URL.createObjectURL ===
11771178
undefined) {
11781179
return API.output('dataurlnewwindow');
@@ -1284,18 +1285,17 @@ var jsPDF = (function (global) {
12841285
return activeCharSpace;
12851286
},
12861287
'getTextColor': function getTextColor() {
1287-
var colorEncoded = textColor.split(' ')
1288-
if (colorEncoded.length == 2 && colorEncoded[-1] == 'g') {
1289-
return '#000000'
1290-
} else {
1291-
var x;
1292-
var colorAsHex = '#'
1293-
for (var i = 0; i < 3; i++) {
1294-
x = Math.floor(parseFloat(colorEncoded[i]) * 255).toString(16);
1295-
colorAsHex += (x.length == 1) ? "0"+x : x;
1296-
}
1288+
var colorEncoded = textColor.split(' ');
1289+
if (colorEncoded.length === 2 && colorEncoded[1] === 'g') {
1290+
// convert grayscale value to rgb so that it can be converted to hex for consistency
1291+
var floatVal = parseFloat(colorEncoded[0]);
1292+
colorEncoded = [floatVal, floatVal, floatVal, 'r'];
1293+
}
1294+
var colorAsHex = '#';
1295+
for (var i = 0; i < 3; i++) {
1296+
colorAsHex += ('0' + Math.floor(parseFloat(colorEncoded[i]) * 255).toString(16)).slice(-2);
12971297
}
1298-
return colorAsHex
1298+
return colorAsHex;
12991299
},
13001300
'getLineHeight': function() {
13011301
return activeFontSize * lineHeightProportion;
@@ -2874,9 +2874,12 @@ var jsPDF = (function (global) {
28742874
return jsPDF;
28752875
});
28762876
} else if (typeof module !== 'undefined' && module.exports) {
2877-
module.exports = jsPDF;
2877+
module.exports.jsPDF = jsPDF;
28782878
} else {
28792879
global.jsPDF = jsPDF;
28802880
}
28812881
return jsPDF;
2882-
})(typeof self !== "undefined" && self || typeof global !== "undefined" && global || typeof window !== "undefined" && window || (Function ("return this"))());
2882+
}(typeof self !== "undefined" && self || typeof window !== "undefined" && window || typeof global !== "undefined" && global || Function('return typeof this === "object" && this.content')() || Function('return this')()));
2883+
// `self` is undefined in Firefox for Android content script context
2884+
// while `this` is nsIContentFrameMessageManager
2885+
// with an attribute `content` that corresponds to the window

libs/deflate.js renamed to libs/Deflater.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/*
2-
Deflate.js - https://github.com/gildas-lormeau/zip.js
32
Copyright (c) 2013 Gildas Lormeau. All rights reserved.
43
54
Redistribution and use in source and binary forms, with or without
@@ -34,7 +33,8 @@
3433
* and contributors of zlib.
3534
*/
3635

37-
var Deflater = (function(obj) {
36+
(function(global) {
37+
"use strict";
3838

3939
// Global
4040

@@ -1989,13 +1989,13 @@ var Deflater = (function(obj) {
19891989

19901990
// Deflater
19911991

1992-
return function Deflater(level) {
1992+
function Deflater(options) {
19931993
var that = this;
19941994
var z = new ZStream();
19951995
var bufsize = 512;
19961996
var flush = Z_NO_FLUSH;
19971997
var buf = new Uint8Array(bufsize);
1998-
1998+
var level = options ? options.level : Z_DEFAULT_COMPRESSION;
19991999
if (typeof level == "undefined")
20002000
level = Z_DEFAULT_COMPRESSION;
20012001
z.deflateInit(level);
@@ -2013,7 +2013,7 @@ var Deflater = (function(obj) {
20132013
z.avail_out = bufsize;
20142014
err = z.deflate(flush);
20152015
if (err != Z_OK)
2016-
throw "deflating: " + z.msg;
2016+
throw new Error("deflating: " + z.msg);
20172017
if (z.next_out_index)
20182018
if (z.next_out_index == bufsize)
20192019
buffers.push(new Uint8Array(buf));
@@ -2039,7 +2039,7 @@ var Deflater = (function(obj) {
20392039
z.avail_out = bufsize;
20402040
err = z.deflate(Z_FINISH);
20412041
if (err != Z_STREAM_END && err != Z_OK)
2042-
throw "deflating: " + z.msg;
2042+
throw new Error("deflating: " + z.msg);
20432043
if (bufsize - z.avail_out > 0)
20442044
buffers.push(new Uint8Array(buf.subarray(0, z.next_out_index)));
20452045
bufferSize += z.next_out_index;
@@ -2052,5 +2052,12 @@ var Deflater = (function(obj) {
20522052
});
20532053
return array;
20542054
};
2055-
};
2056-
})(this);
2055+
}
2056+
2057+
// 'zip' may not be defined in z-worker and some tests
2058+
var env = global.zip || global;
2059+
env.Deflater = env._jzlib_Deflater = Deflater;
2060+
}(typeof self !== "undefined" && self || typeof window !== "undefined" && window || typeof global !== "undefined" && global || Function('return typeof this === "object" && this.content')() || Function('return this')()));
2061+
// `self` is undefined in Firefox for Android content script context
2062+
// while `this` is nsIContentFrameMessageManager
2063+
// with an attribute `content` that corresponds to the window

libs/png_support/png.js

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libs/polyfill.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,24 @@
55
*/
66

77
(function (global) {
8+
9+
if (typeof global.console !== "object") {
10+
// Console-polyfill. MIT license.
11+
// https://github.com/paulmillr/console-polyfill
12+
// Make it safe to do console.log() always.
13+
global.console = {};
14+
15+
var con = global.console;
16+
var prop, method;
17+
var dummy = function() {};
18+
var properties = ['memory'];
19+
var methods = ('assert,clear,count,debug,dir,dirxml,error,exception,group,' +
20+
'groupCollapsed,groupEnd,info,log,markTimeline,profile,profiles,profileEnd,' +
21+
'show,table,time,timeEnd,timeline,timelineEnd,timeStamp,trace,warn').split(',');
22+
while (prop = properties.pop()) if (!con[prop]) con[prop] = {};
23+
while (method = methods.pop()) if (!con[method]) con[method] = dummy;
24+
}
25+
826
var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
927

1028
if (typeof global.btoa === 'undefined') {
@@ -248,4 +266,7 @@
248266
};
249267
}
250268

251-
})(typeof self !== "undefined" && self || typeof window !== "undefined" && window || this);
269+
}(typeof self !== "undefined" && self || typeof window !== "undefined" && window || typeof global !== "undefined" && global || Function('return typeof this === "object" && this.content')() || Function('return this')()));
270+
// `self` is undefined in Firefox for Android content script context
271+
// while `this` is nsIContentFrameMessageManager
272+
// with an attribute `content` that corresponds to the window

main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import './plugins/vfs';
2828
import './node_modules/cf-blob.js/Blob.js';
2929
import './node_modules/file-saver/FileSaver.js';
3030
import './node_modules/adler32cs/adler32cs.js';
31+
import './libs/Deflater.js';
3132
import './libs/css_colors.js';
32-
import './libs/deflate.js';
3333
import './libs/html2canvas/dist/html2canvas.js';
3434
import './libs/ttffont.js';
3535
import './libs/png_support/png.js';

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,25 @@
2626
"babel-preset-es2015": "6.24.1",
2727
"babel-preset-es2015-rollup": "3.0.0",
2828
"codeclimate-test-reporter": "^0.5.0",
29-
"diff": "3.3.1",
29+
"diff": "3.4.0",
3030
"docdash": "0.4.0",
31-
"jasmine": "2.8.0",
31+
"jasmine": "3.0.0",
3232
"js-yaml": "3.10.0",
3333
"jsdoc": "3.5.5",
3434
"karma": "2.0.0",
3535
"karma-babel-preprocessor": "6.0.1",
3636
"karma-chrome-launcher": "2.2.0",
3737
"karma-coverage": "1.1.1",
38-
"karma-firefox-launcher": "1.0.1",
39-
"karma-jasmine": "1.1.0",
38+
"karma-firefox-launcher": "1.1.0",
39+
"karma-jasmine": "1.1.1",
4040
"karma-mocha-reporter": "^2.2.0",
4141
"karma-sauce-launcher": "1.2.0",
42-
"local-web-server": "2.3.0",
42+
"local-web-server": "2.4.0",
4343
"markdown": "^0.5.0",
44-
"pdfjs-dist": "2.0.91",
45-
"rollup": "0.50.0",
44+
"pdfjs-dist": "2.0.385",
45+
"rollup": "0.56.1",
4646
"rollup-plugin-babel": "3.0.3",
47-
"uglify-js": "3.3.5"
47+
"uglify-js": "3.3.11"
4848
},
4949
"scripts": {
5050
"start": "ws",

0 commit comments

Comments
 (0)