/* * Copyright (C) 2016-2019 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. */ #pragma once #include "AffineTransform.h" #include "ExceptionOr.h" #include "SVGValueProperty.h" namespace WebCore { // FIXME: Remove this class once SVGMatrix becomes an alias to DOMMatrix. class SVGMatrix : public SVGValueProperty { using Base = SVGValueProperty; using Base::Base; public: static Ref create(const AffineTransform& value = { }) { return adoptRef(*new SVGMatrix(value)); } static Ref create(SVGPropertyOwner* owner, SVGPropertyAccess access, const AffineTransform& value = { }) { return adoptRef(*new SVGMatrix(owner, access, value)); } template static ExceptionOr> create(ExceptionOr&& value) { if (value.hasException()) return value.releaseException(); return create(value.releaseReturnValue()); } double a() const { return m_value.a(); } ExceptionOr setA(double value) { if (isReadOnly()) return Exception { NoModificationAllowedError }; m_value.setA(value); commitChange(); return { }; } double b() const { return m_value.b(); } ExceptionOr setB(double value) { if (isReadOnly()) return Exception { NoModificationAllowedError }; m_value.setB(value); commitChange(); return { }; } double c() const { return m_value.c(); } ExceptionOr setC(double value) { if (isReadOnly()) return Exception { NoModificationAllowedError }; m_value.setC(value); commitChange(); return { }; } double d() const { return m_value.d(); } ExceptionOr setD(double value) { if (isReadOnly()) return Exception { NoModificationAllowedError }; m_value.setD(value); commitChange(); return { }; } double e() const { return m_value.e(); } ExceptionOr setE(double value) { if (isReadOnly()) return Exception { NoModificationAllowedError }; m_value.setE(value); commitChange(); return { }; } double f() const { return m_value.f(); } ExceptionOr setF(double value) { if (isReadOnly()) return Exception { NoModificationAllowedError }; m_value.setF(value); commitChange(); return { }; } Ref multiply(SVGMatrix& secondMatrix) const { auto copy = m_value; copy.multiply(secondMatrix.value()); return SVGMatrix::create(copy); } ExceptionOr> inverse() const { auto inverse = m_value.inverse(); if (!inverse) return Exception { InvalidStateError, "Matrix is not invertible"_s }; return SVGMatrix::create(*inverse); } Ref translate(float x, float y) const { auto copy = m_value; copy.translate(x, y); return SVGMatrix::create(copy); } Ref scale(float scaleFactor) const { auto copy = m_value; copy.scale(scaleFactor); return SVGMatrix::create(copy); } Ref scaleNonUniform(float scaleFactorX, float scaleFactorY) const { auto copy = m_value; copy.scaleNonUniform(scaleFactorX, scaleFactorY); return SVGMatrix::create(copy); } Ref rotate(float angle) const { auto copy = m_value; copy.rotate(angle); return SVGMatrix::create(copy); } ExceptionOr> rotateFromVector(float x, float y) const { if (!x || !y) return Exception { TypeError }; auto copy = m_value; copy.rotateFromVector(x, y); return SVGMatrix::create(copy); } Ref flipX() const { auto copy = m_value; copy.flipX(); return SVGMatrix::create(copy); } Ref flipY() const { auto copy = m_value; copy.flipY(); return SVGMatrix::create(copy); } Ref skewX(float angle) const { auto copy = m_value; copy.skewX(angle); return SVGMatrix::create(copy); } Ref skewY(float angle) const { auto copy = m_value; copy.skewY(angle); return SVGMatrix::create(copy); } }; } // namespace WebCore