dia r4215 - in trunk: . plug-ins plug-ins/drs
- From: hans svn gnome org
- To: svn-commits-list gnome org
- Subject: dia r4215 - in trunk: . plug-ins plug-ins/drs
- Date: Sat, 24 Jan 2009 13:48:42 +0000 (UTC)
Author: hans
Date: Sat Jan 24 13:48:42 2009
New Revision: 4215
URL: http://svn.gnome.org/viewvc/dia?rev=4215&view=rev
Log:
2009-01-24 Hans Breuer <hans breuer org>
[
Start of plug-in implementation around idea "DiaRenderScript", an
XML-dialect modelled after the DiaRenderer API. Currently it is
only useful for debugging other parts of Dia or itsef ;)
]
* plug-ins/drs/dia-render-script.dtd : to verify the xml files
* plug-ins/drs/dia-render-script-renderer.c : implementing allmost all
required and medium-level methods a renderer should have
* plug-ins/drs/dia-render-script.[ch] : registration of the exporter
and some dedicated diagram/layer render functions to preserve invisble
layers when writing .drs
* plug-ins/drs/dia-render-script-import.c : unfinished (some helpers
to parse back .drs, but far away from real import)
* plug-ins/drs/dia-render-script-object.c : mostly empty (should later
include the implmentation of a DiaObject capable to render .drs
* plug-ins/makefile.msc : build it
Added:
trunk/plug-ins/drs/
trunk/plug-ins/drs/dia-render-script-import.c (contents, props changed)
trunk/plug-ins/drs/dia-render-script-object.c (contents, props changed)
trunk/plug-ins/drs/dia-render-script-renderer.c (contents, props changed)
trunk/plug-ins/drs/dia-render-script-renderer.h (contents, props changed)
trunk/plug-ins/drs/dia-render-script.c (contents, props changed)
trunk/plug-ins/drs/dia-render-script.dtd
Modified:
trunk/ChangeLog
trunk/plug-ins/makefile.msc
Added: trunk/plug-ins/drs/dia-render-script-import.c
==============================================================================
--- (empty file)
+++ trunk/plug-ins/drs/dia-render-script-import.c Sat Jan 24 13:48:42 2009
@@ -0,0 +1,100 @@
+/* Dia -- an diagram creation/manipulation program
+ * Copyright (C) 1998 Alexander Larsson
+ *
+ * dia-render-script-import.c - plugin for dia
+ * Copyright (C) 2009, Hans Breuer, <Hans Breuer Org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/*! \file dia-render-script-import.c import of dia-render-script either to
+ * diagram with objects or maybe as one object */
+#include <config.h>
+
+#include "geometry.h"
+
+#include <libxml/tree.h>
+
+static Point *
+_parse_point (xmlNodePtr node, const char *attrib)
+{
+ xmlChar *str = xmlGetProp(node, (const xmlChar *)attrib);
+ Point *pt = g_new0(Point, 1);
+ if (str) {
+ gchar *ep = NULL;
+ pt->x = g_strtod ((gchar *)str, &ep);
+ if (ep) {
+ ++ep;
+ pt->y = g_strtod (ep, NULL);
+ }
+ }
+ return pt;
+}
+static GArray *
+_parse_points (xmlNodePtr node, const char *attrib)
+{
+ xmlChar *str = xmlGetProp(node, (const xmlChar *)attrib);
+ GArray *arr = NULL;
+
+ if (str) {
+ GArray *arr = g_array_new(FALSE, TRUE, sizeof(Point));
+ gint i;
+ gchar **split = g_strsplit ((gchar *)str, " ", -1);
+ gchar *val, *ep = NULL;
+ for (i = 0, val = split[i]; split[i] != NULL; ++i)
+ /* count them */;
+ g_array_set_size (arr, i);
+ for (i = 0, val = split[i]; split[i] != 0; ++i) {
+ Point *pt = &g_array_index(arr, Point, i);
+
+ pt->x = g_strtod (val, &ep);
+ pt->y = ep ? g_strtod (++ep, &ep) : 0;
+ }
+ g_strfreev(split);
+ xmlFree(str);
+ }
+ return arr;
+}
+static GArray *
+_parse_bezpoints (xmlNodePtr node, const char *attrib)
+{
+ xmlChar *str = xmlGetProp(node, (const xmlChar *)attrib);
+ GArray *arr = NULL;
+
+ if (str) {
+ GArray *arr = g_array_new(FALSE, TRUE, sizeof(BezPoint));
+ gint i;
+ gchar **split = g_strsplit ((gchar *)str, " ", -1);
+ gchar *val, *ep = NULL;
+ for (i = 0, val = split[i]; split[i] != NULL; ++i)
+ /* count them */;
+ g_array_set_size (arr, i);
+ for (i = 0, val = split[i]; split[i] != 0; ++i) {
+ BezPoint *pt = &g_array_index(arr, BezPoint, i);
+ pt->type = val[0] == 'M' ? BEZ_MOVE_TO : (val[0] == 'L' ? BEZ_LINE_TO : BEZ_CURVE_TO);
+ ep = (gchar *)str + 1;
+
+ pt->p1.x = ep ? g_strtod (ep, &ep) : 0;
+ pt->p1.y = ep ? g_strtod (++ep, &ep) : 0;
+ pt->p2.x = ep ? g_strtod (++ep, &ep) : 0;
+ pt->p2.y = ep ? g_strtod (++ep, &ep) : 0;
+ pt->p3.x = ep ? g_strtod (++ep, &ep) : 0;
+ pt->p3.y = ep ? g_strtod (++ep, &ep) : 0;
+ }
+ g_strfreev(split);
+ xmlFree(str);
+ }
+ return arr;
+}
Added: trunk/plug-ins/drs/dia-render-script-object.c
==============================================================================
--- (empty file)
+++ trunk/plug-ins/drs/dia-render-script-object.c Sat Jan 24 13:48:42 2009
@@ -0,0 +1 @@
+/*! DiaObject implementation directly renderering from dia-render-script */
Added: trunk/plug-ins/drs/dia-render-script-renderer.c
==============================================================================
--- (empty file)
+++ trunk/plug-ins/drs/dia-render-script-renderer.c Sat Jan 24 13:48:42 2009
@@ -0,0 +1,717 @@
+/* Dia -- an diagram creation/manipulation program
+ * Copyright (C) 1998 Alexander Larsson
+ *
+ * dia-render-script-renderer.c - plugin for dia
+ * Copyright (C) 2009, Hans Breuer, <Hans Breuer Org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/*! A DiaRenderer mapping every renderer method to some metafile representation */
+
+#include <config.h>
+
+#define G_LOG_DOMAIN "DiaRenderScript"
+#include <glib.h>
+
+#include "intl.h"
+#include "diarenderer.h"
+
+#include "object.h" /* object->type->name */
+#include "dia_image.h" /* dia_image_filename */
+#include "properties.h" /* object_save_props */
+
+#include <pango/pango.h>
+
+#include "dia-render-script-renderer.h"
+
+static gpointer parent_class = NULL;
+
+/* constructor */
+static void
+drs_renderer_init (GTypeInstance *self, gpointer g_class)
+{
+ DrsRenderer *renderer = DRS_RENDERER (self);
+
+ renderer->parents = g_queue_new ();
+ renderer->save_props = FALSE;
+}
+
+/* destructor */
+static void
+drs_renderer_finalize (GObject *object)
+{
+ DrsRenderer *renderer = DRS_RENDERER (object);
+
+ g_queue_free (renderer->parents);
+
+ G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static void drs_renderer_class_init (DrsRendererClass *klass);
+
+GType
+drs_renderer_get_type (void)
+{
+ static GType object_type = 0;
+
+ if (!object_type)
+ {
+ static const GTypeInfo object_info =
+ {
+ sizeof (DrsRendererClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) drs_renderer_class_init,
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof (DrsRenderer),
+ 0, /* n_preallocs */
+ drs_renderer_init /* init */
+ };
+
+ object_type = g_type_register_static (DIA_TYPE_RENDERER,
+ "DrsRenderer",
+ &object_info, 0);
+ }
+
+ return object_type;
+}
+
+/*
+ * renderer methods
+ */
+static void
+draw_object(DiaRenderer *self,
+ DiaObject *object)
+{
+ DrsRenderer *renderer = DRS_RENDERER (self);
+ xmlNodePtr node;
+
+ 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 (renderer->save_props) {
+ xmlNodePtr props_node;
+
+ props_node = xmlNewChild(node, NULL, (const xmlChar *)"properties", NULL);
+ object_save_props (object, props_node);
+ }
+ /* TODO: special handling for group object? */
+ object->ops->draw(object, DIA_RENDERER (renderer));
+
+ renderer->root = g_queue_pop_tail (renderer->parents);
+}
+
+static void
+begin_render(DiaRenderer *self)
+{
+ DrsRenderer *renderer = DRS_RENDERER (self);
+ xmlNodePtr node;
+
+ renderer->root = node = xmlNewChild(renderer->root, NULL, (const xmlChar *)"diagram", NULL);
+#if 0
+ _node_set_color (node, "bg_color", &data->bg_color);
+#endif
+}
+static void
+end_render(DiaRenderer *self)
+{
+ DrsRenderer *renderer = DRS_RENDERER (self);
+
+ renderer->root = g_queue_pop_tail (renderer->parents);
+}
+
+
+static void
+_node_set_color (xmlNodePtr node, const char *name, const Color *color)
+{
+ gchar *value;
+
+ value = g_strdup_printf ("#%02x%02x%02x",
+ (int)ceil(255*color->red), (int)ceil(255*color->green),
+ (int)ceil(255*color->blue));
+ xmlSetProp(node, (const xmlChar *)name, (xmlChar *)value);
+ g_free (value);
+}
+static void
+_node_set_real (xmlNodePtr node, const char *name, real v)
+{
+ gchar value[G_ASCII_DTOSTR_BUF_SIZE];
+
+ g_ascii_formatd (value, sizeof(value), "%g", v);
+ xmlSetProp (node, (const xmlChar *)name, (xmlChar *)value);
+}
+static void
+_string_append_point (GString *str, Point *pt, gboolean first)
+{
+ gchar value[G_ASCII_DTOSTR_BUF_SIZE];
+
+ if (!first)
+ g_string_append (str, " ");
+ g_ascii_formatd (value, sizeof(value), "%g", pt->x);
+ g_string_append (str, value);
+ g_string_append (str, ",");
+ g_ascii_formatd (value, sizeof(value), "%g", pt->y);
+ g_string_append (str, value);
+}
+static void
+_node_set_point (xmlNodePtr node, const char *name, Point *point)
+{
+ GString *str;
+
+ str = g_string_new (NULL);
+ _string_append_point (str, point, TRUE);
+ xmlSetProp(node, (const xmlChar *)name, (xmlChar *) str->str);
+
+ g_string_free(str, TRUE);
+}
+static void
+_node_set_points (xmlNodePtr node, Point *points, int num_points)
+{
+ GString *str;
+ int i;
+
+ str = g_string_new (NULL);
+
+ for (i = 0; i < num_points; ++i)
+ _string_append_point (str, &points[i], i == 0);
+ xmlSetProp(node, (const xmlChar *)"points", (xmlChar *) str->str);
+
+ g_string_free(str, TRUE);
+}
+static void
+_node_set_bezpoints (xmlNodePtr node, BezPoint *points, int num_points)
+{
+ GString *str = NULL;
+ int i;
+
+ str = g_string_new (NULL);
+
+ for (i = 0; i < num_points; ++i) {
+ BezPoint *bpt = &points[i];
+ if (i != 0)
+ g_string_append (str, " ");
+ switch (bpt->type) {
+ case BEZ_MOVE_TO:
+ g_string_append (str, "M");
+ break;
+ case BEZ_LINE_TO:
+ g_string_append (str, "L");
+ break;
+ case BEZ_CURVE_TO:
+ g_string_append (str, "C");
+ break;
+ }
+ _string_append_point (str, &points[i].p1, TRUE);
+ if (bpt->type == BEZ_CURVE_TO) {
+ /* no space between bez-points, simplifies parsing */
+ g_string_append (str, ";");
+ _string_append_point (str, &points[i].p2, TRUE);
+ g_string_append (str, ";");
+ _string_append_point (str, &points[i].p3, TRUE);
+ }
+ }
+ xmlSetProp(node, (const xmlChar *)"bezpoints", (xmlChar *) str->str);
+
+ g_string_free(str, TRUE);
+}
+
+static void
+set_linewidth(DiaRenderer *self, real width)
+{
+ DrsRenderer *renderer = DRS_RENDERER (self);
+ xmlNodePtr node;
+
+ node = xmlNewChild(renderer->root, NULL, (const xmlChar *)"set-linewidth", NULL);
+ _node_set_real (node, "width", width);
+}
+
+static void
+set_linecaps(DiaRenderer *self, LineCaps mode)
+{
+ DrsRenderer *renderer = DRS_RENDERER (self);
+ xmlNodePtr node;
+ gchar *value = NULL;
+
+ switch(mode) {
+ case LINECAPS_BUTT:
+ value = "butt";
+ break;
+ case LINECAPS_ROUND:
+ value = "round";
+ break;
+ case LINECAPS_PROJECTING:
+ value = "projecting";
+ break;
+ /* intentionally no default to let 'good' compilers warn about new constants*/
+ }
+ node = xmlNewChild(renderer->root, NULL, (const xmlChar *)"set-linecaps", NULL);
+ xmlSetProp(node, (const xmlChar *)"mode",
+ value ? (xmlChar *)value : (xmlChar *)"?");
+}
+
+static void
+set_linejoin(DiaRenderer *self, LineJoin mode)
+{
+ DrsRenderer *renderer = DRS_RENDERER (self);
+ xmlNodePtr node;
+ gchar *value = NULL;
+
+ switch(mode) {
+ case LINEJOIN_MITER:
+ value = "miter";
+ break;
+ case LINEJOIN_ROUND:
+ value = "round";
+ break;
+ case LINEJOIN_BEVEL:
+ value = "bevel";
+ break;
+ /* intentionally no default to let 'good' compilers warn about new constants*/
+ }
+ node = xmlNewChild(renderer->root, NULL, (const xmlChar *)"set-linejoin", NULL);
+ xmlSetProp(node, (const xmlChar *)"mode",
+ value ? (xmlChar *)value : (xmlChar *)"?");
+}
+
+static void
+set_linestyle(DiaRenderer *self, LineStyle mode)
+{
+ DrsRenderer *renderer = DRS_RENDERER (self);
+ xmlNodePtr node;
+ const gchar *value;
+
+ /* line type */
+ switch (mode) {
+ case LINESTYLE_SOLID:
+ value = "solid";
+ break;
+ case LINESTYLE_DASHED:
+ value = "dashed";
+ break;
+ case LINESTYLE_DASH_DOT:
+ value = "dash-dot";
+ break;
+ case LINESTYLE_DASH_DOT_DOT:
+ value = "dash-dot-dot";
+ break;
+ case LINESTYLE_DOTTED:
+ value = "dotted";
+ break;
+ /* intentionally no default to let 'good' compilers warn about new constants*/
+ }
+ node = xmlNewChild(renderer->root, NULL, (const xmlChar *)"set-linestyle", NULL);
+ xmlSetProp(node, (const xmlChar *)"mode",
+ value ? (xmlChar *)value : (xmlChar *)"?");
+}
+
+static void
+set_dashlength(DiaRenderer *self, real length)
+{
+ DrsRenderer *renderer = DRS_RENDERER (self);
+ xmlNodePtr node;
+
+ node = xmlNewChild(renderer->root, NULL, (const xmlChar *)"set-dashlength", NULL);
+ _node_set_real (node, "length", length);
+}
+
+static void
+set_fillstyle(DiaRenderer *self, FillStyle mode)
+{
+ DrsRenderer *renderer = DRS_RENDERER (self);
+ xmlNodePtr node;
+ const gchar *value = NULL;
+
+ switch(mode) {
+ case FILLSTYLE_SOLID:
+ value = "solid";
+ break;
+ /* intentionally no default to let 'good' compilers warn about new constants*/
+ }
+ node = xmlNewChild(renderer->root, NULL, (const xmlChar *)"set-fillstyle", NULL);
+ xmlSetProp(node, (const xmlChar *)"mode",
+ value ? (xmlChar *)value : (xmlChar *)"?");
+}
+
+static void
+set_font(DiaRenderer *self, DiaFont *font, real height)
+{
+ DrsRenderer *renderer = DRS_RENDERER (self);
+ xmlNodePtr node;
+ const PangoFontDescription *pfd = dia_font_get_description (font);
+ char *desc = pango_font_description_to_string (pfd);
+
+ node = xmlNewChild(renderer->root, NULL, (const xmlChar *)"set-font", NULL);
+ xmlSetProp(node, (const xmlChar *)"description", (xmlChar *)desc);
+
+ xmlSetProp(node, (const xmlChar *)"family", (xmlChar *)dia_font_get_family (font));
+ xmlSetProp(node, (const xmlChar *)"weight", (xmlChar *)dia_font_get_weight_string (font));
+ xmlSetProp(node, (const xmlChar *)"slant", (xmlChar *)dia_font_get_slant_string (font));
+ _node_set_real (node, "size", dia_font_get_size (font));
+ _node_set_real (node, "height", height);
+
+ g_free(desc);
+}
+
+static void
+draw_line(DiaRenderer *self,
+ Point *start, Point *end,
+ Color *color)
+{
+ DrsRenderer *renderer = DRS_RENDERER (self);
+ xmlNodePtr node;
+
+ node = xmlNewChild(renderer->root, NULL, (const xmlChar *)"draw-line", NULL);
+ _node_set_point (node, "start", start);
+ _node_set_point (node, "end", end);
+ _node_set_color (node, "stroke", color);
+}
+
+static void
+draw_polyline(DiaRenderer *self,
+ Point *points, int num_points,
+ Color *color)
+{
+ DrsRenderer *renderer = DRS_RENDERER (self);
+ xmlNodePtr node;
+
+ node = xmlNewChild(renderer->root, NULL, (const xmlChar *)"draw-polyline", NULL);
+ _node_set_points (node, points, num_points);
+ _node_set_color (node, "stroke", color);
+}
+
+static void
+_polygon(DiaRenderer *self,
+ Point *points, int num_points,
+ Color *color,
+ gboolean fill)
+{
+ DrsRenderer *renderer = DRS_RENDERER (self);
+ xmlNodePtr node;
+
+ g_return_if_fail(1 < num_points);
+
+ node = xmlNewChild(renderer->root, NULL,
+ (const xmlChar *)(fill ? "fill-polygon" : "draw-polygon"), NULL);
+ _node_set_points (node, points, num_points);
+ if (fill)
+ _node_set_color (node, (const xmlChar *)"fill", color);
+ else
+ _node_set_color (node, (const xmlChar *)"stroke", color);
+}
+static void
+draw_polygon(DiaRenderer *self,
+ Point *points, int num_points,
+ Color *color)
+{
+ _polygon (self, points, num_points, color, FALSE);
+}
+
+static void
+fill_polygon(DiaRenderer *self,
+ Point *points, int num_points,
+ Color *color)
+{
+ _polygon (self, points, num_points, color, TRUE);
+}
+
+static void
+_rounded_rect(DiaRenderer *self,
+ Point *lefttop, Point *rightbottom,
+ Color *color, real *rounding, gboolean fill)
+{
+ DrsRenderer *renderer = DRS_RENDERER (self);
+ xmlNodePtr node;
+
+ if (rounding)
+ node = xmlNewChild(renderer->root, NULL,
+ (const xmlChar *)(fill ? "fill-rounded-rect" : "draw-rounded-rect"), NULL);
+ else
+ node = xmlNewChild(renderer->root, NULL,
+ (const xmlChar *)(fill ? "fill-rect" : "draw-rect"), NULL);
+
+ _node_set_point (node, "lefttop", lefttop);
+ _node_set_point (node, "rightbottom", rightbottom);
+ if (rounding)
+ _node_set_real (node, (const xmlChar *)"r", *rounding);
+ if (fill)
+ _node_set_color (node, (const xmlChar *)"fill", color);
+ else
+ _node_set_color (node, (const xmlChar *)"stroke", color);
+}
+static void
+draw_rect(DiaRenderer *self,
+ Point *lefttop, Point *rightbottom,
+ Color *color)
+{
+ _rounded_rect(self, lefttop, rightbottom, color, NULL, FALSE);
+}
+static void
+fill_rect(DiaRenderer *self,
+ Point *lefttop, Point *rightbottom,
+ Color *color)
+{
+ _rounded_rect(self, lefttop, rightbottom, color, NULL, TRUE);
+}
+static void
+draw_rounded_rect(DiaRenderer *self,
+ Point *lefttop, Point *rightbottom,
+ Color *color, real rounding)
+{
+ _rounded_rect(self, lefttop, rightbottom, color, &rounding, FALSE);
+}
+static void
+fill_rounded_rect(DiaRenderer *self,
+ Point *lefttop, Point *rightbottom,
+ Color *color, real rounding)
+{
+ _rounded_rect(self, lefttop, rightbottom, color, &rounding, FALSE);
+}
+
+static void
+_arc(DiaRenderer *self,
+ Point *center,
+ real width, real height,
+ real angle1, real angle2,
+ Color *color,
+ gboolean fill)
+{
+ DrsRenderer *renderer = DRS_RENDERER (self);
+ xmlNodePtr node;
+
+ node = xmlNewChild(renderer->root, NULL, (const xmlChar *)(fill ? "fill-arc" : "draw-arc"), NULL);
+ _node_set_point (node, "center", center);
+ _node_set_real (node, "width", width);
+ _node_set_real (node, "height", height);
+ _node_set_real (node, "angle1", angle1);
+ _node_set_real (node, "angle2", angle2);
+ if (fill)
+ _node_set_color (node, "fill", color);
+ else
+ _node_set_color (node, "stroke", color);
+}
+static void
+draw_arc(DiaRenderer *self,
+ Point *center,
+ real width, real height,
+ real angle1, real angle2,
+ Color *color)
+{
+ _arc (self, center, width, height, angle1, angle2, color, FALSE);
+}
+static void
+fill_arc(DiaRenderer *self,
+ Point *center,
+ real width, real height,
+ real angle1, real angle2,
+ Color *color)
+{
+ _arc (self, center, width, height, angle1, angle2, color, TRUE);
+}
+
+static void
+_ellipse(DiaRenderer *self,
+ Point *center,
+ real width, real height,
+ Color *color,
+ gboolean fill)
+{
+ DrsRenderer *renderer = DRS_RENDERER (self);
+ xmlNodePtr node;
+
+ node = xmlNewChild(renderer->root, NULL,
+ (const xmlChar *)(fill ? "fill-ellipse" : "draw-ellipse"), NULL);
+ _node_set_point (node, "center", center);
+ _node_set_real (node, "width", width);
+ _node_set_real (node, "height", height);
+ if (fill)
+ _node_set_color (node, "fill", color);
+ else
+ _node_set_color (node, "stroke", color);
+}
+static void
+draw_ellipse(DiaRenderer *self,
+ Point *center,
+ real width, real height,
+ Color *color)
+{
+ _ellipse (self, center, width, height, color, FALSE);
+}
+static void
+fill_ellipse(DiaRenderer *self,
+ Point *center,
+ real width, real height,
+ Color *color)
+{
+ _ellipse (self, center, width, height, color, TRUE);
+}
+
+static void
+_bezier(DiaRenderer *self,
+ BezPoint *points,
+ int numpoints,
+ Color *color,
+ gboolean fill)
+{
+ DrsRenderer *renderer = DRS_RENDERER (self);
+ xmlNodePtr node;
+
+ node = xmlNewChild (renderer->root, NULL,
+ (const xmlChar *)(fill ? "fill-bezier" : "draw-bezier"), NULL);
+ _node_set_bezpoints (node, points, numpoints);
+ if (fill)
+ _node_set_color (node, "fill", color);
+ else
+ _node_set_color (node, "stroke", color);
+}
+static void
+draw_bezier(DiaRenderer *self,
+ BezPoint *points,
+ int numpoints,
+ Color *color)
+{
+ _bezier (self, points, numpoints, color, FALSE);
+}
+static void
+fill_bezier(DiaRenderer *self,
+ BezPoint *points,
+ int numpoints,
+ Color *color)
+{
+ _bezier (self, points, numpoints, color, TRUE);
+}
+
+static void
+draw_rounded_polyline (DiaRenderer *self,
+ Point *points, int num_points,
+ Color *color, real radius )
+{
+ DrsRenderer *renderer = DRS_RENDERER (self);
+ xmlNodePtr node;
+
+ node = xmlNewChild (renderer->root, NULL, (const xmlChar *)"draw-rounded-polyline", NULL);
+ _node_set_points (node, points, num_points);
+ _node_set_color (node, (const xmlChar *)"stroke", color);
+ _node_set_real (node, "r", radius);
+}
+
+static void
+draw_string(DiaRenderer *self,
+ const char *text,
+ Point *pos, Alignment alignment,
+ Color *color)
+{
+ DrsRenderer *renderer = DRS_RENDERER (self);
+ xmlNodePtr node;
+ gchar *align = NULL;
+
+ node = xmlNewChild(renderer->root, NULL, (const xmlChar *)"draw-string", NULL);
+ _node_set_point (node, "pos", pos);
+ _node_set_color (node, "fill", color);
+ switch (alignment) {
+ case ALIGN_LEFT :
+ align = "left";
+ break;
+ case ALIGN_RIGHT :
+ align = "right";
+ break;
+ case ALIGN_CENTER :
+ align = "center";
+ break;
+ /* intentionally no default */
+ }
+ if (align)
+ xmlSetProp(node, (const xmlChar *)"alignment", (xmlChar *) align);
+
+ xmlNodeSetContent (node, (const xmlChar *)text);
+}
+
+static void
+draw_image(DiaRenderer *self,
+ Point *point,
+ real width, real height,
+ DiaImage image)
+{
+ DrsRenderer *renderer = DRS_RENDERER (self);
+ xmlNodePtr node;
+ gchar *uri;
+
+ node = xmlNewChild(renderer->root, NULL, (const xmlChar *)"draw-image", NULL);
+ _node_set_point (node, "point", point);
+ _node_set_real (node, "width", width);
+ _node_set_real (node, "height", height);
+ /* TODO: also save the data? */
+ uri = g_filename_to_uri (dia_image_filename(image), NULL, NULL);
+ if (uri)
+ xmlSetProp (node, (const xmlChar *)"uri", (xmlChar *) uri);
+ g_free (uri);
+}
+
+static void
+drs_renderer_class_init (DrsRendererClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ DiaRendererClass *renderer_class = DIA_RENDERER_CLASS (klass);
+
+ parent_class = g_type_class_peek_parent (klass);
+
+ object_class->finalize = drs_renderer_finalize;
+
+ /* renderer members */
+ renderer_class->begin_render = begin_render;
+ renderer_class->end_render = end_render;
+
+ renderer_class->draw_object = draw_object;
+
+ renderer_class->set_linewidth = set_linewidth;
+ renderer_class->set_linecaps = set_linecaps;
+ renderer_class->set_linejoin = set_linejoin;
+ renderer_class->set_linestyle = set_linestyle;
+ renderer_class->set_dashlength = set_dashlength;
+ renderer_class->set_fillstyle = set_fillstyle;
+
+ renderer_class->set_font = set_font;
+
+ renderer_class->draw_line = draw_line;
+ renderer_class->fill_polygon = fill_polygon;
+ renderer_class->draw_rect = draw_rect;
+ renderer_class->fill_rect = fill_rect;
+ renderer_class->draw_arc = draw_arc;
+ renderer_class->fill_arc = fill_arc;
+ renderer_class->draw_ellipse = draw_ellipse;
+ renderer_class->fill_ellipse = fill_ellipse;
+
+ renderer_class->draw_string = draw_string;
+ renderer_class->draw_image = draw_image;
+
+ /* medium level functions */
+ renderer_class->draw_rect = draw_rect;
+ renderer_class->draw_polyline = draw_polyline;
+ renderer_class->draw_polygon = draw_polygon;
+
+ renderer_class->draw_bezier = draw_bezier;
+ renderer_class->fill_bezier = fill_bezier;
+
+ renderer_class->draw_rounded_polyline = draw_rounded_polyline;
+ /* highest level functions */
+ renderer_class->draw_rounded_rect = draw_rounded_rect;
+ renderer_class->fill_rounded_rect = fill_rounded_rect;
+#if 0
+ renderer_class->draw_text = draw_text;
+ renderer_class->draw_text_line = draw_text_line;
+ /* TODO: more to come ... */
+#endif
+}
Added: trunk/plug-ins/drs/dia-render-script-renderer.h
==============================================================================
--- (empty file)
+++ trunk/plug-ins/drs/dia-render-script-renderer.h Sat Jan 24 13:48:42 2009
@@ -0,0 +1,57 @@
+/* Dia -- an diagram creation/manipulation program
+ * Copyright (C) 1998 Alexander Larsson
+ *
+ * dia-render-script.h - plugin for dia
+ * Copyright (C) 2009, Hans Breuer, <Hans Breuer Org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+#include "diarenderer.h"
+#include <libxml/tree.h>
+
+G_BEGIN_DECLS
+
+#define DRS_TYPE_RENDERER (drs_renderer_get_type ())
+#define DRS_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DRS_TYPE_RENDERER, DrsRenderer))
+#define DRS_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DRS_TYPE_RENDERER, DrsRendererClass))
+#define DRS_IS_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DRS_TYPE_RENDERER))
+#define DRS_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DRS_TYPE_RENDERER, DrsRendererClass))
+
+GType drs_renderer_get_type (void) G_GNUC_CONST;
+
+typedef struct _DrsRenderer DrsRenderer;
+typedef struct _DrsRendererClass DrsRendererClass;
+
+struct _DrsRenderer
+{
+ DiaRenderer parent_instance;
+
+ gboolean save_props;
+
+ /*< private >*/
+ /*! current root */
+ xmlNodePtr root;
+ /* track the parents */
+ GQueue *parents;
+};
+
+struct _DrsRendererClass
+{
+ DiaRendererClass parent_class;
+};
+
+void drs_render_layer (DiaRenderer *self, Layer *layer);
+
+G_END_DECLS
Added: trunk/plug-ins/drs/dia-render-script.c
==============================================================================
--- (empty file)
+++ trunk/plug-ins/drs/dia-render-script.c Sat Jan 24 13:48:42 2009
@@ -0,0 +1,168 @@
+/* Dia -- an diagram creation/manipulation program
+ * Copyright (C) 1998 Alexander Larsson
+ *
+ * dia-render-script.c - plugin for dia
+ * Copyright (C) 2009, Hans Breuer, <Hans Breuer Org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/* Dia Render File - Serialization of Dia Renderers.
+ * May also provide some DiaObject implementation which could offer parameters like
+ * - scale: overall scaling of the 'object diagram' done on the renderer level
+ * - tweaking renderer parameters otherwise not in the UI, e.g. LineCaps
+ *
+ * The format is similar to Windows MetaFile.i.e a serialization of function calls together
+ * with their parameters.
+ * An XML representation as well as some binary variant could be provided.
+ *
+ * <diagram>
+ * <meta />
+ * <layer name="" >
+ * <object type="">
+ * <properties>
+ * <render>
+ * <set- />
+ *
+ * <rectangle />
+ * <ellipse />
+ * <string />
+ * </render>
+ * </object>
+ * </layer>
+ * </diagram>
+ */
+
+#include <config.h>
+
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#define G_LOG_DOMAIN "DiaRenderScript"
+#include <glib.h>
+#include <gstdio.h>
+
+#include "intl.h"
+#include "filter.h"
+#include "plug-ins.h"
+#include "message.h"
+#include "diagramdata.h"
+#include "dia_xml_libxml.h"
+
+#include "dia-render-script-renderer.h"
+
+static void
+drs_render_layer (DiaRenderer *self, Layer *layer)
+{
+ DrsRenderer *renderer = DRS_RENDERER (self);
+ xmlNodePtr node;
+ GList *list;
+ DiaObject *obj;
+ DiaRendererClass *renderer_class = DIA_RENDERER_GET_CLASS(renderer);
+
+ g_queue_push_tail (renderer->parents, renderer->root);
+ renderer->root = node = xmlNewChild(renderer->root, NULL, (const xmlChar *)"layer", NULL);
+ xmlSetProp(node, (const xmlChar *)"name", (xmlChar *)layer->name);
+ xmlSetProp(node, (const xmlChar *)"visible", (xmlChar *)(layer->visible ? "true" : "false"));
+
+ /* Draw all objects: */
+ list = layer->objects;
+ while (list!=NULL) {
+ obj = (DiaObject *) list->data;
+ renderer_class->draw_object(self, obj);
+ list = g_list_next(list);
+ }
+
+ renderer->root = g_queue_pop_tail (renderer->parents);
+}
+
+/*! own version to render invisible layers, too */
+static void
+drs_data_render (DiagramData *data, DiaRenderer *renderer)
+{
+ int i;
+
+ DIA_RENDERER_GET_CLASS(renderer)->begin_render(renderer);
+ for (i=0; i<data->layers->len; i++) {
+ Layer *layer = (Layer *) g_ptr_array_index(data->layers, i);
+ drs_render_layer (renderer, layer);
+ }
+ DIA_RENDERER_GET_CLASS(renderer)->end_render(renderer);
+}
+
+/* dia export funtion */
+static void
+export_data(DiagramData *data, const gchar *filename,
+ const gchar *diafilename, void* user_data)
+{
+ DrsRenderer *renderer;
+ xmlDtdPtr dtd;
+ xmlDocPtr doc;
+
+ /* write check - almost same code in every renderer */
+ {
+ FILE *file = g_fopen(filename, "w");
+
+ if (!file) {
+ message_error(_("Can't open output file %s: %s\n"),
+ dia_message_filename(filename), strerror(errno));
+ return;
+ }
+ fclose(file);
+ }
+ renderer = DRS_RENDERER (g_object_new(DRS_TYPE_RENDERER, NULL));
+
+ /* set up the root node */
+ doc = xmlNewDoc((const xmlChar *)"1.0");
+ doc->encoding = xmlStrdup((const xmlChar *)"UTF-8");
+ doc->standalone = FALSE;
+ dtd = xmlCreateIntSubset(doc, (const xmlChar *)"drs",
+ (const xmlChar *)"-//DIA//DTD DRS " VERSION "//EN",
+ (const xmlChar *)"http://projects.gnome.org/dia/dia-render-script.dtd");
+ xmlAddChild((xmlNodePtr) doc, (xmlNodePtr) dtd);
+ renderer->root = xmlNewDocNode(doc, NULL, (const xmlChar *)"drs", NULL);
+ xmlAddSibling(doc->children, (xmlNodePtr) renderer->root);
+
+ drs_data_render(data, DIA_RENDERER(renderer));
+
+ xmlSetDocCompressMode(doc, 0);
+ xmlDiaSaveFile(filename, doc);
+ xmlFreeDoc(doc);
+
+ g_object_unref(renderer);
+}
+
+static const gchar *extensions[] = { "drs", NULL };
+DiaExportFilter export_filter = {
+ N_("DiaRenderScript"),
+ extensions,
+ export_data
+};
+
+DIA_PLUGIN_CHECK_INIT
+
+PluginInitResult
+dia_plugin_init(PluginInfo *info)
+{
+ if (!dia_plugin_info_init(info, "drs",
+ N_("DiaRenderScript filter"),
+ NULL, NULL))
+ return DIA_PLUGIN_INIT_ERROR;
+
+ filter_register_export(&export_filter);
+
+ return DIA_PLUGIN_INIT_OK;
+}
Added: trunk/plug-ins/drs/dia-render-script.dtd
==============================================================================
--- (empty file)
+++ trunk/plug-ins/drs/dia-render-script.dtd Sat Jan 24 13:48:42 2009
@@ -0,0 +1,162 @@
+<!ELEMENT drs (diagram) >
+<!ATTLIST drs
+ xmlns:drs CDATA #FIXED "http://projects.gnome.org/dia/dia-render-script.dtd" >
+
+<!ELEMENT diagram (meta|layer)* >
+
+<!ELEMENT layer (object)*>
+<!ATTLIST layer
+ name CDATA #REQUIRED
+ visible (true|false) #REQUIRED
+ active (true|false) #IMPLIED>
+
+<!ELEMENT object (object|
+ set-linewidth|set-linecaps|set-linejoin|set-linestyle|set-dashlength|set-fillstyle|set-font|
+ draw-line|draw-polyline|draw-rounded-polyline|draw-polygon|fill-polygon|
+ draw-rect|fill-rect|draw-rounded-rect|fill-rounded-rect|
+ draw-arc|fill-arc|draw-ellipse|fill-ellipse|
+ draw-bezier|fill-bezier|
+ draw-string|draw-image)* >
+<!ATTLIST object
+ type CDATA #IMPLIED >
+
+
+<!ELEMENT set-linewidth EMPTY >
+<!ATTLIST set-linewidth
+ width CDATA #REQUIRED >
+
+<!ELEMENT set-linecaps EMPTY >
+<!ATTLIST set-linecaps
+ mode (butt|round|projecting) #REQUIRED >
+
+<!ELEMENT set-linejoin EMPTY >
+<!ATTLIST set-linejoin
+ mode (miter|round|bevel) #REQUIRED >
+
+<!ELEMENT set-linestyle EMPTY >
+<!ATTLIST set-linestyle
+ mode (solid|dashed|dash-dot|dash-dot-dot|dotted) #REQUIRED >
+
+<!ELEMENT set-dashlength EMPTY >
+<!ATTLIST set-dashlength
+ length CDATA #REQUIRED >
+
+<!ELEMENT set-fillstyle EMPTY >
+<!ATTLIST set-fillstyle
+ mode (solid) #REQUIRED >
+
+<!ELEMENT set-font EMPTY >
+<!ATTLIST set-font
+ family CDATA #REQUIRED
+ height CDATA #REQUIRED
+ description CDATA #IMPLIED
+ slant CDATA #IMPLIED
+ size CDATA #IMPLIED
+ weight CDATA #IMPLIED>
+
+<!ELEMENT draw-line EMPTY >
+<!ATTLIST draw-line
+ start CDATA #REQUIRED
+ end CDATA #REQUIRED
+ stroke CDATA #IMPLIED>
+
+<!ELEMENT draw-polyline EMPTY >
+<!ATTLIST draw-polyline
+ points CDATA #REQUIRED
+ stroke CDATA #IMPLIED>
+
+<!ELEMENT draw-rounded-polyline EMPTY >
+<!ATTLIST draw-rounded-polyline
+ points CDATA #REQUIRED
+ r CDATA #REQUIRED
+ stroke CDATA #IMPLIED>
+
+<!ELEMENT draw-polygon EMPTY >
+<!ATTLIST draw-polygon
+ points CDATA #REQUIRED
+ stroke CDATA #IMPLIED >
+
+<!ELEMENT fill-polygon EMPTY >
+<!ATTLIST fill-polygon
+ points CDATA #REQUIRED
+ fill CDATA #IMPLIED>
+
+<!ELEMENT draw-rect EMPTY >
+<!ATTLIST draw-rect
+ lefttop CDATA #REQUIRED
+ rightbottom CDATA #REQUIRED
+ stroke CDATA #IMPLIED>
+
+<!ELEMENT fill-rect EMPTY >
+<!ATTLIST fill-rect
+ lefttop CDATA #REQUIRED
+ rightbottom CDATA #REQUIRED
+ fill CDATA #IMPLIED>
+
+<!ELEMENT draw-rounded-rect EMPTY >
+<!ATTLIST draw-rounded-rect
+ lefttop CDATA #REQUIRED
+ rightbottom CDATA #REQUIRED
+ r CDATA #REQUIRED
+ stroke CDATA #IMPLIED>
+
+<!ELEMENT fill-rounded-rect EMPTY >
+<!ATTLIST fill-rounded-rect
+ lefttop CDATA #REQUIRED
+ rightbottom CDATA #REQUIRED
+ r CDATA #REQUIRED
+ fill CDATA #IMPLIED>
+
+<!ELEMENT draw-arc EMPTY >
+<!ATTLIST draw-arc
+ center CDATA #REQUIRED
+ width CDATA #REQUIRED
+ height CDATA #REQUIRED
+ angle1 CDATA #REQUIRED
+ angle2 CDATA #REQUIRED
+ stroke CDATA #IMPLIED>
+
+<!ELEMENT fill-arc EMPTY >
+<!ATTLIST fill-arc
+ center CDATA #REQUIRED
+ width CDATA #REQUIRED
+ height CDATA #REQUIRED
+ angle1 CDATA #REQUIRED
+ angle2 CDATA #REQUIRED
+ fill CDATA #IMPLIED>
+
+<!ELEMENT draw-ellipse EMPTY >
+<!ATTLIST draw-ellipse
+ center CDATA #REQUIRED
+ width CDATA #REQUIRED
+ height CDATA #REQUIRED
+ stroke CDATA #IMPLIED>
+
+<!ELEMENT fill-ellipse EMPTY >
+<!ATTLIST fill-ellipse
+ center CDATA #REQUIRED
+ width CDATA #REQUIRED
+ height CDATA #REQUIRED
+ fill CDATA #IMPLIED>
+
+<!ELEMENT draw-bezier EMPTY >
+<!ATTLIST draw-bezier
+ bezpoints CDATA #REQUIRED
+ stroke CDATA #IMPLIED>
+<!ELEMENT fill-bezier EMPTY >
+<!ATTLIST fill-bezier
+ bezpoints CDATA #REQUIRED
+ fill CDATA #IMPLIED>
+
+<!ELEMENT draw-string ANY >
+<!ATTLIST draw-string
+ pos CDATA #IMPLIED
+ fill CDATA #IMPLIED
+ alignment (left|right|center) #IMPLIED >
+
+<!ELEMENT draw-image EMPTY >
+<!ATTLIST draw-image
+ point CDATA #REQUIRED
+ width CDATA #REQUIRED
+ height CDATA #REQUIRED
+ uri CDATA #IMPLIED >
Modified: trunk/plug-ins/makefile.msc
==============================================================================
--- trunk/plug-ins/makefile.msc (original)
+++ trunk/plug-ins/makefile.msc Sat Jan 24 13:48:42 2009
@@ -2,9 +2,8 @@
# dummy sissi
PLUGINS = cairo cgm dxf hpgl libart metapost pgf pixbuf \
- postscript pstricks shape svg vdx wmf wpg xfig xslt
-
-#broken since StdProp overhaul : diaimport
+ postscript pstricks shape svg vdx wmf wpg xfig xslt \
+ drs
# The main target
all : sub-all
@@ -64,6 +63,14 @@
diacairo-print.obj
!ENDIF
+!IFDEF OBJ_drs
+OBJECTS = \
+ dia-render-script.obj \
+ dia-render-script-object.obj \
+ dia-render-script-renderer.obj \
+ dia-render-script-import.obj
+!ENDIF
+
!IFDEF OBJ_dxf
OBJECTS = \
autocad_pal.obj \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]