]> saetta.ns0.it Git - reptool/libreptool/commitdiff
Moved some functions from rpt_print to rpt_common.
authorAndrea Zagli <azagli@libero.it>
Mon, 26 Mar 2007 16:16:23 +0000 (16:16 +0000)
committerAndrea Zagli <azagli@libero.it>
Mon, 26 Mar 2007 16:16:23 +0000 (16:16 +0000)
Extended RptObjText.
RptObjText's source attribute now read value from database field.

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

configure.ac
data/reptool_report.dtd
src/rptcommon.c
src/rptcommon.h
src/rptobjecttext.c
src/rptprint.c
src/rptreport.c
tests/test_report_db.rpt

index 7a37f9c9a1af29f60d2eab55d656e46e63eaa736..10e3d65e11af4653e2cd48b97cfa240be7ddafe7 100644 (file)
@@ -2,7 +2,7 @@
 # Process this file with autoconf to produce a configure script.
 
 AC_PREREQ(2.59)
-AC_INIT([libreptool], [0.0.1], [azagli@inwind.it])
+AC_INIT([libreptool], [0.0.2], [azagli@inwind.it])
 AC_CONFIG_SRCDIR([src/rptprint.c])
 AC_CONFIG_HEADER([config.h])
 
index bc7cff75cb94e764f028d1fb9941f182fc37fcaf..4b230efe5288c6f7c8f81b47f25bf42f92e3f326 100644 (file)
@@ -3,13 +3,13 @@
 >
 
 <!ENTITY % object_position_attrs
- "x        CDATA #REQUIRED
-  y        CDATA #REQUIRED"
 "x        CDATA #REQUIRED
+   y        CDATA #REQUIRED"
 >
 
 <!ENTITY % object_size_attrs
- "width    CDATA #REQUIRED
-  height   CDATA #REQUIRED"
 "width    CDATA #REQUIRED
+   height   CDATA #REQUIRED"
 >
 
 <!ENTITY % object_border_attrs
@@ -44,8 +44,8 @@
 >
 
 <!ENTITY % object_text_align_attrs
- "horizontal-align   (left | center | right | justified) #IMPLIED
-  vertical-align     (top | center | bottom) #IMPLIED"
 "horizontal-align   (left | center | right | justified) #IMPLIED
+   vertical-align     (top | center | bottom) #IMPLIED"
 >
 
 <!ELEMENT text (#PCDATA)>
index f8d43f265c1d1546400041de4568dd2566a8b10d..e4dbf6a39c39ba0f445c8ec2fa275e65da4df235 100644 (file)
@@ -21,6 +21,8 @@
 
 #include "rptcommon.h"
 
+static gchar *convert_to_str_color (RptColor color);
+
 /**
  * rpt_common_get_position:
  * @xnode:
@@ -72,3 +74,393 @@ rpt_common_get_size (xmlNode *xnode, RptSize *size)
                        size->height = strtod (prop, NULL);
                }
 }
+
+/**
+ * rpt_common_get_font:
+ * @xnode:
+ * @font:
+ *
+ */
+void
+rpt_common_get_font (xmlNode *xnode, RptFont *font)
+{
+       gchar *prop;
+
+       font->name = g_strdup ("sans");
+       font->size = 12.0;
+       font->bold = FALSE;
+       font->italic = FALSE;
+       font->underline = FALSE;
+       font->strike = FALSE;
+       font->color.r = 0.0;
+       font->color.g = 0.0;
+       font->color.b = 0.0;
+       font->color.a = 1.0;
+
+       prop = xmlGetProp (xnode, "font-name");
+       if (prop != NULL)
+               {
+                       font->name = g_strdup (prop);
+               }
+
+       prop = xmlGetProp (xnode, "font-size");
+       if (prop != NULL)
+               {
+                       font->size = strtod (prop, NULL);
+               }
+
+       prop = xmlGetProp (xnode, "font-bold");
+       if (prop != NULL)
+               {
+                       font->bold = (strcmp (g_strstrip (prop), "y") == 0);
+               }
+
+       prop = xmlGetProp (xnode, "font-italic");
+       if (prop != NULL)
+               {
+                       font->italic = (strcmp (g_strstrip (prop), "y") == 0);
+               }
+
+       prop = xmlGetProp (xnode, "font-underline");
+       if (prop != NULL)
+               {
+                       font->underline = (strcmp (g_strstrip (prop), "y") == 0);
+               }
+
+       prop = xmlGetProp (xnode, "font-strike");
+       if (prop != NULL)
+               {
+                       font->strike = (strcmp (g_strstrip (prop), "y") == 0);
+               }
+
+       prop = xmlGetProp (xnode, "font-color");
+       if (prop != NULL)
+               {
+                       rpt_common_parse_color (prop, &font->color);
+               }
+}
+
+/**
+ * rpt_common_set_font:
+ * @xnode:
+ * @font:
+ *
+ */
+void
+rpt_common_set_font (xmlNode *xnode, RptFont font)
+{
+       xmlSetProp (xnode, "font-name", font.name);
+       xmlSetProp (xnode, "font-size", g_strdup_printf ("%f", font.size));
+       if (font.bold)
+               {
+                       xmlSetProp (xnode, "font-bold", "y");
+               }
+       if (font.italic)
+               {
+                       xmlSetProp (xnode, "font-italic", "y");
+               }
+       if (font.underline)
+               {
+                       xmlSetProp (xnode, "font-underline", "y");
+               }
+       if (font.strike)
+               {
+                       xmlSetProp (xnode, "font-strike", "y");
+               }
+       xmlSetProp (xnode, "font-color", convert_to_str_color (font.color));
+}
+
+/**
+ * rpt_common_get_border:
+ * @xnode:
+ * @border:
+ *
+ */
+void
+rpt_common_get_border (xmlNode *xnode, RptBorder *border)
+{
+       gchar *prop;
+
+       border->top_width = 0.0;
+       border->right_width = 0.0;
+       border->bottom_width = 0.0;
+       border->left_width = 0.0;
+       border->top_color.r = 0.0;
+       border->top_color.g = 0.0;
+       border->top_color.b = 0.0;
+       border->top_color.a = 1.0;
+       border->right_color.r = 0.0;
+       border->right_color.g = 0.0;
+       border->right_color.b = 0.0;
+       border->right_color.a = 1.0;
+       border->bottom_color.r = 0.0;
+       border->bottom_color.g = 0.0;
+       border->bottom_color.b = 0.0;
+       border->bottom_color.a = 1.0;
+       border->left_color.r = 0.0;
+       border->left_color.g = 0.0;
+       border->left_color.b = 0.0;
+       border->left_color.a = 1.0;
+
+       prop = xmlGetProp (xnode, "border-top-width");
+       if (prop != NULL)
+               {
+                       border->top_width = strtod (prop, NULL);
+               }
+
+       prop = xmlGetProp (xnode, "border-right-width");
+       if (prop != NULL)
+               {
+                       border->right_width = strtod (prop, NULL);
+               }
+
+       prop = xmlGetProp (xnode, "border-bottom-width");
+       if (prop != NULL)
+               {
+                       border->bottom_width = strtod (prop, NULL);
+               }
+
+       prop = xmlGetProp (xnode, "border-left-width");
+       if (prop != NULL)
+               {
+                       border->left_width = strtod (prop, NULL);
+               }
+
+       prop = xmlGetProp (xnode, "border-top-color");
+       if (prop != NULL)
+               {
+                       rpt_common_parse_color (prop, &border->top_color);
+               }
+
+       prop = xmlGetProp (xnode, "border-right-color");
+       if (prop != NULL)
+               {
+                       rpt_common_parse_color (prop, &border->right_color);
+               }
+
+       prop = xmlGetProp (xnode, "border-bottom-color");
+       if (prop != NULL)
+               {
+                       rpt_common_parse_color (prop, &border->bottom_color);
+               }
+
+       prop = xmlGetProp (xnode, "border-left-color");
+       if (prop != NULL)
+               {
+                       rpt_common_parse_color (prop, &border->left_color);
+               }
+}
+
+/**
+ * rpt_common_set_border:
+ * @xnode:
+ * @border:
+ *
+ */
+void
+rpt_common_set_border (xmlNode *xnode, RptBorder border)
+{
+       if (border.top_width > 0.0)
+               {
+                       xmlSetProp (xnode, "border-top-width", g_strdup_printf ("%f", border.top_width));
+                       xmlSetProp (xnode, "border-top-color", convert_to_str_color (border.top_color));
+               }
+       if (border.right_width > 0.0)
+               {
+                       xmlSetProp (xnode, "border-right-width", g_strdup_printf ("%f", border.right_width));
+                       xmlSetProp (xnode, "border-right-color", convert_to_str_color (border.right_color));
+               }
+       if (border.bottom_width > 0.0)
+               {
+                       xmlSetProp (xnode, "border-bottom-width", g_strdup_printf ("%f", border.bottom_width));
+                       xmlSetProp (xnode, "border-bottom-color", convert_to_str_color (border.bottom_color));
+               }
+       if (border.left_width > 0.0)
+               {
+                       xmlSetProp (xnode, "border-left-width", g_strdup_printf ("%f", border.left_width));
+                       xmlSetProp (xnode, "border-left-color", convert_to_str_color (border.left_color));
+               }
+}
+
+/**
+ * rpt_common_get_align:
+ * @xnode:
+ * @align:
+ *
+ */
+void
+rpt_common_get_align (xmlNode *xnode, RptAlign *align)
+{
+       gchar *prop;
+
+       align->h_align = RPT_HALIGN_LEFT;
+       align->v_align = RPT_VALIGN_TOP;
+
+       prop = xmlGetProp (xnode, "horizontal-align");
+       if (prop != NULL)
+               {
+                       if (strcmp (prop, "center") == 0)
+                               {
+                                       align->h_align = RPT_HALIGN_CENTER;
+                               }
+                       else if (strcmp (prop, "right") == 0)
+                               {
+                                       align->h_align = RPT_HALIGN_RIGHT;
+                               }
+                       else if (strcmp (prop, "justified") == 0)
+                               {
+                                       align->h_align = RPT_HALIGN_JUSTIFIED;
+                               }
+               }
+
+       prop = xmlGetProp (xnode, "vertical-align");
+       if (prop != NULL)
+               {
+                       if (strcmp (prop, "center") == 0)
+                               {
+                                       align->v_align = RPT_VALIGN_CENTER;
+                               }
+                       else if (strcmp (prop, "bottom") == 0)
+                               {
+                                       align->v_align = RPT_VALIGN_BOTTOM;
+                               }
+               }
+}
+
+/**
+ * rpt_common_set_align:
+ * @xnode:
+ * @align:
+ *
+ */
+void
+rpt_common_set_align (xmlNode *xnode, RptAlign align)
+{
+       if (align.h_align != RPT_HALIGN_LEFT)
+               {
+                       switch (align.h_align)
+                               {
+                                       case RPT_HALIGN_CENTER:
+                                               xmlSetProp (xnode, "horizontal-align", "center");
+                                               break;
+
+                                       case RPT_HALIGN_RIGHT:
+                                               xmlSetProp (xnode, "horizontal-align", "right");
+                                               break;
+
+                                       case RPT_HALIGN_JUSTIFIED:
+                                               xmlSetProp (xnode, "horizontal-align", "justified");
+                                               break;
+                               }
+               }
+       if (align.v_align != RPT_VALIGN_TOP)
+               {
+                       switch (align.v_align)
+                               {
+                                       case RPT_VALIGN_CENTER:
+                                               xmlSetProp (xnode, "vertical-align", "center");
+                                               break;
+
+                                       case RPT_VALIGN_BOTTOM:
+                                               xmlSetProp (xnode, "vertical-align", "bottom");
+                                               break;
+                               }
+               }
+}
+
+/**
+ * rpt_common_get_stroke:
+ * @xnode:
+ * @stroke:
+ *
+ */
+void
+rpt_common_get_stroke (xmlNode *xnode, RptStroke *stroke)
+{
+       gchar *prop;
+
+       stroke->width = 1.0;
+       stroke->color.r = 0.0;
+       stroke->color.g = 0.0;
+       stroke->color.b = 0.0;
+       stroke->color.a = 1.0;
+
+       prop = xmlGetProp (xnode, "stroke-width");
+       if (prop != NULL)
+               {
+                       stroke->width = strtod (prop, NULL);
+               }
+
+       prop = xmlGetProp (xnode, "stroke-color");
+       if (prop != NULL)
+               {
+                       rpt_common_parse_color (prop, &stroke->color);
+               }
+}
+
+/**
+ * rpt_common_parse_color:
+ * @str_color:
+ * @color:
+ *
+ */
+void
+rpt_common_parse_color (const gchar *str_color, RptColor *color)
+{
+       gchar *c = g_strstrip (g_strdup (str_color));
+
+       if (c[0] == '#')
+               {
+                       if (strlen (c) == 4 || strlen (c) == 5)
+                               {
+                                       if (isxdigit (c[1]))
+                                               {
+                                                       color->r = strtol (g_strdup_printf ("%c%c", c[1], c[1]), NULL, 16) / 255.0;
+                                               }
+                                       if (isxdigit (c[2]))
+                                               {
+                                                       color->g = strtol (g_strdup_printf ("%c%c", c[2], c[2]), NULL, 16) / 255.0;
+                                               }
+                                       if (isxdigit (c[3]))
+                                               {
+                                                       color->b = strtol (g_strdup_printf ("%c%c", c[3], c[3]), NULL, 16) / 255.0;
+                                               }
+                                       if (strlen (c) == 5 && isxdigit (c[4]))
+                                               {
+                                                       color->a = strtol (g_strdup_printf ("%c%c", c[4], c[4]), NULL, 16) / 255.0;
+                                               }
+                               }
+                       else if (strlen (c) == 7 || strlen (c) == 9)
+                               {
+                                       if (isxdigit (c[1]) && isxdigit (c[2]))
+                                               {
+                                                       color->r = strtol (g_strndup (&c[1], 2), NULL, 16) / 255.0;
+                                               }
+                                       if (isxdigit (c[3]) && isxdigit (c[4]))
+                                               {
+                                                       color->g = strtol (g_strndup (&c[3], 2), NULL, 16) / 255.0;
+                                               }
+                                       if (isxdigit (c[5]) && isxdigit (c[6]))
+                                               {
+                                                       color->b = strtol (g_strndup (&c[5], 2), NULL, 16) / 255.0;
+                                               }
+                                       if (strlen (c) == 9)
+                                               {
+                                                       color->a = strtol (g_strndup (&c[7], 2), NULL, 16) / 255.0;
+                                               }
+                               }
+               }
+}
+
+static gchar *
+convert_to_str_color (RptColor color)
+{
+       gchar *ret = "#";
+
+       ret = g_strconcat (ret, g_strdup_printf ("%.2X", (gint)color.r * 255), NULL);
+       ret = g_strconcat (ret, g_strdup_printf ("%.2X", (gint)color.g * 255), NULL);
+       ret = g_strconcat (ret, g_strdup_printf ("%.2X", (gint)color.b * 255), NULL);
+       ret = g_strconcat (ret, g_strdup_printf ("%.2X", (gint)color.a * 255), NULL);
+
+       return ret;
+}
index 4dce0bb6ebfaa4cafd0ed5e5c177ca3497e3c6ad..cde6af73867deee050ad6f8c0fb3f01dbccb077b 100644 (file)
 G_BEGIN_DECLS
 
 
+typedef struct
+{
+       gdouble r;
+       gdouble g;
+       gdouble b;
+       gdouble a;
+} RptColor;
+
 typedef struct
 {
        gdouble x;
@@ -38,11 +46,77 @@ typedef struct
        gdouble height;
 } RptSize;
 
+typedef struct
+{
+       gchar *name;
+       gdouble size;
+       gboolean bold;
+       gboolean italic;
+       gboolean underline;
+       gboolean strike;
+       RptColor color;
+} RptFont;
+
+typedef struct
+{
+       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 enum
+{
+       RPT_HALIGN_LEFT,
+       RPT_HALIGN_CENTER,
+       RPT_HALIGN_RIGHT,
+       RPT_HALIGN_JUSTIFIED
+} eRptHAlign;
+
+typedef enum
+{
+       RPT_VALIGN_TOP,
+       RPT_VALIGN_CENTER,
+       RPT_VALIGN_BOTTOM
+} eRptVAlign;
+
+typedef struct
+{
+       eRptHAlign h_align;
+       eRptVAlign v_align;
+} RptAlign;
+
+typedef struct
+{
+       gdouble width;
+       RptColor color;
+} RptStroke;
+
 
 void rpt_common_get_position (xmlNode *xnode,
                               RptPoint *position);
 void rpt_common_get_size (xmlNode *xnode,
                           RptSize *size);
+void rpt_common_get_font (xmlNode *xnode,
+                          RptFont *font);
+void rpt_common_set_font (xmlNode *xnode,
+                          RptFont font);
+void rpt_common_get_border (xmlNode *xnode,
+                            RptBorder *border);
+void rpt_common_set_border (xmlNode *xnode,
+                            RptBorder border);
+void rpt_common_get_align (xmlNode *xnode,
+                           RptAlign *align);
+void rpt_common_set_align (xmlNode *xnode,
+                           RptAlign align);
+void rpt_common_get_stroke (xmlNode *xnode,
+                            RptStroke *stroke);
+void rpt_common_parse_color (const gchar *str_color,
+                             RptColor *color);
 
 
 G_END_DECLS
index 69d77a930bf696c5287d732bfaeefc9e18f6bbb0..56c8b9fc22c1064bfdb5be5e8d269d2be854a890 100644 (file)
@@ -23,6 +23,9 @@ enum
 {
        PROP_0,
        PROP_SIZE,
+       PROP_BORDER,
+       PROP_FONT,
+       PROP_ALIGN,
        PROP_SOURCE
 };
 
@@ -30,13 +33,13 @@ 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);
+                                       guint property_id,
+                                       const GValue *value,
+                                       GParamSpec *pspec);
 static void rpt_obj_text_get_property (GObject *object,
-                                    guint property_id,
-                                    GValue *value,
-                                    GParamSpec *pspec);
+                                       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))
@@ -45,7 +48,9 @@ typedef struct _RptObjTextPrivate RptObjTextPrivate;
 struct _RptObjTextPrivate
        {
                RptSize *size;
-
+               RptBorder *border;
+               RptFont *font;
+               RptAlign *align;
                gchar *source;
        };
 
@@ -95,6 +100,21 @@ rpt_obj_text_class_init (RptObjTextClass *klass)
                                                               "Size",
                                                               "The object's size.",
                                                               G_PARAM_READWRITE));
+       g_object_class_install_property (object_class, PROP_BORDER,
+                                        g_param_spec_pointer ("border",
+                                                              "Border",
+                                                              "The object's border.",
+                                                              G_PARAM_READWRITE));
+       g_object_class_install_property (object_class, PROP_FONT,
+                                        g_param_spec_pointer ("font",
+                                                              "Font",
+                                                              "The object's font.",
+                                                              G_PARAM_READWRITE));
+       g_object_class_install_property (object_class, PROP_ALIGN,
+                                        g_param_spec_pointer ("align",
+                                                              "Align",
+                                                              "The text's align.",
+                                                              G_PARAM_READWRITE));
        g_object_class_install_property (object_class, PROP_SOURCE,
                                         g_param_spec_string ("source",
                                                              "Source",
@@ -111,6 +131,10 @@ rpt_obj_text_init (RptObjText *rpt_obj_text)
        priv->size = (RptSize *)g_malloc0 (sizeof (RptSize));
        priv->size->width = 0.0;
        priv->size->height = 0.0;
+
+       priv->border = (RptBorder *)g_malloc0 (sizeof (RptBorder));
+       priv->font = (RptFont *)g_malloc0 (sizeof (RptFont));
+       priv->align = (RptAlign *)g_malloc0 (sizeof (RptAlign));
 }
 
 /**
@@ -167,6 +191,8 @@ RptObject
                                        priv = RPT_OBJ_TEXT_GET_PRIVATE (rpt_obj_text);
 
                                        rpt_common_get_size (xnode, priv->size);
+                                       rpt_common_get_border (xnode, priv->border);
+                                       rpt_common_get_font (xnode, priv->font);
 
                                        g_object_set (rpt_obj_text, "source", xmlGetProp (xnode, "source"), NULL);
                                }
@@ -184,6 +210,10 @@ rpt_obj_text_get_xml (RptObject *rpt_objtext, xmlNode *xnode)
 
        xmlSetProp (xnode, "width", g_strdup_printf ("%f", priv->size->width));
        xmlSetProp (xnode, "height", g_strdup_printf ("%f", priv->size->height));
+
+       rpt_common_set_border (xnode, (RptBorder)*priv->border);
+       rpt_common_set_font (xnode, (RptFont)*priv->font);
+       rpt_common_set_align (xnode, (RptAlign)*priv->font);
 }
 
 static void
@@ -199,6 +229,18 @@ rpt_obj_text_set_property (GObject *object, guint property_id, const GValue *val
                                priv->size = g_memdup (g_value_get_pointer (value), sizeof (RptSize));
                                break;
 
+                       case PROP_BORDER:
+                               priv->border = g_memdup (g_value_get_pointer (value), sizeof (RptBorder));
+                               break;
+
+                       case PROP_FONT:
+                               priv->font = g_memdup (g_value_get_pointer (value), sizeof (RptFont));
+                               break;
+
+                       case PROP_ALIGN:
+                               priv->align = g_memdup (g_value_get_pointer (value), sizeof (RptAlign));
+                               break;
+
                        case PROP_SOURCE:
                                priv->source = g_strstrip (g_strdup (g_value_get_string (value)));
                                break;
@@ -222,6 +264,18 @@ rpt_obj_text_get_property (GObject *object, guint property_id, GValue *value, GP
                                g_value_set_pointer (value, g_memdup (priv->size, sizeof (RptSize)));
                                break;
 
+                       case PROP_BORDER:
+                               g_value_set_pointer (value, g_memdup (priv->border, sizeof (RptBorder)));
+                               break;
+
+                       case PROP_FONT:
+                               g_value_set_pointer (value, g_memdup (priv->font, sizeof (RptFont)));
+                               break;
+
+                       case PROP_ALIGN:
+                               g_value_set_pointer (value, g_memdup (priv->align, sizeof (RptAlign)));
+                               break;
+
                        case PROP_SOURCE:
                                g_value_set_string (value, priv->source);
                                break;
index ac351db0fe32db7c8a84e0711c50984e136bb19a..95baa708a6112d7d504620f24d89e50148bd3b39 100644 (file)
 #include <string.h>
 
 #include <cairo.h>
+#include <cairo-pdf.h>
+#include <cairo-ps.h>
+#include <cairo-svg.h>
 #include <pango/pangocairo.h>
 
 #include "rptprint.h"
 #include "rptcommon.h"
 
-typedef enum
-{
-       RPT_HALIGN_LEFT,
-       RPT_HALIGN_CENTER,
-       RPT_HALIGN_RIGHT,
-       RPT_HALIGN_JUSTIFIED
-} eRptHAlign;
-
-typedef enum
-{
-       RPT_VALIGN_TOP,
-       RPT_VALIGN_CENTER,
-       RPT_VALIGN_BOTTOM
-} eRptVAlign;
-
-typedef struct
-{
-       eRptHAlign h_align;
-       eRptVAlign v_align;
-} RptAlign;
-
-typedef struct
-{
-       gdouble r;
-       gdouble g;
-       gdouble b;
-       gdouble a;
-} RptColor;
-
-typedef struct
-{
-       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;
-       gboolean italic;
-       gboolean underline;
-       gboolean strike;
-       RptColor color;
-} RptFont;
-
-typedef struct
-{
-       gdouble width;
-       RptColor color;
-} RptStroke;
-
 enum
 {
        PROP_0
@@ -118,16 +63,6 @@ static void rpt_print_border (RptPrint *rpt_print,
                               RptPoint position,
                               RptSize size,
                               RptBorder border);
-static void rpt_print_get_align (xmlNode *xnode,
-                                 RptAlign *align);
-static void rpt_print_get_border (xmlNode *xnode,
-                                  RptBorder *border);
-static void rpt_print_get_stroke (xmlNode *xnode,
-                                  RptStroke *stroke);
-static void rpt_print_get_font (xmlNode *xnode,
-                                RptFont *font);
-static void rpt_print_parse_color (const gchar *str_color,
-                                   RptColor *color);
 
 
 #define RPT_PRINT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_RPT_PRINT, RptPrintPrivate))
@@ -430,9 +365,9 @@ rpt_print_text_xml (RptPrint *rpt_print, xmlNode *xnode)
 
        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);
+       rpt_common_get_align (xnode, &align);
+       rpt_common_get_border (xnode, &border);
+       rpt_common_get_font (xnode, &font);
 
        /* padding */
        prop = xmlGetProp (xnode, (const xmlChar *)"padding-top");
@@ -493,7 +428,7 @@ rpt_print_text_xml (RptPrint *rpt_print, xmlNode *xnode)
        prop = xmlGetProp (xnode, (const xmlChar *)"background-color");
        if (prop != NULL)
                {
-                       rpt_print_parse_color (prop, &color);
+                       rpt_common_parse_color (prop, &color);
                }
 
        /* drawing border */
@@ -554,7 +489,7 @@ rpt_print_line_xml (RptPrint *rpt_print, xmlNode *xnode)
 
        rpt_common_get_position (xnode, &position);
        rpt_common_get_size (xnode, &size);
-       rpt_print_get_stroke (xnode, &stroke);
+       rpt_common_get_stroke (xnode, &stroke);
 
        from_p.x = position.x;
        from_p.y = position.y;
@@ -578,7 +513,7 @@ rpt_print_rect_xml (RptPrint *rpt_print, xmlNode *xnode)
 
        rpt_common_get_position (xnode, &position);
        rpt_common_get_size (xnode, &size);
-       rpt_print_get_stroke (xnode, &stroke);
+       rpt_common_get_stroke (xnode, &stroke);
 
        gchar *prop = xmlGetProp (xnode, (const xmlChar *)"fill-color");
        if (prop != NULL)
@@ -587,7 +522,7 @@ rpt_print_rect_xml (RptPrint *rpt_print, xmlNode *xnode)
                        fill_color.g = 0.0;
                        fill_color.b = 0.0;
                        fill_color.a = 1.0;
-                       rpt_print_parse_color (prop, &fill_color);
+                       rpt_common_parse_color (prop, &fill_color);
                }
 
        /*cairo_set_line_width (priv->cr, stroke.width);*/
@@ -637,7 +572,7 @@ rpt_print_image_xml (RptPrint *rpt_print, xmlNode *xnode)
 
        rpt_common_get_position (xnode, &position);
        rpt_common_get_size (xnode, &size);
-       rpt_print_get_border (xnode, &border);
+       rpt_common_get_border (xnode, &border);
 
        image = cairo_image_surface_create_from_png (filename);
 
@@ -735,248 +670,3 @@ rpt_print_border (RptPrint *rpt_print, RptPoint position, RptSize size, RptBorde
                        rpt_print_line (rpt_print, from_p, to_p, stroke);
                }
 }
-
-static void
-rpt_print_get_align (xmlNode *xnode, RptAlign *align)
-{
-       gchar *prop;
-
-       align->h_align = RPT_HALIGN_LEFT;
-       align->v_align = RPT_VALIGN_TOP;
-
-       prop = xmlGetProp (xnode, "horizontal-align");
-       if (prop != NULL)
-               {
-                       if (strcmp (prop, "center") == 0)
-                               {
-                                       align->h_align = RPT_HALIGN_CENTER;
-                               }
-                       else if (strcmp (prop, "right") == 0)
-                               {
-                                       align->h_align = RPT_HALIGN_RIGHT;
-                               }
-                       else if (strcmp (prop, "justified") == 0)
-                               {
-                                       align->h_align = RPT_HALIGN_JUSTIFIED;
-                               }
-               }
-
-       prop = xmlGetProp (xnode, "vertical-align");
-       if (prop != NULL)
-               {
-                       if (strcmp (prop, "center") == 0)
-                               {
-                                       align->v_align = RPT_VALIGN_CENTER;
-                               }
-                       else if (strcmp (prop, "bottom") == 0)
-                               {
-                                       align->v_align = RPT_VALIGN_BOTTOM;
-                               }
-               }
-}
-
-static void
-rpt_print_get_border (xmlNode *xnode, RptBorder *border)
-{
-       gchar *prop;
-
-       border->top_width = 0.0;
-       border->right_width = 0.0;
-       border->bottom_width = 0.0;
-       border->left_width = 0.0;
-       border->top_color.r = 0.0;
-       border->top_color.g = 0.0;
-       border->top_color.b = 0.0;
-       border->top_color.a = 1.0;
-       border->right_color.r = 0.0;
-       border->right_color.g = 0.0;
-       border->right_color.b = 0.0;
-       border->right_color.a = 1.0;
-       border->bottom_color.r = 0.0;
-       border->bottom_color.g = 0.0;
-       border->bottom_color.b = 0.0;
-       border->bottom_color.a = 1.0;
-       border->left_color.r = 0.0;
-       border->left_color.g = 0.0;
-       border->left_color.b = 0.0;
-       border->left_color.a = 1.0;
-
-       prop = xmlGetProp (xnode, "border-top-width");
-       if (prop != NULL)
-               {
-                       border->top_width = strtod (prop, NULL);
-               }
-
-       prop = xmlGetProp (xnode, "border-right-width");
-       if (prop != NULL)
-               {
-                       border->right_width = strtod (prop, NULL);
-               }
-
-       prop = xmlGetProp (xnode, "border-bottom-width");
-       if (prop != NULL)
-               {
-                       border->bottom_width = strtod (prop, NULL);
-               }
-
-       prop = xmlGetProp (xnode, "border-left-width");
-       if (prop != NULL)
-               {
-                       border->left_width = strtod (prop, NULL);
-               }
-
-       prop = xmlGetProp (xnode, "border-top-color");
-       if (prop != NULL)
-               {
-                       rpt_print_parse_color (prop, &border->top_color);
-               }
-
-       prop = xmlGetProp (xnode, "border-right-color");
-       if (prop != NULL)
-               {
-                       rpt_print_parse_color (prop, &border->right_color);
-               }
-
-       prop = xmlGetProp (xnode, "border-bottom-color");
-       if (prop != NULL)
-               {
-                       rpt_print_parse_color (prop, &border->bottom_color);
-               }
-
-       prop = xmlGetProp (xnode, "border-left-color");
-       if (prop != NULL)
-               {
-                       rpt_print_parse_color (prop, &border->left_color);
-               }
-}
-
-static void
-rpt_print_get_stroke (xmlNode *xnode, RptStroke *stroke)
-{
-       gchar *prop;
-
-       stroke->width = 1.0;
-       stroke->color.r = 0.0;
-       stroke->color.g = 0.0;
-       stroke->color.b = 0.0;
-       stroke->color.a = 1.0;
-
-       prop = xmlGetProp (xnode, "stroke-width");
-       if (prop != NULL)
-               {
-                       stroke->width = strtod (prop, NULL);
-               }
-
-       prop = xmlGetProp (xnode, "stroke-color");
-       if (prop != NULL)
-               {
-                       rpt_print_parse_color (prop, &stroke->color);
-               }
-}
-
-static void
-rpt_print_get_font (xmlNode *xnode, RptFont *font)
-{
-       gchar *prop;
-
-       font->name = g_strdup ("sans");
-       font->size = 12.0;
-       font->bold = FALSE;
-       font->italic = FALSE;
-       font->underline = FALSE;
-       font->strike = FALSE;
-       font->color.r = 0.0;
-       font->color.g = 0.0;
-       font->color.b = 0.0;
-       font->color.a = 1.0;
-
-       prop = xmlGetProp (xnode, "font-name");
-       if (prop != NULL)
-               {
-                       font->name = g_strdup (prop);
-               }
-
-       prop = xmlGetProp (xnode, "font-size");
-       if (prop != NULL)
-               {
-                       font->size = strtod (prop, NULL);
-               }
-
-       prop = xmlGetProp (xnode, "font-bold");
-       if (prop != NULL)
-               {
-                       font->bold = (strcmp (g_strstrip (prop), "y") == 0);
-               }
-
-       prop = xmlGetProp (xnode, "font-italic");
-       if (prop != NULL)
-               {
-                       font->italic = (strcmp (g_strstrip (prop), "y") == 0);
-               }
-
-       prop = xmlGetProp (xnode, "font-underline");
-       if (prop != NULL)
-               {
-                       font->underline = (strcmp (g_strstrip (prop), "y") == 0);
-               }
-
-       prop = xmlGetProp (xnode, "font-strike");
-       if (prop != NULL)
-               {
-                       font->strike = (strcmp (g_strstrip (prop), "y") == 0);
-               }
-
-       prop = xmlGetProp (xnode, "font-color");
-       if (prop != NULL)
-               {
-                       rpt_print_parse_color (prop, &font->color);
-               }
-}
-
-static void
-rpt_print_parse_color (const gchar *str_color, RptColor *color)
-{
-       gchar *c = g_strstrip (g_strdup (str_color));
-
-       if (c[0] == '#')
-               {
-                       if (strlen (c) == 4 || strlen (c) == 5)
-                               {
-                                       if (isxdigit (c[1]))
-                                               {
-                                                       color->r = strtol (g_strdup_printf ("%c%c", c[1], c[1]), NULL, 16) / 255.0;
-                                               }
-                                       if (isxdigit (c[2]))
-                                               {
-                                                       color->g = strtol (g_strdup_printf ("%c%c", c[2], c[2]), NULL, 16) / 255.0;
-                                               }
-                                       if (isxdigit (c[3]))
-                                               {
-                                                       color->b = strtol (g_strdup_printf ("%c%c", c[3], c[3]), NULL, 16) / 255.0;
-                                               }
-                                       if (strlen (c) == 5 && isxdigit (c[4]))
-                                               {
-                                                       color->a = strtol (g_strdup_printf ("%c%c", c[4], c[4]), NULL, 16) / 255.0;
-                                               }
-                               }
-                       else if (strlen (c) == 7 || strlen (c) == 9)
-                               {
-                                       if (isxdigit (c[1]) && isxdigit (c[2]))
-                                               {
-                                                       color->r = strtol (g_strndup (&c[1], 2), NULL, 16) / 255.0;
-                                               }
-                                       if (isxdigit (c[3]) && isxdigit (c[4]))
-                                               {
-                                                       color->g = strtol (g_strndup (&c[3], 2), NULL, 16) / 255.0;
-                                               }
-                                       if (isxdigit (c[5]) && isxdigit (c[6]))
-                                               {
-                                                       color->b = strtol (g_strndup (&c[5], 2), NULL, 16) / 255.0;
-                                               }
-                                       if (strlen (c) == 9)
-                                               {
-                                                       color->a = strtol (g_strndup (&c[7], 2), NULL, 16) / 255.0;
-                                               }
-                               }
-               }
-}
index 8644f460e6dc217a0d32b5a8f2687aa048b043c5..aed82f1b846c0cb2eae7bbd75188b46a30bbbb03 100644 (file)
@@ -91,11 +91,13 @@ static xmlNode *rpt_report_rptprint_new_page (RptReport *rpt_report,
 static void rpt_report_rptprint_section (RptReport *rpt_report,
                                          xmlNode *xpage,
                                          gdouble *cur_y,
-                                         RptReportSection section);
+                                         RptReportSection section,
+                                         gint row);
                                                                          
 static void rpt_report_rptprint_parse_text_source (RptReport *rpt_report,
                                                    RptObject *rptobj,
-                                                   xmlNode *xnode);
+                                                   xmlNode *xnode,
+                                                   gint row);
 
 
 #define RPT_REPORT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_RPT_REPORT, RptReportPrivate))
@@ -425,7 +427,7 @@ xmlDoc
                                                        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);
+                                                                       rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_PAGE_FOOTER, row - 1);
                                                                }
 
                                                        cur_y = 0.0;
@@ -434,34 +436,34 @@ xmlDoc
 
                                                        if (priv->page_header != NULL)
                                                                {
-                                                                       rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_PAGE_HEADER);
+                                                                       rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_PAGE_HEADER, row);
                                                                }
                                                }
 
-                                       rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_BODY);
+                                       rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_BODY, row);
                                }
 
                        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);
+                                       rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_PAGE_FOOTER, row - 1);
                                }
                }
        else
                {
                        if (priv->page_header != NULL)
                                {
-                                       rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_PAGE_HEADER);
+                                       rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_PAGE_HEADER, -1);
                                }
 
                        pages++;
                        xpage = rpt_report_rptprint_new_page (rpt_report, xroot);
-                       rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_BODY);
+                       rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_BODY, -1);
 
                        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);
+                                       rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_PAGE_FOOTER, -1);
                                }
                }
 
@@ -631,7 +633,7 @@ static xmlNode
 }
 
 static void
-rpt_report_rptprint_section (RptReport *rpt_report, xmlNode *xpage, gdouble *cur_y, RptReportSection section)
+rpt_report_rptprint_section (RptReport *rpt_report, xmlNode *xpage, gdouble *cur_y, RptReportSection section, gint row)
 {
        GList *objects;
        xmlAttrPtr attr;
@@ -678,7 +680,7 @@ rpt_report_rptprint_section (RptReport *rpt_report, xmlNode *xpage, gdouble *cur
 
                        if (IS_RPT_OBJ_TEXT (rptobj))
                                {
-                                       rpt_report_rptprint_parse_text_source (rpt_report, rptobj, xnode);
+                                       rpt_report_rptprint_parse_text_source (rpt_report, rptobj, xnode, row);
                                }
                        else if (IS_RPT_OBJ_IMAGE (rptobj))
                                {
@@ -708,12 +710,28 @@ rpt_report_rptprint_section (RptReport *rpt_report, xmlNode *xpage, gdouble *cur
 }
 
 static void
-rpt_report_rptprint_parse_text_source (RptReport *rpt_report, RptObject *rptobj, xmlNode *xnode)
+rpt_report_rptprint_parse_text_source (RptReport *rpt_report, RptObject *rptobj, xmlNode *xnode, gint row)
 {
        /* TO DO */
        gchar *source;
 
+       RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report);
+
        g_object_get (G_OBJECT (rptobj), "source", &source, NULL);
 
+       if (row > -1 && source[0] == '[' && source[strlen (source) - 1] == ']')
+               {
+                       gint col;
+                       gchar *field;
+
+                       field = g_strstrip (g_strndup (source + 1, strlen (source) - 2));
+                       col = gda_data_model_get_column_position (priv->gda_datamodel, field);
+
+                       if (col > -1)
+                               {
+                                       source = gda_value_stringify ((GdaValue *)gda_data_model_get_value_at (priv->gda_datamodel, col, row));
+                               }
+               }
+
        xmlNodeSetContent (xnode, source);
 }
index b173566a672af94b2b86d13504aea39e336e3b29..b1fb59dc378ebbcdf8b6fe1d9f1969e2e55b9f03 100644 (file)
 
        <report>
                <page-header height="80">
-                       <text name="title" x="10" y="10" width="300" height="50" source="the page title" />
+                       <text name="title" x="10" y="10" width="300" height="50" font-name="Courier New" font-size="10" font-bold="y" 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_id" x="50" y="50" width="100" height="50" border-top-width="1.0" border-top-color="#FF0000" 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" />