From 35a96bde514a8897f6f0fcc41c5833bf63df2e2a Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 18:29:01 +0200 Subject: Adding upstream version 1.0.2. Signed-off-by: Daniel Baumann --- src/object/sp-polyline.cpp | 132 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 src/object/sp-polyline.cpp (limited to 'src/object/sp-polyline.cpp') diff --git a/src/object/sp-polyline.cpp b/src/object/sp-polyline.cpp new file mode 100644 index 0000000..c75e4bc --- /dev/null +++ b/src/object/sp-polyline.cpp @@ -0,0 +1,132 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * SVG implementation + * + * Authors: + * Lauris Kaplinski + * Abhishek Sharma + * Jon A. Cruz + * + * Copyright (C) 1999-2002 Lauris Kaplinski + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include "attributes.h" +#include "sp-polyline.h" +#include "display/curve.h" +#include +#include "xml/repr.h" +#include "document.h" + +SPPolyLine::SPPolyLine() : SPShape() { +} + +SPPolyLine::~SPPolyLine() = default; + +void SPPolyLine::build(SPDocument * document, Inkscape::XML::Node * repr) { + SPShape::build(document, repr); + + this->readAttr("points"); +} + +void SPPolyLine::set(SPAttributeEnum key, const gchar* value) { + switch (key) { + case SP_ATTR_POINTS: { + SPCurve * curve; + const gchar * cptr; + char * eptr; + gboolean hascpt; + + if (!value) { + break; + } + + curve = new SPCurve (); + hascpt = FALSE; + + cptr = value; + eptr = nullptr; + + while (TRUE) { + gdouble x, y; + + while (*cptr != '\0' && (*cptr == ',' || *cptr == '\x20' || *cptr == '\x9' || *cptr == '\xD' || *cptr == '\xA')) { + cptr++; + } + + if (!*cptr) { + break; + } + + x = g_ascii_strtod (cptr, &eptr); + + if (eptr == cptr) { + break; + } + + cptr = eptr; + + while (*cptr != '\0' && (*cptr == ',' || *cptr == '\x20' || *cptr == '\x9' || *cptr == '\xD' || *cptr == '\xA')) { + cptr++; + } + + if (!*cptr) { + break; + } + + y = g_ascii_strtod (cptr, &eptr); + + if (eptr == cptr) { + break; + } + + cptr = eptr; + + if (hascpt) { + curve->lineto(x, y); + } else { + curve->moveto(x, y); + hascpt = TRUE; + } + } + + this->setCurve(curve); + curve->unref(); + break; + } + default: + SPShape::set(key, value); + break; + } +} + +Inkscape::XML::Node* SPPolyLine::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { + repr = xml_doc->createElement("svg:polyline"); + } + + if (repr != this->getRepr()) { + repr->mergeFrom(this->getRepr(), "id"); + } + + SPShape::write(xml_doc, repr, flags); + + return repr; +} + +gchar* SPPolyLine::description() const { + return g_strdup(_("Polyline")); +} + + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : -- cgit v1.2.3