]> saetta.ns0.it Git - reptool/libreptool/commitdiff
Started RptReport.
authorAndrea Zagli <azagli@libero.it>
Sat, 17 Mar 2007 18:15:19 +0000 (18:15 +0000)
committerAndrea Zagli <azagli@libero.it>
Sat, 17 Mar 2007 18:15:19 +0000 (18:15 +0000)
git-svn-id: svn+ssh://saetta.homelinux.org/svn/libreptool/trunk@3 3191ed1d-3fce-41bb-ab4a-0cebc0943b59

19 files changed:
configure.ac
data/reptool.dtd
data/reptool_report.dtd
src/Makefile.am
src/libreptool.h
src/rptcommon.c [new file with mode: 0644]
src/rptcommon.h [new file with mode: 0644]
src/rptobject.c [new file with mode: 0644]
src/rptobject.h [new file with mode: 0644]
src/rptobjecttext.c [new file with mode: 0644]
src/rptobjecttext.h [new file with mode: 0644]
src/rptprint.c
src/rptprint.h
src/rptreport.c [new file with mode: 0644]
src/rptreport.h [new file with mode: 0644]
tests/rptprint.c
tests/test.rptr [deleted file]
tests/test_report.rpt [new file with mode: 0644]
tests/test_rptprint.rptr [new file with mode: 0644]

index c56acbfef4227c4a7a22ab1aba9c072b6393bd15..c4193c2efa5594a800ede271b4165057bd5ab809 100644 (file)
@@ -21,6 +21,7 @@ GTK_DOC_CHECK
 PKG_CHECK_MODULES([REPTOOL], [glib-2.0 >= 2.6.0
                               gobject-2.0 >= 2.6.0
                               libxml-2.0 >= 2.6.0
+                              libgda >= 1.2.3
                               cairo >= 1.0.0
                               pangocairo >= 1.12])
 
index 2efcf242455803b9bf20ef88a04d5e6c7ce97d51..5146ec34f36e183acae498fe76a518740f8dd6b7 100644 (file)
@@ -1,12 +1,19 @@
 <!ENTITY % objects
- "text*, line*, rect*, image*"
 "text*, line*, rect*, image*"
 >
 
-<!ENTITY % object_attrs
- "x1   CDATA #REQUIRED
-  y1   CDATA #REQUIRED
-  x2   CDATA #REQUIRED
-  y2   CDATA #REQUIRED"
+<!ENTITY % object_commons_attrs
+  "name   CDATA #REQUIRED"
+>
+
+<!ENTITY % object_position_attrs
+  "x        CDATA #REQUIRED
+   y        CDATA #REQUIRED"
+>
+
+<!ENTITY % object_size_attrs
+ "width    CDATA #REQUIRED
+  height   CDATA #REQUIRED"
 >
 
 <!ENTITY % object_data_attrs
   border-left-style     CDATA #IMPLIED"
 >
 
-<!ENTITY % object_draw_attrs
+<!ENTITY % object_stroke_attrs
  "stroke-width   CDATA #IMPLIED
   stroke-color   CDATA #IMPLIED
-  stroke-style   CDATA #IMPLIED
-  fill-color     CDATA #IMPLIED"
+  stroke-style   CDATA #IMPLIED"
 >
 
 <!ENTITY % object_font_attrs
@@ -40,7 +46,9 @@
   font-size          CDATA #IMPLIED
   font-bold          (y | n) #IMPLIED
   font-italic        (y | n) #IMPLIED
-  font-underline     (y | n) #IMPLIED"
+  font-underline     (y | n) #IMPLIED
+  font-strike        (y | n) #IMPLIED
+  font-color         CDATA #IMPLIED"
 >
 
 <!ENTITY % object_text_align_attrs
   vertical-align     (top | center | bottom) #IMPLIED"
 >
 
-<!ELEMENT text EMPTY>
+<!ELEMENT text (#PCDATA)>
 <!ATTLIST text
-  %object_attrs;
-  %object_data_attr;
+  %object_commons_attrs;
+  %object_position_attrs;
+  %object_size_attrs;
   %object_border_attrs;
-  %object_draw_attrs;
   %object_font_attrs;
   %object_text_align_attrs;
->
-
-<!ELEMENT rect EMPTY>
-<!ATTLIST rect
-  %object_attrs;
-  %object_border_attrs;
-  %object_draw_attrs;
+  %object_data_attrs;
+  background-color   CDATA #IMPLIED
+  padding-top        CDATA #IMPLIED
+  padding-right      CDATA #IMPLIED
+  padding-bottom     CDATA #IMPLIED
+  padding-left       CDATA #IMPLIED
+  adapt              (to-text | none) #IMPLIED
 >
 
 <!ELEMENT line EMPTY>
 <!ATTLIST line
-  %object_attrs;
-  %object_draw_attrs;
+  %object_commons_attrs;
+  %object_poisition_attrs;
+  %object_size_attrs;
+  %object_stroke_attrs;
+>
+
+<!ELEMENT rect EMPTY>
+<!ATTLIST rect
+  %object_commons_attrs;
+  %object_poisition_attrs;
+  %object_size_attrs;
+  %object_stroke_attrs;
+  fill-color   CDATA #IMPLIED
 >
 
 <!ELEMENT image EMPTY>
 <!ATTLIST image
-  %object_attrs;
-  %object_data_attr;
+  %object_commons_attrs;
+  %object_position_attrs;
+  %object_size_attrs;
   %object_border_attrs;
+  source   CDATA #REQUIRED
+  adapt    (to-box | to-image | none) #IMPLIED
 >
 
 <!ELEMENT reptool (page, database?, report)>
 
 <!ELEMENT page EMPTY>
 <!ATTLIST page
-  size            (A3, A4, A5, LETTER, LEGAL, TABLOID, CUSTOM) "A4"
-  width           CDATA #IMPLIED
-  height          CDATA #IMPLIED
-  orientation     (0 | 90 | 180 | 270) "0"
+  width           CDATA #REQUIRED
+  height          CDATA #REQUIRED
   margin-top      CDATA #IMPLIED
   margin-right    CDATA #IMPLIED
   margin-bottom   CDATA #IMPLIED
   margin-left     CDATA #IMPLIED
 >
 
-<!ELEMENT database EMPTY>
-<!ATTLIST database
-  provider        CDATA #REQUIRED
-  connection_string CDATA #REQUIRED
-  sql             CDATA #REQUIRED
->
+<!ELEMENT database (provider, connection_string, sql)>
+<!ELEMENT provider (#PCDATA)>
+<!ELEMENT connection_string (#PCDATA)>
+<!ELEMENT sql (#PCDATA)>
 
 <!ELEMENT report (report-header?, report-footer?, page-header?, page-footer?, group*, body)>
 
index 5fe1e16fd5c7ab721d308de275d6950401156647..bc7cff75cb94e764f028d1fb9941f182fc37fcaf 100644 (file)
@@ -6,6 +6,7 @@
  "x        CDATA #REQUIRED
   y        CDATA #REQUIRED"
 >
+
 <!ENTITY % object_size_attrs
  "width    CDATA #REQUIRED
   height   CDATA #REQUIRED"
index 27617e4a2aa20298c80e74edbfaf1d758a76ffc3..572fee6fa3bc1d75ce912cfaf920488af4ff1e22 100644 (file)
@@ -4,6 +4,16 @@ AM_CPPFLAGS = $(REPTOOL_CFLAGS)
 
 lib_LTLIBRARIES = libreptool.la
 
-libreptool_la_SOURCES = rptprint.c
+libreptool_la_SOURCES = \
+                        rptobject.c \
+                        rptobjecttext.c \
+                        rptreport.c \
+                        rptprint.c \
+                        rptcommon.c
 
-include_HEADERS = rptprint.h
+include_HEADERS = \
+                  rptobject.h \
+                  rptobjecttext.h \
+                  rptreport.h \
+                  rptprint.h \
+                  rptcommon.h
index f7b585163e5ee69d68cdbecce426cf8f190b1f63..c81832be78bd4fb5a63542e560ff5e6ee411b736 100644 (file)
@@ -20,6 +20,7 @@
 #ifndef __LIBREPTOOL_H__
 #define __LIBREPTOOL_H__
 
+#include <rptreport.h>
 #include <rptprint.h>
 
 #endif /* __LIBREPTOOL_H__ */
diff --git a/src/rptcommon.c b/src/rptcommon.c
new file mode 100644 (file)
index 0000000..54952a6
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2006-2007 Andrea Zagli <azagli@inwind.it>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library 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
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "rptcommon.h"
+
+void
+rpt_common_get_position (xmlNode *xnode, RptPoint *position)
+{
+       gchar *prop;
+
+       position->x = 0.0;
+       position->y = 0.0;
+
+       prop = xmlGetProp (xnode, (const xmlChar *)"x");
+       if (prop != NULL)
+               {
+                       position->x = strtod (prop, NULL);
+               }
+       prop = xmlGetProp (xnode, (const xmlChar *)"y");
+       if (prop != NULL)
+               {
+                       position->y = strtod (prop, NULL);
+               }
+}
+
+void
+rpt_common_get_size (xmlNode *xnode, RptSize *size)
+{
+       gchar *prop;
+
+       size->width = 0.0;
+       size->height = 0.0;
+
+       prop = xmlGetProp (xnode, (const xmlChar *)"width");
+       if (prop != NULL)
+               {
+                       size->width = strtod (prop, NULL);
+               }
+       prop = xmlGetProp (xnode, (const xmlChar *)"height");
+       if (prop != NULL)
+               {
+                       size->height = strtod (prop, NULL);
+               }
+}
diff --git a/src/rptcommon.h b/src/rptcommon.h
new file mode 100644 (file)
index 0000000..167a1cb
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2006-2007 Andrea Zagli <azagli@inwind.it>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library 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
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ * 
+ */
+
+#ifndef __RPT_COMMON_H__
+#define __RPT_COMMON_H__
+
+#include <glib.h>
+#include <libxml/tree.h>
+
+G_BEGIN_DECLS
+
+
+typedef struct
+{
+       gdouble x;
+       gdouble y;
+} RptPoint;
+
+typedef struct
+{
+       gdouble width;
+       gdouble height;
+} RptSize;
+
+
+void rpt_common_get_position (xmlNode *xnode,
+                              RptPoint *position);
+void rpt_common_get_size (xmlNode *xnode,
+                          RptSize *size);
+
+
+G_END_DECLS
+
+#endif /* __RPT_COMMON_H__ */
diff --git a/src/rptobject.c b/src/rptobject.c
new file mode 100644 (file)
index 0000000..8b44b45
--- /dev/null
@@ -0,0 +1,151 @@
+/*
+ * Copyright (C) 2006-2007 Andrea Zagli <azagli@inwind.it>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library 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
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "rptobject.h"
+
+enum
+{
+       PROP_0,
+       PROP_NAME
+};
+
+static void rpt_object_class_init (RptObjectClass *klass);
+static void rpt_object_init (RptObject *rpt_object);
+
+static void rpt_object_set_property (GObject *object,
+                                    guint property_id,
+                                    const GValue *value,
+                                    GParamSpec *pspec);
+static void rpt_object_get_property (GObject *object,
+                                    guint property_id,
+                                    GValue *value,
+                                    GParamSpec *pspec);
+
+
+#define RPT_OBJECT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_RPT_OBJECT, RptObjectPrivate))
+
+typedef struct _RptObjectPrivate RptObjectPrivate;
+struct _RptObjectPrivate
+       {
+               gchar *name;
+       };
+
+GType
+rpt_object_get_type (void)
+{
+       static GType rpt_object_type = 0;
+
+       if (!rpt_object_type)
+               {
+                       static const GTypeInfo rpt_object_info =
+                       {
+                               sizeof (RptObjectClass),
+                               NULL,   /* base_init */
+                               NULL,   /* base_finalize */
+                               (GClassInitFunc) rpt_object_class_init,
+                               NULL,   /* class_finalize */
+                               NULL,   /* class_data */
+                               sizeof (RptObject),
+                               0,      /* n_preallocs */
+                               (GInstanceInitFunc) rpt_object_init,
+                               NULL
+                       };
+
+                       rpt_object_type = g_type_register_static (G_TYPE_OBJECT, "RptObject",
+                                                                 &rpt_object_info, 0);
+               }
+
+       return rpt_object_type;
+}
+
+static void
+rpt_object_class_init (RptObjectClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+       g_type_class_add_private (object_class, sizeof (RptObjectPrivate));
+
+       object_class->set_property = rpt_object_set_property;
+       object_class->get_property = rpt_object_get_property;
+
+       g_object_class_install_property (object_class, PROP_NAME,
+                                        g_param_spec_string ("name",
+                                                             "Name",
+                                                             "The object's name.",
+                                                             "",
+                                                             G_PARAM_READWRITE));
+}
+
+static void
+rpt_object_init (RptObject *rpt_object)
+{
+}
+
+/**
+ * rpt_object_new:
+ * @name: the #RptObject's name.
+ *
+ * Returns: the newly created #RptObject object.
+ */
+RptObject
+*rpt_object_new (const gchar *name)
+{
+       RptObject *rpt_object = RPT_OBJECT (g_object_new (rpt_object_get_type (), NULL));;
+
+       g_object_set (rpt_object, "name", name, NULL);
+
+       return rpt_object;
+}
+
+static void
+rpt_object_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+       RptObject *rpt_object = RPT_OBJECT (object);
+
+       RptObjectPrivate *priv = RPT_OBJECT_GET_PRIVATE (rpt_object);
+
+       switch (property_id)
+               {
+                       case PROP_NAME:
+                               priv->name = g_strstrip (g_strdup (g_value_get_string (value)));
+                               break;
+
+                       default:
+                               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                               break;
+               }
+}
+
+static void
+rpt_object_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+       RptObject *rpt_object = RPT_OBJECT (object);
+
+       RptObjectPrivate *priv = RPT_OBJECT_GET_PRIVATE (rpt_object);
+
+       switch (property_id)
+               {
+                       case PROP_NAME:
+                               g_value_set_string (value, priv->name);
+                               break;
+
+                       default:
+                               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                               break;
+               }
+}
diff --git a/src/rptobject.h b/src/rptobject.h
new file mode 100644 (file)
index 0000000..ff74300
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2006-2007 Andrea Zagli <azagli@inwind.it>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library 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
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ * 
+ */
+
+#ifndef __RPT_OBJECT_H__
+#define __RPT_OBJECT_H__
+
+#include <glib.h>
+#include <glib-object.h>
+#include <libxml/tree.h>
+
+G_BEGIN_DECLS
+
+
+#define TYPE_RPT_OBJECT                 (rpt_object_get_type ())
+#define RPT_OBJECT(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_RPT_OBJECT, RptObject))
+#define RPT_OBJECT_COMMON_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_RPT_OBJECT, RptObjectClass))
+#define IS_RPT_OBJECT(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_RPT_OBJECT))
+#define IS_RPT_OBJECT_COMMON_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_RPT_OBJECT))
+#define RPT_OBJECT_COMMON_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_RPT_OBJECT, RptObjectClass))
+
+
+typedef struct _RptObject RptObject;
+typedef struct _RptObjectClass RptObjectClass;
+
+struct _RptObject
+       {
+               GObject parent;
+       };
+
+struct _RptObjectClass
+       {
+               GObjectClass parent_class;
+       };
+
+GType rpt_object_get_type (void) G_GNUC_CONST;
+
+
+RptObject *rpt_object_new (const gchar *name);
+
+void rpt_object_get_xml (RptObject *rptobj, xmlNode *xnode);
+
+
+G_END_DECLS
+
+#endif /* __RPT_OBJECT_H__ */
diff --git a/src/rptobjecttext.c b/src/rptobjecttext.c
new file mode 100644 (file)
index 0000000..0299f28
--- /dev/null
@@ -0,0 +1,169 @@
+/*
+ * Copyright (C) 2006-2007 Andrea Zagli <azagli@inwind.it>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library 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
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "rptobjecttext.h"
+#include "rptcommon.h"
+
+enum
+{
+       PROP_0,
+       PROP_POSITION,
+       PROP_SIZE
+};
+
+static void rpt_obj_text_class_init (RptObjTextClass *klass);
+static void rpt_obj_text_init (RptObjText *rpt_obj_text);
+
+static void rpt_obj_text_set_property (GObject *object,
+                                    guint property_id,
+                                    const GValue *value,
+                                    GParamSpec *pspec);
+static void rpt_obj_text_get_property (GObject *object,
+                                    guint property_id,
+                                    GValue *value,
+                                    GParamSpec *pspec);
+
+
+#define RPT_OBJ_TEXT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_RPT_OBJ_TEXT, RptObjTextPrivate))
+
+typedef struct _RptObjTextPrivate RptObjTextPrivate;
+struct _RptObjTextPrivate
+       {
+               RptPoint *position;
+               RptSize *size;
+
+               gchar *text;
+       };
+
+GType
+rpt_obj_text_get_type (void)
+{
+       static GType rpt_obj_text_type = 0;
+
+       if (!rpt_obj_text_type)
+               {
+                       static const GTypeInfo rpt_obj_text_info =
+                       {
+                               sizeof (RptObjTextClass),
+                               NULL,   /* base_init */
+                               NULL,   /* base_finalize */
+                               (GClassInitFunc) rpt_obj_text_class_init,
+                               NULL,   /* class_finalize */
+                               NULL,   /* class_data */
+                               sizeof (RptObjText),
+                               0,      /* n_preallocs */
+                               (GInstanceInitFunc) rpt_obj_text_init,
+                               NULL
+                       };
+
+                       rpt_obj_text_type = g_type_register_static (TYPE_RPT_OBJECT, "RptObjText",
+                                                                   &rpt_obj_text_info, 0);
+               }
+
+       return rpt_obj_text_type;
+}
+
+static void
+rpt_obj_text_class_init (RptObjTextClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+       g_type_class_add_private (object_class, sizeof (RptObjTextPrivate));
+
+       object_class->set_property = rpt_obj_text_set_property;
+       object_class->get_property = rpt_obj_text_get_property;
+}
+
+static void
+rpt_obj_text_init (RptObjText *rpt_obj_text)
+{
+}
+
+/**
+ * rpt_obj_text_new:
+ * @name: the #RptObjText's name.
+ *
+ * Returns: the newly created #RptObject object.
+ */
+RptObject
+*rpt_obj_text_new (const gchar *name)
+{
+       RptObject *rpt_obj_text = RPT_OBJ_TEXT (g_object_new (rpt_obj_text_get_type (), NULL));
+
+       g_object_set (rpt_obj_text, "name", name, NULL);
+
+       return rpt_obj_text;
+}
+
+/**
+ * rpt_obj_text_new_from_xml:
+ * @xnode:
+ *
+ * Returns: the newly created #RptObject object.
+ */
+RptObject
+*rpt_obj_text_new_from_xml (xmlNode *xnode)
+{
+       gchar *name;
+       RptObject *rpt_obj_text = NULL;
+
+       name = (gchar *)xmlGetProp (xnode, "name");
+       if (strcmp (g_strstrip (name), "") != 0)
+               {
+                       RptObjTextPrivate *priv;
+
+                       rpt_obj_text = rpt_obj_text_new (name);
+
+                       priv = RPT_OBJ_TEXT_GET_PRIVATE (rpt_obj_text);
+
+                       rpt_common_get_position (xnode, priv->position);
+                       rpt_common_get_size (xnode, priv->size);
+               }
+
+       return rpt_obj_text;
+}
+
+static void
+rpt_obj_text_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+       RptObjText *rpt_obj_text = RPT_OBJ_TEXT (object);
+
+       RptObjTextPrivate *priv = RPT_OBJ_TEXT_GET_PRIVATE (rpt_obj_text);
+
+       switch (property_id)
+               {
+                       default:
+                               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                               break;
+               }
+}
+
+static void
+rpt_obj_text_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+       RptObjText *rpt_obj_text = RPT_OBJ_TEXT (object);
+
+       RptObjTextPrivate *priv = RPT_OBJ_TEXT_GET_PRIVATE (rpt_obj_text);
+
+       switch (property_id)
+               {
+                       default:
+                               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                               break;
+               }
+}
diff --git a/src/rptobjecttext.h b/src/rptobjecttext.h
new file mode 100644 (file)
index 0000000..7ba304d
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2006-2007 Andrea Zagli <azagli@inwind.it>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library 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
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ * 
+ */
+
+#ifndef __RPT_OBJ_TEXT_H__
+#define __RPT_OBJ_TEXT_H__
+
+#include <glib.h>
+#include <glib-object.h>
+#include <libxml/tree.h>
+
+#include "rptobject.h"
+
+G_BEGIN_DECLS
+
+
+#define TYPE_RPT_OBJ_TEXT                 (rpt_obj_text_get_type ())
+#define RPT_OBJ_TEXT(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_RPT_OBJ_TEXT, RptObjText))
+#define RPT_OBJ_TEXT_COMMON_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_RPT_OBJ_TEXT, RptObjTextClass))
+#define IS_RPT_OBJ_TEXT(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_RPT_OBJ_TEXT))
+#define IS_RPT_OBJ_TEXT_COMMON_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_RPT_OBJ_TEXT))
+#define RPT_OBJ_TEXT_COMMON_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_RPT_OBJ_TEXT, RptObjTextClass))
+
+
+typedef struct _RptObjText RptObjText;
+typedef struct _RptObjTextClass RptObjTextClass;
+
+struct _RptObjText
+       {
+               RptObject parent;
+       };
+
+struct _RptObjTextClass
+       {
+               RptObjectClass parent_class;
+       };
+
+GType rpt_obj_text_get_type (void) G_GNUC_CONST;
+
+
+RptObject *rpt_obj_text_new (const gchar *name);
+RptObject *rpt_obj_text_new_from_xml (xmlNode *xnode);
+
+xmlNode *rpt_obj_text_get_xml (RptObjText *rpt_obj_text);
+
+
+G_END_DECLS
+
+#endif /* __RPT_OBJ_TEXT_H__ */
index e071735a5332a5df9ab07938bf576bd311af9d9d..ac351db0fe32db7c8a84e0711c50984e136bb19a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006 Andrea Zagli <azagli@inwind.it>
+ * Copyright (C) 2006-2007 Andrea Zagli <azagli@inwind.it>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
 #include <pango/pangocairo.h>
 
 #include "rptprint.h"
-
-typedef struct
-{
-       gdouble x,
-               y;
-} RptPoint;
-
-typedef struct
-{
-       gdouble width,
-               height;
-} RptSize;
+#include "rptcommon.h"
 
 typedef enum
 {
@@ -59,32 +48,32 @@ typedef struct
 
 typedef struct
 {
-       gdouble r,
-               g,
-               b,
-               a;
+       gdouble r;
+       gdouble g;
+       gdouble b;
+       gdouble a;
 } RptColor;
 
 typedef struct
 {
-       gdouble top_width,
-               right_width,
-               bottom_width,
-               left_width;
-       RptColor top_color,
-                right_color,
-                bottom_color,
-                left_color;
+       gdouble top_width;
+       gdouble right_width;
+       gdouble bottom_width;
+       gdouble left_width;
+       RptColor top_color;
+       RptColor right_color;
+       RptColor bottom_color;
+       RptColor left_color;
 } RptBorder;
 
 typedef struct
 {
        gchar *name;
        gdouble size;
-       gboolean bold,
-                italic,
-                underline,
-                strike;
+       gboolean bold;
+       gboolean italic;
+       gboolean underline;
+       gboolean strike;
        RptColor color;
 } RptFont;
 
@@ -129,10 +118,6 @@ static void rpt_print_border (RptPrint *rpt_print,
                               RptPoint position,
                               RptSize size,
                               RptBorder border);
-static void rpt_print_get_position (xmlNode *xnode,
-                                    RptPoint *position);
-static void rpt_print_get_size (xmlNode *xnode,
-                                RptSize *size);
 static void rpt_print_get_align (xmlNode *xnode,
                                  RptAlign *align);
 static void rpt_print_get_border (xmlNode *xnode,
@@ -150,8 +135,8 @@ static void rpt_print_parse_color (const gchar *str_color,
 typedef struct _RptPrintPrivate RptPrintPrivate;
 struct _RptPrintPrivate
        {
-               gint width,
-                    height;
+               gint width;
+               gint height;
                cairo_surface_t *surface;
                cairo_t *cr;
        };
@@ -218,9 +203,7 @@ RptPrint
                {
                        if (strcmp (cur->name, "reptool_report") == 0)
                                {
-#if 0
                                        FILE *fout;
-#endif
                                        RptPrintPrivate *priv;
 
                                        gint npage = 0;
@@ -228,17 +211,17 @@ RptPrint
                                        rpt_print = RPT_PRINT (g_object_new (rpt_print_get_type (), NULL));
 
                                        priv = RPT_PRINT_GET_PRIVATE (rpt_print);
-#if 0
+
                                        if (output_type != RPTP_OUTPUT_PNG)
                                                {
-                                                       fout = fopen ("test.pdf", "w");
+                                                       fout = fopen (out_filename, "w");
                                                        if (fout == NULL)
                                                                {
                                                                        /* TO DO */
                                                                        return NULL;
                                                                }
                                                }
-#endif
+
                                        cur = cur->children;
                                        while (cur != NULL)
                                                {
@@ -260,15 +243,15 @@ RptPrint
                                                                                                                                break;
                                                                                                                
                                                                                                                        case RPTP_OUTPUT_PDF:
-                                                                                                                               priv->surface = cairo_pdf_surface_create ("test.pdf", (double)priv->width, (double)priv->height);
+                                                                                                                               priv->surface = cairo_pdf_surface_create (out_filename, (double)priv->width, (double)priv->height);
                                                                                                                                break;
                
                                                                                                                        case RPTP_OUTPUT_PS:
-                                                                                                                               priv->surface = cairo_ps_surface_create ("test.ps", (double)priv->width, (double)priv->height);
+                                                                                                                               priv->surface = cairo_ps_surface_create (out_filename, (double)priv->width, (double)priv->height);
                                                                                                                                break;
                
                                                                                                                        case RPTP_OUTPUT_SVG:
-                                                                                                                               priv->surface = cairo_svg_surface_create ("test.svg", (double)priv->width, (double)priv->height);
+                                                                                                                               priv->surface = cairo_svg_surface_create (out_filename, (double)priv->width, (double)priv->height);
                                                                                                                                break;
                                                                                                                }
                                                                                                }
@@ -294,7 +277,7 @@ RptPrint
                                                                                                                        rpt_print_page (rpt_print, cur);
                                                                                                                        if (output_type == RPTP_OUTPUT_PNG)
                                                                                                                                {
-                                                                                                                                       cairo_surface_write_to_png (priv->surface, "test.png");
+                                                                                                                                       cairo_surface_write_to_png (priv->surface, out_filename);
                                                                                                                                        cairo_surface_destroy (priv->surface);
                                                                                                                                }
 
@@ -327,12 +310,10 @@ RptPrint
                                                {                                               
                                                        cairo_destroy (priv->cr);
                                                }
-#if 0
                                        if (output_type != RPTP_OUTPUT_PNG)
                                                {
                                                        fclose (fout);
                                                }
-#endif
                                }
                        else
                                {
@@ -447,8 +428,8 @@ rpt_print_text_xml (RptPrint *rpt_print, xmlNode *xnode)
                pad_bottom,
                pad_left;
 
-       rpt_print_get_position (xnode, &position);
-       rpt_print_get_size (xnode, &size);
+       rpt_common_get_position (xnode, &position);
+       rpt_common_get_size (xnode, &size);
        rpt_print_get_align (xnode, &align);
        rpt_print_get_border (xnode, &border);
        rpt_print_get_font (xnode, &font);
@@ -571,8 +552,8 @@ rpt_print_line_xml (RptPrint *rpt_print, xmlNode *xnode)
        RptSize size;
        RptStroke stroke;
 
-       rpt_print_get_position (xnode, &position);
-       rpt_print_get_size (xnode, &size);
+       rpt_common_get_position (xnode, &position);
+       rpt_common_get_size (xnode, &size);
        rpt_print_get_stroke (xnode, &stroke);
 
        from_p.x = position.x;
@@ -595,8 +576,8 @@ rpt_print_rect_xml (RptPrint *rpt_print, xmlNode *xnode)
 
        RptPrintPrivate *priv = RPT_PRINT_GET_PRIVATE (rpt_print);
 
-       rpt_print_get_position (xnode, &position);
-       rpt_print_get_size (xnode, &size);
+       rpt_common_get_position (xnode, &position);
+       rpt_common_get_size (xnode, &size);
        rpt_print_get_stroke (xnode, &stroke);
 
        gchar *prop = xmlGetProp (xnode, (const xmlChar *)"fill-color");
@@ -637,8 +618,8 @@ rpt_print_image_xml (RptPrint *rpt_print, xmlNode *xnode)
 
        RptPrintPrivate *priv = RPT_PRINT_GET_PRIVATE (rpt_print);
 
-       gchar *adapt,
-             *filename= xmlGetProp (xnode, (const xmlChar *)"source");
+       gchar *adapt;
+       gchar *filename= xmlGetProp (xnode, (const xmlChar *)"source");
        if (filename == NULL)
                {
                        return;
@@ -654,8 +635,8 @@ rpt_print_image_xml (RptPrint *rpt_print, xmlNode *xnode)
                        g_strstrip (adapt);
                }
 
-       rpt_print_get_position (xnode, &position);
-       rpt_print_get_size (xnode, &size);
+       rpt_common_get_position (xnode, &position);
+       rpt_common_get_size (xnode, &size);
        rpt_print_get_border (xnode, &border);
 
        image = cairo_image_surface_create_from_png (filename);
@@ -755,46 +736,6 @@ rpt_print_border (RptPrint *rpt_print, RptPoint position, RptSize size, RptBorde
                }
 }
 
-static void
-rpt_print_get_position (xmlNode *xnode, RptPoint *position)
-{
-       gchar *prop;
-
-       position->x = 0.0;
-       position->y = 0.0;
-
-       prop = xmlGetProp (xnode, (const xmlChar *)"x");
-       if (prop != NULL)
-               {
-                       position->x = strtod (prop, NULL);
-               }
-       prop = xmlGetProp (xnode, (const xmlChar *)"y");
-       if (prop != NULL)
-               {
-                       position->y = strtod (prop, NULL);
-               }
-}
-
-static void
-rpt_print_get_size (xmlNode *xnode, RptSize *size)
-{
-       gchar *prop;
-
-       size->width = 0.0;
-       size->height = 0.0;
-
-       prop = xmlGetProp (xnode, (const xmlChar *)"width");
-       if (prop != NULL)
-               {
-                       size->width = strtod (prop, NULL);
-               }
-       prop = xmlGetProp (xnode, (const xmlChar *)"height");
-       if (prop != NULL)
-               {
-                       size->height = strtod (prop, NULL);
-               }
-}
-
 static void
 rpt_print_get_align (xmlNode *xnode, RptAlign *align)
 {
index c9b406bc7ee2b7bd8753e06c1ea59ee6df2d7b6e..028106aa9fc5b43b6ed733e632f6ec4082ff9688 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006 Andrea Zagli <azagli@inwind.it>
+ * Copyright (C) 2006-2007 Andrea Zagli <azagli@inwind.it>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
diff --git a/src/rptreport.c b/src/rptreport.c
new file mode 100644 (file)
index 0000000..7aa3e36
--- /dev/null
@@ -0,0 +1,423 @@
+/*
+ * Copyright (C) 2006-2007 Andrea Zagli <azagli@inwind.it>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library 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
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <libgda/libgda.h>
+#include <libxml/xpath.h>
+
+#ifdef HAVE_CONFIG_H
+       #include <config.h>
+#endif
+
+#include "rptreport.h"
+#include "rptcommon.h"
+#include "rptobject.h"
+#include "rptobjecttext.h"
+
+typedef struct
+{
+       RptSize *size;
+} Page;
+
+typedef struct
+{
+       gdouble height;
+       GList *objects;
+} Body;
+
+enum
+{
+       PROP_0
+};
+
+static void rpt_report_class_init (RptReportClass *klass);
+static void rpt_report_init (RptReport *rpt_report);
+
+static void rpt_report_set_property (GObject *object,
+                                     guint property_id,
+                                     const GValue *value,
+                                     GParamSpec *pspec);
+static void rpt_report_get_property (GObject *object,
+                                     guint property_id,
+                                     GValue *value,
+                                     GParamSpec *pspec);
+
+static void rpt_report_xml_parse_body (RptReport *rpt_report, xmlNodeSetPtr xnodeset);
+static RptObject *rpt_report_get_object_from_name (GList *list, const gchar *name);
+
+
+#define RPT_REPORT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_RPT_REPORT, RptReportPrivate))
+
+typedef struct _RptReportPrivate RptReportPrivate;
+struct _RptReportPrivate
+       {
+               GdaClient *gda_client;
+               GdaConnection *gda_conn;
+               GdaDataModel *gda_datamodel;
+
+               Page *page;
+               Body *body;
+       };
+
+GType
+rpt_report_get_type (void)
+{
+       static GType rpt_report_type = 0;
+
+       if (!rpt_report_type)
+               {
+                       static const GTypeInfo rpt_report_info =
+                       {
+                               sizeof (RptReportClass),
+                               NULL,   /* base_init */
+                               NULL,   /* base_finalize */
+                               (GClassInitFunc) rpt_report_class_init,
+                               NULL,   /* class_finalize */
+                               NULL,   /* class_data */
+                               sizeof (RptReport),
+                               0,      /* n_preallocs */
+                               (GInstanceInitFunc) rpt_report_init,
+                               NULL
+                       };
+
+                       rpt_report_type = g_type_register_static (G_TYPE_OBJECT, "RptReport",
+                                                                 &rpt_report_info, 0);
+               }
+
+       return rpt_report_type;
+}
+
+static void
+rpt_report_class_init (RptReportClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+       g_type_class_add_private (object_class, sizeof (RptReportPrivate));
+
+       object_class->set_property = rpt_report_set_property;
+       object_class->get_property = rpt_report_get_property;
+}
+
+static void
+rpt_report_init (RptReport *rpt_report)
+{
+       RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report);
+
+       priv->page = (Page *)g_malloc0 (sizeof (Page));
+       priv->body = (Body *)g_malloc0 (sizeof (Body));
+}
+
+/**
+ * rpt_report_new_from_xml:
+ * @xdoc: an #xmlDoc.
+ *
+ * Returns: the newly created #RptReport object.
+ */
+RptReport
+*rpt_report_new_from_xml (xmlDoc *xdoc)
+{
+       RptReport *rpt_report = NULL;
+
+       xmlNode *cur = xmlDocGetRootElement (xdoc);
+       if (cur != NULL)
+               {
+                       if (strcmp (cur->name, "reptool") == 0)
+                               {
+                                       xmlXPathContextPtr xpcontext;
+                                       xmlXPathObjectPtr xpresult;
+                                       xmlNodeSetPtr xnodeset;
+                                       RptReportPrivate *priv;
+
+                                       rpt_report = RPT_REPORT (g_object_new (rpt_report_get_type (), NULL));
+
+                                       priv = RPT_REPORT_GET_PRIVATE (rpt_report);
+                                       xpcontext = xmlXPathNewContext (xdoc);
+
+                                       /* search for node "page" */
+                                       xpcontext->node = cur;
+                                       xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::page", xpcontext);
+                                       if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval))
+                                               {
+                                                       xnodeset = xpresult->nodesetval;
+                                                       if (xnodeset->nodeNr == 1)
+                                                               {
+                                                                       priv->page->size->width = atol (xmlGetProp (xnodeset->nodeTab[0], (const xmlChar *)"width"));
+                                                                       priv->page->size->height = atol (xmlGetProp (xnodeset->nodeTab[0], (const xmlChar *)"height"));
+                                                               }
+                                                       else
+                                                               {
+                                                                       /* TO DO */
+                                                                       /* return */
+                                                               }
+                                               }
+                                       else
+                                               {
+                                                       /* TO DO */
+                                                       /* return */
+                                               }
+
+                                       /* search for node "database" */
+                                       xpcontext->node = cur;
+                                       xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::database", xpcontext);
+                                       if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval))
+                                               {
+                                                       xnodeset = xpresult->nodesetval;
+                                                       if (xnodeset->nodeNr == 1)
+                                                               {
+                                                                       gchar *provider;
+                                                                       gchar *connection_string;
+                                                                       gchar *sql;
+                                                               
+                                                                       xmlNode *cur_database = xnodeset->nodeTab[0]->children;
+                                                                       while (cur_database != NULL)
+                                                                               {
+                                                                                       if (strcmp (cur_database->name, "provider") == 0)
+                                                                                               {
+                                                                                                       provider = g_strstrip ((gchar *)xmlNodeGetContent (cur_database));
+                                                                                               }
+                                                                                       else if (strcmp (cur_database->name, "connection_string") == 0)
+                                                                                               {
+                                                                                                       connection_string = g_strstrip ((gchar *)xmlNodeGetContent (cur_database));
+                                                                                               }
+                                                                                       else if (strcmp (cur_database->name, "sql") == 0)
+                                                                                               {
+                                                                                                       sql = g_strstrip ((gchar *)xmlNodeGetContent (cur_database));
+                                                                                               }
+                                                                                       
+                                                                                       cur_database = cur_database->next;
+                                                                               }
+
+                                                                       if (strcmp (provider, "") == 0 ||
+                                                                               strcmp (connection_string, "") == 0 ||
+                                                                               strcmp (sql, "") == 0)
+                                                                               {
+                                                                                       /* TO DO */
+                                                                               }
+                                                                       else
+                                                                               {
+                                                                                       /* database connection */
+                                                                                       gda_init (PACKAGE_NAME, PACKAGE_VERSION, 0, NULL);
+                                                                                       priv->gda_client = gda_client_new ();
+                                                                                       priv->gda_conn = gda_client_open_connection_from_string (priv->gda_client,
+                                                                                                                                                                                                        provider,
+                                                                                                                                                                                                        connection_string,
+                                                                                                                                                                                                        0);
+                                                                                       if (priv->gda_conn == NULL)
+                                                                                               {
+                                                                                                       /* TO DO */
+                                                                                               }
+                                                                                       else
+                                                                                               {
+                                                                                                       GdaCommand *command = gda_command_new (sql, GDA_COMMAND_TYPE_SQL, GDA_COMMAND_OPTION_STOP_ON_ERRORS);
+
+                                                                                                       priv->gda_datamodel = gda_connection_execute_single_command (priv->gda_conn, command, NULL);
+
+                                                                                                       gda_command_free (command);
+                                                                                               }
+                                                                               }
+                                                               }
+                                               }
+
+                                       /* search for node "report" */
+                                       xpcontext->node = cur;
+                                       xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::report", xpcontext);
+                                       if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval))
+                                               {
+                                                       xnodeset = xpresult->nodesetval;
+                                                       if (xnodeset->nodeNr == 1)
+                                                               {
+                                                                       /* search for node "body" */
+                                                                       xpcontext->node = xnodeset->nodeTab[0];
+                                                                       xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::body", xpcontext);
+                                                                       if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval))
+                                                                               {
+                                                                                       xnodeset = xpresult->nodesetval;
+                                                                                       if (xnodeset->nodeNr == 1)
+                                                                                               {
+                                                                                                       rpt_report_xml_parse_body (rpt_report, xnodeset);
+                                                                                               }
+                                                                               }
+                                                               }
+                                                       else
+                                                               {
+                                                                       /* TO DO */
+                                                                       /* return */
+                                                               }
+                                               }
+                                       else
+                                               {
+                                                       /* TO DO */
+                                                       /* return */
+                                               }
+                               }
+                       else
+                               {
+                                       /* TO DO */
+                               }
+               }
+
+       return rpt_report;
+}
+
+/**
+ * rpt_report_new_from_file:
+ * @filename: the path of the xml file to load.
+ *
+ * Returns: the newly created #RptReport object.
+ */
+RptReport
+*rpt_report_new_from_file (const gchar *filename)
+{
+       RptReport *rpt_report = NULL;
+
+       xmlDoc *xdoc = xmlParseFile (filename);
+       if (xdoc != NULL)
+               {
+                       rpt_report = rpt_report_new_from_xml (xdoc);
+               }
+
+       return rpt_report;
+}
+
+/**
+ * rpt_report_get_xml:
+ * @rptreport: an #RptReport object.
+ *
+ */
+xmlDoc
+*rpt_report_get_xml (RptReport *rptreport)
+{
+       xmlDoc *xdoc;
+
+       RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rptreport);
+
+       return xdoc;
+}
+
+/**
+ * rpt_report_get_rptprint:
+ * @rptreport: an #RptReport object.
+ *
+ */
+xmlDoc
+*rpt_report_get_rptprint (RptReport *rptreport)
+{
+       xmlDoc *xdoc;
+       xmlNode *xroot;
+
+       RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rptreport);
+
+       xdoc = xmlNewDoc ("1.0");
+       xroot = xmlNewNode (NULL, "reptool_report");
+       xmlDocSetRootElement (xdoc, xroot);
+               
+       return xdoc;
+}
+
+static void
+rpt_report_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+       RptReport *rpt_report = RPT_REPORT (object);
+
+       RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report);
+
+       switch (property_id)
+               {
+                       default:
+                               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                               break;
+               }
+}
+
+static void
+rpt_report_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+       RptReport *rpt_report = RPT_REPORT (object);
+
+       RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report);
+
+       switch (property_id)
+               {
+                       default:
+                               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                               break;
+               }
+}
+
+static void
+rpt_report_xml_parse_body (RptReport *rpt_report, xmlNodeSetPtr xnodeset)
+{
+       RptObject *rptobj;
+       gchar *objname;
+       xmlNode *cur = xnodeset->nodeTab[0];
+
+       RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report);
+
+       while (cur != NULL)
+               {
+                       if (strcmp (cur->name, "text") == 0)
+                               {
+                                       rptobj = rpt_obj_text_new_from_xml (cur);
+                                       g_object_get (rptobj, "name", objname, NULL);
+
+                                       if (rpt_report_get_object_from_name (priv->body->objects, objname) != NULL)
+                                               {
+                                                       priv->body->objects = g_list_append (priv->body->objects, rptobj);
+                                               }
+                                       else
+                                               {
+                                                       /* TO DO */
+                                               }
+                               }
+                       else if (strcmp (cur->name, "line") == 0)
+                               {
+                               }
+                       else if (strcmp (cur->name, "rect") == 0)
+                               {
+                               }
+                       else if (strcmp (cur->name, "image") == 0)
+                               {
+                               }
+
+                       cur = cur->next;
+               }
+}
+
+static RptObject
+*rpt_report_get_object_from_name (GList *list, const gchar *name)
+{
+       gchar *objname;
+       RptObject *obj = NULL;
+
+       list = g_list_first (list);
+       while (list != NULL)
+               {
+                       g_object_get ((RptObject *)list->data, "name", objname, NULL);
+                       if (strcmp (name, objname) == 0)
+                               {
+                                       obj = (RptObject *)list->data;
+                                       break;
+                               }
+               
+                       list = g_list_next (list);
+               }
+
+       return obj;
+}
diff --git a/src/rptreport.h b/src/rptreport.h
new file mode 100644 (file)
index 0000000..d0e59c9
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2006-2007 Andrea Zagli <azagli@inwind.it>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library 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
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ * 
+ */
+
+#ifndef __RPT_REPORT_H__
+#define __RPT_REPORT_H__
+
+#include <glib.h>
+#include <glib-object.h>
+#include <libxml/tree.h>
+
+G_BEGIN_DECLS
+
+
+#define TYPE_RPT_REPORT                 (rpt_report_get_type ())
+#define RPT_REPORT(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_RPT_REPORT, RptReport))
+#define RPT_REPORT_COMMON_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_RPT_REPORT, RptReportClass))
+#define IS_RPT_REPORT(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_RPT_REPORT))
+#define IS_RPT_REPORT_COMMON_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_RPT_REPORT))
+#define RPT_REPORT_COMMON_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_RPT_REPORT, RptReportClass))
+
+
+typedef struct _RptReport RptReport;
+typedef struct _RptReportClass RptReportClass;
+
+struct _RptReport
+       {
+               GObject parent;
+       };
+
+struct _RptReportClass
+       {
+               GObjectClass parent_class;
+       };
+
+GType rpt_report_get_type (void) G_GNUC_CONST;
+
+
+RptReport *rpt_report_new_from_xml (xmlDoc *xdoc);
+RptReport *rpt_report_new_from_file (const gchar *filename);
+
+xmlDoc *rpt_report_get_xml (RptReport *rptreport);
+
+xmlDoc *rpt_report_get_rptprint (RptReport *rptreport);
+
+
+G_END_DECLS
+
+#endif /* __RPT_REPORT_H__ */
index 62bbcd735f8f716feaa000bb13767f4825985fd4..dd3f82d558197811187ba03bd78eb21ceef15011 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006 Andrea Zagli <azagli@inwind.it>
+ * Copyright (C) 2006-2007 Andrea Zagli <azagli@inwind.it>
  *
  * 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
@@ -25,7 +25,7 @@ main (int argc, char **argv)
 
        g_type_init ();
 
-       rptp = rpt_print_new_from_file (argv[1], RPTP_OUTPUT_PDF, "");
+       rptp = rpt_print_new_from_file (argv[1], RPTP_OUTPUT_PDF, "test.pdf");
 
        if (rptp != NULL)
                {
diff --git a/tests/test.rptr b/tests/test.rptr
deleted file mode 100644 (file)
index fc5781f..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-<?xml version="1.0" ?>
-<reptool_report>
-       <page width="595" height="842">
-               <text x="10" y="20" width="300" height="10" border-top-width="1.0" border-bottom-width="1.0" font-size="12" font-color="#0F0">Text sample</text>
-               <line x="10" y="300" width="100" height="0" stroke-color="#F00" />
-               <image x="250" y="180" width="300" height="200" border-top-width="1.0" border-right-width="1.0" border-bottom-width="1.0" border-left-width="1.0" source="tests/city.png" />
-               <rect x="10" y="500" width="400" height="10" fill-color="#00F" />
-       </page>
-
-       <page width="595" height="842">
-               <text x="10" y="300" width="300" height="800" font-size="30" font-color="#FF0">Text sample on second page</text>
-               <line x="10" y="300" width="100" height="0" stroke-color="#0F0" />
-       </page>
-</reptool_report>
diff --git a/tests/test_report.rpt b/tests/test_report.rpt
new file mode 100644 (file)
index 0000000..2feadeb
--- /dev/null
@@ -0,0 +1,12 @@
+<?xml version="1.0" ?>
+<reptool>
+  <page width="595" height="842" />
+
+  <report>
+    <body height="200">
+      <text name="text1" x="100" y="50" width="500" height="200">
+        the text's content
+      </text>
+    </body>
+  </report>
+</reptool>
diff --git a/tests/test_rptprint.rptr b/tests/test_rptprint.rptr
new file mode 100644 (file)
index 0000000..fc5781f
--- /dev/null
@@ -0,0 +1,14 @@
+<?xml version="1.0" ?>
+<reptool_report>
+       <page width="595" height="842">
+               <text x="10" y="20" width="300" height="10" border-top-width="1.0" border-bottom-width="1.0" font-size="12" font-color="#0F0">Text sample</text>
+               <line x="10" y="300" width="100" height="0" stroke-color="#F00" />
+               <image x="250" y="180" width="300" height="200" border-top-width="1.0" border-right-width="1.0" border-bottom-width="1.0" border-left-width="1.0" source="tests/city.png" />
+               <rect x="10" y="500" width="400" height="10" fill-color="#00F" />
+       </page>
+
+       <page width="595" height="842">
+               <text x="10" y="300" width="300" height="800" font-size="30" font-color="#FF0">Text sample on second page</text>
+               <line x="10" y="300" width="100" height="0" stroke-color="#0F0" />
+       </page>
+</reptool_report>