@@ -522,15 +522,18 @@ var CCLScripting = function(workerUrl){
522522 return elem ;
523523 } ;
524524
525+ var globalDefs = __ ( 'defs' ) ;
525526 var defaultEffects = __ ( "defs" ) ;
526527 var defaultGroup = __ ( "g" , {
527528 } ) ;
528529 var defaultContainer = __ ( "g" , {
529530 "transform" :"translate(" + this . _x + "," + this . _y + ")" ,
530531 "opacity" :this . _alpha ,
531532 } ) ;
533+
532534 defaultContainer . appendChild ( defaultGroup ) ;
533535 var defaultGroupWithEffects = defaultContainer ;
536+ this . DOM . appendChild ( globalDefs ) ;
534537 this . DOM . appendChild ( defaultEffects ) ;
535538 this . DOM . appendChild ( defaultGroupWithEffects ) ;
536539 /** PROPS **/
@@ -549,6 +552,13 @@ var CCLScripting = function(workerUrl){
549552 this . __defineSetter__ ( "alpha" , function ( f ) {
550553 this . setAlpha ( f ) ;
551554 } ) ;
555+ this . __defineSetter__ ( "blendMode" , function ( f ) {
556+ this . DOM . style . backgroundBlendMode = f ;
557+ this . DOM . style . mixBlendMode = f ;
558+ } ) ;
559+ this . __defineGetter__ ( "blendMode" , function ( f ) {
560+ return '' ;
561+ } ) ;
552562 this . __defineGetter__ ( "x" , function ( f ) {
553563 return this . _x ;
554564 } ) ;
@@ -772,6 +782,31 @@ var CCLScripting = function(workerUrl){
772782 this . fill . alpha = params [ 1 ] ;
773783 }
774784 } ;
785+ this . beginGradientFill = function ( params ) {
786+ if ( params . length === 0 ) {
787+ return ;
788+ }
789+ var gradId = 'gradient-' + params [ 0 ] + '-' + globalDefs . childNodes . length ;
790+ var grad ;
791+ if ( params [ 0 ] === 'linear' ) {
792+ grad = __ ( 'linearGradient' , { 'id' : gradId , 'spreadMethod' : params [ 5 ] } ) ;
793+ } else {
794+ grad = __ ( 'radialGradient' , { 'id' : gradId , 'spreadMethod' : params [ 5 ] } ) ;
795+ }
796+ // Figure out all the stops
797+ var colors = params [ 1 ] ;
798+ var alphas = params [ 2 ] ;
799+ var ratios = params [ 3 ] ;
800+ for ( var i = 0 ; i < ratios . length ; i ++ ) {
801+ grad . appendChild ( __ ( 'stop' , {
802+ 'offset' : ratios [ i ] / 255 ,
803+ 'stop-color' : toRGB ( colors [ i ] ) ,
804+ 'stop-opacity' : alphas [ i ]
805+ } ) ) ;
806+ }
807+ globalDefs . appendChild ( grad ) ;
808+ this . fill . fill = 'url(#' + gradId + ')' ;
809+ } ;
775810 this . endFill = function ( params ) {
776811 this . fill . fill = "none" ;
777812 } ;
@@ -807,7 +842,7 @@ var CCLScripting = function(workerUrl){
807842 } ) ;
808843 applyFill ( r , this ) ;
809844 applyStroke ( r , this ) ;
810- this . DOM . appendChild ( r ) ;
845+ defaultGroup . appendChild ( r ) ;
811846 } ;
812847 this . drawCircle = function ( params ) {
813848 var c = __ ( "circle" , {
@@ -889,10 +924,10 @@ var CCLScripting = function(workerUrl){
889924 var filter = filters [ i ] ;
890925 var dFilter = __ ( "filter" , {
891926 "id" :"fe" + filter . type + i ,
892- "x" :"-100 %" ,
893- "y" :"-100 %" ,
894- "width" :"400 %" ,
895- "height" :"400 %"
927+ "x" :"-50 %" ,
928+ "y" :"-50 %" ,
929+ "width" :"200 %" ,
930+ "height" :"200 %"
896931 } ) ;
897932 switch ( filter . type ) {
898933 default :break ;
@@ -992,6 +1027,13 @@ var CCLScripting = function(workerUrl){
9921027 this . __defineSetter__ ( "y" , function ( f ) {
9931028 this . setY ( f ) ;
9941029 } ) ;
1030+ this . __defineSetter__ ( "blendMode" , function ( f ) {
1031+ this . DOM . style . backgroundBlendMode = f ;
1032+ this . DOM . style . mixBlendMode = f ;
1033+ } ) ;
1034+ this . __defineGetter__ ( "blendMode" , function ( f ) {
1035+ return '' ;
1036+ } ) ;
9951037 this . __defineGetter__ ( "x" , function ( f ) {
9961038 return this . DOM . offsetLeft ;
9971039 } ) ;
@@ -1072,10 +1114,10 @@ var CCLScripting = function(workerUrl){
10721114 return ;
10731115 if ( child . DOM ) {
10741116 if ( child . getClass ( ) === "Shape" ) {
1075- child . DOM . style . left = - this . x + "px" ;
1076- child . DOM . style . top = - this . y + "px" ;
1077- child . setX ( this . x ) ;
1078- child . setY ( this . y ) ;
1117+ var tX = ( stage . offsetWidth / 2 ) , tY = ( stage . offsetHeight / 2 ) ;
1118+ child . offset ( tX , tY ) ;
1119+ child . DOM . style . left = - tX + "px" ;
1120+ child . DOM . style . top = - tY + "px" ;
10791121 }
10801122 this . DOM . appendChild ( child . DOM ) ;
10811123 } else {
0 commit comments