diff options
| author | MenTaLguY <mental@rydia.net> | 2006-01-16 02:36:01 +0000 |
|---|---|---|
| committer | mental <mental@users.sourceforge.net> | 2006-01-16 02:36:01 +0000 |
| commit | 179fa413b047bede6e32109e2ce82437c5fb8d34 (patch) | |
| tree | a5a6ac2c1708bd02288fbd8edb2ff500ff2e0916 /src/sp-string.cpp | |
| download | inkscape-179fa413b047bede6e32109e2ce82437c5fb8d34.tar.gz inkscape-179fa413b047bede6e32109e2ce82437c5fb8d34.zip | |
moving trunk for module inkscape
(bzr r1)
Diffstat (limited to 'src/sp-string.cpp')
| -rw-r--r-- | src/sp-string.cpp | 178 |
1 files changed, 178 insertions, 0 deletions
diff --git a/src/sp-string.cpp b/src/sp-string.cpp new file mode 100644 index 000000000..ba3df3ef2 --- /dev/null +++ b/src/sp-string.cpp @@ -0,0 +1,178 @@ +#define __SP_STRING_C__ + +/* + * SVG <text> and <tspan> implementation + * + * Author: + * Lauris Kaplinski <lauris@kaplinski.com> + * + * Copyright (C) 1999-2002 Lauris Kaplinski + * Copyright (C) 2000-2001 Ximian, Inc. + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +/* + * fixme: + * + * These subcomponents should not be items, or alternately + * we have to invent set of flags to mark, whether standard + * attributes are applicable to given item (I even like this + * idea somewhat - Lauris) + * + */ + + + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + + +#include "sp-string.h" +#include "xml/repr.h" + + +/*##################################################### +# SPSTRING +#####################################################*/ + +static void sp_string_class_init(SPStringClass *classname); +static void sp_string_init(SPString *string); + +static void sp_string_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); +static void sp_string_release(SPObject *object); +static void sp_string_read_content(SPObject *object); +static void sp_string_update(SPObject *object, SPCtx *ctx, unsigned flags); + +static void sp_string_calculate_dimensions(SPString *string); + +static SPObjectClass *string_parent_class; + +GType +sp_string_get_type() +{ + static GType type = 0; + if (!type) { + GTypeInfo info = { + sizeof(SPStringClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) sp_string_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof(SPString), + 16, /* n_preallocs */ + (GInstanceInitFunc) sp_string_init, + NULL, /* value_table */ + }; + type = g_type_register_static(SP_TYPE_OBJECT, "SPString", &info, (GTypeFlags)0); + } + return type; +} + +static void +sp_string_class_init(SPStringClass *classname) +{ + SPObjectClass *sp_object_class; + SPItemClass *item_class; + + sp_object_class = (SPObjectClass *) classname; + item_class = (SPItemClass *) classname; + + string_parent_class = (SPObjectClass*)g_type_class_ref(SP_TYPE_OBJECT); + + sp_object_class->build = sp_string_build; + sp_object_class->release = sp_string_release; + sp_object_class->read_content = sp_string_read_content; + sp_object_class->update = sp_string_update; +} + +static void +sp_string_init(SPString *string) +{ + new (&string->string) Glib::ustring(); +} + +static void +sp_string_build(SPObject *object, SPDocument *doc, Inkscape::XML::Node *repr) +{ + sp_string_read_content(object); + + if (((SPObjectClass *) string_parent_class)->build) + ((SPObjectClass *) string_parent_class)->build(object, doc, repr); +} + +static void +sp_string_release(SPObject *object) +{ + SPString *string = SP_STRING(object); + + string->string.~ustring(); + + if (((SPObjectClass *) string_parent_class)->release) + ((SPObjectClass *) string_parent_class)->release(object); +} + +static void +sp_string_read_content(SPObject *object) +{ + SPString *string = SP_STRING(object); + + string->string.clear(); + gchar const *xml_string = string->repr->content(); + // see algorithms described in svg 1.1 section 10.15 + if (object->xml_space.value == SP_XML_SPACE_PRESERVE) { + for ( ; *xml_string ; xml_string = g_utf8_next_char(xml_string) ) { + gunichar c = g_utf8_get_char(xml_string); + if (c == '\n' || c == '\t') c = ' '; + string->string += c; + } + } + else { + bool whitespace = false; + for ( ; *xml_string ; xml_string = g_utf8_next_char(xml_string) ) { + gunichar c = g_utf8_get_char(xml_string); + if (c == '\n') continue; + if (c == ' ' || c == '\t') whitespace = true; + else { + if (whitespace && (!string->string.empty() || SP_OBJECT_PREV(object) != NULL)) + string->string += ' '; + string->string += c; + whitespace = false; + } + } + if (whitespace && SP_OBJECT_REPR(object)->next() != NULL) // can't use SP_OBJECT_NEXT() when the SPObject tree is still being built + string->string += ' '; + } + object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); +} + +static void +sp_string_update(SPObject *object, SPCtx *ctx, unsigned flags) +{ + if (((SPObjectClass *) string_parent_class)->update) + ((SPObjectClass *) string_parent_class)->update(object, ctx, flags); + + if (flags & (SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_MODIFIED_FLAG)) { + /* Parent style or we ourselves changed, so recalculate */ + flags &= ~SP_OBJECT_USER_MODIFIED_FLAG_B; // won't be "just a transformation" anymore, we're going to recompute "x" and "y" attributes + sp_string_calculate_dimensions(SP_STRING(object)); + } +} + +static void +sp_string_calculate_dimensions(SPString *) +{ +} + +/* + 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:encoding=utf-8:textwidth=99 : |
