Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
componenttransfer-funcnode.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
5/*
6 * Authors:
7 * Hugo Rodrigues <haa.rodrigues@gmail.com>
8 * Niko Kiirala <niko@kiirala.com>
9 * Felipe CorrĂȘa da Silva Sanches <juca@members.fsf.org>
10 * Abhishek Sharma
11 *
12 * Copyright (C) 2006, 2007, 2008 Authors
13 *
14 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
15 */
16
18
19#include <cstring> // for strcmp
20#include "attributes.h" // for SPAttr
21#include "document.h" // for SPDocument
22#include "util/numeric/converters.h" // for read_number, read_vector
23
24namespace Inkscape::XML {
25class Node;
26} // namespace Inkscape::XML
27
42
44{
45 if (document) {
46 document->removeResource("fefuncnode", this);
47 }
48
49 tableValues.clear();
50
52}
53
55{
56 if (!value) {
57 return Inkscape::Filters::COMPONENTTRANSFER_TYPE_ERROR; //type attribute is REQUIRED.
58 }
59
60 switch (value[0]) {
61 case 'i':
62 if (!std::strcmp(value, "identity")) {
64 }
65 break;
66 case 't':
67 if (!std::strcmp(value, "table")) {
69 }
70 break;
71 case 'd':
72 if (!std::strcmp(value, "discrete")) {
74 }
75 break;
76 case 'l':
77 if (!std::strcmp(value, "linear")) {
79 }
80 break;
81 case 'g':
82 if (!std::strcmp(value, "gamma")) {
84 }
85 break;
86 default:
87 break;
88 }
89
90 return Inkscape::Filters::COMPONENTTRANSFER_TYPE_ERROR; //type attribute is REQUIRED.
91}
92
93void SPFeFuncNode::set(SPAttr key, char const *value)
94{
95 switch (key) {
96 case SPAttr::TYPE: {
97 auto const new_type = sp_feComponenttransfer_read_type(value);
98
99 if (type != new_type) {
100 type = new_type;
101 requestModified(SP_OBJECT_MODIFIED_FLAG);
102 }
103 break;
104 }
105 case SPAttr::TABLEVALUES: {
106 if (value) {
108 } else {
109 tableValues.clear();
110 }
111 requestModified(SP_OBJECT_MODIFIED_FLAG);
112 break;
113 }
114 case SPAttr::SLOPE: {
115 auto new_slope = value ? Inkscape::Util::read_number(value) : 1;
116
117 if (slope != new_slope) {
118 slope = new_slope;
119 requestModified(SP_OBJECT_MODIFIED_FLAG);
120 }
121 break;
122 }
123 case SPAttr::INTERCEPT: {
124 auto new_intercept = value ? Inkscape::Util::read_number(value) : 0;
125
126 if (intercept != new_intercept) {
127 intercept = new_intercept;
128 requestModified(SP_OBJECT_MODIFIED_FLAG);
129 }
130 break;
131 }
132 case SPAttr::AMPLITUDE: {
133 auto new_amplitude = value ? Inkscape::Util::read_number(value) : 1;
134
135 if (amplitude != new_amplitude) {
136 amplitude = new_amplitude;
137 requestModified(SP_OBJECT_MODIFIED_FLAG);
138 }
139 break;
140 }
141 case SPAttr::EXPONENT: {
142 auto new_exponent = value ? Inkscape::Util::read_number(value) : 1;
143
144 if (exponent != new_exponent) {
145 exponent = new_exponent;
146 requestModified(SP_OBJECT_MODIFIED_FLAG);
147 }
148 break;
149 }
150 case SPAttr::OFFSET: {
151 auto new_offset = value ? Inkscape::Util::read_number(value) : 0;
152
153 if (offset != new_offset) {
154 offset = new_offset;
155 requestModified(SP_OBJECT_MODIFIED_FLAG);
156 }
157 break;
158 }
159 default:
160 SPObject::set(key, value);
161 break;
162 }
163}
164
165/*
166 Local Variables:
167 mode:c++
168 c-file-style:"stroustrup"
169 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
170 indent-tabs-mode:nil
171 fill-column:99
172 End:
173*/
174// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
Lookup dictionary for attributes/properties.
SPAttr
Definition attributes.h:27
@ TABLEVALUES
Interface for refcounted XML nodes.
Definition node.h:80
Typed SVG document implementation.
Definition document.h:101
bool removeResource(char const *key, SPObject *object)
bool addResource(char const *key, SPObject *object)
Inkscape::Filters::FilterComponentTransferType type
std::vector< double > tableValues
void build(SPDocument *doc, Inkscape::XML::Node *repr) override
void set(SPAttr key, char const *value) override
Inkscape::XML::Node * repr
Definition sp-object.h:193
void requestModified(unsigned int flags)
Requests that a modification notification signal be emitted later (e.g.
SPDocument * document
Definition sp-object.h:188
virtual void set(SPAttr key, const char *value)
virtual void release()
void readAttr(char const *key)
Read value of key attribute from XML node into object.
virtual void build(SPDocument *doc, Inkscape::XML::Node *repr)
static Inkscape::Filters::FilterComponentTransferType sp_feComponenttransfer_read_type(char const *value)
SVG <filter> implementation, see sp-filter.cpp.
Utility functions to convert ascii representations to numbers.
std::vector< gdouble > read_vector(const gchar *value)
Definition converters.h:84
double read_number(gchar const *value, bool warning=true)
Definition converters.h:42
@Inkscape XML tree.
static cairo_user_data_key_t key