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])
<!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
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)>
"x CDATA #REQUIRED
y CDATA #REQUIRED"
>
+
<!ENTITY % object_size_attrs
"width CDATA #REQUIRED
height CDATA #REQUIRED"
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
#ifndef __LIBREPTOOL_H__
#define __LIBREPTOOL_H__
+#include <rptreport.h>
#include <rptprint.h>
#endif /* __LIBREPTOOL_H__ */
--- /dev/null
+/*
+ * 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);
+ }
+}
--- /dev/null
+/*
+ * 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__ */
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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__ */
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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__ */
/*
- * 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
{
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;
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,
typedef struct _RptPrintPrivate RptPrintPrivate;
struct _RptPrintPrivate
{
- gint width,
- height;
+ gint width;
+ gint height;
cairo_surface_t *surface;
cairo_t *cr;
};
{
if (strcmp (cur->name, "reptool_report") == 0)
{
-#if 0
FILE *fout;
-#endif
RptPrintPrivate *priv;
gint npage = 0;
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)
{
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;
}
}
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);
}
{
cairo_destroy (priv->cr);
}
-#if 0
if (output_type != RPTP_OUTPUT_PNG)
{
fclose (fout);
}
-#endif
}
else
{
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);
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;
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");
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;
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);
}
}
-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)
{
/*
- * 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
--- /dev/null
+/*
+ * 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;
+}
--- /dev/null
+/*
+ * 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__ */
/*
- * 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
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)
{
+++ /dev/null
-<?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>
--- /dev/null
+<?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>
--- /dev/null
+<?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>