]> saetta.ns0.it Git - reptool/libreptool/commitdiff
Added and managed property translation (closes #199).
authorAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Tue, 8 Nov 2011 12:39:19 +0000 (13:39 +0100)
committerAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Wed, 9 Nov 2011 07:55:49 +0000 (08:55 +0100)
data/reptool.dtd
data/reptool_report.dtd
src/rptcommon.c
src/rptcommon.h
src/rptprint.c
src/rptprint.h
src/rptreport.c
src/rptreport.h

index 7e916a4de3457d731468574c49491516bd32c513..6897fd0f5ecf13030514afa8f187b0fcf150c9f2 100644 (file)
 
 <!ELEMENT reptool (properties?, database?, page, report)>
 
-<!ELEMENT properties (name?, description?, unit-length?, output-type?, output-filename?, copies?)>
+<!ELEMENT properties (name?, description?, unit-length?, output-type?, output-filename?, copies?, translation?)>
 <!ELEMENT name CDATA #IMPLIED>
 <!ELEMENT description CDATA #IMPLIED>
 <!ELEMENT unit-length (pt | in | cm | mm) #IMPLIED>
 <!ELEMENT output-type (png, pdf, ps, svg, gtk, gtk-default) #IMPLIED>
 <!ELEMENT output-filename CDATA #IMPLIED>
 <!ELEMENT copies CDATA #IMPLIED>
+<!ELEMENT translation EMPTY>
+<!ATTLIST translation
+  x          CDATA #REQUIRED
+  y          CDATA #REQUIRED
+>
 
 <!ELEMENT database (provider, connection-string, sql)>
 <!ELEMENT provider (#PCDATA)>
index 32568988a781cbc747ea9222be2e29f544a87723..4cca3089cd671e20f8c0b846a91091b645ed5e1e 100644 (file)
@@ -2,10 +2,13 @@
   "text*, line*, rect*, ellipse*, image*"
 >
 
+<!ENTITY % object_commons_attrs
+  "visible  (y | n) #IMPLIED"
+>
+
 <!ENTITY % object_position_attrs
   "x        CDATA #REQUIRED
    y        CDATA #REQUIRED
-   visible  (y | n) #IMPLIED"
 >
 
 <!ENTITY % object_size_attrs
@@ -55,6 +58,7 @@
 
 <!ELEMENT text (#PCDATA)>
 <!ATTLIST text
+  %object_common_attrs;
   %object_position_attrs;
   %object_size_attrs;
   %object_rotation_attrs;
@@ -73,6 +77,7 @@
 
 <!ELEMENT line EMPTY>
 <!ATTLIST line
+  %object_common_attrs;
   %object_poisition_attrs;
   %object_size_attrs;
   %object_rotation_attrs;
@@ -81,6 +86,7 @@
 
 <!ELEMENT rect EMPTY>
 <!ATTLIST rect
+  %object_common_attrs;
   %object_poisition_attrs;
   %object_size_attrs;
   %object_rotation_attrs;
@@ -90,6 +96,7 @@
 
 <!ELEMENT ellipse EMPTY>
 <!ATTLIST ellipse
+  %object_common_attrs;
   %object_poisition_attrs;
   %object_size_attrs;
   %object_rotation_attrs;
 
 <!ELEMENT image EMPTY>
 <!ATTLIST image
+  %object_common_attrs;
   %object_position_attrs;
   %object_size_attrs;
   %object_rotation_attrs;
 
 <!ELEMENT reptool_report (properties?, page*)>
 
-<!ELEMENT properties (name?, description?, unit-length?, output-type?, output-filename?, copies?)>
+<!ELEMENT properties (name?, description?, unit-length?, output-type?, output-filename?, copies?, translation?)>
 <!ELEMENT name CDATA #IMPLIED>
 <!ELEMENT description CDATA #IMPLIED>
 <!ELEMENT unit-length (pt | in | cm | mm) #IMPLIED>
 <!ELEMENT output-type (png, pdf, ps, svg, gtk, gtk-default) #IMPLIED>
 <!ELEMENT output-filename CDATA #IMPLIED>
 <!ELEMENT copies CDATA #IMPLIED>
+<!ELEMENT translation EMPTY>
+<!ATTLIST translation
+  x          CDATA #REQUIRED
+  y          CDATA #REQUIRED
+>
 
 <!ELEMENT page (%objects;)>
 <!ATTLIST page
index db73db03bbd0ab201afccd7c8139b0741af5bcc7..8f8a181a61eb03624c1379e3af5f62be42b19b9e 100644 (file)
@@ -518,6 +518,118 @@ rpt_common_set_size (xmlNode *xnode, const RptSize *size)
                }
 }
 
+/**
+ * rpt_common_rpttranslation_new:
+ *
+ * Returns: an new allocated #RptTranslation struct.
+ */
+RptTranslation
+*rpt_common_rpttranslation_new (void)
+{
+       RptTranslation *translation;
+
+       translation = (RptTranslation *)g_new0 (RptTranslation, 1);
+       translation->x = 0.0;
+       translation->y = 0.0;
+
+       return translation;
+}
+
+/**
+ * rpt_common_rpttranslation_new_with_values:
+ * @x:
+ * @y:
+ *
+ * Returns: an new allocated #RptTranslation struct.
+ */
+RptTranslation
+*rpt_common_rpttranslation_new_with_values (gdouble x, gdouble y)
+{
+       RptTranslation *translation;
+
+       translation = rpt_common_rpttranslation_new ();
+       translation->x = x;
+       translation->y = y;
+
+       return translation;
+}
+
+/**
+ * rpt_common_get_translation:
+ * @xnode: an #xmlNode.
+ *
+ * Returns: an #RptTranslation struct that represent the object's rotation
+ * specified on @xnode.
+ */
+RptTranslation
+*rpt_common_get_translation (xmlNode *xnode)
+{
+       gchar *prop;
+       RptTranslation *translation = NULL;
+
+       gdouble x;
+       gdouble y;
+
+       /* TODO try the first level of children */
+       if (xmlStrcmp (xnode->name, "translation") == 0)
+               {
+                       x = 0.0;
+                       y = 0.0;
+
+                       prop = xmlGetProp (xnode, "x");
+                       if (prop != NULL)
+                               {
+                                       translation = rpt_common_rpttranslation_new ();
+                                       translation->x = g_strtod (prop, NULL);
+                                       xmlFree (prop);
+                               }
+                       prop = xmlGetProp (xnode, "y");
+                       if (prop != NULL)
+                               {
+                                       if (translation == NULL)
+                                               {
+                                                       translation = rpt_common_rpttranslation_new ();
+                                               }
+                                       translation->y = g_strtod (prop, NULL);
+                                       xmlFree (prop);
+                               }
+               }
+
+       return translation;
+}
+
+/**
+ * rpt_common_set_translation:
+ * @xnode: an #xmlNode.
+ * @rotation:
+ *
+ */
+void
+rpt_common_set_translation (xmlNode *xnode, const RptTranslation *translation)
+{
+       xmlNode *_node;
+
+       if (translation != NULL)
+               {
+                       _node = NULL;
+                       if (xmlStrcmp (xnode->name, "translation") == 0)
+                               {
+                                       _node = xnode;
+                               }
+                       else
+                               {
+                                       _node = xmlNewNode (NULL, "translation");
+                                       xmlAddChild (xnode, _node);
+                               }
+
+                       if (_node != NULL)
+                               {
+                                       xmlSetProp (_node, "x", g_strdup_printf ("%f", translation->x));
+                                       xmlSetProp (_node, "y", g_strdup_printf ("%f", translation->y));
+                               }
+               }
+}
+
 /**
  * rpt_common_rptrotation_new:
  *
index 523987827e8b16c6d4285e8836fb06350c500107..5fd860956a32be9ac45e4e4f6800da968a644574 100644 (file)
@@ -78,6 +78,13 @@ struct _RptSize
 };
 typedef struct _RptSize RptSize;
 
+struct _RptTranslation
+{
+       gdouble x;
+       gdouble y;
+};
+typedef struct _RptTranslation RptTranslation;
+
 struct _RptRotation
 {
        gdouble angle;
@@ -216,6 +223,12 @@ RptSize *rpt_common_get_size (xmlNode *xnode);
 void rpt_common_set_size (xmlNode *xnode,
                           const RptSize *size);
 
+RptTranslation *rpt_common_rpttranslation_new (void);
+RptTranslation *rpt_common_rpttranslation_new_with_values (gdouble x, gdouble y);
+RptTranslation *rpt_common_get_translation (xmlNode *xnode);
+void rpt_common_set_translation (xmlNode *xnode,
+                                 const RptTranslation *translation);
+
 RptRotation *rpt_common_rptrotation_new (void);
 RptRotation *rpt_common_rptrotation_new_with_values (gdouble angle);
 RptRotation *rpt_common_get_rotation (xmlNode *xnode);
index 27dec1afc1e722f43888827cb27a57edb0cb5eb6..9eac7d9e7a85c8e4fc8d087ea228fa159bfc5494 100644 (file)
@@ -39,6 +39,7 @@ enum
        PROP_OUTPUT_TYPE,
        PROP_OUTPUT_FILENAME,
        PROP_COPIES,
+       PROP_TRANSLATION,
        PROP_PATH_RELATIVES_TO
 };
 
@@ -115,6 +116,8 @@ struct _RptPrintPrivate
 
                GtkPrintSettings *gtk_print_settings;
 
+               RptTranslation *translation;
+
                gchar *path_relatives_to;
 
                gdouble width;
@@ -176,6 +179,12 @@ rpt_print_class_init (RptPrintClass *klass)
                                                            1,
                                                            G_PARAM_READWRITE));
 
+       g_object_class_install_property (object_class, PROP_TRANSLATION,
+                                        g_param_spec_pointer ("translation",
+                                                              "Translation",
+                                                              "Translation of the entire report.",
+                                                              G_PARAM_READWRITE));
+
        g_object_class_install_property (object_class, PROP_PATH_RELATIVES_TO,
                                         g_param_spec_string ("path-relatives-to",
                                                              "Path are relatives to",
@@ -194,6 +203,7 @@ rpt_print_init (RptPrint *rpt_print)
        priv->output_filename = NULL;
        priv->gtk_print_settings = NULL;
        priv->path_relatives_to = g_strdup ("");
+       priv->translation = NULL;
 
        priv->surface = NULL;
        priv->cr = NULL;
@@ -345,6 +355,30 @@ rpt_print_set_copies (RptPrint *rpt_print, guint copies)
        gtk_print_settings_set_n_copies (priv->gtk_print_settings, copies);
 }
 
+/**
+ * rpt_print_set_translation:
+ * @rpt_print: an #RptPrint object.
+ * @translation: an #RptTranslation struct.
+ *
+ */
+void
+rpt_print_set_translation (RptPrint *rpt_print, RptTranslation *translation)
+{
+       g_return_if_fail (IS_RPT_PRINT (rpt_print));
+
+       RptPrintPrivate *priv = RPT_PRINT_GET_PRIVATE (rpt_print);
+
+       if (priv->translation != NULL)
+               {
+                       g_free (priv->translation);
+                       priv->translation = NULL;
+               }
+       if (translation != NULL)
+               {
+                       priv->translation = rpt_common_rpttranslation_new_with_values (translation->x, translation->y);
+               }
+}
+
 /**
  * rpt_print_print:
  * @rpt_print: an #RptPrint object.
@@ -418,6 +452,11 @@ rpt_print_print (RptPrint *rpt_print, GtkWindow *transient)
                                                                {
                                                                        rpt_print_set_copies (rpt_print, strtol ((const gchar *)xmlNodeGetContent (cur_property), NULL, 10));
                                                                }
+                                                       else if (g_strcmp0 (cur_property->name, "translation") == 0
+                                                                && priv->translation == NULL)
+                                                               {
+                                                                       rpt_print_set_translation (rpt_print, rpt_common_get_translation (cur_property));
+                                                               }
 
                                                        cur_property = cur_property->next;
                                                }
@@ -648,6 +687,10 @@ rpt_print_set_property (GObject *object, guint property_id, const GValue *value,
                                rpt_print_set_copies (rpt_print, g_value_get_uint (value));
                                break;
 
+                       case PROP_TRANSLATION:
+                               rpt_print_set_translation (rpt_print, g_value_get_pointer (value));
+                               break;
+
                        case PROP_PATH_RELATIVES_TO:
                                priv->path_relatives_to = g_strstrip (g_strdup (g_value_get_string (value)));
                                break;
@@ -689,6 +732,10 @@ rpt_print_get_property (GObject *object, guint property_id, GValue *value, GPara
                                        }
                                break;
 
+                       case PROP_TRANSLATION:
+                               g_value_set_pointer (value, priv->translation);
+                               break;
+
                        case PROP_PATH_RELATIVES_TO:
                                g_value_set_string (value, priv->path_relatives_to);
                                break;
@@ -1656,6 +1703,11 @@ rpt_print_gtk_draw_page (GtkPrintOperation *operation,
                     gtk_print_context_get_width (priv->gtk_print_context) / rpt_common_value_to_points (priv->unit, priv->width),
                     gtk_print_context_get_height (priv->gtk_print_context) / rpt_common_value_to_points (priv->unit, priv->height));
 
+       if (priv->translation != NULL)
+               {
+                       cairo_translate (priv->cr, priv->translation->x, priv->translation->y);
+               }
+
        if (priv->width != 0 && priv->height != 0)
                {
                        rpt_print_page (rpt_print, priv->pages->nodeTab[page_nr]);
index 434f4c7f3008e54f59663aeeeb42c61c0465ab5a..e76b530a376030cda18f60b7841853b39525e259 100644 (file)
@@ -62,6 +62,7 @@ void rpt_print_set_output_filename (RptPrint *rpt_print, const gchar *output_fil
 
 void rpt_print_set_gtkprintsettings (RptPrint *rpt_print, GtkPrintSettings *settings);
 void rpt_print_set_copies (RptPrint *rpt_print, guint copies);
+void rpt_print_set_translation (RptPrint *rpt_print, RptTranslation *translation);
 
 void rpt_print_print (RptPrint *rpt_print, GtkWindow *transient);
 
index 1e19845c24ac48eb7694e5dc8692e89f86ba1798..abc8920845ae3d5216fffe2eee02a4c98e58fbe9 100644 (file)
@@ -102,7 +102,8 @@ enum
        PROP_0,
        PROP_UNIT_LENGTH,
        PROP_NAME,
-       PROP_DESCRIPTION
+       PROP_DESCRIPTION,
+       PROP_TRANSLATION
 };
 
 static void rpt_report_class_init (RptReportClass *klass);
@@ -148,6 +149,9 @@ static void rpt_report_change_specials (RptReport *rpt_report, xmlDoc *xdoc);
 typedef struct _RptReportPrivate RptReportPrivate;
 struct _RptReportPrivate
        {
+               gchar *name;
+               gchar *description;
+
                eRptUnitLength unit;
 
                eRptOutputType output_type;
@@ -155,6 +159,8 @@ struct _RptReportPrivate
 
                guint copies;
 
+               RptTranslation *translation;
+
                Database *db;
 
                Page *page;
@@ -164,9 +170,6 @@ struct _RptReportPrivate
                PageFooter *page_footer;
                Body *body;
 
-               gchar *name;
-               gchar *description;
-
                guint cur_page;
                gint cur_row;
                GtkTreeIter *cur_iter;
@@ -203,6 +206,11 @@ rpt_report_class_init (RptReportClass *klass)
                                                           "Report's description.",
                                                           "",
                                                           G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+       g_object_class_install_property (object_class, PROP_TRANSLATION,
+                                        g_param_spec_pointer ("translation",
+                                                              "Translation",
+                                                              "Translation of the entire report.",
+                                                              G_PARAM_READWRITE));
 
        /**
         * RptReport::field-request:
@@ -237,6 +245,11 @@ rpt_report_init (RptReport *rpt_report)
 {
        RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report);
 
+       priv->output_type = RPT_OUTPUT_PDF;
+       priv->output_filename = g_strdup ("rptreport.pdf");
+       priv->copies = 1;
+       priv->translation = NULL;
+
        priv->db = NULL;
 
        priv->page = (Page *)g_malloc0 (sizeof (Page));
@@ -254,10 +267,6 @@ rpt_report_init (RptReport *rpt_report)
        priv->body->objects = NULL;
        priv->body->new_page_after = FALSE;
 
-       priv->output_type = RPT_OUTPUT_PDF;
-       priv->output_filename = g_strdup ("rptreport.pdf");
-       priv->copies = 1;
-
        priv->cur_row = -1;
        priv->cur_iter = NULL;
 }
@@ -355,6 +364,10 @@ RptReport
                                                                                {
                                                                                        rpt_report_set_copies (rpt_report, strtol ((const gchar *)xmlNodeGetContent (cur_property), NULL, 10));
                                                                                }
+                                                                       else if (g_strcmp0 (cur_property->name, "translation") == 0)
+                                                                               {
+                                                                                       rpt_report_set_translation (rpt_report, rpt_common_get_translation (cur_property));
+                                                                               }
 
                                                                        cur_property = cur_property->next;
                                                                }
@@ -810,6 +823,30 @@ rpt_report_set_copies (RptReport *rpt_report, guint copies)
        priv->copies = copies;
 }
 
+/**
+ * rpt_report_set_translation:
+ * @rpt_report:
+ * @translation:
+ *
+ */
+void
+rpt_report_set_translation (RptReport *rpt_report, RptTranslation *translation)
+{
+       g_return_if_fail (IS_RPT_REPORT (rpt_report));
+
+       RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report);
+
+       if (priv->translation != NULL)
+               {
+                       g_free (priv->translation);
+                       priv->translation = NULL;
+               }
+       if (translation != NULL)
+               {
+                       priv->translation = rpt_common_rpttranslation_new_with_values (translation->x, translation->y);
+               }
+}
+
 /**
  * rpt_report_database_get_provider:
  * @rpt_report:
@@ -1510,6 +1547,11 @@ xmlDoc
        xmlNodeSetContent (xnode, g_strdup_printf ("%d", priv->copies));
        xmlAddChild (xnodeprop, xnode);
 
+       if (priv->translation != NULL)
+               {
+                       rpt_common_set_translation (xnodeprop, priv->translation);
+               }
+
        if (priv->db != NULL)
                {
                        xmlNode *xnodedb = xmlNewNode (NULL, "database");
@@ -1611,6 +1653,10 @@ xmlDoc
        rpt_report_rptprint_set_output_type (xdoc, priv->output_type);
        rpt_report_rptprint_set_output_filename (xdoc, priv->output_filename);
        rpt_report_rptprint_set_copies (xdoc, priv->copies);
+       if (priv->translation != NULL)
+               {
+                       rpt_report_rptprint_set_translation (xdoc, priv->translation);
+               }
 
        if (priv->db != NULL)
                {
@@ -2010,6 +2056,26 @@ rpt_report_rptprint_set_copies (xmlDoc *xdoc, guint copies)
        xmlAddChild (xnodeprop, xnode);
 }
 
+void
+rpt_report_rptprint_set_translation (xmlDoc *xdoc, RptTranslation *translation)
+{
+       xmlNode *xnodeprop;
+       xmlNode *xnode;
+       xmlNode *xroot;
+
+       xnodeprop = rpt_report_rptprint_get_properties_node (xdoc);
+       if (xnodeprop == NULL)
+               {
+                       xroot = xmlDocGetRootElement (xdoc);
+                       xnodeprop = xmlNewNode (NULL, "properties");
+                       xmlAddChild (xroot, xnodeprop);
+               }
+
+       /* TODO
+        * replace eventually already present node */
+       rpt_common_set_translation (xnodeprop, translation);
+}
+
 xmlNode
 *rpt_report_rptprint_page_new (xmlDoc *xdoc, RptSize *size, RptMargin *margin)
 {
@@ -2247,6 +2313,10 @@ rpt_report_set_property (GObject *object, guint property_id, const GValue *value
                                priv->unit = g_value_get_int (value);
                                break;
 
+                       case PROP_TRANSLATION:
+                               priv->translation = g_value_get_pointer (value);
+                               break;
+
                        default:
                                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
                                break;
@@ -2273,6 +2343,10 @@ rpt_report_get_property (GObject *object, guint property_id, GValue *value, GPar
                                g_value_set_int (value, priv->unit);
                                break;
 
+                       case PROP_TRANSLATION:
+                               g_value_set_pointer (value, priv->translation);
+                               break;
+
                        default:
                                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
                                break;
index d31131f55ad06a2b2e85fd186104ac9d4f7fdc69..3abefa83d88a3d77cba436111e7f4204f9500027 100644 (file)
@@ -78,6 +78,7 @@ void rpt_report_set_output_type (RptReport *rpt_report, eRptOutputType output_ty
 void rpt_report_set_output_filename (RptReport *rpt_report, const gchar *output_filename);
 
 void rpt_report_set_copies (RptReport *rpt_report, guint copies);
+void rpt_report_set_translation (RptReport *rpt_report, RptTranslation *translation);
 
 const gchar *rpt_report_database_get_provider (RptReport *rpt_report);
 const gchar *rpt_report_database_get_connection_string (RptReport *rpt_report);
@@ -169,6 +170,7 @@ void rpt_report_rptprint_set_unit_length (xmlDoc *xdoc, eRptUnitLength unit);
 void rpt_report_rptprint_set_output_type (xmlDoc *xdoc, eRptOutputType output_type);
 void rpt_report_rptprint_set_output_filename (xmlDoc *xdoc, const gchar *output_filename);
 void rpt_report_rptprint_set_copies (xmlDoc *xdoc, guint copies);
+void rpt_report_rptprint_set_translation (xmlDoc *xdoc, RptTranslation *translation);
 
 xmlNode *rpt_report_rptprint_page_new (xmlDoc *xdoc, RptSize *size, RptMargin *margin);
 void rpt_report_rptprint_page_add_object (xmlNode *xnodepage, RptObject *rpt_object);