summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Cecchetti <marco.cecchetti@collabora.com>2016-01-13 16:44:51 +0100
committerMarco Cecchetti <marco.cecchetti@collabora.com>2016-01-13 17:39:54 +0100
commit86a1be7c4742828c706842eb87cc2091edaafb79 (patch)
treed39299a53d5d95ebb19efa20d998b1026845b324
parent800040426b62169524e532f0e11e147c93e6850e (diff)
svg export: added support for anim:formula attribute
Added support for formula attribute used from some effect such as spiral in. Better support for parsing value list. Change-Id: Ibf25482eba359acb279d9b212d7a829b3dc668b6
-rw-r--r--filter/source/svg/presentation_engine.js68
1 files changed, 60 insertions, 8 deletions
diff --git a/filter/source/svg/presentation_engine.js b/filter/source/svg/presentation_engine.js
index 757f4e149dbb..46946a01b38c 100644
--- a/filter/source/svg/presentation_engine.js
+++ b/filter/source/svg/presentation_engine.js
@@ -5986,6 +5986,7 @@ function AnimationBaseNode3( aAnimElem, aParentNode, aNodeContext )
this.aByValue = null;
this.aKeyTimes = null;
this.aValues = null;
+ this.aFormula= null;
}
extend( AnimationBaseNode3, AnimationBaseNode2 );
@@ -6036,6 +6037,9 @@ AnimationBaseNode3.prototype.parseElement = function()
this.aValues = [];
}
+ // formula attribute
+ this.aFormula = aAnimElem.getAttributeNS( NSS['anim'], 'formula' );
+
return bRet;
};
@@ -6069,6 +6073,11 @@ AnimationBaseNode3.prototype.getValues = function()
return this.aValues;
};
+AnimationBaseNode3.prototype.getFormula = function()
+{
+ return this.aFormula;
+};
+
AnimationBaseNode3.prototype.info = function( bVerbose )
{
var sInfo = AnimationBaseNode3.superclass.info.call( this, bVerbose );
@@ -6097,6 +6106,10 @@ AnimationBaseNode3.prototype.info = function( bVerbose )
// values
if( this.getKeyTimes().length )
sInfo += '; values: ' + this.getValues().join( ',' );
+
+ // formula
+ if( this.getFormula() )
+ sInfo += '; formula: ' + this.getFormula();
}
return sInfo;
@@ -10977,6 +10990,7 @@ function ActivityParamSet()
this.nDecelerationFraction = 0.0;
this.nSlideWidth = undefined;
this.nSlideHeight = undefined;
+ this.aFormula = null;
this.aDiscreteTimes = [];
}
@@ -11642,6 +11656,7 @@ function FromToByActivityTemplate( BaseType ) // template parameter
this.bDynamicStartValue = false;
this.nIteration = 0;
this.bCumulative = bAccumulate;
+ this.aFormula = aActivityParamSet.aFormula;
//this.initAnimatedElement();
@@ -11651,7 +11666,10 @@ function FromToByActivityTemplate( BaseType ) // template parameter
FromToByActivity.prototype.initAnimatedElement = function()
{
if( this.aAnimation && this.aFrom )
- this.aAnimation.perform( this.aFrom );
+ {
+ var aValue = this.aFormula ? this.aFormula( this.aFrom ) : this.aFrom;
+ this.aAnimation.perform(aValue);
+ }
};
FromToByActivity.prototype.startAnimation = function()
@@ -11790,6 +11808,7 @@ function FromToByActivityTemplate( BaseType ) // template parameter
aValue = this.add( this.scale( nRepeatCount, this.aEndValue ), aValue );
}
+ aValue = this.aFormula ? this.aFormula( aValue ) : aValue;
this.aAnimation.perform( aValue );
if( this.bDynamicStartValue )
@@ -11803,10 +11822,9 @@ function FromToByActivityTemplate( BaseType ) // template parameter
{
if( this.aAnimation )
{
- if( this.isAutoReverse() )
- this.aAnimation.perform( this.aStartValue );
- else
- this.aAnimation.perform( this.aEndValue );
+ var aValue = this.isAutoReverse() ? this.aStartValue : this.aEndValue;
+ aValue = this.aFormula ? this.aFormula( aValue ) : aValue;
+ this.aAnimation.perform( aValue );
}
};
@@ -11848,6 +11866,7 @@ function ValueListActivityTemplate( BaseType ) // template parameter
this.scale = aOperatorSet.scale;
this.bCumulative = bAccumulate;
this.aLastValue = this.aValueList[ this.aValueList.length - 1 ];
+ this.aFormula = aActivityParamSet.aFormula;
//this.initAnimatedElement();
}
@@ -11867,7 +11886,11 @@ function ValueListActivityTemplate( BaseType ) // template parameter
ValueListActivity.prototype.initAnimatedElement = function()
{
if( this.aAnimation )
- this.aAnimation.perform( this.aValueList[0] );
+ {
+ var aValue = this.aValueList[0];
+ aValue = this.aFormula ? this.aFormula( aValue ) : aValue;
+ this.aAnimation.perform(aValue);
+ }
};
ValueListActivity.prototype.startAnimation = function()
@@ -11912,6 +11935,8 @@ function ValueListActivityTemplate( BaseType ) // template parameter
aValue = this.add( aValue, this.scale( nRepeatCount, this.aLastValue ) );
//aValue = aValue + nRepeatCount * this.aLastValue;
}
+
+ aValue = this.aFormula ? this.aFormula( aValue ) : aValue;
this.aAnimation.perform( aValue );
};
@@ -11919,7 +11944,8 @@ function ValueListActivityTemplate( BaseType ) // template parameter
{
if( this.aAnimation )
{
- this.aAnimation.perform( this.aLastValue );
+ var aValue = this.aFormula ? this.aFormula( this.aLastValue ) : this.aLastValue;
+ this.aAnimation.perform( aValue );
}
};
@@ -11967,7 +11993,27 @@ function createActivity( aActivityParamSet, aAnimationNode, aAnimation, aInterpo
eValueType === STRING_PROPERTY ||
eValueType === ENUM_PROPERTY );
+ if( aAnimationNode.getFormula() )
+ {
+ var sFormula = aAnimationNode.getFormula();
+ var reMath = /abs|sqrt|asin|acos|atan|sin|cos|tan|exp|log|min|max/g;
+ sFormula = sFormula.replace(reMath, 'Math.$&');
+ sFormula = sFormula.replace(/pi(?!\w)/g, 'Math.PI');
+ sFormula = sFormula.replace(/e(?!\w)/g, 'Math.E');
+ sFormula = sFormula.replace(/\$/g, '__PARAM0__');
+
+ var aAnimatedElement = aAnimationNode.getAnimatedElement();
+ var aBBox = aAnimatedElement.getBaseBBox();
+ var width = aBBox.width / aActivityParamSet.nSlideWidth;
+ var height = aBBox.height / aActivityParamSet.nSlideHeight;
+ var x = ( aBBox.x + aBBox.width / 2 ) / aActivityParamSet.nSlideWidth;
+ var y = ( aBBox.y + aBBox.height / 2 ) / aActivityParamSet.nSlideHeight;
+ aActivityParamSet.aFormula = function( __PARAM0__ ) {
+
+ return eval(sFormula);
+ };
+ }
aActivityParamSet.aDiscreteTimes = aAnimationNode.getKeyTimes();
@@ -12156,9 +12202,15 @@ function evalValuesAttribute( aValueList, aValueSet, aBBox, nSlideWidth, nSlideH
var x = ( aBBox.x + aBBox.width / 2 ) / nSlideWidth;
var y = ( aBBox.y + aBBox.height / 2 ) / nSlideHeight;
+ var reMath = /abs|sqrt|asin|acos|atan|sin|cos|tan|exp|log|min|max/g;
+
for( var i = 0; i < aValueSet.length; ++i )
{
- var aValue = eval( aValueSet[i] );
+ var sValue = aValueSet[i];
+ sValue = sValue.replace(reMath, 'Math.$&');
+ sValue = sValue.replace(/pi(?!\w)/g, 'Math.PI');
+ sValue = sValue.replace(/e(?!\w)/g, 'Math.E');
+ var aValue = eval( sValue );
aValueList.push( aValue );
}
}