Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
morphology.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
5/*
6 * Authors:
7 * Felipe Sanches <juca@members.fsf.org>
8 * Hugo Rodrigues <haa.rodrigues@gmail.com>
9 * Abhishek Sharma
10 *
11 * Copyright (C) 2006 Hugo Rodrigues
12 *
13 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
14 */
15
16#include "morphology.h"
17
18#include <cstring> // for strcmp
19
20#include "attributes.h" // for SPAttr
21#include "object/filters/sp-filter-primitive.h" // for SPFilterPrimitive
22#include "object/sp-object.h" // for SP_OBJECT_MODIFIED_FLAG
23
24class SPDocument;
25
26namespace Inkscape {
27class DrawingItem;
28namespace Filters {
29class FilterPrimitive;
30} // namespace Filters
31namespace XML {
32class Node;
33} // namespace XML
34} // namespace Inkscape
35
43
45{
46 if (!value) {
47 return Inkscape::Filters::MORPHOLOGY_OPERATOR_ERODE; // erode is default
48 }
49
50 switch (value[0]) {
51 case 'e':
52 if (std::strcmp(value, "erode") == 0) {
54 }
55 break;
56 case 'd':
57 if (std::strcmp(value, "dilate") == 0) {
59 }
60 break;
61 }
62
63 return Inkscape::Filters::MORPHOLOGY_OPERATOR_ERODE; // erode is default
64}
65
66void SPFeMorphology::set(SPAttr key, char const *value)
67{
68 switch (key) {
69 case SPAttr::OPERATOR: {
70 auto n_op = ::read_operator(value);
71 if (n_op != Operator) {
72 Operator = n_op;
74 }
75 break;
76 }
77 case SPAttr::RADIUS:
78 radius.set(value);
79
80 // From SVG spec: If <y-radius> is not provided, it defaults to <x-radius>.
81 if (!radius.optNumIsSet()) {
83 }
84
86 break;
87 default:
89 break;
90 }
91}
92
93std::unique_ptr<Inkscape::Filters::FilterPrimitive> SPFeMorphology::build_renderer(Inkscape::DrawingItem*) const
94{
95 auto morphology = std::make_unique<Inkscape::Filters::FilterMorphology>();
97
98 morphology->set_operator(Operator);
99 morphology->set_xradius(radius.getNumber());
100 morphology->set_yradius(radius.getOptNumber());
101
102 return morphology;
103}
104
111{
112 auto r = region;
114 if (radius.optNumIsSet()) {
116 } else {
117 r.expandBy(radius.getNumber());
118 }
120 if (radius.optNumIsSet()) {
121 r.expandBy(-1 * radius.getNumber(), -1 * radius.getOptNumber());
122 } else {
123 r.expandBy(-1 * radius.getNumber());
124 }
125 }
126 return r;
127}
128
129/*
130 Local Variables:
131 mode:c++
132 c-file-style:"stroustrup"
133 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
134 indent-tabs-mode:nil
135 fill-column:99
136 End:
137*/
138// 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
void expandBy(C amount)
Expand the rectangle in both directions by the specified amount.
Axis aligned, non-empty rectangle.
Definition rect.h:92
SVG drawing item for display.
Interface for refcounted XML nodes.
Definition node.h:80
float getOptNumber(bool or_num=false) const
float getNumber() const
void set(char const *str)
bool optNumIsSet() const
void setOptNumber(float optnum)
SVGLength x
Typed SVG document implementation.
Definition document.h:101
NumberOptNumber radius
Definition morphology.h:29
void set(SPAttr key, char const *value) override
void build(SPDocument *doc, Inkscape::XML::Node *repr) override
std::unique_ptr< Inkscape::Filters::FilterPrimitive > build_renderer(Inkscape::DrawingItem *item) const override
Geom::Rect calculate_region(Geom::Rect const &region) const override
Calculate the region taken up by a mophoplogy primitive.
void build(SPDocument *doc, Inkscape::XML::Node *repr) override
void set(SPAttr key, char const *value) override
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
void readAttr(char const *key)
Read value of key attribute from XML node into object.
static FeCompositeOperator read_operator(char const *value)
Definition composite.cpp:52
Operator
Definition cr-term.h:64
static Inkscape::Filters::FilterMorphologyOperator read_operator(char const *value)
Helper class to stream background task notifications as a series of messages.
static cairo_user_data_key_t key
Document level base class for all SVG filter primitives.