Skip to content

Commit 65a003c

Browse files
committed
Merge pull request #209 from bgribaudo/patch-3
Allow style setting postponement for all drawing methods + direct use of select path-painting operators
2 parents e8a92c1 + d3b7d7b commit 65a003c

File tree

1 file changed

+31
-15
lines changed

1 file changed

+31
-15
lines changed

jspdf.js

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Copyright (c) 2010-2014 James Hall, https://github.com/MrRio/jsPDF
77
* 2010 Aaron Spike, https://github.com/acspike
88
* 2012 Willow Systems Corporation, willow-systems.com
9-
* 2012 Pablo Hess, https://github.com/pablohess
9+
* 2012 Pablo Hess, https://github.gcom/pablohess
1010
* 2012 Florian Jenett, https://github.com/fjenett
1111
* 2013 Warren Weckesser, https://github.com/warrenweckesser
1212
* 2013 Youssef Beddad, https://github.com/lifof
@@ -711,12 +711,21 @@ var jsPDF = (function(global) {
711711
return content.join('\n');
712712
},
713713
getStyle = function(style) {
714-
// see Path-Painting Operators of PDF spec
714+
// see path-painting operators in PDF spec
715715
var op = 'S'; // stroke
716716
if (style === 'F') {
717717
op = 'f'; // fill
718718
} else if (style === 'FD' || style === 'DF') {
719719
op = 'B'; // both
720+
} else if (style === 'f' || style === 'f*' || style === 'B' || style === 'B*') {
721+
/*
722+
Allow direct use of these PDF path-painting operators:
723+
- f fill using nonzero winding number rule
724+
- f* fill using even-odd rule
725+
- B fill then stroke with fill using non-zero winding number rule
726+
- B* fill then stroke with fill using even-odd rule
727+
*/
728+
op = style;
720729
}
721730
return op;
722731
},
@@ -1003,7 +1012,7 @@ var jsPDF = (function(global) {
10031012
* @param {Number} x Coordinate (in units declared at inception of PDF document) against left edge of the page
10041013
* @param {Number} y Coordinate (in units declared at inception of PDF document) against upper edge of the page
10051014
* @param {Number} scale (Defaults to [1.0,1.0]) x,y Scaling factor for all vectors. Elements can be any floating number Sub-one makes drawing smaller. Over-one grows the drawing. Negative flips the direction.
1006-
* @param {String} style One of 'S' (the default), 'F', 'FD', 'DF' or null. 'S' draws just the curve. 'F' fills the region defined by the curves. 'DF' or 'FD' draws the curves and fills the region. A null value postpones setting the style so that a shape may be composed using multiple method calls. The last drawing method call used to define the shape should not have a null style argument.
1015+
* @param {String} style A string specifying the painting style or null. Valid styles include: 'S' [default] - stroke, 'F' - fill, and 'DF' (or 'FD') - fill then stroke. A null value postpones setting the style so that a shape may be composed using multiple method calls. The last drawing method call used to define the shape should not have a null style argument.
10071016
* @param {Boolean} closed If true, the path is closed with a straight line from the end of the last curve to the starting point.
10081017
* @function
10091018
* @returns {jsPDF}
@@ -1069,7 +1078,7 @@ var jsPDF = (function(global) {
10691078
}
10701079

10711080
// stroking / filling / both the path
1072-
if (style) {
1081+
if (style !== null) {
10731082
out(getStyle(style));
10741083
}
10751084
return this;
@@ -1082,7 +1091,7 @@ var jsPDF = (function(global) {
10821091
* @param {Number} y Coordinate (in units declared at inception of PDF document) against upper edge of the page
10831092
* @param {Number} w Width (in units declared at inception of PDF document)
10841093
* @param {Number} h Height (in units declared at inception of PDF document)
1085-
* @param {String} style (Defaults to active fill/stroke style) A string signalling if stroke, fill or both are to be applied.
1094+
* @param {String} style A string specifying the painting style or null. Valid styles include: 'S' [default] - stroke, 'F' - fill, and 'DF' (or 'FD') - fill then stroke. A null value postpones setting the style so that a shape may be composed using multiple method calls. The last drawing method call used to define the shape should not have a null style argument.
10861095
* @function
10871096
* @returns {jsPDF}
10881097
* @methodOf jsPDF#
@@ -1095,9 +1104,13 @@ var jsPDF = (function(global) {
10951104
f2((pageHeight - y) * k),
10961105
f2(w * k),
10971106
f2(-h * k),
1098-
're',
1099-
op
1107+
're'
11001108
].join(' '));
1109+
1110+
if (style !== null) {
1111+
out(getStyle(style));
1112+
}
1113+
11011114
return this;
11021115
};
11031116

@@ -1110,7 +1123,7 @@ var jsPDF = (function(global) {
11101123
* @param {Number} y2 Coordinate (in units declared at inception of PDF document) against upper edge of the page
11111124
* @param {Number} x3 Coordinate (in units declared at inception of PDF document) against left edge of the page
11121125
* @param {Number} y3 Coordinate (in units declared at inception of PDF document) against upper edge of the page
1113-
* @param {String} style (Defaults to active fill/stroke style) A string signalling if stroke, fill or both are to be applied.
1126+
* @param {String} style A string specifying the painting style or null. Valid styles include: 'S' [default] - stroke, 'F' - fill, and 'DF' (or 'FD') - fill then stroke. A null value postpones setting the style so that a shape may be composed using multiple method calls. The last drawing method call used to define the shape should not have a null style argument.
11141127
* @function
11151128
* @returns {jsPDF}
11161129
* @methodOf jsPDF#
@@ -1140,7 +1153,7 @@ var jsPDF = (function(global) {
11401153
* @param {Number} h Height (in units declared at inception of PDF document)
11411154
* @param {Number} rx Radius along x axis (in units declared at inception of PDF document)
11421155
* @param {Number} rx Radius along y axis (in units declared at inception of PDF document)
1143-
* @param {String} style (Defaults to active fill/stroke style) A string signalling if stroke, fill or both are to be applied.
1156+
* @param {String} style A string specifying the painting style or null. Valid styles include: 'S' [default] - stroke, 'F' - fill, and 'DF' (or 'FD') - fill then stroke. A null value postpones setting the style so that a shape may be composed using multiple method calls. The last drawing method call used to define the shape should not have a null style argument.
11441157
* @function
11451158
* @returns {jsPDF}
11461159
* @methodOf jsPDF#
@@ -1173,15 +1186,14 @@ var jsPDF = (function(global) {
11731186
* @param {Number} y Coordinate (in units declared at inception of PDF document) against upper edge of the page
11741187
* @param {Number} rx Radius along x axis (in units declared at inception of PDF document)
11751188
* @param {Number} rx Radius along y axis (in units declared at inception of PDF document)
1176-
* @param {String} style (Defaults to active fill/stroke style) A string signalling if stroke, fill or both are to be applied.
1189+
* @param {String} style A string specifying the painting style or null. Valid styles include: 'S' [default] - stroke, 'F' - fill, and 'DF' (or 'FD') - fill then stroke. A null value postpones setting the style so that a shape may be composed using multiple method calls. The last drawing method call used to define the shape should not have a null style argument.
11771190
* @function
11781191
* @returns {jsPDF}
11791192
* @methodOf jsPDF#
11801193
* @name ellipse
11811194
*/
11821195
API.ellipse = function(x, y, rx, ry, style) {
1183-
var op = getStyle(style),
1184-
lx = 4 / 3 * (Math.SQRT2 - 1) * rx,
1196+
var lx = 4 / 3 * (Math.SQRT2 - 1) * rx,
11851197
ly = 4 / 3 * (Math.SQRT2 - 1) * ry;
11861198

11871199
out([
@@ -1221,9 +1233,13 @@ var jsPDF = (function(global) {
12211233
f2((pageHeight - (y + ly)) * k),
12221234
f2((x + rx) * k),
12231235
f2((pageHeight - y) * k),
1224-
'c',
1225-
op
1236+
'c'
12261237
].join(' '));
1238+
1239+
if (style !== null) {
1240+
out(getStyle(style));
1241+
}
1242+
12271243
return this;
12281244
};
12291245

@@ -1233,7 +1249,7 @@ var jsPDF = (function(global) {
12331249
* @param {Number} x Coordinate (in units declared at inception of PDF document) against left edge of the page
12341250
* @param {Number} y Coordinate (in units declared at inception of PDF document) against upper edge of the page
12351251
* @param {Number} r Radius (in units declared at inception of PDF document)
1236-
* @param {String} style (Defaults to active fill/stroke style) A string signalling if stroke, fill or both are to be applied.
1252+
* @param {String} style A string specifying the painting style or null. Valid styles include: 'S' [default] - stroke, 'F' - fill, and 'DF' (or 'FD') - fill then stroke. A null value postpones setting the style so that a shape may be composed using multiple method calls. The last drawing method call used to define the shape should not have a null style argument.
12371253
* @function
12381254
* @returns {jsPDF}
12391255
* @methodOf jsPDF#

0 commit comments

Comments
 (0)