1515 * Paper.js DOM to a SVG DOM.
1616 */
1717new function ( ) {
18- var formatter = Formatter . instance ;
18+ var formatter ;
1919
2020 function setAttributes ( node , attrs ) {
2121 for ( var key in attrs ) {
@@ -466,7 +466,7 @@ new function() {
466466 definitions . svgs [ type + '-' + item . _id ] = node ;
467467 }
468468
469- function exportDefinitions ( node , asString ) {
469+ function exportDefinitions ( node , options ) {
470470 if ( ! definitions )
471471 return node ;
472472 // We can only use svg nodes as defintion containers. Have the loop
@@ -489,7 +489,9 @@ new function() {
489489 }
490490 // Clear definitions at the end of export
491491 definitions = null ;
492- return asString ? new XMLSerializer ( ) . serializeToString ( svg ) : svg ;
492+ return options && options . asString
493+ ? new XMLSerializer ( ) . serializeToString ( svg )
494+ : svg ;
493495 }
494496
495497 function exportSVG ( item ) {
@@ -500,14 +502,22 @@ new function() {
500502 return node && applyStyle ( item , node ) ;
501503 }
502504
505+ function setOptions ( options ) {
506+ formatter = options && options . precision
507+ ? new Formatter ( options . precision )
508+ : Formatter . instance ;
509+ }
510+
503511 Item . inject ( {
504- exportSVG : function ( asString ) {
505- return exportDefinitions ( exportSVG ( this ) , asString ) ;
512+ exportSVG : function ( options ) {
513+ setOptions ( options ) ;
514+ return exportDefinitions ( exportSVG ( this ) , options ) ;
506515 }
507516 } ) ;
508517
509518 Project . inject ( {
510- exportSVG : function ( asString ) {
519+ exportSVG : function ( options ) {
520+ setOptions ( options ) ;
511521 var layers = this . layers ,
512522 size = this . view . getSize ( ) ,
513523 node = createElement ( 'svg' , {
@@ -521,7 +531,7 @@ new function() {
521531 } ) ;
522532 for ( var i = 0 , l = layers . length ; i < l ; i ++ )
523533 node . appendChild ( exportSVG ( layers [ i ] ) ) ;
524- return exportDefinitions ( node , asString ) ;
534+ return exportDefinitions ( node , options ) ;
525535 }
526536 } ) ;
527537} ;
0 commit comments