Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
array.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright (C) Johan Engelen 2008 <j.b.c.engelen@utwente.nl>
4 *
5 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
6 */
7
9
10#include <utility>
11#include <2geom/coord.h>
12#include <2geom/point.h>
13
14#include "live_effects/effect.h"
16#include "svg/svg.h"
17
19
20template <>
21double
22ArrayParam<double>::readsvg(char const * const str)
23{
24 double newx = Geom::infinity();
25 sp_svg_number_read_d(str, &newx);
26 return newx;
27}
28
29template <>
30float
31ArrayParam<float>::readsvg(char const * const str)
32{
33 float newx = Geom::infinity();
34 sp_svg_number_read_f(str, &newx);
35 return newx;
36}
37
38template <>
39Glib::ustring
41{
42 if (str) {
43 return Glib::ustring(str);
44 }
45 return Glib::ustring("");
46}
47
48template <>
50ArrayParam<Geom::Point>::readsvg(char const * const str)
51{
52 auto const strarray = g_strsplit(str, ",", 2);
53 double newx, newy;
54 unsigned int success = sp_svg_number_read_d(strarray[0], &newx);
55 success += sp_svg_number_read_d(strarray[1], &newy);
56 g_strfreev (strarray);
57 if (success == 2) {
58 return Geom::Point(newx, newy);
59 }
61}
62
63template <>
64std::shared_ptr<SatelliteReference>
65ArrayParam<std::shared_ptr<SatelliteReference>>::readsvg(char const * const str)
66{
67 std::shared_ptr<SatelliteReference> satellitereference = nullptr;
68 if (!str) {
69 return satellitereference;
70 }
71
72 auto const strarray = g_strsplit(str, ",", 2);
73 if (strarray[0] != nullptr && g_strstrip(strarray[0])[0] == '#') {
74 try {
75 bool active = strarray[1] != nullptr;
76 satellitereference = std::make_shared<SatelliteReference>(param_effect->getLPEObj(), active);
77 satellitereference->attach(Inkscape::URI(g_strstrip(strarray[0])));
78 if (active) {
79 satellitereference->setActive(strncmp(strarray[1], "1", 1) == 0);
80 }
81 } catch (Inkscape::BadURIException &e) {
82 g_warning("%s (%s)", e.what(), strarray[0]);
83 satellitereference->detach();
84 }
85 }
86 g_strfreev(strarray);
87 return satellitereference;
88}
89
90template <>
91std::vector<NodeSatellite> ArrayParam<std::vector<NodeSatellite>>::readsvg(char const * const str)
92{
93 std::vector<NodeSatellite> subpath_nodesatellites;
94 if (!str) {
95 return subpath_nodesatellites;
96 }
97 auto const strarray = g_strsplit(str, "@", 0);
98 auto iter = strarray;
99 while (*iter != nullptr) {
100 auto const strsubarray = g_strsplit(*iter, ",", 8);
101 if (*strsubarray[7]) {//steps always > 0
102 NodeSatellite nodesatellite{};
103 nodesatellite.setNodeSatellitesType(g_strstrip(strsubarray[0]));
104 nodesatellite.is_time = strncmp(strsubarray[1], "1", 1) == 0;
105 nodesatellite.selected = strncmp(strsubarray[2], "1", 1) == 0;
106 nodesatellite.has_mirror = strncmp(strsubarray[3], "1", 1) == 0;
107 nodesatellite.hidden = strncmp(strsubarray[4], "1", 1) == 0;
108 double amount,angle;
109 float stepsTmp;
110 sp_svg_number_read_d(strsubarray[5], &amount);
111 sp_svg_number_read_d(strsubarray[6], &angle);
112 sp_svg_number_read_f(g_strstrip(strsubarray[7]), &stepsTmp);
113 unsigned int steps = (unsigned int)stepsTmp;
114 nodesatellite.amount = amount;
115 nodesatellite.angle = angle;
116 nodesatellite.steps = steps;
117 subpath_nodesatellites.push_back(std::move(nodesatellite));
118 }
119 g_strfreev (strsubarray);
120 iter++;
121 }
122 g_strfreev (strarray);
123 return subpath_nodesatellites;
124}
125
126} // namespace Inkscape::LivePathEffect
127
128/*
129 Local Variables:
130 mode:c++
131 c-file-style:"stroustrup"
132 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
133 indent-tabs-mode:nil
134 fill-column:99
135 End:
136*/
137// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
Cartesian point / 2D vector and related operations.
Two-dimensional point that doubles as a vector.
Definition point.h:66
StorageType readsvg(char const *str)
Represents an URI as per RFC 2396.
Definition uri.h:36
NodeSatellite a per node holder of data.
void setNodeSatellitesType(gchar const *A)
Map a nodesatellite type with gchar.
Integral and real coordinate types and some basic utilities.
constexpr Coord infinity()
Get a value representing infinity.
Definition coord.h:88
Live Path Effects code.
unsigned int sp_svg_number_read_f(gchar const *str, float *val)
unsigned int sp_svg_number_read_d(gchar const *str, double *val)