1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
#define __SP_POLYLINE_C__
/*
* SVG <polyline> implementation
*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
*
* Copyright (C) 1999-2002 Lauris Kaplinski
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include "config.h"
#include "attributes.h"
#include "sp-polyline.h"
#include "display/curve.h"
#include <glibmm/i18n.h>
#include "xml/repr.h"
#include "document.h"
static void sp_polyline_class_init (SPPolyLineClass *klass);
static void sp_polyline_init (SPPolyLine *polyline);
static void sp_polyline_build (SPObject * object, SPDocument * document, Inkscape::XML::Node * repr);
static void sp_polyline_set (SPObject *object, unsigned int key, const gchar *value);
static Inkscape::XML::Node *sp_polyline_write (SPObject *object, Inkscape::XML::Node *repr, guint flags);
static gchar * sp_polyline_description (SPItem * item);
static SPShapeClass *parent_class;
GType
sp_polyline_get_type (void)
{
static GType polyline_type = 0;
if (!polyline_type) {
GTypeInfo polyline_info = {
sizeof (SPPolyLineClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) sp_polyline_class_init,
NULL, /* klass_finalize */
NULL, /* klass_data */
sizeof (SPPolyLine),
16, /* n_preallocs */
(GInstanceInitFunc) sp_polyline_init,
NULL, /* value_table */
};
polyline_type = g_type_register_static (SP_TYPE_SHAPE, "SPPolyLine", &polyline_info, (GTypeFlags)0);
}
return polyline_type;
}
static void
sp_polyline_class_init (SPPolyLineClass *klass)
{
GObjectClass * gobject_class;
SPObjectClass * sp_object_class;
SPItemClass * item_class;
gobject_class = (GObjectClass *) klass;
sp_object_class = (SPObjectClass *) klass;
item_class = (SPItemClass *) klass;
parent_class = (SPShapeClass *)g_type_class_ref (SP_TYPE_SHAPE);
sp_object_class->build = sp_polyline_build;
sp_object_class->set = sp_polyline_set;
sp_object_class->write = sp_polyline_write;
item_class->description = sp_polyline_description;
}
static void
sp_polyline_init (SPPolyLine * /*polyline*/)
{
/* Nothing here */
}
static void
sp_polyline_build (SPObject * object, SPDocument * document, Inkscape::XML::Node * repr)
{
if (((SPObjectClass *) parent_class)->build)
((SPObjectClass *) parent_class)->build (object, document, repr);
sp_object_read_attr (object, "points");
}
static void
sp_polyline_set (SPObject *object, unsigned int key, const gchar *value)
{
SPPolyLine *polyline;
polyline = SP_POLYLINE (object);
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 = NULL;
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;
}
}
sp_shape_set_curve (SP_SHAPE (polyline), curve, TRUE);
curve->unref();
break;
}
default:
if (((SPObjectClass *) parent_class)->set)
((SPObjectClass *) parent_class)->set (object, key, value);
break;
}
}
static Inkscape::XML::Node *
sp_polyline_write (SPObject *object, Inkscape::XML::Node *repr, guint flags)
{
SPPolyLine *polyline;
polyline = SP_POLYLINE (object);
if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_OBJECT_DOCUMENT(object));
repr = xml_doc->createElement("svg:polyline");
}
if (repr != SP_OBJECT_REPR (object)) {
repr->mergeFrom(SP_OBJECT_REPR (object), "id");
}
if (((SPObjectClass *) (parent_class))->write)
((SPObjectClass *) (parent_class))->write (object, repr, flags);
return repr;
}
static gchar *
sp_polyline_description(SPItem */*item*/)
{
return g_strdup(_("<b>Polyline</b>"));
}
|