Code

Support for title and desc elements when serializing as Plain SVG.
authorjeff_schiller <jeff_schiller@users.sourceforge.net>
Sat, 23 Aug 2008 06:13:23 +0000 (06:13 +0000)
committerjeff_schiller <jeff_schiller@users.sourceforge.net>
Sat, 23 Aug 2008 06:13:23 +0000 (06:13 +0000)
src/Makefile_insert
src/sp-desc.cpp [new file with mode: 0644]
src/sp-desc.h [new file with mode: 0644]
src/sp-flowregion.cpp
src/sp-item-group.cpp
src/sp-item.cpp
src/sp-object-repr.cpp
src/sp-text.cpp
src/sp-title.cpp [new file with mode: 0644]
src/sp-title.h [new file with mode: 0644]

index 8769597985933bf4ba945a065705cb97f0300775..2aaf3607b41af4fe1c72b5716e28d5190409fad2 100644 (file)
@@ -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 (file)
index 0000000..1c82298
--- /dev/null
@@ -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 (file)
index 0000000..8c5a8a6
--- /dev/null
@@ -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
index 490407f81150ef9dc7e1dffa09d9ad8483865623..3b45951b8232655c0af3b02bf9a58c837877bba3 100644 (file)
@@ -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);
         }
     }
index 186b766635f1115ee63e0817401f4fd83af249c5..4cea8aad5fde6d52f32aa49dd0809c4acb4d55fe 100644 (file)
@@ -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);
                }
        }
index f88d7b9e04b728f2047e9f031c752c98078f7275..0d285c3f0f3c970b5b80548d4734282bf21e6df6 100644 (file)
@@ -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);
index 87c27214dbd974e3de3db760c246aa44f9c3d0c8..f45ed12830094aa45027c49d5f140e6b817ef806 100644 (file)
@@ -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 },
index 09b926e63de723f77e8bbcd55c00edde7898f960..59ced44e56e836bd8f33b64068feb15ad2dd3ed3 100644 (file)
@@ -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 (file)
index 0000000..c820c70
--- /dev/null
@@ -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 (file)
index 0000000..a5f0a2f
--- /dev/null
@@ -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