dia r4253 - in trunk: . plug-ins/drs
- From: hans svn gnome org
- To: svn-commits-list gnome org
- Subject: dia r4253 - in trunk: . plug-ins/drs
- Date: Sun, 1 Feb 2009 18:03:56 +0000 (UTC)
Author: hans
Date: Sun Feb 1 18:03:56 2009
New Revision: 4253
URL: http://svn.gnome.org/viewvc/dia?rev=4253&view=rev
Log:
2009-02-01 Hans Breuer <hans breuer org>
* plug-ins/drs/dia-render-script-renderer.c
plug-ins/drs/dia-render-script.c : wrap <render>calls</render>,
save <properties/> by default
* plug-ins/drs/dia-render-script-import.c : more code, still unused
Modified:
trunk/ChangeLog
trunk/plug-ins/drs/dia-render-script-import.c
trunk/plug-ins/drs/dia-render-script-renderer.c
trunk/plug-ins/drs/dia-render-script.c
Modified: trunk/plug-ins/drs/dia-render-script-import.c
==============================================================================
--- trunk/plug-ins/drs/dia-render-script-import.c (original)
+++ trunk/plug-ins/drs/dia-render-script-import.c Sun Feb 1 18:03:56 2009
@@ -24,9 +24,22 @@
#include <config.h>
#include "geometry.h"
+#include "color.h"
+#include "diagramdata.h"
#include <libxml/tree.h>
+static real
+_parse_real (xmlNodePtr node, const char *attrib)
+{
+ xmlChar *str = xmlGetProp(node, (const xmlChar *)attrib);
+ real val = 0;
+ if (str) {
+ val = g_strtod ((gchar *)str, NULL);
+ xmlFree(str);
+ }
+ return val;
+}
static Point *
_parse_point (xmlNodePtr node, const char *attrib)
{
@@ -39,6 +52,7 @@
++ep;
pt->y = g_strtod (ep, NULL);
}
+ xmlFree(str);
}
return pt;
}
@@ -98,3 +112,67 @@
}
return arr;
}
+static Color *
+_parse_color (xmlNodePtr node, const char *attrib)
+{
+ xmlChar *str = xmlGetProp(node, (const xmlChar *)attrib);
+ Color *val = NULL;
+
+ if (str) {
+ PangoColor color;
+ if (!pango_color_parse (&color, (gchar *)str)) {
+ val = g_new (Color, 1);
+ val->red = color.red / 65535.0;
+ val->green = color.green / 65535.0;
+ val->blue = color.blue / 65535.0;
+ }
+ xmlFree(str);
+ }
+ return val;
+}
+
+typedef struct _RenderOp RenderOp;
+struct _RenderOp {
+ void (*render) (RenderOp *self, ...);
+ void (*destroy)(RenderOp *self);
+ void *params[6];
+};
+
+/*!
+ * Fill a GList* with objects which is to be put in a
+ * diagram or a group by the caller.
+ * Can be called recusively to allow groups in groups.
+ */
+static GList*
+read_items (xmlNodePtr startnode)
+{
+ xmlNodePtr node;
+ GList *items = NULL;
+
+ for (node = startnode; node != NULL; node = node->next) {
+ if (xmlIsBlankNode(node))
+ continue;
+ if (node->type != XML_ELEMENT_NODE)
+ continue;
+
+ }
+ return items;
+}
+
+/* imports the given SVG file, returns TRUE if successful */
+gboolean
+import_drs (const gchar *filename, DiagramData *dia, void* user_data)
+{
+ GList *item, *items;
+ xmlNodePtr root;
+ xmlDocPtr doc = xmlParseFile(filename);
+
+ items = read_items (root->xmlChildrenNode);
+ for (item = items; item != NULL; item = g_list_next (item)) {
+ DiaObject *obj = (DiaObject *)item->data;
+ layer_add_object(dia->active_layer, obj);
+ }
+ g_list_free (items);
+ xmlFreeDoc(doc);
+ return TRUE;
+}
Modified: trunk/plug-ins/drs/dia-render-script-renderer.c
==============================================================================
--- trunk/plug-ins/drs/dia-render-script-renderer.c (original)
+++ trunk/plug-ins/drs/dia-render-script-renderer.c Sun Feb 1 18:03:56 2009
@@ -103,6 +103,12 @@
g_queue_push_tail (renderer->parents, renderer->root);
renderer->root = node = xmlNewChild(renderer->root, NULL, (const xmlChar *)"object", NULL);
xmlSetProp(node, (const xmlChar *)"type", (xmlChar *)object->type->name);
+ /* if it looks like intdata store it as well */
+ if ((int)object->type->default_user_data > 0 && (int)object->type->default_user_data < 0xFF) {
+ gchar buffer[30];
+ g_snprintf(buffer, sizeof(buffer), "%d", (int)object->type->default_user_data);
+ xmlSetProp(node, (const xmlChar *)"intdata", (xmlChar *)buffer);
+ }
if (renderer->save_props) {
xmlNodePtr props_node;
@@ -110,8 +116,12 @@
object_save_props (object, props_node);
}
/* TODO: special handling for group object? */
- object->ops->draw(object, DIA_RENDERER (renderer));
-
+ {
+ g_queue_push_tail (renderer->parents, renderer->root);
+ renderer->root = node = xmlNewChild(renderer->root, NULL, (const xmlChar *)"render", NULL);
+ object->ops->draw(object, DIA_RENDERER (renderer));
+ renderer->root = g_queue_pop_tail (renderer->parents);
+ }
renderer->root = g_queue_pop_tail (renderer->parents);
}
Modified: trunk/plug-ins/drs/dia-render-script.c
==============================================================================
--- trunk/plug-ins/drs/dia-render-script.c (original)
+++ trunk/plug-ins/drs/dia-render-script.c Sun Feb 1 18:03:56 2009
@@ -32,14 +32,15 @@
* <meta />
* <layer name="" >
* <object type="">
- * <properties>
+ * <!-- optional stdprops to restore the real object type -->
+ * <properties />
* <render>
- * <set- />
- *
- * <rectangle />
- * <ellipse />
- * <string />
- * </render>
+ * <set-font />
+ * <draw-rectangle />
+ * <fill-ellipse />
+ * <draw-string />
+ * <!-- ... -->
+ * </render>
* </object>
* </layer>
* </diagram>
@@ -124,6 +125,8 @@
fclose(file);
}
renderer = DRS_RENDERER (g_object_new(DRS_TYPE_RENDERER, NULL));
+ /* store also object properties */
+ renderer->save_props = (user_data == NULL);
/* set up the root node */
doc = xmlNewDoc((const xmlChar *)"1.0");
@@ -138,7 +141,7 @@
drs_data_render(data, DIA_RENDERER(renderer));
- xmlSetDocCompressMode(doc, 0);
+ xmlSetDocCompressMode(doc, 1);
xmlDiaSaveFile(filename, doc);
xmlFreeDoc(doc);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]