Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
sp-filter-primitive.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
6/*
7 * Authors:
8 * Kees Cook <kees@outflux.net>
9 * Niko Kiirala <niko@kiirala.com>
10 * Abhishek Sharma
11 *
12 * Copyright (C) 2004-2007 Authors
13 *
14 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
15 */
16
17#include <cstring>
18
19#include "sp-filter-primitive.h"
20#include "attributes.h"
22#include "style.h"
23#include "slot-resolver.h"
24#include "util/optstr.h"
25
27{
28 // We must keep track if a value is set or not, if not set then the region defaults to 0%, 0%,
29 // 100%, 100% ("x", "y", "width", "height") of the -> filter <- region. If set then
30 // percentages are in terms of bounding box or viewbox, depending on value of "primitiveUnits"
31
32 // NB: SVGLength.set takes prescaled percent values: 1 means 100%
37}
38
40
42{
43 readAttr(SPAttr::STYLE); // struct not derived from SPItem, we need to do this ourselves.
50
52}
53
58
59void SPFilterPrimitive::set(SPAttr key, char const *value)
60{
61 switch (key) {
62 case SPAttr::IN_:
63 if (Inkscape::Util::assign(in_name, value)) {
66 }
67 break;
68 case SPAttr::RESULT:
69 if (Inkscape::Util::assign(out_name, value)) {
72 }
73 break;
74 case SPAttr::X:
75 x.readOrUnset(value);
77 break;
78 case SPAttr::Y:
79 y.readOrUnset(value);
81 break;
82 case SPAttr::WIDTH:
83 width.readOrUnset(value);
85 break;
86 case SPAttr::HEIGHT:
87 height.readOrUnset(value);
89 break;
90 default:
91 SPObject::set(key, value);
92 break;
93 }
94}
95
96void SPFilterPrimitive::update(SPCtx *ctx, unsigned flags)
97{
98 auto ictx = static_cast<SPItemCtx const*>(ctx);
99
100 // Do here since we know viewport (Bounding box case handled during rendering)
104 {
106 }
107}
108
110{
111 if (!repr) {
112 repr = getRepr()->duplicate(doc);
113 }
114
117
118 // Do we need to add x, y, width, height?
119 SPObject::write(doc, repr, flags);
120
121 return repr;
122}
123
125{
126 if (auto filter = cast<SPFilter>(parent)) {
127 filter->invalidate_slots();
128 }
129}
130
136
137// Common initialization for filter primitives
139{
140 g_assert(primitive);
141
142 primitive->set_input(in_slot);
143 primitive->set_output(out_slot);
144
145 /* TODO: place here code to handle input images, filter area etc. */
146 // We don't know current viewport or bounding box, this is wrong approach.
147 primitive->set_subregion(x, y, width, height);
148
149 // Give renderer access to filter properties
150 primitive->setStyle(style);
151}
152
153/* Calculate the region taken up by this filter, given the previous region.
154 *
155 * @param current_region The original shape's region or previous primitive's calculate_region output.
156 */
158{
159 return region; // No change.
160}
161
162/*
163 Local Variables:
164 mode:c++
165 c-file-style:"stroustrup"
166 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
167 indent-tabs-mode:nil
168 fill-column:99
169 End:
170*/
171// 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
Axis aligned, non-empty rectangle.
Definition rect.h:92
virtual void set_output(int slot)
Sets the slot number 'slot' to be used as output from filter primitive 'primitive' If output slot for...
void setStyle(SPStyle const *style)
Sets style for access to properties used by filter primitives.
void set_subregion(SVGLength const &x, SVGLength const &y, SVGLength const &width, SVGLength const &height)
virtual void set_input(int slot)
Sets the input slot number 'slot' to be used as input in rendering filter primitive 'primitive' For f...
Interface for refcounted XML nodes.
Definition node.h:80
void setAttributeOrRemoveIfEmpty(Inkscape::Util::const_char_ptr key, Inkscape::Util::const_char_ptr value)
Change an attribute of this node.
Definition node.cpp:167
virtual Node * duplicate(Document *doc) const =0
Create a duplicate of this node.
void calcDimsFromParentViewport(const SPItemCtx *ictx, bool assign_to_set=false, SPDimensions const *use=nullptr)
Update computed x/y/width/height for "percent" units and/or from its referencing clone parent.
SVGLength y
SVGLength height
SVGLength width
SVGLength x
Typed SVG document implementation.
Definition document.h:101
void update(SPCtx *ctx, unsigned flags) override
void build(SPDocument *doc, Inkscape::XML::Node *repr) override
std::optional< std::string > out_name
std::optional< std::string > in_name
Inkscape::XML::Node * write(Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, unsigned flags) override
virtual void resolve_slots(SlotResolver &)
void set(SPAttr key, char const *value) override
~SPFilterPrimitive() override
virtual Geom::Rect calculate_region(Geom::Rect const &region) const
void build_renderer_common(Inkscape::Filters::FilterPrimitive *primitive) const
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)
SPStyle * style
Represents the style properties, whether from presentation attributes, the style attribute,...
Definition sp-object.h:248
virtual Inkscape::XML::Node * write(Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, unsigned int flags)
SPObject * parent
Definition sp-object.h:189
virtual void release()
void readAttr(char const *key)
Read value of key attribute from XML node into object.
Inkscape::XML::Node * getRepr()
Returns the XML representation of tree.
virtual void build(SPDocument *doc, Inkscape::XML::Node *repr)
bool read(char const *str)
std::string write() const
void readOrUnset(char const *str, Unit u=NONE, float v=0, float c=0)
void unset(Unit u=NONE, float v=0, float c=0)
auto to_cstr(std::optional< std::string > const &s)
Definition optstr.h:26
bool assign(std::optional< std::string > &a, char const *b)
Definition optstr.h:31
static cairo_user_data_key_t key
Document level base class for all SVG filter primitives.
@ SP_FILTER_UNITS_USERSPACEONUSE
Interface for XML documents.
Definition document.h:43
Unused.
Definition sp-object.h:94
Contains transformations to document/viewport and the viewport size.
Definition sp-item.h:92
SPStyle - a style object for SPItem objects.