Code

clean up unused code
[inkscape.git] / src / sp-string.cpp
1 #define __SP_STRING_C__
3 /*
4  * SVG <text> and <tspan> implementation
5  *
6  * Author:
7  *   Lauris Kaplinski <lauris@kaplinski.com>
8  *
9  * Copyright (C) 1999-2002 Lauris Kaplinski
10  * Copyright (C) 2000-2001 Ximian, Inc.
11  *
12  * Released under GNU GPL, read the file 'COPYING' for more information
13  */
15 /*
16  * fixme:
17  *
18  * These subcomponents should not be items, or alternately
19  * we have to invent set of flags to mark, whether standard
20  * attributes are applicable to given item (I even like this
21  * idea somewhat - Lauris)
22  *
23  */
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
32 #include "sp-string.h"
33 #include "xml/repr.h"
36 /*#####################################################
37 #  SPSTRING
38 #####################################################*/
40 static void sp_string_class_init(SPStringClass *classname);
41 static void sp_string_init(SPString *string);
43 static void sp_string_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
44 static void sp_string_release(SPObject *object);
45 static void sp_string_read_content(SPObject *object);
46 static void sp_string_update(SPObject *object, SPCtx *ctx, unsigned flags);
48 static SPObjectClass *string_parent_class;
50 GType
51 sp_string_get_type()
52 {
53     static GType type = 0;
54     if (!type) {
55         GTypeInfo info = {
56             sizeof(SPStringClass),
57             NULL,    /* base_init */
58             NULL,    /* base_finalize */
59             (GClassInitFunc) sp_string_class_init,
60             NULL,    /* class_finalize */
61             NULL,    /* class_data */
62             sizeof(SPString),
63             16,    /* n_preallocs */
64             (GInstanceInitFunc) sp_string_init,
65             NULL,    /* value_table */
66         };
67         type = g_type_register_static(SP_TYPE_OBJECT, "SPString", &info, (GTypeFlags)0);
68     }
69     return type;
70 }
72 static void
73 sp_string_class_init(SPStringClass *classname)
74 {
75     SPObjectClass *sp_object_class;
76     SPItemClass   *item_class;
78     sp_object_class = (SPObjectClass *) classname;
80     string_parent_class = (SPObjectClass*)g_type_class_ref(SP_TYPE_OBJECT);
82     sp_object_class->build        = sp_string_build;
83     sp_object_class->release      = sp_string_release;
84     sp_object_class->read_content = sp_string_read_content;
85     sp_object_class->update       = sp_string_update;
86 }
88 static void
89 sp_string_init(SPString *string)
90 {
91     new (&string->string) Glib::ustring();
92 }
94 static void
95 sp_string_build(SPObject *object, SPDocument *doc, Inkscape::XML::Node *repr)
96 {
97     sp_string_read_content(object);
99     if (((SPObjectClass *) string_parent_class)->build)
100         ((SPObjectClass *) string_parent_class)->build(object, doc, repr);
103 static void
104 sp_string_release(SPObject *object)
106     SPString *string = SP_STRING(object);
108     string->string.~ustring();
110     if (((SPObjectClass *) string_parent_class)->release)
111         ((SPObjectClass *) string_parent_class)->release(object);
114 static void
115 sp_string_read_content(SPObject *object)
117     SPString *string = SP_STRING(object);
119     string->string.clear();
120     gchar const *xml_string = string->repr->content();
121     // see algorithms described in svg 1.1 section 10.15
122     if (object->xml_space.value == SP_XML_SPACE_PRESERVE) {
123         for ( ; *xml_string ; xml_string = g_utf8_next_char(xml_string) ) {
124             gunichar c = g_utf8_get_char(xml_string);
125             if (c == '\n' || c == '\t') c = ' ';
126             string->string += c;
127         }
128     }
129     else {
130         bool whitespace = false;
131         for ( ; *xml_string ; xml_string = g_utf8_next_char(xml_string) ) {
132             gunichar c = g_utf8_get_char(xml_string);
133             if (c == '\n') continue;
134             if (c == ' ' || c == '\t') whitespace = true;
135             else {
136                 if (whitespace && (!string->string.empty() || SP_OBJECT_PREV(object) != NULL))
137                     string->string += ' ';
138                 string->string += c;
139                 whitespace = false;
140             }
141         }
142         if (whitespace && SP_OBJECT_REPR(object)->next() != NULL)   // can't use SP_OBJECT_NEXT() when the SPObject tree is still being built
143             string->string += ' ';
144     }
145     object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
148 static void
149 sp_string_update(SPObject *object, SPCtx *ctx, unsigned flags)
151     if (((SPObjectClass *) string_parent_class)->update)
152         ((SPObjectClass *) string_parent_class)->update(object, ctx, flags);
154     if (flags & (SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_MODIFIED_FLAG)) {
155         /* Parent style or we ourselves changed, so recalculate */
156         flags &= ~SP_OBJECT_USER_MODIFIED_FLAG_B; // won't be "just a transformation" anymore, we're going to recompute "x" and "y" attributes
157     }
161 /*
162   Local Variables:
163   mode:c++
164   c-file-style:"stroustrup"
165   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
166   indent-tabs-mode:nil
167   fill-column:99
168   End:
169 */
170 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :