2011-09-26 01:03:26 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
|
2012-05-21 15:12:37 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2000-04-01 18:38:51 +04:00
|
|
|
|
2009-04-29 08:31:34 +04:00
|
|
|
/**
|
|
|
|
* Notes on transforms in Mozilla and the SVG code.
|
|
|
|
*
|
|
|
|
* It's important to note that the matrix convention used in the SVG standard
|
|
|
|
* is the opposite convention to the one used in the Mozilla code or, more
|
|
|
|
* specifically, the convention used in Thebes code (code using gfxMatrix).
|
|
|
|
* Whereas the SVG standard uses the column vector convention, Thebes code uses
|
|
|
|
* the row vector convention. Thus, whereas in the SVG standard you have
|
|
|
|
* [M1][M2][M3]|p|, in Thebes you have |p|'[M3]'[M2]'[M1]'. In other words, the
|
|
|
|
* following are equivalent:
|
|
|
|
*
|
|
|
|
* / a1 c1 tx1 \ / a2 c2 tx2 \ / a3 c3 tx3 \ / x \
|
|
|
|
* SVG: | b1 d1 ty1 | | b2 d2 ty2 | | b3 d3 ty3 | | y |
|
|
|
|
* \ 0 0 1 / \ 0 0 1 / \ 0 0 1 / \ 1 /
|
|
|
|
*
|
|
|
|
* / a3 b3 0 \ / a2 b2 0 \ / a1 b1 0 \
|
|
|
|
* Thebes: [ x y 1 ] | c3 d3 0 | | c2 d2 0 | | c1 d1 0 |
|
|
|
|
* \ tx3 ty3 1 / \ tx2 ty2 1 / \ tx1 ty1 1 /
|
|
|
|
*
|
|
|
|
* Because the Thebes representation of a transform is the transpose of the SVG
|
|
|
|
* representation, our transform order must be reversed when representing SVG
|
|
|
|
* transforms using gfxMatrix in the SVG code. Since the SVG implementation
|
|
|
|
* stores and obtains matrices in SVG order, to do this we must pre-multiply
|
|
|
|
* gfxMatrix objects that represent SVG transforms instead of post-multiplying
|
|
|
|
* them as we would for matrices using SVG's column vector convention.
|
|
|
|
* Pre-multiplying may look wrong if you're only familiar with the SVG
|
|
|
|
* convention, but in that case hopefully the above explanation clears things
|
|
|
|
* up.
|
|
|
|
*/
|
|
|
|
|
2013-01-12 00:30:21 +04:00
|
|
|
#ifndef mozilla_dom_SVGMatrix_h
|
|
|
|
#define mozilla_dom_SVGMatrix_h
|
2000-04-01 18:38:51 +04:00
|
|
|
|
2013-04-02 23:17:41 +04:00
|
|
|
#include "mozilla/dom/SVGTransform.h"
|
2009-04-29 08:31:34 +04:00
|
|
|
#include "gfxMatrix.h"
|
2010-04-01 22:05:40 +04:00
|
|
|
#include "nsAutoPtr.h"
|
2011-09-26 01:03:26 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2012-12-23 08:54:20 +04:00
|
|
|
#include "nsWrapperCache.h"
|
2012-06-19 06:30:09 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2000-04-01 18:38:51 +04:00
|
|
|
|
2011-09-26 01:03:26 +04:00
|
|
|
namespace mozilla {
|
2013-01-12 00:30:21 +04:00
|
|
|
namespace dom {
|
2011-09-26 01:03:26 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* DOM wrapper for an SVG matrix.
|
|
|
|
*/
|
2015-03-21 19:28:04 +03:00
|
|
|
class SVGMatrix final : public nsWrapperCache
|
2011-09-26 01:03:26 +04:00
|
|
|
{
|
|
|
|
public:
|
2013-03-02 10:08:42 +04:00
|
|
|
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(SVGMatrix)
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(SVGMatrix)
|
2011-09-26 01:03:26 +04:00
|
|
|
|
|
|
|
/**
|
2013-04-02 23:17:41 +04:00
|
|
|
* Ctor for SVGMatrix objects that belong to a SVGTransform.
|
2011-09-26 01:03:26 +04:00
|
|
|
*/
|
2014-10-07 13:44:49 +04:00
|
|
|
explicit SVGMatrix(SVGTransform& aTransform) : mTransform(&aTransform) {}
|
2011-09-26 01:03:26 +04:00
|
|
|
|
|
|
|
/**
|
2013-04-02 23:17:41 +04:00
|
|
|
* Ctors for SVGMatrix objects created independently of a SVGTransform.
|
2011-09-26 01:03:26 +04:00
|
|
|
*/
|
2012-12-23 08:54:20 +04:00
|
|
|
// Default ctor for gfxMatrix will produce identity mx
|
2014-10-07 13:44:49 +04:00
|
|
|
SVGMatrix() {}
|
2012-12-23 08:54:20 +04:00
|
|
|
|
2014-10-07 13:44:49 +04:00
|
|
|
explicit SVGMatrix(const gfxMatrix &aMatrix) : mMatrix(aMatrix) {}
|
2012-12-23 08:54:20 +04:00
|
|
|
|
2014-03-18 06:41:35 +04:00
|
|
|
const gfxMatrix& GetMatrix() const {
|
2012-12-23 08:54:20 +04:00
|
|
|
return mTransform ? mTransform->Matrixgfx() : mMatrix;
|
2009-06-18 01:39:59 +04:00
|
|
|
}
|
|
|
|
|
2012-12-23 08:54:20 +04:00
|
|
|
// WebIDL
|
2013-04-02 23:17:41 +04:00
|
|
|
SVGTransform* GetParentObject() const;
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2012-12-23 08:54:20 +04:00
|
|
|
|
2014-06-17 21:35:51 +04:00
|
|
|
float A() const { return static_cast<float>(GetMatrix()._11); }
|
2012-12-23 08:54:20 +04:00
|
|
|
void SetA(float aA, ErrorResult& rv);
|
2014-06-17 21:35:51 +04:00
|
|
|
float B() const { return static_cast<float>(GetMatrix()._12); }
|
2012-12-23 08:54:20 +04:00
|
|
|
void SetB(float aB, ErrorResult& rv);
|
2014-06-17 21:35:51 +04:00
|
|
|
float C() const { return static_cast<float>(GetMatrix()._21); }
|
2012-12-23 08:54:20 +04:00
|
|
|
void SetC(float aC, ErrorResult& rv);
|
2014-06-17 21:35:51 +04:00
|
|
|
float D() const { return static_cast<float>(GetMatrix()._22); }
|
2012-12-23 08:54:20 +04:00
|
|
|
void SetD(float aD, ErrorResult& rv);
|
2014-06-17 21:35:51 +04:00
|
|
|
float E() const { return static_cast<float>(GetMatrix()._31); }
|
2012-12-23 08:54:20 +04:00
|
|
|
void SetE(float aE, ErrorResult& rv);
|
2014-06-17 21:35:51 +04:00
|
|
|
float F() const { return static_cast<float>(GetMatrix()._32); }
|
2012-12-23 08:54:20 +04:00
|
|
|
void SetF(float aF, ErrorResult& rv);
|
2013-01-12 00:30:21 +04:00
|
|
|
already_AddRefed<SVGMatrix> Multiply(SVGMatrix& aMatrix);
|
|
|
|
already_AddRefed<SVGMatrix> Inverse(ErrorResult& aRv);
|
|
|
|
already_AddRefed<SVGMatrix> Translate(float x, float y);
|
|
|
|
already_AddRefed<SVGMatrix> Scale(float scaleFactor);
|
|
|
|
already_AddRefed<SVGMatrix> ScaleNonUniform(float scaleFactorX,
|
|
|
|
float scaleFactorY);
|
|
|
|
already_AddRefed<SVGMatrix> Rotate(float angle);
|
|
|
|
already_AddRefed<SVGMatrix> RotateFromVector(float x,
|
|
|
|
float y,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
already_AddRefed<SVGMatrix> FlipX();
|
|
|
|
already_AddRefed<SVGMatrix> FlipY();
|
|
|
|
already_AddRefed<SVGMatrix> SkewX(float angle, ErrorResult& rv);
|
|
|
|
already_AddRefed<SVGMatrix> SkewY(float angle, ErrorResult& rv);
|
2012-12-23 08:54:20 +04:00
|
|
|
|
2011-09-26 01:03:26 +04:00
|
|
|
private:
|
2014-06-24 20:36:45 +04:00
|
|
|
~SVGMatrix() {}
|
|
|
|
|
2011-09-26 01:03:26 +04:00
|
|
|
void SetMatrix(const gfxMatrix& aMatrix) {
|
|
|
|
if (mTransform) {
|
|
|
|
mTransform->SetMatrix(aMatrix);
|
|
|
|
} else {
|
|
|
|
mMatrix = aMatrix;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsAnimVal() const {
|
2011-10-17 18:59:28 +04:00
|
|
|
return mTransform ? mTransform->IsAnimVal() : false;
|
2011-09-26 01:03:26 +04:00
|
|
|
}
|
|
|
|
|
2013-04-02 23:17:41 +04:00
|
|
|
nsRefPtr<SVGTransform> mTransform;
|
2011-09-26 01:03:26 +04:00
|
|
|
|
|
|
|
// Typically we operate on the matrix data accessed via mTransform but for
|
|
|
|
// matrices that exist independently of an SVGTransform we use mMatrix below.
|
|
|
|
gfxMatrix mMatrix;
|
|
|
|
};
|
|
|
|
|
2013-01-12 00:30:21 +04:00
|
|
|
} // namespace dom
|
2011-09-26 01:03:26 +04:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2013-01-12 00:30:21 +04:00
|
|
|
#endif // mozilla_dom_SVGMatrix_h
|