File tree Expand file tree Collapse file tree 2 files changed +62
-1
lines changed Expand file tree Collapse file tree 2 files changed +62
-1
lines changed Original file line number Diff line number Diff line change @@ -2764,6 +2764,39 @@ var jsPDF = (function (global) {
2764
2764
return this ;
2765
2765
} ;
2766
2766
2767
+ /**
2768
+ * Sets the dash pattern for upcoming lines.
2769
+ *
2770
+ * To reset the settings simply call the method without any parameters.
2771
+ * @param {array } dashArray The pattern of the line, expects numbers.
2772
+ * @param {number } dashPhase The phase at which the dash pattern starts.
2773
+ * @function
2774
+ * @instance
2775
+ * @returns {jsPDF }
2776
+ * @memberOf jsPDF
2777
+ * @name setLineDash
2778
+ */
2779
+ var setLineDash = API . __private__ . setLineDash = jsPDF . API . setLineDash = function ( dashArray , dashPhase ) {
2780
+ dashArray = dashArray || [ ] ;
2781
+ dashPhase = dashPhase || 0 ;
2782
+
2783
+ if ( isNaN ( dashPhase ) || ! Array . isArray ( dashArray ) ) {
2784
+ throw new Error ( 'Invalid arguments passed to jsPDF.setLineDash' ) ;
2785
+ }
2786
+
2787
+ dashArray = dashArray . map ( function ( x ) { return ( x * k ) . toFixed ( 3 ) } ) . join ( ' ' ) ;
2788
+ dashPhase = parseFloat ( ( dashPhase * k ) . toFixed ( 3 ) ) ;
2789
+
2790
+ out ( '[' + dashArray + '] ' + dashPhase + ' d' ) ;
2791
+ return this ;
2792
+ } ;
2793
+
2794
+ var lineHeightFactor ;
2795
+
2796
+ var getLineHeight = API . __private__ . getLineHeight = API . getLineHeight = function ( ) {
2797
+ return activeFontSize * lineHeightFactor ;
2798
+ } ;
2799
+
2767
2800
var lineHeightFactor ;
2768
2801
2769
2802
var getLineHeight = API . __private__ . getLineHeight = API . getLineHeight = function ( ) {
Original file line number Diff line number Diff line change @@ -429,7 +429,35 @@ describe('jsPDF unit tests', () => {
429
429
430
430
expect ( writeArray ) . toEqual ( [ '1687.41 w' ] ) ;
431
431
} ) ;
432
-
432
+
433
+ it ( 'jsPDF private function setLineDash' , ( ) => {
434
+ const doc = jsPDF ( )
435
+ var writeArray = [ ] ;
436
+ doc . __private__ . setCustomOutputDestination ( writeArray ) ;
437
+
438
+ expect ( function ( ) { doc . __private__ . setLineDash ( '' ) ; } ) . not . toThrow ( new Error ( 'Invalid arguments passed to jsPDF.setLineDash' ) ) ;
439
+
440
+ var writeArray = [ ] ;
441
+ doc . __private__ . setCustomOutputDestination ( writeArray ) ;
442
+ expect ( function ( ) { doc . __private__ . setLineDash ( ) ; } ) . not . toThrow ( new Error ( 'Invalid arguments passed to jsPDF.setLineDash' ) ) ;
443
+
444
+ expect ( writeArray ) . toEqual ( [ '[] 0 d' ] ) ;
445
+
446
+ var writeArray = [ ] ;
447
+ doc . __private__ . setCustomOutputDestination ( writeArray ) ;
448
+ expect ( function ( ) { doc . __private__ . setLineDash ( '1 1' , '1' ) ; } ) . toThrow ( new Error ( 'Invalid arguments passed to jsPDF.setLineDash' ) ) ;
449
+
450
+ var writeArray = [ ] ;
451
+ doc . __private__ . setCustomOutputDestination ( writeArray ) ;
452
+ expect ( function ( ) { doc . __private__ . setLineDash ( '1 1' , 1 ) ; } ) . toThrow ( new Error ( 'Invalid arguments passed to jsPDF.setLineDash' ) ) ;
453
+
454
+ var writeArray = [ ] ;
455
+ doc . __private__ . setCustomOutputDestination ( writeArray ) ;
456
+ expect ( function ( ) { doc . __private__ . setLineDash ( [ 1 , 1 ] , 1 ) } ) . not . toThrow ( new Error ( 'Invalid arguments passed to jsPDF.setLineDash' ) ) ;
457
+
458
+ expect ( writeArray ) . toEqual ( [ '[2.835 2.835] 2.835 d' ] ) ;
459
+ } ) ;
460
+
433
461
it ( 'jsPDF private function getLineHeight' , ( ) => {
434
462
const doc = jsPDF ( )
435
463
You can’t perform that action at this time.
0 commit comments