Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
sp-polyline.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * SVG <polyline> implementation
4 *
5 * Authors:
6 * Lauris Kaplinski <lauris@kaplinski.com>
7 * Abhishek Sharma
8 * Jon A. Cruz <jon@joncruz.org>
9 *
10 * Copyright (C) 1999-2002 Lauris Kaplinski
11 *
12 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
13 */
14
15#include "sp-polyline.h"
16
17#include <glibmm/i18n.h>
18
19#include "attributes.h" // for SPAttr
20#include "object/sp-object.h" // for SP_OBJECT_WRITE_BUILD
21#include "object/sp-shape.h" // for SPShape
22#include "sp-polygon.h" // for sp_poly_parse_curve
23#include "xml/document.h" // for Document
24#include "xml/node.h" // for Node
25
26class SPDocument;
27
30
31SPPolyLine::~SPPolyLine() = default;
32
38
39void SPPolyLine::set(SPAttr key, const gchar* value) {
40 switch (key) {
41 case SPAttr::POINTS:
42 if (value) {
43 setCurve(sp_poly_parse_curve(value).value_or(Geom::Path{}));
44 }
45 break;
46 default:
47 SPShape::set(key, value);
48 break;
49 }
50}
51
53 if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
54 repr = xml_doc->createElement("svg:polyline");
55 }
56
57 if (repr != this->getRepr()) {
58 repr->mergeFrom(this->getRepr(), "id");
59 }
60
61 SPShape::write(xml_doc, repr, flags);
62
63 return repr;
64}
65
66const char* SPPolyLine::typeName() const {
67 return "path";
68}
69
71 return g_strdup(_("<b>Polyline</b>"));
72}
73
74
75/*
76 Local Variables:
77 mode:c++
78 c-file-style:"stroustrup"
79 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
80 indent-tabs-mode:nil
81 fill-column:99
82 End:
83*/
84// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
Lookup dictionary for attributes/properties.
SPAttr
Definition attributes.h:27
Sequence of contiguous curves, aka spline.
Definition path.h:353
Interface for refcounted XML nodes.
Definition node.h:80
virtual void mergeFrom(Node const *src, char const *key, bool extension=false, bool clean=false)=0
Merge all children of another node with the current.
Typed SVG document implementation.
Definition document.h:101
Inkscape::XML::Node * repr
Definition sp-object.h:193
SPDocument * document
Definition sp-object.h:188
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.
~SPPolyLine() override
char * description() const override
void build(SPDocument *doc, Inkscape::XML::Node *repr) override
void set(SPAttr key, char const *value) override
Inkscape::XML::Node * write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, unsigned int flags) override
const char * typeName() const override
The item's type name, not node tag name.
Base class for shapes, including <path> element.
Definition sp-shape.h:38
void setCurve(Geom::PathVector const *)
Definition sp-shape.cpp:923
void set(SPAttr key, char const *value) override
Definition sp-shape.cpp:114
void build(SPDocument *document, Inkscape::XML::Node *repr) override
Definition sp-shape.cpp:62
Inkscape::XML::Node * write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, unsigned int flags) override
Definition sp-shape.cpp:119
static cairo_user_data_key_t key
std::optional< Geom::Path > sp_poly_parse_curve(char const *points)
Parse a 'points' attribute, printing a warning when an error occurs.
TODO: insert short description here.
Interface for XML documents.
Definition document.h:43
virtual Node * createElement(char const *name)=0
Interface for XML documents.
Interface for XML nodes.