sp-string.cpp revision a2759d9c7b73ddc82d2f402fab0fa0ac660eb051
246N/A#define __SP_STRING_C__
246N/A
246N/A/*
281N/A * SVG <text> and <tspan> implementation
281N/A *
246N/A * Author:
131N/A * Lauris Kaplinski <lauris@kaplinski.com>
131N/A *
131N/A * Copyright (C) 1999-2002 Lauris Kaplinski
131N/A * Copyright (C) 2000-2001 Ximian, Inc.
131N/A *
131N/A * Released under GNU GPL, read the file 'COPYING' for more information
131N/A */
131N/A
131N/A/*
131N/A * fixme:
131N/A *
131N/A * These subcomponents should not be items, or alternately
131N/A * we have to invent set of flags to mark, whether standard
131N/A * attributes are applicable to given item (I even like this
131N/A * idea somewhat - Lauris)
131N/A *
131N/A */
131N/A
131N/A
144N/A
131N/A#ifdef HAVE_CONFIG_H
131N/A# include "config.h"
246N/A#endif
131N/A
131N/A
183N/A#include "sp-string.h"
183N/A#include "xml/repr.h"
131N/A
131N/A
131N/A/*#####################################################
131N/A# SPSTRING
131N/A#####################################################*/
340N/A
340N/Astatic void sp_string_class_init(SPStringClass *classname);
131N/Astatic void sp_string_init(SPString *string);
131N/A
131N/Astatic void sp_string_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
246N/Astatic void sp_string_release(SPObject *object);
131N/Astatic void sp_string_read_content(SPObject *object);
131N/Astatic void sp_string_update(SPObject *object, SPCtx *ctx, unsigned flags);
183N/A
183N/Astatic SPObjectClass *string_parent_class;
131N/A
131N/AGType
131N/Asp_string_get_type()
131N/A{
340N/A static GType type = 0;
340N/A if (!type) {
340N/A GTypeInfo info = {
340N/A sizeof(SPStringClass),
131N/A NULL, /* base_init */
131N/A NULL, /* base_finalize */
131N/A (GClassInitFunc) sp_string_class_init,
131N/A NULL, /* class_finalize */
131N/A NULL, /* class_data */
131N/A sizeof(SPString),
131N/A 16, /* n_preallocs */
131N/A (GInstanceInitFunc) sp_string_init,
214N/A NULL, /* value_table */
214N/A };
131N/A type = g_type_register_static(SP_TYPE_OBJECT, "SPString", &info, (GTypeFlags)0);
131N/A }
131N/A return type;
131N/A}
131N/A
131N/Astatic void
131N/Asp_string_class_init(SPStringClass *classname)
131N/A{
131N/A SPObjectClass *sp_object_class;
131N/A
131N/A sp_object_class = (SPObjectClass *) classname;
131N/A
131N/A string_parent_class = (SPObjectClass*)g_type_class_ref(SP_TYPE_OBJECT);
131N/A
131N/A sp_object_class->build = sp_string_build;
131N/A sp_object_class->release = sp_string_release;
131N/A sp_object_class->read_content = sp_string_read_content;
131N/A sp_object_class->update = sp_string_update;
131N/A}
131N/A
131N/Astatic void
131N/Asp_string_init(SPString *string)
131N/A{
131N/A new (&string->string) Glib::ustring();
131N/A}
131N/A
227N/Astatic void
131N/Asp_string_build(SPObject *object, SPDocument *doc, Inkscape::XML::Node *repr)
131N/A{
131N/A sp_string_read_content(object);
131N/A
131N/A if (((SPObjectClass *) string_parent_class)->build)
131N/A ((SPObjectClass *) string_parent_class)->build(object, doc, repr);
131N/A}
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
}
}
/*
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 :