summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJeff Schiller <codedread@gmail.com>2008-08-23 06:13:23 +0000
committerjeff_schiller <jeff_schiller@users.sourceforge.net>2008-08-23 06:13:23 +0000
commit7dba27edc91ec41f0ab7fa30aab75c31e97a1947 (patch)
treeff29af2d0b0b053f4464a94eff8978bbdcf13dfe /src
parentHopefully fix for the recently experienced crashes when building with -O2. I ... (diff)
downloadinkscape-7dba27edc91ec41f0ab7fa30aab75c31e97a1947.tar.gz
inkscape-7dba27edc91ec41f0ab7fa30aab75c31e97a1947.zip
Support for title and desc elements when serializing as Plain SVG.
(bzr r6709)
Diffstat (limited to 'src')
-rw-r--r--src/Makefile_insert2
-rw-r--r--src/sp-desc.cpp76
-rw-r--r--src/sp-desc.h32
-rw-r--r--src/sp-flowregion.cpp4
-rw-r--r--src/sp-item-group.cpp4
-rw-r--r--src/sp-item.cpp26
-rw-r--r--src/sp-object-repr.cpp4
-rw-r--r--src/sp-text.cpp4
-rw-r--r--src/sp-title.cpp76
-rw-r--r--src/sp-title.h32
10 files changed, 260 insertions, 0 deletions
diff --git a/src/Makefile_insert b/src/Makefile_insert
index 876959798..2aaf3607b 100644
--- a/src/Makefile_insert
+++ b/src/Makefile_insert
@@ -166,6 +166,7 @@ libinkpre_a_SOURCES = \
sp-conn-end.cpp sp-conn-end.h \
sp-cursor.cpp sp-cursor.h \
sp-defs.cpp sp-defs.h \
+ sp-desc.cpp sp-desc.h \
sp-ellipse.cpp sp-ellipse.h \
sp-feblend.cpp sp-feblend.h \
sp-feblend-fns.h \
@@ -271,6 +272,7 @@ libinkpre_a_SOURCES = \
sp-switch.cpp sp-switch.h\
sp-text.cpp sp-text.h \
sp-textpath.h \
+ sp-title.cpp sp-title.h \
sp-tref-reference.cpp sp-tref-reference.h \
sp-tref.cpp sp-tref.h \
sp-tspan.cpp sp-tspan.h \
diff --git a/src/sp-desc.cpp b/src/sp-desc.cpp
new file mode 100644
index 000000000..1c8229847
--- /dev/null
+++ b/src/sp-desc.cpp
@@ -0,0 +1,76 @@
+#define __SP_DESC_C__
+
+/*
+ * SVG <desc> implementation
+ *
+ * Authors:
+ * Jeff Schiller <codedread@gmail.com>
+ *
+ * Copyright (C) 2008 Jeff Schiller
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "sp-desc.h"
+#include "xml/repr.h"
+
+static void sp_desc_class_init(SPDescClass *klass);
+static void sp_desc_init(SPDesc *rect);
+static Inkscape::XML::Node *sp_desc_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
+
+static SPObjectClass *desc_parent_class;
+
+GType
+sp_desc_get_type (void)
+{
+ static GType desc_type = 0;
+
+ if (!desc_type) {
+ GTypeInfo desc_info = {
+ sizeof (SPDescClass),
+ NULL, NULL,
+ (GClassInitFunc) sp_desc_class_init,
+ NULL, NULL,
+ sizeof (SPDesc),
+ 16,
+ (GInstanceInitFunc) sp_desc_init,
+ NULL, /* value_table */
+ };
+ desc_type = g_type_register_static (SP_TYPE_OBJECT, "SPDesc", &desc_info, (GTypeFlags)0);
+ }
+ return desc_type;
+}
+
+static void
+sp_desc_class_init(SPDescClass *klass)
+{
+ SPObjectClass *sp_object_class = (SPObjectClass *) klass;
+ desc_parent_class = (SPObjectClass *) g_type_class_ref(SP_TYPE_OBJECT);;
+
+ sp_object_class->write = sp_desc_write;
+}
+
+static void
+sp_desc_init(SPDesc */*desc*/)
+{
+}
+
+/*
+ * \brief Writes it's settings to an incoming repr object, if any
+ */
+static Inkscape::XML::Node *
+sp_desc_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags)
+{
+ if (!repr) {
+ repr = SP_OBJECT_REPR (object)->duplicate(doc);
+ }
+
+ if (((SPObjectClass *) desc_parent_class)->write)
+ ((SPObjectClass *) desc_parent_class)->write(object, doc, repr, flags);
+
+ return repr;
+}
diff --git a/src/sp-desc.h b/src/sp-desc.h
new file mode 100644
index 000000000..8c5a8a663
--- /dev/null
+++ b/src/sp-desc.h
@@ -0,0 +1,32 @@
+#ifndef __SP_DESC_H__
+#define __SP_DESC_H__
+
+/*
+ * SVG <desc> implementation
+ *
+ * Authors:
+ * Jeff Schiller <codedread@gmail.com>
+ *
+ * Copyright (C) 2008 Jeff Schiller
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include "sp-object.h"
+
+#define SP_TYPE_DESC (sp_desc_get_type ())
+#define SP_IS_DESC(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SP_TYPE_DESC))
+
+class SPDesc;
+class SPDescClass;
+
+struct SPDesc : public SPObject {
+};
+
+struct SPDescClass {
+ SPObjectClass parent_class;
+};
+
+GType sp_desc_get_type (void);
+
+#endif
diff --git a/src/sp-flowregion.cpp b/src/sp-flowregion.cpp
index 490407f81..3b45951b8 100644
--- a/src/sp-flowregion.cpp
+++ b/src/sp-flowregion.cpp
@@ -15,6 +15,8 @@
#include "sp-use.h"
#include "style.h"
#include "document.h"
+#include "sp-title.h"
+#include "sp-desc.h"
#include "sp-flowregion.h"
@@ -240,6 +242,7 @@ sp_flowregion_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscap
GSList *l = NULL;
for ( SPObject *child = sp_object_first_child(object) ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
+ if (SP_IS_TITLE(child) || SP_IS_DESC(child)) continue;
Inkscape::XML::Node *crepr = child->updateRepr(xml_doc, NULL, flags);
if (crepr) l = g_slist_prepend(l, crepr);
}
@@ -252,6 +255,7 @@ sp_flowregion_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscap
} else {
for ( SPObject *child = sp_object_first_child(object) ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
+ if (SP_IS_TITLE(child) || SP_IS_DESC(child)) continue;
child->updateRepr(flags);
}
}
diff --git a/src/sp-item-group.cpp b/src/sp-item-group.cpp
index 186b76663..4cea8aad5 100644
--- a/src/sp-item-group.cpp
+++ b/src/sp-item-group.cpp
@@ -45,6 +45,8 @@
#include "selection.h"
#include "live_effects/lpeobject.h"
#include "live_effects/lpeobject-reference.h"
+#include "sp-title.h"
+#include "sp-desc.h"
static void sp_group_class_init (SPGroupClass *klass);
static void sp_group_init (SPGroup *group);
@@ -233,6 +235,7 @@ sp_group_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XM
}
l = NULL;
for (child = sp_object_first_child(object); child != NULL; child = SP_OBJECT_NEXT(child) ) {
+ if (SP_IS_TITLE(child) || SP_IS_DESC(child)) continue;
crepr = child->updateRepr(xml_doc, NULL, flags);
if (crepr) l = g_slist_prepend (l, crepr);
}
@@ -243,6 +246,7 @@ sp_group_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XM
}
} else {
for (child = sp_object_first_child(object) ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
+ if (SP_IS_TITLE(child) || SP_IS_DESC(child)) continue;
child->updateRepr(flags);
}
}
diff --git a/src/sp-item.cpp b/src/sp-item.cpp
index f88d7b9e0..0d285c3f0 100644
--- a/src/sp-item.cpp
+++ b/src/sp-item.cpp
@@ -55,6 +55,8 @@
#include "sp-filter-reference.h"
#include "filter-chemistry.h"
#include "sp-guide.h"
+#include "sp-title.h"
+#include "sp-desc.h"
#include "libnr/nr-matrix-fns.h"
#include "libnr/nr-matrix-scale-ops.h"
@@ -657,8 +659,32 @@ sp_item_update(SPObject *object, SPCtx *ctx, guint flags)
static Inkscape::XML::Node *
sp_item_write(SPObject *const object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
{
+ SPObject *child;
SPItem *item = SP_ITEM(object);
+ // in the case of SP_OBJECT_WRITE_BUILD, the item should always be newly created,
+ // so we need to add any children from the underlying object to the new repr
+ if (flags & SP_OBJECT_WRITE_BUILD) {
+ Inkscape::XML::Node *crepr;
+ GSList *l;
+ l = NULL;
+ for (child = sp_object_first_child(object); child != NULL; child = SP_OBJECT_NEXT(child) ) {
+ if (!SP_IS_TITLE(child) && !SP_IS_DESC(child)) continue;
+ crepr = child->updateRepr(xml_doc, NULL, flags);
+ if (crepr) l = g_slist_prepend (l, crepr);
+ }
+ while (l) {
+ repr->addChild((Inkscape::XML::Node *) l->data, NULL);
+ Inkscape::GC::release((Inkscape::XML::Node *) l->data);
+ l = g_slist_remove (l, l->data);
+ }
+ } else {
+ for (child = sp_object_first_child(object) ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
+ if (!SP_IS_TITLE(child) && !SP_IS_DESC(child)) continue;
+ child->updateRepr(flags);
+ }
+ }
+
gchar *c = sp_svg_transform_write(item->transform);
repr->setAttribute("transform", c);
g_free(c);
diff --git a/src/sp-object-repr.cpp b/src/sp-object-repr.cpp
index 87c27214d..f45ed1283 100644
--- a/src/sp-object-repr.cpp
+++ b/src/sp-object-repr.cpp
@@ -81,6 +81,8 @@
#include "sp-feturbulence.h"
#include "sp-femergenode.h"
#include "live_effects/lpeobject.h"
+#include "sp-title.h"
+#include "sp-desc.h"
enum NameType { REPR_NAME, SODIPODI_TYPE };
@@ -138,6 +140,7 @@ populate_dtables()
{ "svg:color-profile", COLORPROFILE_TYPE },
{ "svg:clipPath", SP_TYPE_CLIPPATH },
{ "svg:defs", SP_TYPE_DEFS },
+ { "svg:desc", SP_TYPE_DESC },
{ "svg:ellipse", SP_TYPE_ELLIPSE },
{ "svg:filter", SP_TYPE_FILTER },
/* Note: flow* elements are proposed additions for SVG 1.2, they aren't in
@@ -203,6 +206,7 @@ populate_dtables()
{ "svg:symbol", SP_TYPE_SYMBOL },
{ "svg:text", SP_TYPE_TEXT },
{ "svg:textPath", SP_TYPE_TEXTPATH },
+ { "svg:title", SP_TYPE_TITLE },
{ "svg:tref", SP_TYPE_TREF },
{ "svg:tspan", SP_TYPE_TSPAN },
{ "svg:use", SP_TYPE_USE },
diff --git a/src/sp-text.cpp b/src/sp-text.cpp
index 09b926e63..59ced44e5 100644
--- a/src/sp-text.cpp
+++ b/src/sp-text.cpp
@@ -44,6 +44,8 @@
#include "xml/quote.h"
#include "xml/repr.h"
#include "mod360.h"
+#include "sp-title.h"
+#include "sp-desc.h"
#include "sp-textpath.h"
#include "sp-tref.h"
@@ -308,6 +310,7 @@ sp_text_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML
repr = xml_doc->createElement("svg:text");
GSList *l = NULL;
for (SPObject *child = sp_object_first_child(object) ; child != NULL ; child = SP_OBJECT_NEXT(child) ) {
+ if (SP_IS_TITLE(child) || SP_IS_DESC(child)) continue;
Inkscape::XML::Node *crepr = NULL;
if (SP_IS_STRING(child)) {
crepr = xml_doc->createTextNode(SP_STRING(child)->string.c_str());
@@ -323,6 +326,7 @@ sp_text_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML
}
} else {
for (SPObject *child = sp_object_first_child(object) ; child != NULL ; child = SP_OBJECT_NEXT(child) ) {
+ if (SP_IS_TITLE(child) || SP_IS_DESC(child)) continue;
if (SP_IS_STRING(child)) {
SP_OBJECT_REPR(child)->setContent(SP_STRING(child)->string.c_str());
} else {
diff --git a/src/sp-title.cpp b/src/sp-title.cpp
new file mode 100644
index 000000000..c820c70f0
--- /dev/null
+++ b/src/sp-title.cpp
@@ -0,0 +1,76 @@
+#define __SP_TITLE_C__
+
+/*
+ * SVG <title> implementation
+ *
+ * Authors:
+ * Jeff Schiller <codedread@gmail.com>
+ *
+ * Copyright (C) 2008 Jeff Schiller
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "sp-title.h"
+#include "xml/repr.h"
+
+static void sp_title_class_init(SPTitleClass *klass);
+static void sp_title_init(SPTitle *rect);
+static Inkscape::XML::Node *sp_title_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
+
+static SPObjectClass *title_parent_class;
+
+GType
+sp_title_get_type (void)
+{
+ static GType title_type = 0;
+
+ if (!title_type) {
+ GTypeInfo title_info = {
+ sizeof (SPTitleClass),
+ NULL, NULL,
+ (GClassInitFunc) sp_title_class_init,
+ NULL, NULL,
+ sizeof (SPTitle),
+ 16,
+ (GInstanceInitFunc) sp_title_init,
+ NULL, /* value_table */
+ };
+ title_type = g_type_register_static (SP_TYPE_OBJECT, "SPTitle", &title_info, (GTypeFlags)0);
+ }
+ return title_type;
+}
+
+static void
+sp_title_class_init(SPTitleClass *klass)
+{
+ SPObjectClass *sp_object_class = (SPObjectClass *) klass;
+ title_parent_class = (SPObjectClass *) g_type_class_ref(SP_TYPE_OBJECT);
+
+ sp_object_class->write = sp_title_write;
+}
+
+static void
+sp_title_init(SPTitle */*desc*/)
+{
+}
+
+/*
+ * \brief Writes it's settings to an incoming repr object, if any
+ */
+static Inkscape::XML::Node *
+sp_title_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags)
+{
+ if (!repr) {
+ repr = SP_OBJECT_REPR (object)->duplicate(doc);
+ }
+
+ if (((SPObjectClass *) title_parent_class)->write)
+ ((SPObjectClass *) title_parent_class)->write(object, doc, repr, flags);
+
+ return repr;
+}
diff --git a/src/sp-title.h b/src/sp-title.h
new file mode 100644
index 000000000..a5f0a2fea
--- /dev/null
+++ b/src/sp-title.h
@@ -0,0 +1,32 @@
+#ifndef __SP_TITLE_H__
+#define __SP_TITLE_H__
+
+/*
+ * SVG <title> implementation
+ *
+ * Authors:
+ * Jeff Schiller <codedread@gmail.com>
+ *
+ * Copyright (C) 2008 Jeff Schiller
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include "sp-object.h"
+
+#define SP_TYPE_TITLE (sp_title_get_type ())
+#define SP_IS_TITLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SP_TYPE_TITLE))
+
+class SPTitle;
+class SPTitleClass;
+
+struct SPTitle : public SPObject {
+};
+
+struct SPTitleClass {
+ SPObjectClass parent_class;
+};
+
+GType sp_title_get_type (void);
+
+#endif