]> saetta.ns0.it Git - reptool/libreptool/commitdiff
RptReport with text, line, rect and image objects.
authorAndrea Zagli <azagli@libero.it>
Sun, 25 Mar 2007 08:08:51 +0000 (08:08 +0000)
committerAndrea Zagli <azagli@libero.it>
Sun, 25 Mar 2007 08:08:51 +0000 (08:08 +0000)
Only few features implemented.

git-svn-id: svn+ssh://saetta.homelinux.org/svn/libreptool/trunk@6 3191ed1d-3fce-41bb-ab4a-0cebc0943b59

21 files changed:
data/reptool.dtd
src/Makefile.am
src/rptcommon.c
src/rptcommon.h
src/rptobject.c
src/rptobject.h
src/rptobjectimage.c [new file with mode: 0644]
src/rptobjectimage.h [new file with mode: 0644]
src/rptobjectline.c [new file with mode: 0644]
src/rptobjectline.h [new file with mode: 0644]
src/rptobjectrect.c [new file with mode: 0644]
src/rptobjectrect.h [new file with mode: 0644]
src/rptreport.c
src/rptreport.h
tests/Makefile.am
tests/gnome-globe.png [new file with mode: 0644]
tests/rptprint.c [deleted file]
tests/rptreport.c [deleted file]
tests/test_report_db.rpt
tests/test_rptprint.c [new file with mode: 0644]
tests/test_rptreport.c [new file with mode: 0644]

index b1f192b896d588e1e0d95cd663a174b585514e8a..35a7f41ae42950f59df059d1bd0d4145912f765b 100644 (file)
 <!ELEMENT group-header (%objects;)>
 <!ATTLIST group-header
   height   CDATA #REQUIRED
+  new-page-after   (y | n) #IMPLIED
 >
 
 <!ELEMENT group-footer (%objects;)>
index 572fee6fa3bc1d75ce912cfaf920488af4ff1e22..e8e4e2949701da30795ef4dbe812b40ee2447330 100644 (file)
@@ -7,6 +7,9 @@ lib_LTLIBRARIES = libreptool.la
 libreptool_la_SOURCES = \
                         rptobject.c \
                         rptobjecttext.c \
+                        rptobjectline.c \
+                        rptobjectrect.c \
+                        rptobjectimage.c \
                         rptreport.c \
                         rptprint.c \
                         rptcommon.c
@@ -14,6 +17,9 @@ libreptool_la_SOURCES = \
 include_HEADERS = \
                   rptobject.h \
                   rptobjecttext.h \
+                  rptobjectline.h \
+                  rptobjectrect.h \
+                  rptobjectimage.h \
                   rptreport.h \
                   rptprint.h \
                   rptcommon.h
index 54952a6db9552815c17ea28f7bba872b1ead6152..9c129355f253dd1b04861eebbe82df894998b8ac 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006-2007 Andrea Zagli <azagli@inwind.it>
+ * Copyright (C) 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
index 167a1cb0ca5afcc704b960a94599361fe5cc164a..4dce0bb6ebfaa4cafd0ed5e5c177ca3497e3c6ad 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006-2007 Andrea Zagli <azagli@inwind.it>
+ * Copyright (C) 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
index 938e9f5e393be9f598612484832b48efb6d4803e..2abcdfbc8677b0139440d782ef1e90673714d3b8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006-2007 Andrea Zagli <azagli@inwind.it>
+ * Copyright (C) 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
@@ -125,6 +125,12 @@ RptObject
        return rpt_object;
 }
 
+/**
+ * rpt_object_get_xml:
+ * @rpt_object:
+ * @xnode:
+ *
+ */
 void
 rpt_object_get_xml (RptObject *rpt_object, xmlNode *xnode)
 {
index fd52e5649bca045e1502075c3d7055dffafbccb6..2d14bf45363349cf52fded8b7e2984e51dd70d1b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006-2007 Andrea Zagli <azagli@inwind.it>
+ * Copyright (C) 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/rptobjectimage.c b/src/rptobjectimage.c
new file mode 100644 (file)
index 0000000..8f201f8
--- /dev/null
@@ -0,0 +1,241 @@
+/*
+ * Copyright (C) 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 "rptobjectimage.h"
+#include "rptcommon.h"
+
+enum
+{
+       PROP_0,
+       PROP_SIZE,
+       PROP_SOURCE
+};
+
+static void rpt_obj_image_class_init (RptObjImageClass *klass);
+static void rpt_obj_image_init (RptObjImage *rpt_obj_image);
+
+static void rpt_obj_image_set_property (GObject *object,
+                                       guint property_id,
+                                       const GValue *value,
+                                       GParamSpec *pspec);
+static void rpt_obj_image_get_property (GObject *object,
+                                       guint property_id,
+                                       GValue *value,
+                                       GParamSpec *pspec);
+
+
+#define RPT_OBJ_IMAGE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_RPT_OBJ_IMAGE, RptObjImagePrivate))
+
+typedef struct _RptObjImagePrivate RptObjImagePrivate;
+struct _RptObjImagePrivate
+       {
+               RptSize *size;
+               gchar *source;
+       };
+
+GType
+rpt_obj_image_get_type (void)
+{
+       static GType rpt_obj_image_type = 0;
+
+       if (!rpt_obj_image_type)
+               {
+                       static const GTypeInfo rpt_obj_image_info =
+                       {
+                               sizeof (RptObjImageClass),
+                               NULL,   /* base_init */
+                               NULL,   /* base_finalize */
+                               (GClassInitFunc) rpt_obj_image_class_init,
+                               NULL,   /* class_finalize */
+                               NULL,   /* class_data */
+                               sizeof (RptObjImage),
+                               0,      /* n_preallocs */
+                               (GInstanceInitFunc) rpt_obj_image_init,
+                               NULL
+                       };
+
+                       rpt_obj_image_type = g_type_register_static (TYPE_RPT_OBJECT, "RptObjImage",
+                                                                    &rpt_obj_image_info, 0);
+               }
+
+       return rpt_obj_image_type;
+}
+
+static void
+rpt_obj_image_class_init (RptObjImageClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+       RptObjectClass *rptobject_class = RPT_OBJECT_CLASS (klass);
+
+       g_type_class_add_private (object_class, sizeof (RptObjImagePrivate));
+
+       object_class->set_property = rpt_obj_image_set_property;
+       object_class->get_property = rpt_obj_image_get_property;
+
+       rptobject_class->get_xml = rpt_obj_image_get_xml;
+
+       g_object_class_install_property (object_class, PROP_SIZE,
+                                        g_param_spec_pointer ("size",
+                                                              "Size",
+                                                              "The object's size.",
+                                                              G_PARAM_READWRITE));
+       g_object_class_install_property (object_class, PROP_SOURCE,
+                                        g_param_spec_string ("source",
+                                                             "Source",
+                                                             "The image's source.",
+                                                             "",
+                                                             G_PARAM_READWRITE));
+}
+
+static void
+rpt_obj_image_init (RptObjImage *rpt_obj_image)
+{
+       RptObjImagePrivate *priv = RPT_OBJ_IMAGE_GET_PRIVATE (rpt_obj_image);
+
+       priv->size = (RptSize *)g_malloc0 (sizeof (RptSize));
+       priv->size->width = 0.0;
+       priv->size->height = 0.0;
+
+       priv->source = g_strdup ("");
+}
+
+/**
+ * rpt_obj_image_new:
+ * @name: the #RptObjImage's name.
+ * @position:
+ *
+ * Returns: the newly created #RptObject object.
+ */
+RptObject
+*rpt_obj_image_new (const gchar *name, RptPoint position)
+{
+       RptObject *rpt_obj_image = NULL;
+
+       gchar *name_ = g_strstrip (g_strdup (name));
+
+       if (strcmp (name_, "") != 0)
+               {
+                       rpt_obj_image = RPT_OBJECT (g_object_new (rpt_obj_image_get_type (), NULL));
+
+                       g_object_set (G_OBJECT (rpt_obj_image),
+                             "name", name_,
+                             "position", &position,
+                             NULL);
+               }
+
+       return rpt_obj_image;
+}
+
+/**
+ * rpt_obj_image_new_from_xml:
+ * @xnode:
+ *
+ * Returns: the newly created #RptObject object.
+ */
+RptObject
+*rpt_obj_image_new_from_xml (xmlNode *xnode)
+{
+       gchar *name;
+       RptObject *rpt_obj_image = NULL;
+
+       name = g_strdup ((gchar *)xmlGetProp (xnode, "name"));
+       if (name != NULL && strcmp (g_strstrip (name), "") != 0)
+               {
+                       RptPoint position;
+                       RptObjImagePrivate *priv;
+
+                       rpt_common_get_position (xnode, &position);
+
+                       rpt_obj_image = rpt_obj_image_new ((const gchar *)name, position);
+
+                       if (rpt_obj_image != NULL)
+                               {
+                                       priv = RPT_OBJ_IMAGE_GET_PRIVATE (rpt_obj_image);
+
+                                       rpt_common_get_size (xnode, priv->size);
+
+                                       priv->source = (gchar *)xmlGetProp (xnode, "source");
+                               }
+               }
+
+       return rpt_obj_image;
+}
+
+/**
+ * rpt_obj_image_get_xml:
+ * @rpt_objimage:
+ * @xnode:
+ *
+ */
+void
+rpt_obj_image_get_xml (RptObject *rpt_objimage, xmlNode *xnode)
+{
+       RptObjImagePrivate *priv = RPT_OBJ_IMAGE_GET_PRIVATE (rpt_objimage);
+
+       xmlNodeSetName (xnode, "image");
+
+       xmlSetProp (xnode, "width", g_strdup_printf ("%f", priv->size->width));
+       xmlSetProp (xnode, "height", g_strdup_printf ("%f", priv->size->height));
+       xmlSetProp (xnode, "source", priv->source);
+}
+
+static void
+rpt_obj_image_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+       RptObjImage *rpt_obj_image = RPT_OBJ_IMAGE (object);
+
+       RptObjImagePrivate *priv = RPT_OBJ_IMAGE_GET_PRIVATE (rpt_obj_image);
+
+       switch (property_id)
+               {
+                       case PROP_SIZE:
+                               priv->size = g_memdup (g_value_get_pointer (value), sizeof (RptSize));
+                               break;
+
+                       case PROP_SOURCE:
+                               priv->source = 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_obj_image_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+       RptObjImage *rpt_obj_image = RPT_OBJ_IMAGE (object);
+
+       RptObjImagePrivate *priv = RPT_OBJ_IMAGE_GET_PRIVATE (rpt_obj_image);
+
+       switch (property_id)
+               {
+                       case PROP_SIZE:
+                               g_value_set_pointer (value, g_memdup (priv->size, sizeof (RptSize)));
+                               break;
+
+                       case PROP_SOURCE:
+                               g_value_set_string (value, priv->source);
+                               break;
+
+                       default:
+                               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                               break;
+               }
+}
diff --git a/src/rptobjectimage.h b/src/rptobjectimage.h
new file mode 100644 (file)
index 0000000..c30bf92
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 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_IMAGE_H__
+#define __RPT_OBJ_IMAGE_H__
+
+#include <glib.h>
+#include <glib-object.h>
+#include <libxml/tree.h>
+
+#include "rptobject.h"
+
+G_BEGIN_DECLS
+
+
+#define TYPE_RPT_OBJ_IMAGE                 (rpt_obj_image_get_type ())
+#define RPT_OBJ_IMAGE(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_RPT_OBJ_IMAGE, RptObjImage))
+#define RPT_OBJ_IMAGE_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_RPT_OBJ_IMAGE, RptObjImageClass))
+#define IS_RPT_OBJ_IMAGE(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_RPT_OBJ_IMAGE))
+#define IS_RPT_OBJ_IMAGE_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_RPT_OBJ_IMAGE))
+#define RPT_OBJ_IMAGE_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_RPT_OBJ_IMAGE, RptObjImageClass))
+
+
+typedef struct _RptObjImage RptObjImage;
+typedef struct _RptObjImageClass RptObjImageClass;
+
+struct _RptObjImage
+       {
+               RptObject parent;
+       };
+
+struct _RptObjImageClass
+       {
+               RptObjectClass parent_class;
+       };
+
+GType rpt_obj_image_get_type (void) G_GNUC_CONST;
+
+
+RptObject *rpt_obj_image_new (const gchar *name, RptPoint position);
+RptObject *rpt_obj_image_new_from_xml (xmlNode *xnode);
+
+void rpt_obj_image_get_xml (RptObject *rpt_objimage, xmlNode *xnode);
+
+
+G_END_DECLS
+
+#endif /* __RPT_OBJ_IMAGE_H__ */
diff --git a/src/rptobjectline.c b/src/rptobjectline.c
new file mode 100644 (file)
index 0000000..4bfc138
--- /dev/null
@@ -0,0 +1,220 @@
+/*
+ * Copyright (C) 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 "rptobjectline.h"
+#include "rptcommon.h"
+
+enum
+{
+       PROP_0,
+       PROP_SIZE
+};
+
+static void rpt_obj_line_class_init (RptObjLineClass *klass);
+static void rpt_obj_line_init (RptObjLine *rpt_obj_line);
+
+static void rpt_obj_line_set_property (GObject *object,
+                                       guint property_id,
+                                       const GValue *value,
+                                       GParamSpec *pspec);
+static void rpt_obj_line_get_property (GObject *object,
+                                       guint property_id,
+                                       GValue *value,
+                                       GParamSpec *pspec);
+
+
+#define RPT_OBJ_LINE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_RPT_OBJ_LINE, RptObjLinePrivate))
+
+typedef struct _RptObjLinePrivate RptObjLinePrivate;
+struct _RptObjLinePrivate
+       {
+               RptSize *size;
+       };
+
+GType
+rpt_obj_line_get_type (void)
+{
+       static GType rpt_obj_line_type = 0;
+
+       if (!rpt_obj_line_type)
+               {
+                       static const GTypeInfo rpt_obj_line_info =
+                       {
+                               sizeof (RptObjLineClass),
+                               NULL,   /* base_init */
+                               NULL,   /* base_finalize */
+                               (GClassInitFunc) rpt_obj_line_class_init,
+                               NULL,   /* class_finalize */
+                               NULL,   /* class_data */
+                               sizeof (RptObjLine),
+                               0,      /* n_preallocs */
+                               (GInstanceInitFunc) rpt_obj_line_init,
+                               NULL
+                       };
+
+                       rpt_obj_line_type = g_type_register_static (TYPE_RPT_OBJECT, "RptObjLine",
+                                                                   &rpt_obj_line_info, 0);
+               }
+
+       return rpt_obj_line_type;
+}
+
+static void
+rpt_obj_line_class_init (RptObjLineClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+       RptObjectClass *rptobject_class = RPT_OBJECT_CLASS (klass);
+
+       g_type_class_add_private (object_class, sizeof (RptObjLinePrivate));
+
+       object_class->set_property = rpt_obj_line_set_property;
+       object_class->get_property = rpt_obj_line_get_property;
+
+       rptobject_class->get_xml = rpt_obj_line_get_xml;
+
+       g_object_class_install_property (object_class, PROP_SIZE,
+                                        g_param_spec_pointer ("size",
+                                                              "Size",
+                                                              "The object's size.",
+                                                              G_PARAM_READWRITE));
+}
+
+static void
+rpt_obj_line_init (RptObjLine *rpt_obj_line)
+{
+       RptObjLinePrivate *priv = RPT_OBJ_LINE_GET_PRIVATE (rpt_obj_line);
+
+       priv->size = (RptSize *)g_malloc0 (sizeof (RptSize));
+       priv->size->width = 0.0;
+       priv->size->height = 0.0;
+}
+
+/**
+ * rpt_obj_line_new:
+ * @name: the #RptObjLine's name.
+ * @position:
+ *
+ * Returns: the newly created #RptObject object.
+ */
+RptObject
+*rpt_obj_line_new (const gchar *name, RptPoint position)
+{
+       RptObject *rpt_obj_line = NULL;
+
+       gchar *name_ = g_strstrip (g_strdup (name));
+
+       if (strcmp (name_, "") != 0)
+               {
+                       rpt_obj_line = RPT_OBJECT (g_object_new (rpt_obj_line_get_type (), NULL));
+
+                       g_object_set (G_OBJECT (rpt_obj_line),
+                             "name", name_,
+                             "position", &position,
+                             NULL);
+               }
+
+       return rpt_obj_line;
+}
+
+/**
+ * rpt_obj_line_new_from_xml:
+ * @xnode:
+ *
+ * Returns: the newly created #RptObject object.
+ */
+RptObject
+*rpt_obj_line_new_from_xml (xmlNode *xnode)
+{
+       gchar *name;
+       RptObject *rpt_obj_line = NULL;
+
+       name = g_strdup ((gchar *)xmlGetProp (xnode, "name"));
+       if (name != NULL && strcmp (g_strstrip (name), "") != 0)
+               {
+                       RptPoint position;
+                       RptObjLinePrivate *priv;
+
+                       rpt_common_get_position (xnode, &position);
+
+                       rpt_obj_line = rpt_obj_line_new ((const gchar *)name, position);
+
+                       if (rpt_obj_line != NULL)
+                               {
+                                       priv = RPT_OBJ_LINE_GET_PRIVATE (rpt_obj_line);
+
+                                       rpt_common_get_size (xnode, priv->size);
+                               }
+               }
+
+       return rpt_obj_line;
+}
+
+/**
+ * rpt_obj_line_get_xml:
+ * @rpt_objline:
+ * @xnode:
+ *
+ */
+void
+rpt_obj_line_get_xml (RptObject *rpt_objline, xmlNode *xnode)
+{
+       RptObjLinePrivate *priv = RPT_OBJ_LINE_GET_PRIVATE (rpt_objline);
+
+       xmlNodeSetName (xnode, "line");
+
+       xmlSetProp (xnode, "width", g_strdup_printf ("%f", priv->size->width));
+       xmlSetProp (xnode, "height", g_strdup_printf ("%f", priv->size->height));
+}
+
+static void
+rpt_obj_line_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+       RptObjLine *rpt_obj_line = RPT_OBJ_LINE (object);
+
+       RptObjLinePrivate *priv = RPT_OBJ_LINE_GET_PRIVATE (rpt_obj_line);
+
+       switch (property_id)
+               {
+                       case PROP_SIZE:
+                               priv->size = g_memdup (g_value_get_pointer (value), sizeof (RptSize));
+                               break;
+
+                       default:
+                               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                               break;
+               }
+}
+
+static void
+rpt_obj_line_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+       RptObjLine *rpt_obj_line = RPT_OBJ_LINE (object);
+
+       RptObjLinePrivate *priv = RPT_OBJ_LINE_GET_PRIVATE (rpt_obj_line);
+
+       switch (property_id)
+               {
+                       case PROP_SIZE:
+                               g_value_set_pointer (value, g_memdup (priv->size, sizeof (RptSize)));
+                               break;
+
+                       default:
+                               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                               break;
+               }
+}
diff --git a/src/rptobjectline.h b/src/rptobjectline.h
new file mode 100644 (file)
index 0000000..647a17b
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 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_LINE_H__
+#define __RPT_OBJ_LINE_H__
+
+#include <glib.h>
+#include <glib-object.h>
+#include <libxml/tree.h>
+
+#include "rptobject.h"
+
+G_BEGIN_DECLS
+
+
+#define TYPE_RPT_OBJ_LINE                 (rpt_obj_line_get_type ())
+#define RPT_OBJ_LINE(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_RPT_OBJ_LINE, RptObjLine))
+#define RPT_OBJ_LINE_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_RPT_OBJ_LINE, RptObjLineClass))
+#define IS_RPT_OBJ_LINE(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_RPT_OBJ_LINE))
+#define IS_RPT_OBJ_LINE_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_RPT_OBJ_LINE))
+#define RPT_OBJ_LINE_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_RPT_OBJ_LINE, RptObjLineClass))
+
+
+typedef struct _RptObjLine RptObjLine;
+typedef struct _RptObjLineClass RptObjLineClass;
+
+struct _RptObjLine
+       {
+               RptObject parent;
+       };
+
+struct _RptObjLineClass
+       {
+               RptObjectClass parent_class;
+       };
+
+GType rpt_obj_line_get_type (void) G_GNUC_CONST;
+
+
+RptObject *rpt_obj_line_new (const gchar *name, RptPoint position);
+RptObject *rpt_obj_line_new_from_xml (xmlNode *xnode);
+
+void rpt_obj_line_get_xml (RptObject *rpt_objline, xmlNode *xnode);
+
+G_END_DECLS
+
+#endif /* __RPT_OBJ_LINE_H__ */
diff --git a/src/rptobjectrect.c b/src/rptobjectrect.c
new file mode 100644 (file)
index 0000000..a47bc64
--- /dev/null
@@ -0,0 +1,202 @@
+/*
+ * Copyright (C) 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 "rptobjectrect.h"
+#include "rptcommon.h"
+
+enum
+{
+       PROP_0
+};
+
+static void rpt_obj_rect_class_init (RptObjRectClass *klass);
+static void rpt_obj_rect_init (RptObjRect *rpt_obj_rect);
+
+static void rpt_obj_rect_set_property (GObject *object,
+                                       guint property_id,
+                                       const GValue *value,
+                                       GParamSpec *pspec);
+static void rpt_obj_rect_get_property (GObject *object,
+                                       guint property_id,
+                                       GValue *value,
+                                       GParamSpec *pspec);
+
+
+#define RPT_OBJ_RECT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_RPT_OBJ_RECT, RptObjRectPrivate))
+
+typedef struct _RptObjRectPrivate RptObjRectPrivate;
+struct _RptObjRectPrivate
+       {
+       };
+
+GType
+rpt_obj_rect_get_type (void)
+{
+       static GType rpt_obj_rect_type = 0;
+
+       if (!rpt_obj_rect_type)
+               {
+                       static const GTypeInfo rpt_obj_rect_info =
+                       {
+                               sizeof (RptObjRectClass),
+                               NULL,   /* base_init */
+                               NULL,   /* base_finalize */
+                               (GClassInitFunc) rpt_obj_rect_class_init,
+                               NULL,   /* class_finalize */
+                               NULL,   /* class_data */
+                               sizeof (RptObjRect),
+                               0,      /* n_preallocs */
+                               (GInstanceInitFunc) rpt_obj_rect_init,
+                               NULL
+                       };
+
+                       rpt_obj_rect_type = g_type_register_static (TYPE_RPT_OBJ_LINE, "RptObjRect",
+                                                                   &rpt_obj_rect_info, 0);
+               }
+
+       return rpt_obj_rect_type;
+}
+
+static void
+rpt_obj_rect_class_init (RptObjRectClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+       RptObjectClass *rptobject_class = RPT_OBJECT_CLASS (klass);
+
+       g_type_class_add_private (object_class, sizeof (RptObjRectPrivate));
+
+       object_class->set_property = rpt_obj_rect_set_property;
+       object_class->get_property = rpt_obj_rect_get_property;
+
+       rptobject_class->get_xml = rpt_obj_rect_get_xml;
+}
+
+static void
+rpt_obj_rect_init (RptObjRect *rpt_obj_rect)
+{
+       RptObjRectPrivate *priv = RPT_OBJ_RECT_GET_PRIVATE (rpt_obj_rect);
+}
+
+/**
+ * rpt_obj_rect_new:
+ * @name: the #RptObjRect's name.
+ * @position:
+ *
+ * Returns: the newly created #RptObject object.
+ */
+RptObject
+*rpt_obj_rect_new (const gchar *name, RptPoint position)
+{
+       RptObject *rpt_obj_rect = NULL;
+
+       gchar *name_ = g_strstrip (g_strdup (name));
+
+       if (strcmp (name_, "") != 0)
+               {
+                       rpt_obj_rect = RPT_OBJECT (g_object_new (rpt_obj_rect_get_type (), NULL));
+
+                       g_object_set (G_OBJECT (rpt_obj_rect),
+                             "name", name_,
+                             "position", &position,
+                             NULL);
+               }
+
+       return rpt_obj_rect;
+}
+
+/**
+ * rpt_obj_rect_new_from_xml:
+ * @xnode:
+ *
+ * Returns: the newly created #RptObject object.
+ */
+RptObject
+*rpt_obj_rect_new_from_xml (xmlNode *xnode)
+{
+       gchar *name;
+       RptObject *rpt_obj_rect = NULL;
+
+       name = g_strdup ((gchar *)xmlGetProp (xnode, "name"));
+       if (name != NULL && strcmp (g_strstrip (name), "") != 0)
+               {
+                       RptPoint position;
+                       RptObjRectPrivate *priv;
+
+                       rpt_common_get_position (xnode, &position);
+
+                       rpt_obj_rect = rpt_obj_rect_new ((const gchar *)name, position);
+
+                       if (rpt_obj_rect != NULL)
+                               {
+                                       RptSize size;
+
+                                       priv = RPT_OBJ_RECT_GET_PRIVATE (rpt_obj_rect);
+
+                                       rpt_common_get_size (xnode, &size);
+                                       g_object_set (G_OBJECT (rpt_obj_rect), "size", &size, NULL);
+                               }
+               }
+
+       return rpt_obj_rect;
+}
+
+/**
+ * rpt_obj_rect_get_xml:
+ * @rpt_object:
+ * @xnode:
+ *
+ */
+void
+rpt_obj_rect_get_xml (RptObject *rpt_object, xmlNode *xnode)
+{
+       RptObjRectPrivate *priv = RPT_OBJ_RECT_GET_PRIVATE (RPT_OBJ_RECT (rpt_object));
+
+       rpt_obj_line_get_xml (rpt_object, xnode);
+
+       xmlNodeSetName (xnode, "rect");
+}
+
+static void
+rpt_obj_rect_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+       RptObjRect *rpt_obj_rect = RPT_OBJ_RECT (object);
+
+       RptObjRectPrivate *priv = RPT_OBJ_RECT_GET_PRIVATE (rpt_obj_rect);
+
+       switch (property_id)
+               {
+                       default:
+                               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                               break;
+               }
+}
+
+static void
+rpt_obj_rect_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+       RptObjRect *rpt_obj_rect = RPT_OBJ_RECT (object);
+
+       RptObjRectPrivate *priv = RPT_OBJ_RECT_GET_PRIVATE (rpt_obj_rect);
+
+       switch (property_id)
+               {
+                       default:
+                               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                               break;
+               }
+}
diff --git a/src/rptobjectrect.h b/src/rptobjectrect.h
new file mode 100644 (file)
index 0000000..89279a9
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 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_RECT_H__
+#define __RPT_OBJ_RECT_H__
+
+#include <glib.h>
+#include <glib-object.h>
+#include <libxml/tree.h>
+
+#include "rptobjectline.h"
+
+G_BEGIN_DECLS
+
+
+#define TYPE_RPT_OBJ_RECT                 (rpt_obj_rect_get_type ())
+#define RPT_OBJ_RECT(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_RPT_OBJ_RECT, RptObjRect))
+#define RPT_OBJ_RECT_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_RPT_OBJ_RECT, RptObjRectClass))
+#define IS_RPT_OBJ_RECT(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_RPT_OBJ_RECT))
+#define IS_RPT_OBJ_RECT_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_RPT_OBJ_RECT))
+#define RPT_OBJ_RECT_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_RPT_OBJ_RECT, RptObjRectClass))
+
+
+typedef struct _RptObjRect RptObjRect;
+typedef struct _RptObjRectClass RptObjRectClass;
+
+struct _RptObjRect
+       {
+               RptObjLine parent;
+       };
+
+struct _RptObjRectClass
+       {
+               RptObjLineClass parent_class;
+       };
+
+GType rpt_obj_rect_get_type (void) G_GNUC_CONST;
+
+
+RptObject *rpt_obj_rect_new (const gchar *name, RptPoint position);
+RptObject *rpt_obj_rect_new_from_xml (xmlNode *xnode);
+
+void rpt_obj_rect_get_xml (RptObject *rpt_object, xmlNode *xnode);
+
+G_END_DECLS
+
+#endif /* __RPT_OBJ_RECT_H__ */
index d654ebc5b25f46f511234ac019e95babdf10c487..8644f460e6dc217a0d32b5a8f2687aa048b043c5 100644 (file)
 #include "rptcommon.h"
 #include "rptobject.h"
 #include "rptobjecttext.h"
+#include "rptobjectline.h"
+#include "rptobjectrect.h"
+#include "rptobjectimage.h"
+
+typedef enum
+{
+       RPTREPORT_SECTION_PAGE_HEADER,
+       RPTREPORT_SECTION_PAGE_FOOTER,
+       RPTREPORT_SECTION_BODY
+} RptReportSection;
 
 typedef struct
 {
        RptSize *size;
 } Page;
 
+typedef struct
+{
+       gdouble height;
+       GList *objects;
+} PageHeader;
+
+typedef struct
+{
+       gdouble height;
+       GList *objects;
+} PageFooter;
+
 typedef struct
 {
        gdouble height;
@@ -59,17 +81,21 @@ static void rpt_report_get_property (GObject *object,
                                      GValue *value,
                                      GParamSpec *pspec);
 
-static void rpt_report_xml_parse_body (RptReport *rpt_report, xmlNode *xnode);
-static RptObject *rpt_report_get_object_from_name (GList *list, const gchar *name);
+static void rpt_report_xml_parse_section (RptReport *rpt_report, xmlNode *xnode, RptReportSection section);
 
-static xmlNode *rpt_report_rptprint_new_page (RptReport *rptreport,
+static RptObject *rpt_report_get_object_from_name (RptReport *rpt_report, const gchar *name);
+static RptObject *rpt_report_get_object_from_name_in_list (GList *list, const gchar *name);
+
+static xmlNode *rpt_report_rptprint_new_page (RptReport *rpt_report,
                                               xmlNode *xroot);
-static void rpt_report_rptprint_body (RptReport *rptreport,
-                                      xmlNode *xpage,
-                                      gdouble *cur_y);
-static void rpt_report_rptprint_parse_source (RptReport *rptreport,
-                                              RptObject *rptobj,
-                                              xmlNode *xnode);
+static void rpt_report_rptprint_section (RptReport *rpt_report,
+                                         xmlNode *xpage,
+                                         gdouble *cur_y,
+                                         RptReportSection section);
+                                                                         
+static void rpt_report_rptprint_parse_text_source (RptReport *rpt_report,
+                                                   RptObject *rptobj,
+                                                   xmlNode *xnode);
 
 
 #define RPT_REPORT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_RPT_REPORT, RptReportPrivate))
@@ -82,6 +108,8 @@ struct _RptReportPrivate
                GdaDataModel *gda_datamodel;
 
                Page *page;
+               PageHeader *page_header;
+               PageFooter *page_footer;
                Body *body;
        };
 
@@ -138,8 +166,17 @@ rpt_report_init (RptReport *rpt_report)
        priv->page->size->width = 0.0;
        priv->page->size->height = 0.0;
 
+       priv->page_header = (PageHeader *)g_malloc0 (sizeof (PageHeader));
+       priv->page_header->height = 0.0;
+       priv->page_header->objects = NULL;
+
+       priv->page_footer = (PageFooter *)g_malloc0 (sizeof (PageFooter));
+       priv->page_footer->height = 0.0;
+       priv->page_footer->objects = NULL;
+
        priv->body = (Body *)g_malloc0 (sizeof (Body));
        priv->body->height = 0.0;
+       priv->body->objects = NULL;
 }
 
 /**
@@ -176,17 +213,11 @@ RptReport
                                                        xnodeset = xpresult->nodesetval;
                                                        if (xnodeset->nodeNr == 1)
                                                                {
-                                                                       gchar *prop;
-                                                                       prop = xmlGetProp (xnodeset->nodeTab[0], (const xmlChar *)"width");
-                                                                       if (prop != NULL)
-                                                                               {
-                                                                                       priv->page->size->width = strtod (prop, NULL);
-                                                                               }
-                                                                       prop = xmlGetProp (xnodeset->nodeTab[0], (const xmlChar *)"height");
-                                                                       if (prop != NULL)
-                                                                               {
-                                                                                       priv->page->size->height = strtod (prop, NULL);
-                                                                               }
+                                                                       RptSize size;
+
+                                                                       rpt_common_get_size (xnodeset->nodeTab[0], &size);
+                                                                       priv->page->size->width = size.width;
+                                                                       priv->page->size->height = size.height;
                                                                }
                                                        else
                                                                {
@@ -271,16 +302,33 @@ RptReport
                                                        xnodeset = xpresult->nodesetval;
                                                        if (xnodeset->nodeNr == 1)
                                                                {
+                                                                       /* search for node "page-header" */
+                                                                       xpcontext->node = xnodeset->nodeTab[0];
+                                                                       xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::page-header", xpcontext);
+                                                                       if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval) && xpresult->nodesetval->nodeNr == 1)
+                                                                               {
+                                                                                       rpt_report_xml_parse_section (rpt_report, xpresult->nodesetval->nodeTab[0], RPTREPORT_SECTION_PAGE_HEADER);
+                                                                               }
+
+                                                                       /* search for node "page-footer" */
+                                                                       xpcontext->node = xnodeset->nodeTab[0];
+                                                                       xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::page-footer", xpcontext);
+                                                                       if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval) && xpresult->nodesetval->nodeNr == 1)
+                                                                               {
+                                                                                       rpt_report_xml_parse_section (rpt_report, xpresult->nodesetval->nodeTab[0], RPTREPORT_SECTION_PAGE_FOOTER);
+                                                                               }
+
                                                                        /* search for node "body" */
                                                                        xpcontext->node = xnodeset->nodeTab[0];
                                                                        xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::body", xpcontext);
-                                                                       if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval))
+                                                                       if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval) && xpresult->nodesetval->nodeNr == 1)
                                                                                {
-                                                                                       xnodeset = xpresult->nodesetval;
-                                                                                       if (xnodeset->nodeNr == 1)
-                                                                                               {
-                                                                                                       rpt_report_xml_parse_body (rpt_report, xnodeset->nodeTab[0]);
-                                                                                               }
+                                                                                       rpt_report_xml_parse_section (rpt_report, xpresult->nodesetval->nodeTab[0], RPTREPORT_SECTION_BODY);
+                                                                               }
+                                                                       else
+                                                                               {
+                                                                                       /* TO DO */
+                                                                                       /* return */
                                                                                }
                                                                }
                                                        else
@@ -326,15 +374,15 @@ RptReport
 
 /**
  * rpt_report_get_xml:
- * @rptreport: an #RptReport object.
+ * @rpt_report: an #RptReport object.
  *
  */
 xmlDoc
-*rpt_report_get_xml (RptReport *rptreport)
+*rpt_report_get_xml (RptReport *rpt_report)
 {
-       xmlDoc *xdoc;
+       xmlDoc *xdoc = NULL;
 
-       RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rptreport);
+       RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report);
 
        /* TO DO */
 
@@ -343,19 +391,19 @@ xmlDoc
 
 /**
  * rpt_report_get_xml_rptprint:
- * @rptreport: an #RptReport object.
+ * @rpt_report: an #RptReport object.
  *
  */
 xmlDoc
-*rpt_report_get_xml_rptprint (RptReport *rptreport)
+*rpt_report_get_xml_rptprint (RptReport *rpt_report)
 {
        xmlDoc *xdoc;
        xmlNode *xroot;
        xmlNode *xpage;
-       gint pages;
+       gint pages = 0;
        gdouble cur_y = 0.0;
 
-       RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rptreport);
+       RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report);
 
        xdoc = xmlNewDoc ("1.0");
        xroot = xmlNewNode (NULL, "reptool_report");
@@ -370,21 +418,51 @@ xmlDoc
 
                        for (row = 0; row < rows; row++)
                                {
-                                       if (row == 0 || cur_y > priv->page->size->height)
+                                       if (row == 0 ||
+                                           (priv->page_footer != NULL && (cur_y > priv->page->size->height - priv->page_footer->height)) ||
+                                           cur_y > priv->page->size->height)
                                                {
+                                                       if (pages > 0 && priv->page_footer != NULL)
+                                                               {
+                                                                       cur_y = priv->page->size->height - priv->page_footer->height;
+                                                                       rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_PAGE_FOOTER);
+                                                               }
+
                                                        cur_y = 0.0;
                                                        pages++;
-                                                       xpage = rpt_report_rptprint_new_page (rptreport, xroot);
+                                                       xpage = rpt_report_rptprint_new_page (rpt_report, xroot);
+
+                                                       if (priv->page_header != NULL)
+                                                               {
+                                                                       rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_PAGE_HEADER);
+                                                               }
                                                }
 
-                                       rpt_report_rptprint_body (rptreport, xpage, &cur_y);
+                                       rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_BODY);
+                               }
+
+                       if (pages > 0 && priv->page_footer != NULL)
+                               {
+                                       cur_y = priv->page->size->height - priv->page_footer->height;
+                                       rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_PAGE_FOOTER);
                                }
                }
        else
                {
+                       if (priv->page_header != NULL)
+                               {
+                                       rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_PAGE_HEADER);
+                               }
+
                        pages++;
-                       xpage = rpt_report_rptprint_new_page (rptreport, xroot);
-                       rpt_report_rptprint_body (rptreport, xpage, &cur_y);
+                       xpage = rpt_report_rptprint_new_page (rpt_report, xroot);
+                       rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_BODY);
+
+                       if (priv->page_footer != NULL)
+                               {
+                                       cur_y = priv->page->size->height - priv->page_footer->height;
+                                       rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_PAGE_FOOTER);
+                               }
                }
 
        return xdoc;
@@ -421,9 +499,11 @@ rpt_report_get_property (GObject *object, guint property_id, GValue *value, GPar
 }
 
 static void
-rpt_report_xml_parse_body (RptReport *rpt_report, xmlNode *xnode)
+rpt_report_xml_parse_section (RptReport *rpt_report, xmlNode *xnode, RptReportSection section)
 {
        RptObject *rptobj;
+       GList *objects = NULL;
+       gdouble height;
        gchar *prop;
        gchar *objname;
        xmlNode *cur;
@@ -433,7 +513,7 @@ rpt_report_xml_parse_body (RptReport *rpt_report, xmlNode *xnode)
        prop = (gchar *)xmlGetProp (xnode, "height");
        if (prop != NULL)
                {
-                       priv->body->height = strtod (g_strstrip (g_strdup (prop)), NULL);
+                       height = strtod (g_strstrip (g_strdup (prop)), NULL);
                }
 
        cur = xnode->children;
@@ -442,37 +522,79 @@ rpt_report_xml_parse_body (RptReport *rpt_report, xmlNode *xnode)
                        if (strcmp (cur->name, "text") == 0)
                                {
                                        rptobj = rpt_obj_text_new_from_xml (cur);
-                                       if (rptobj != NULL)
-                                               {
-                                                       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 */
-                                                                       g_warning ("An object with name \"%s\" already exists.", objname);
-                                                               }
-                                               }
                                }
                        else if (strcmp (cur->name, "line") == 0)
                                {
+                                       rptobj = rpt_obj_line_new_from_xml (cur);
                                }
                        else if (strcmp (cur->name, "rect") == 0)
                                {
+                                       rptobj = rpt_obj_rect_new_from_xml (cur);
                                }
                        else if (strcmp (cur->name, "image") == 0)
                                {
+                                       rptobj = rpt_obj_image_new_from_xml (cur);
+                               }
+
+                       if (rptobj != NULL)
+                               {
+                                       g_object_get (rptobj, "name", &objname, NULL);
+
+                                       if (rpt_report_get_object_from_name (rpt_report, objname) == NULL)
+                                               {
+                                                       objects = g_list_append (objects, rptobj);
+                                               }
+                                       else
+                                               {
+                                                       /* TO DO */
+                                                       g_warning ("An object with name \"%s\" already exists.", objname);
+                                               }
                                }
 
                        cur = cur->next;
                }
+
+       switch (section)
+               {
+                       case RPTREPORT_SECTION_PAGE_HEADER:
+                               priv->page_header->height = height;
+                               priv->page_header->objects = objects;
+                               break;
+
+                       case RPTREPORT_SECTION_PAGE_FOOTER:
+                               priv->page_footer->height = height;
+                               priv->page_footer->objects = objects;
+                               break;
+
+                       case RPTREPORT_SECTION_BODY:
+                               priv->body->height = height;
+                               priv->body->objects = objects;
+                               break;
+               }
+}
+
+static RptObject
+*rpt_report_get_object_from_name (RptReport *rpt_report, const gchar *name)
+{
+       RptObject *obj = NULL;
+
+       RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report);
+
+       if ((obj = rpt_report_get_object_from_name_in_list (priv->page_header->objects, name)) != NULL)
+               {
+               }
+       else if ((obj = rpt_report_get_object_from_name_in_list (priv->page_footer->objects, name)) != NULL)
+               {
+               }
+       else if ((obj = rpt_report_get_object_from_name_in_list (priv->body->objects, name)) != NULL)
+               {
+               }
+
+       return obj;
 }
 
 static RptObject
-*rpt_report_get_object_from_name (GList *list, const gchar *name)
+*rpt_report_get_object_from_name_in_list (GList *list, const gchar *name)
 {
        gchar *objname;
        RptObject *obj = NULL;
@@ -494,11 +616,11 @@ static RptObject
 }
 
 static xmlNode
-*rpt_report_rptprint_new_page (RptReport *rptreport, xmlNode *xroot)
+*rpt_report_rptprint_new_page (RptReport *rpt_report, xmlNode *xroot)
 {
        xmlNode *xnode;
 
-       RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rptreport);
+       RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report);
 
        xnode = xmlNewNode (NULL, "page");
        xmlSetProp (xnode, "width", g_strdup_printf ("%f", priv->page->size->width));
@@ -509,7 +631,7 @@ static xmlNode
 }
 
 static void
-rpt_report_rptprint_body (RptReport *rptreport, xmlNode *xpage, gdouble *cur_y)
+rpt_report_rptprint_section (RptReport *rpt_report, xmlNode *xpage, gdouble *cur_y, RptReportSection section)
 {
        GList *objects;
        xmlAttrPtr attr;
@@ -518,9 +640,23 @@ rpt_report_rptprint_body (RptReport *rptreport, xmlNode *xpage, gdouble *cur_y)
 
        RptObject *rptobj;
 
-       RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rptreport);
+       RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report);
+
+       switch (section)
+               {
+                       case RPTREPORT_SECTION_PAGE_HEADER:
+                               objects = g_list_first (priv->page_header->objects);
+                               break;
+
+                       case RPTREPORT_SECTION_PAGE_FOOTER:
+                               objects = g_list_first (priv->page_footer->objects);
+                               break;
+
+                       case RPTREPORT_SECTION_BODY:
+                               objects = g_list_first (priv->body->objects);
+                               break;
+               }
 
-       objects = g_list_first (priv->body->objects);
        while (objects != NULL)
                {
                        xnode = xmlNewNode (NULL, "node");
@@ -542,18 +678,37 @@ rpt_report_rptprint_body (RptReport *rptreport, xmlNode *xpage, gdouble *cur_y)
 
                        if (IS_RPT_OBJ_TEXT (rptobj))
                                {
-                                       rpt_report_rptprint_parse_source (rptreport, rptobj, xnode);
+                                       rpt_report_rptprint_parse_text_source (rpt_report, rptobj, xnode);
+                               }
+                       else if (IS_RPT_OBJ_IMAGE (rptobj))
+                               {
+                                       /* TO DO */
+                                       /* rpt_report_rptprint_parse_image_source (rpt_report, rptobj, xnode); */
                                }
 
                        xmlAddChild (xpage, xnode);
 
                        objects = g_list_next (objects);
                }
-       *cur_y += priv->body->height;
+
+       switch (section)
+               {
+                       case RPTREPORT_SECTION_PAGE_HEADER:
+                               *cur_y += priv->page_header->height;
+                               break;
+
+                       case RPTREPORT_SECTION_PAGE_FOOTER:
+                               *cur_y += priv->page_footer->height;
+                               break;
+
+                       case RPTREPORT_SECTION_BODY:
+                               *cur_y += priv->body->height;
+                               break;
+               }
 }
 
 static void
-rpt_report_rptprint_parse_source (RptReport *rptreport, RptObject *rptobj, xmlNode *xnode)
+rpt_report_rptprint_parse_text_source (RptReport *rpt_report, RptObject *rptobj, xmlNode *xnode)
 {
        /* TO DO */
        gchar *source;
index f909086fa10e72d7664079a105fc47dde88354f0..17a56cbda7a5b61397605b702ebff1cfe0e3ad88 100644 (file)
@@ -54,9 +54,9 @@ 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_xml (RptReport *rpt_report);
 
-xmlDoc *rpt_report_get_xml_rptprint (RptReport *rptreport);
+xmlDoc *rpt_report_get_xml_rptprint (RptReport *rpt_report);
 
 
 G_END_DECLS
index bd83131fc31cac27aede58aa050b12fd8a3bf36d..10c0ceeb8da764b60b865c162289cbfaa00bb7f2 100644 (file)
@@ -5,7 +5,7 @@ AM_CPPFLAGS = $(REPTOOL_CFLAGS) \
 
 libreptool = $(top_builddir)/src/libreptool.la
 
-noinst_PROGRAMS = rptprint \
-                  rptreport
+noinst_PROGRAMS = test_rptprint \
+                  test_rptreport
 
 LDADD = $(libreptool)
diff --git a/tests/gnome-globe.png b/tests/gnome-globe.png
new file mode 100644 (file)
index 0000000..c85ca9f
Binary files /dev/null and b/tests/gnome-globe.png differ
diff --git a/tests/rptprint.c b/tests/rptprint.c
deleted file mode 100644 (file)
index dd3f82d..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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
- * 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 Library 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., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301,  USA
- */
-
-#include <rptprint.h>
-
-int
-main (int argc, char **argv)
-{
-       RptPrint *rptp;
-
-       g_type_init ();
-
-       rptp = rpt_print_new_from_file (argv[1], RPTP_OUTPUT_PDF, "test.pdf");
-
-       if (rptp != NULL)
-               {
-               }
-
-       return 0;
-}
diff --git a/tests/rptreport.c b/tests/rptreport.c
deleted file mode 100644 (file)
index 9302321..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (C) 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
- * 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 Library 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., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301,  USA
- */
-
-#include <rptreport.h>
-
-int
-main (int argc, char **argv)
-{
-       RptReport *rptr;
-
-       g_type_init ();
-
-       rptr = rpt_report_new_from_file (argv[1]);
-
-       if (rptr != NULL)
-               {
-                       xmlDoc *rptprint = rpt_report_get_xml_rptprint (rptr);
-                       xmlSaveFormatFile ("test_report.rptr", rptprint, 2);
-               }
-
-       return 0;
-}
index 525acea26da787c479c1a519ae98ac90a89f9a17..b173566a672af94b2b86d13504aea39e336e3b29 100644 (file)
@@ -9,6 +9,19 @@
        </database>
 
        <report>
-               <body height="200"><text name="txt_id" x="50" y="50" width="100" height="50" source="[id]" /><text name="txt_name" x="200" y="50" width="100" height="50" source="[name]" /></body>
+               <page-header height="80">
+                       <text name="title" x="10" y="10" width="300" height="50" source="the page title" />
+                       <line name="line1" x="10" y="65" width="500" height="0" />
+               </page-header>
+               <body height="200">
+                       <text name="txt_id" x="50" y="50" width="100" height="50" source="[id]" />
+                       <text name="txt_name" x="200" y="50" width="100" height="50" source="[name]" />
+                       <rect name="rect1" x="400" y="10" width="20" height="20" />
+                       <image name="img1" x="450" y="10" width="60" height="60" source="tests/gnome-globe.png" />
+               </body>
+               <page-footer height="80">
+                       <line name="line2" x="10" y="10" width="500" height="0" />
+                       <text name="footer" x="10" y="20" width="300" height="50" source="the page footer" />
+               </page-footer>
        </report>
 </reptool>
diff --git a/tests/test_rptprint.c b/tests/test_rptprint.c
new file mode 100644 (file)
index 0000000..dd3f82d
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * 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
+ * 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 Library 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., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301,  USA
+ */
+
+#include <rptprint.h>
+
+int
+main (int argc, char **argv)
+{
+       RptPrint *rptp;
+
+       g_type_init ();
+
+       rptp = rpt_print_new_from_file (argv[1], RPTP_OUTPUT_PDF, "test.pdf");
+
+       if (rptp != NULL)
+               {
+               }
+
+       return 0;
+}
diff --git a/tests/test_rptreport.c b/tests/test_rptreport.c
new file mode 100644 (file)
index 0000000..9302321
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 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
+ * 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 Library 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., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301,  USA
+ */
+
+#include <rptreport.h>
+
+int
+main (int argc, char **argv)
+{
+       RptReport *rptr;
+
+       g_type_init ();
+
+       rptr = rpt_report_new_from_file (argv[1]);
+
+       if (rptr != NULL)
+               {
+                       xmlDoc *rptprint = rpt_report_get_xml_rptprint (rptr);
+                       xmlSaveFormatFile ("test_report.rptr", rptprint, 2);
+               }
+
+       return 0;
+}