1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
/*
* Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org>
* Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org>
* Copyright (C) 2018-2019 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#pragma once
#include "FEComponentTransfer.h"
#include "NodeName.h"
#include "SVGElement.h"
#include <wtf/SortedArrayMap.h>
namespace WebCore {
template<>
struct SVGPropertyTraits<ComponentTransferType> {
static unsigned highestEnumValue() { return FECOMPONENTTRANSFER_TYPE_GAMMA; }
static String toString(ComponentTransferType type)
{
switch (type) {
case FECOMPONENTTRANSFER_TYPE_UNKNOWN:
return emptyString();
case FECOMPONENTTRANSFER_TYPE_IDENTITY:
return "identity"_s;
case FECOMPONENTTRANSFER_TYPE_TABLE:
return "table"_s;
case FECOMPONENTTRANSFER_TYPE_DISCRETE:
return "discrete"_s;
case FECOMPONENTTRANSFER_TYPE_LINEAR:
return "linear"_s;
case FECOMPONENTTRANSFER_TYPE_GAMMA:
return "gamma"_s;
}
ASSERT_NOT_REACHED();
return emptyString();
}
static ComponentTransferType fromString(const String& value)
{
static constexpr std::pair<PackedASCIILiteral<uint64_t>, ComponentTransferType> mappings[] = {
{ "discrete", FECOMPONENTTRANSFER_TYPE_DISCRETE },
{ "gamma", FECOMPONENTTRANSFER_TYPE_GAMMA },
{ "identity", FECOMPONENTTRANSFER_TYPE_IDENTITY },
{ "linear", FECOMPONENTTRANSFER_TYPE_LINEAR },
{ "table", FECOMPONENTTRANSFER_TYPE_TABLE }
};
static constexpr SortedArrayMap map { mappings };
return map.get(value, FECOMPONENTTRANSFER_TYPE_UNKNOWN);
}
};
class SVGComponentTransferFunctionElement : public SVGElement {
WTF_MAKE_ISO_ALLOCATED(SVGComponentTransferFunctionElement);
public:
virtual ComponentTransferChannel channel() const = 0;
ComponentTransferFunction transferFunction() const;
ComponentTransferType type() const { return m_type->currentValue<ComponentTransferType>(); }
const SVGNumberList& tableValues() const { return m_tableValues->currentValue(); }
float slope() const { return m_slope->currentValue(); }
float intercept() const { return m_intercept->currentValue(); }
float amplitude() const { return m_amplitude->currentValue(); }
float exponent() const { return m_exponent->currentValue(); }
float offset() const { return m_offset->currentValue(); }
SVGAnimatedEnumeration& typeAnimated() { return m_type; }
SVGAnimatedNumberList& tableValuesAnimated() { return m_tableValues; }
SVGAnimatedNumber& slopeAnimated() { return m_slope; }
SVGAnimatedNumber& interceptAnimated() { return m_intercept; }
SVGAnimatedNumber& amplitudeAnimated() { return m_amplitude; }
SVGAnimatedNumber& exponentAnimated() { return m_exponent; }
SVGAnimatedNumber& offsetAnimated() { return m_offset; }
protected:
SVGComponentTransferFunctionElement(const QualifiedName&, Document&);
using PropertyRegistry = SVGPropertyOwnerRegistry<SVGComponentTransferFunctionElement, SVGElement>;
void attributeChanged(const QualifiedName&, const AtomString& oldValue, const AtomString& newValue, AttributeModificationReason) override;
void svgAttributeChanged(const QualifiedName&) override;
bool rendererIsNeeded(const RenderStyle&) override { return false; }
private:
Ref<SVGAnimatedEnumeration> m_type { SVGAnimatedEnumeration::create(this, FECOMPONENTTRANSFER_TYPE_IDENTITY) };
Ref<SVGAnimatedNumberList> m_tableValues { SVGAnimatedNumberList::create(this) };
Ref<SVGAnimatedNumber> m_slope { SVGAnimatedNumber::create(this, 1) };
Ref<SVGAnimatedNumber> m_intercept { SVGAnimatedNumber::create(this) };
Ref<SVGAnimatedNumber> m_amplitude { SVGAnimatedNumber::create(this, 1) };
Ref<SVGAnimatedNumber> m_exponent { SVGAnimatedNumber::create(this, 1) };
Ref<SVGAnimatedNumber> m_offset { SVGAnimatedNumber::create(this) };
};
} // namespace WebCore
|