Bug 539576 - SVGTransform matrix changes still not live in all circumstances. r=jwatt

This commit is contained in:
Robert Longson 2010-01-25 12:26:15 +00:00
parent afce7361da
commit 1034acc582
3 changed files with 97 additions and 22 deletions

View File

@ -315,6 +315,8 @@ NS_IMETHODIMP nsSVGMatrix::SkewX(float angle, nsIDOMSVGMatrix **_retval)
double ta = tan( angle*radPerDegree );
NS_ENSURE_FINITE(ta, NS_ERROR_DOM_SVG_INVALID_VALUE_ERR);
return NS_NewSVGMatrix(_retval,
mA, mB,
(float) ( mC + mA*ta), (float) ( mD + mB*ta),
@ -328,6 +330,8 @@ NS_IMETHODIMP nsSVGMatrix::SkewY(float angle, nsIDOMSVGMatrix **_retval)
double ta = tan( angle*radPerDegree );
NS_ENSURE_FINITE(ta, NS_ERROR_DOM_SVG_INVALID_VALUE_ERR);
return NS_NewSVGMatrix(_retval,
(float) (mA + mC*ta), (float) (mB + mD*ta),
mC, mD,

View File

@ -46,6 +46,8 @@
#include "nsContentUtils.h"
#include "nsDOMError.h"
const double radPerDegree = 2.0*3.1415926535 / 360.0;
//----------------------------------------------------------------------
// Implementation
@ -203,6 +205,9 @@ NS_IMETHODIMP nsSVGTransform::WillModifySVGObservable(nsISVGValue* observable,
NS_IMETHODIMP nsSVGTransform::DidModifySVGObservable (nsISVGValue* observable,
modificationType aModType)
{
// we become a general matrix transform if mMatrix changes
mType = SVG_TRANSFORM_MATRIX;
mAngle = 0.0f;
DidModify();
return NS_OK;
}
@ -245,8 +250,6 @@ NS_IMETHODIMP nsSVGTransform::SetMatrix(nsIDOMSVGMatrix *matrix)
mType = SVG_TRANSFORM_MATRIX;
mAngle = 0.0f;
mOriginX = 0.0f;
mOriginY = 0.0f;
matrix->GetA(&a);
matrix->GetB(&b);
@ -255,12 +258,14 @@ NS_IMETHODIMP nsSVGTransform::SetMatrix(nsIDOMSVGMatrix *matrix)
matrix->GetE(&e);
matrix->GetF(&f);
NS_REMOVE_SVGVALUE_OBSERVER(mMatrix);
mMatrix->SetA(a);
mMatrix->SetB(b);
mMatrix->SetC(c);
mMatrix->SetD(d);
mMatrix->SetE(e);
mMatrix->SetF(f);
NS_ADD_SVGVALUE_OBSERVER(mMatrix);
DidModify();
return NS_OK;
@ -275,14 +280,14 @@ NS_IMETHODIMP nsSVGTransform::SetTranslate(float tx, float ty)
mType = SVG_TRANSFORM_TRANSLATE;
mAngle = 0.0f;
mOriginX = 0.0f;
mOriginY = 0.0f;
NS_REMOVE_SVGVALUE_OBSERVER(mMatrix);
mMatrix->SetA(1.0f);
mMatrix->SetB(0.0f);
mMatrix->SetC(0.0f);
mMatrix->SetD(1.0f);
mMatrix->SetE(tx);
mMatrix->SetF(ty);
NS_ADD_SVGVALUE_OBSERVER(mMatrix);
DidModify();
return NS_OK;
@ -297,14 +302,14 @@ NS_IMETHODIMP nsSVGTransform::SetScale(float sx, float sy)
mType = SVG_TRANSFORM_SCALE;
mAngle = 0.0f;
mOriginX = 0.0f;
mOriginY = 0.0f;
NS_REMOVE_SVGVALUE_OBSERVER(mMatrix);
mMatrix->SetA(sx);
mMatrix->SetB(0.0f);
mMatrix->SetC(0.0f);
mMatrix->SetD(sy);
mMatrix->SetE(0.0f);
mMatrix->SetF(0.0f);
NS_ADD_SVGVALUE_OBSERVER(mMatrix);
DidModify();
return NS_OK;
@ -322,15 +327,17 @@ NS_IMETHODIMP nsSVGTransform::SetRotate(float angle, float cx, float cy)
mOriginX = cx;
mOriginY = cy;
gfxMatrix matrix(1, 0, 0, 1, cx, cy);
matrix.Rotate(angle * radPerDegree);
matrix.Translate(gfxPoint(-cx, -cy));
NS_REMOVE_SVGVALUE_OBSERVER(mMatrix);
NS_NewSVGMatrix(getter_AddRefs(mMatrix));
nsCOMPtr<nsIDOMSVGMatrix> temp;
mMatrix->Translate(cx, cy, getter_AddRefs(temp));
mMatrix = temp;
mMatrix->Rotate(angle, getter_AddRefs(temp));
mMatrix = temp;
mMatrix->Translate(-cx,-cy, getter_AddRefs(temp));
mMatrix = temp;
mMatrix->SetA(static_cast<float>(matrix.xx));
mMatrix->SetB(static_cast<float>(matrix.yx));
mMatrix->SetC(static_cast<float>(matrix.xy));
mMatrix->SetD(static_cast<float>(matrix.yy));
mMatrix->SetE(static_cast<float>(matrix.x0));
mMatrix->SetF(static_cast<float>(matrix.y0));
NS_ADD_SVGVALUE_OBSERVER(mMatrix);
DidModify();
@ -342,16 +349,23 @@ NS_IMETHODIMP nsSVGTransform::SetSkewX(float angle)
{
NS_ENSURE_FINITE(angle, NS_ERROR_ILLEGAL_VALUE);
float ta = static_cast<float>(tan(angle * radPerDegree));
NS_ENSURE_FINITE(ta, NS_ERROR_DOM_SVG_INVALID_VALUE_ERR);
WillModify();
mType = SVG_TRANSFORM_SKEWX;
mAngle = angle;
NS_REMOVE_SVGVALUE_OBSERVER(mMatrix);
NS_NewSVGMatrix(getter_AddRefs(mMatrix));
nsCOMPtr<nsIDOMSVGMatrix> temp;
mMatrix->SkewX(angle, getter_AddRefs(temp));
mMatrix = temp;
mMatrix->SetA(1.0f);
mMatrix->SetB(0.0f);
mMatrix->SetC(ta);
mMatrix->SetD(ta);
mMatrix->SetE(0.0f);
mMatrix->SetF(0.0f);
NS_ADD_SVGVALUE_OBSERVER(mMatrix);
DidModify();
@ -363,16 +377,22 @@ NS_IMETHODIMP nsSVGTransform::SetSkewY(float angle)
{
NS_ENSURE_FINITE(angle, NS_ERROR_ILLEGAL_VALUE);
float ta = static_cast<float>(tan(angle * radPerDegree));
NS_ENSURE_FINITE(ta, NS_ERROR_DOM_SVG_INVALID_VALUE_ERR);
WillModify();
mType = SVG_TRANSFORM_SKEWY;
mAngle = angle;
NS_REMOVE_SVGVALUE_OBSERVER(mMatrix);
NS_NewSVGMatrix(getter_AddRefs(mMatrix));
nsCOMPtr<nsIDOMSVGMatrix> temp;
mMatrix->SkewY(angle, getter_AddRefs(temp));
mMatrix = temp;
mMatrix->SetA(ta);
mMatrix->SetB(ta);
mMatrix->SetC(0.0f);
mMatrix->SetD(1.0f);
mMatrix->SetE(0.0f);
mMatrix->SetF(0.0f);
NS_ADD_SVGVALUE_OBSERVER(mMatrix);
DidModify();

View File

@ -24,6 +24,14 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=512636
SimpleTest.waitForExplicitFinish();
// We don't want to fail just because of rounding errors
var tolerance = 1 / 65535;
function isequal( value, expected, tolerance )
{
ok(Math.abs(value - expected) < tolerance, 'matrix value expected:' +expected + ' actual:' + value);
}
function run()
{
var g, svg, t, m, m2;
@ -80,6 +88,49 @@ function run()
is(m.f, 6, 'm.f for matrix');
is(t.angle, 0, 't.angle for matrix');
// set the SVGTransform to be a translate() then convert to a matrix
t.setTranslate(0, 0);
m.a = 2;
// test that the SVGTransform now reflects the matrix value
is(t.type, SVGTransform.SVG_TRANSFORM_MATRIX, 't.type for matrix');
// set the SVGTransform to be a rotate()
t.setRotate(90, 0, 0);
// test that the SVGTransform now reflects the matrix value
is(t.type, SVGTransform.SVG_TRANSFORM_ROTATE, 't.type for rotate');
isequal(m.a, Math.cos(Math.PI/2), tolerance);
isequal(m.b, Math.sin(Math.PI/2), tolerance);
isequal(m.c, -Math.sin(Math.PI/2), tolerance);
isequal(m.d, Math.cos(Math.PI/2), tolerance);
isequal(m.e, 0, tolerance);
isequal(m.f, 0, tolerance);
// set the SVGTransform to be a skewX()
t.setSkewX(45);
// test that the SVGTransform now reflects the matrix value
is(t.type, SVGTransform.SVG_TRANSFORM_SKEWX, 't.type for skewx');
isequal(m.a, 1, tolerance);
isequal(m.b, 0, tolerance);
isequal(m.c, Math.tan(Math.PI/4), tolerance);
isequal(m.d, Math.tan(Math.PI/4), tolerance);
isequal(m.e, 0, tolerance);
isequal(m.f, 0, tolerance);
// set the SVGTransform to be a skewY()
t.setSkewY(45);
// test that the SVGTransform now reflects the matrix value
is(t.type, SVGTransform.SVG_TRANSFORM_SKEWY, 't.type for skewy');
isequal(m.a, Math.tan(Math.PI/4), tolerance);
isequal(m.b, Math.tan(Math.PI/4), tolerance);
isequal(m.c, 0, tolerance);
isequal(m.d, 1, tolerance);
isequal(m.e, 0, tolerance);
isequal(m.f, 0, tolerance);
SimpleTest.finish();
}