Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
sp-stop.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
5/* Authors:
6 * Lauris Kaplinski <lauris@kaplinski.com>
7 * bulia byak
8 * Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
9 * Jon A. Cruz <jon@joncruz.org>
10 *
11 * Copyright (C) 1999,2005 authors
12 * Copyright (C) 2010 Jon A. Cruz
13 *
14 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
15 */
16
17#include "sp-stop.h"
18#include "style.h"
19
20#include "attributes.h"
21#include "streq.h"
22#include "svg/svg.h"
24
26 this->offset = 0.0;
27}
28
29SPStop::~SPStop() = default;
30
34 this->readAttr(SPAttr::STOP_PATH); // For mesh
35
37}
38
43void SPStop::set(SPAttr key, const gchar* value) {
44 switch (key) {
45 case SPAttr::OFFSET: {
46 this->offset = sp_svg_read_percentage(value, 0.0);
47 this->requestModified(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);
48 break;
49 }
50 case SPAttr::STOP_PATH: {
51 if (value) {
52 this->path_string = Glib::ustring(value);
53 this->requestModified(SP_OBJECT_MODIFIED_FLAG);
54 }
55 break;
56 }
57 default: {
59 this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);
60 } else {
61 SPObject::set(key, value);
62 }
63 // This makes sure that the parent sp-gradient is updated.
64 this->requestModified(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);
65 }
66 }
67}
68
69void SPStop::modified(guint flags)
70{
71 if (parent && !(flags & SP_OBJECT_PARENT_MODIFIED_FLAG)) {
72 parent->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);
73 }
74}
75
81 if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
82 repr = xml_doc->createElement("svg:stop");
83 }
84
85 SPObject::write(xml_doc, repr, flags);
86 repr->setAttributeCssDouble("offset", this->offset);
87 /* strictly speaking, offset an SVG <number> rather than a CSS one, but exponents make no sense
88 * for offset proportions. */
89
90 return repr;
91}
92
97// A stop might have some non-stop siblings
99 SPStop *result = nullptr;
100
101 for (SPObject* obj = getNext(); obj && !result; obj = obj->getNext()) {
102 if (is<SPStop>(obj)) {
103 result = cast<SPStop>(obj);
104 }
105 }
106
107 return result;
108}
109
111 SPStop *result = nullptr;
112
113 for (SPObject* obj = getPrev(); obj; obj = obj->getPrev()) {
114 // The closest previous SPObject that is an SPStop *should* be ourself.
115 if (is<SPStop>(obj)) {
116 auto stop = cast<SPStop>(obj);
117 // Sanity check to ensure we have a proper sibling structure.
118 if (stop->getNextStop() == this) {
119 result = stop;
120 } else {
121 g_warning("SPStop previous/next relationship broken");
122 }
123 break;
124 }
125 }
126
127 return result;
128}
129
131{
132 // Copy color from the right place
133 Inkscape::Colors::Color color = style->stop_color.currentcolor ? style->color.getColor() : style->stop_color.getColor();
134 // Bundle stop opacity into the color
136 return color;
137}
138
143{
144 setColorRepr(getRepr(), color);
145}
146
151{
153 os << "stop-color:" << color.toString(false) << ";stop-opacity:" << color.getOpacity() <<";";
154 node->setAttribute("style", os.str());
155}
156
157/*
158 Local Variables:
159 mode:c++
160 c-file-style:"stroustrup"
161 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
162 indent-tabs-mode:nil
163 fill-column:99
164 End:
165*/
166// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
bool SP_ATTRIBUTE_IS_CSS(SPAttr k)
True iff k is a property in SVG, i.e.
Lookup dictionary for attributes/properties.
SPAttr
Definition attributes.h:27
A thin wrapper around std::ostringstream, but writing floating point numbers in the format required b...
std::string toString(bool opacity=true) const
Format the color as a css string and return it.
Definition color.cpp:106
bool addOpacity(double opacity=1.0)
Definition color.h:56
double getOpacity() const
Get the opacity in this color, if it's stored.
Definition color.cpp:407
Interface for refcounted XML nodes.
Definition node.h:80
void setAttribute(Util::const_char_ptr key, Util::const_char_ptr value)
Change an attribute of this node.
Definition node.cpp:25
bool setAttributeCssDouble(Util::const_char_ptr key, double val)
Set a property attribute to val [slightly rounded], in the format required for CSS properties: in par...
Definition node.cpp:102
Typed SVG document implementation.
Definition document.h:101
SPObject is an abstract base class of all of the document nodes at the SVG document level.
Definition sp-object.h:160
SPObject * getNext()
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.
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 * getPrev()
Returns previous object in sibling list or NULL.
SPObject * parent
Definition sp-object.h:189
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)
void requestDisplayUpdate(unsigned int flags)
Queues an deferred update of this object's display.
Gradient stop.
Definition sp-stop.h:31
Glib::ustring path_string
Definition sp-stop.h:40
float offset
Definition sp-stop.h:38
void modified(guint flags) override
Definition sp-stop.cpp:69
~SPStop() override
SPStop()
Definition sp-stop.cpp:25
SPStop * getNextStop()
Virtual write: write object attributes to repr.
Definition sp-stop.cpp:98
static void setColorRepr(Inkscape::XML::Node *node, Inkscape::Colors::Color const &color)
Set the color and opacity directly into the given xml repr.
Definition sp-stop.cpp:150
void setColor(Inkscape::Colors::Color const &color)
Sets the stop color and stop opacity in the style attribute.
Definition sp-stop.cpp:142
Inkscape::XML::Node * write(Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, unsigned int flags) override
Virtual set: set attribute to value.
Definition sp-stop.cpp:80
void set(SPAttr key, const char *value) override
Virtual build: set stop attributes from its associated XML node.
Definition sp-stop.cpp:43
void build(SPDocument *doc, Inkscape::XML::Node *repr) override
Definition sp-stop.cpp:31
Inkscape::Colors::Color getColor() const
Definition sp-stop.cpp:130
SPStop * getPrevStop()
Definition sp-stop.cpp:110
T< SPAttr::COLOR, SPIColor > color
color
Definition style.h:225
T< SPAttr::STOP_COLOR, SPIColor > stop_color
gradient-stop
Definition style.h:284
T< SPAttr::STOP_OPACITY, SPIScale24 > stop_opacity
Definition style.h:285
TODO: insert short description here.
Css & result
Inkscape::XML::Node * node
static cairo_user_data_key_t key
TODO: insert short description here.
TODO: insert short description here.
Interface for XML documents.
Definition document.h:43
virtual Node * createElement(char const *name)=0
SPStyle - a style object for SPItem objects.
double sp_svg_read_percentage(char const *str, double def)