~valavanisalex/ubuntu/precise/inkscape/fix-943984

« back to all changes in this revision

Viewing changes to inkscape-0.47pre1/src/sp-polyline.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2009-07-02 17:09:45 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20090702170945-nn6d6zswovbwju1t
Tags: 0.47~pre1-0ubuntu1
* New upstream release.
  - Don't constrain maximization on small resolution devices (pre0)
    (LP: #348842)
  - Fixes segfault on startup (pre0)
    (LP: #391149)

Show diffs side-by-side

added added

removed removed

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