]> saetta.ns0.it Git - reptool/libreptool/commitdiff
Added function RptReport::rptprint_page_new.
authorAndrea Zagli <azagli@libero.it>
Sat, 16 Jul 2011 08:40:30 +0000 (10:40 +0200)
committerAndrea Zagli <azagli@libero.it>
Sat, 16 Jul 2011 08:40:30 +0000 (10:40 +0200)
src/rptprint.c
src/rptreport.c
src/rptreport.h
tests/test_report.rpt

index 3b74dd3f244270c3b070fa17ec2715f46454de22..f1e52c41d64b43b3fa7665ac2115511b14c5e743 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006-2010 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2006-2011 Andrea Zagli <azagli@libero.it>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -130,33 +130,7 @@ struct _RptPrintPrivate
                GtkPrintContext *gtk_print_context;
        };
 
-GType
-rpt_print_get_type (void)
-{
-       static GType rpt_print_type = 0;
-
-       if (!rpt_print_type)
-               {
-                       static const GTypeInfo rpt_print_info =
-                       {
-                               sizeof (RptPrintClass),
-                               NULL,   /* base_init */
-                               NULL,   /* base_finalize */
-                               (GClassInitFunc) rpt_print_class_init,
-                               NULL,   /* class_finalize */
-                               NULL,   /* class_data */
-                               sizeof (RptPrint),
-                               0,      /* n_preallocs */
-                               (GInstanceInitFunc) rpt_print_init,
-                               NULL
-                       };
-
-                       rpt_print_type = g_type_register_static (G_TYPE_OBJECT, "RptPrint",
-                                                                &rpt_print_info, 0);
-               }
-
-       return rpt_print_type;
-}
+G_DEFINE_TYPE (RptPrint, rpt_print, G_TYPE_OBJECT)
 
 static void
 rpt_print_class_init (RptPrintClass *klass)
index 7ab85068558a89bb04ae8ebd0af777d5d8ca7fab..0d8e7c3809ad934bf58b98eef3e1ca91ad246f2e 100644 (file)
@@ -122,8 +122,10 @@ static gboolean rpt_report_object_is_in_section (RptReport *rpt_report, RptObjec
 static void rpt_report_section_create (RptReport *rpt_report, RptReportSection section);
 static xmlNode *rpt_report_section_get_xml (RptReport *rpt_report, RptReportSection section);
 
+static xmlNode *rpt_report_rptprint_get_properties_node (xmlDoc *xdoc);
+
 static xmlNode *rpt_report_rptprint_new_page (RptReport *rpt_report,
-                                              xmlNode *xroot);
+                                              xmlDoc *xdoc);
 static void rpt_report_rptprint_section (RptReport *rpt_report,
                                          xmlNode *xpage,
                                          gdouble *cur_y,
@@ -162,33 +164,7 @@ struct _RptReportPrivate
                guint cur_page;
        };
 
-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;
-}
+G_DEFINE_TYPE (RptReport, rpt_report, G_TYPE_OBJECT)
 
 static void
 rpt_report_class_init (RptReportClass *klass)
@@ -320,42 +296,37 @@ RptReport
                                        rpt_report = rpt_report_new ();
 
                                        priv = RPT_REPORT_GET_PRIVATE (rpt_report);
-                                       xpcontext = xmlXPathNewContext (xdoc);
 
                                        /* search for node "properties" */
-                                       xpcontext->node = cur;
-                                       xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::properties", xpcontext);
-                                       if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval))
+                                       xmlNode *xnodeprop = rpt_report_rptprint_get_properties_node (xdoc);
+                                       if (xnodeprop != NULL)
                                                {
-                                                       xnodeset = xpresult->nodesetval;
-                                                       if (xnodeset->nodeNr == 1)
+                                                       xmlNode *cur_property = xnodeprop->children;
+                                                       while (cur_property != NULL)
                                                                {
-                                                                       xmlNode *cur_property = xnodeset->nodeTab[0]->children;
-                                                                       while (cur_property != NULL)
+                                                                       if (g_strcmp0 (cur_property->name, "unit-length") == 0)
                                                                                {
-                                                                                       if (g_strcmp0 (cur_property->name, "unit-length") == 0)
-                                                                                               {
-                                                                                                       g_object_set (G_OBJECT (rpt_report), "unit-length", rpt_common_strunit_to_enum ((const gchar *)xmlNodeGetContent (cur_property)), NULL);
-                                                                                               }
-                                                                                       else if (g_strcmp0 (cur_property->name, "output-type") == 0)
-                                                                                               {
-                                                                                                       rpt_report_set_output_type (rpt_report, rpt_common_stroutputtype_to_enum ((const gchar *)xmlNodeGetContent (cur_property)));
-                                                                                               }
-                                                                                       else if (g_strcmp0 (cur_property->name, "output-filename") == 0)
-                                                                                               {
-                                                                                                       rpt_report_set_output_filename (rpt_report, (const gchar *)xmlNodeGetContent (cur_property));
-                                                                                               }
-                                                                                       else if (g_strcmp0 (cur_property->name, "copies") == 0)
-                                                                                               {
-                                                                                                       rpt_report_set_copies (rpt_report, strtol ((const gchar *)xmlNodeGetContent (cur_property), NULL, 10));
-                                                                                               }
-
-                                                                                       cur_property = cur_property->next;
+                                                                                       g_object_set (G_OBJECT (rpt_report), "unit-length", rpt_common_strunit_to_enum ((const gchar *)xmlNodeGetContent (cur_property)), NULL);
                                                                                }
+                                                                       else if (g_strcmp0 (cur_property->name, "output-type") == 0)
+                                                                               {
+                                                                                       rpt_report_set_output_type (rpt_report, rpt_common_stroutputtype_to_enum ((const gchar *)xmlNodeGetContent (cur_property)));
+                                                                               }
+                                                                       else if (g_strcmp0 (cur_property->name, "output-filename") == 0)
+                                                                               {
+                                                                                       rpt_report_set_output_filename (rpt_report, (const gchar *)xmlNodeGetContent (cur_property));
+                                                                               }
+                                                                       else if (g_strcmp0 (cur_property->name, "copies") == 0)
+                                                                               {
+                                                                                       rpt_report_set_copies (rpt_report, strtol ((const gchar *)xmlNodeGetContent (cur_property), NULL, 10));
+                                                                               }
+
+                                                                       cur_property = cur_property->next;
                                                                }
                                                }
 
                                        /* search for node "database" */
+                                       xpcontext = xmlXPathNewContext (xdoc);
                                        xpcontext->node = cur;
                                        xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::database", xpcontext);
                                        if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval))
@@ -1391,7 +1362,7 @@ xmlDoc
                                                                }
 
                                                        cur_y = priv->page->margin->top;
-                                                       xpage = rpt_report_rptprint_new_page (rpt_report, xroot);
+                                                       xpage = rpt_report_rptprint_new_page (rpt_report, xdoc);
 
                                                        if (priv->page_header != NULL)
                                                                {
@@ -1407,7 +1378,7 @@ xmlDoc
                                                                        if (priv->report_header->new_page_after)
                                                                                {
                                                                                        cur_y = 0.0;
-                                                                                       xpage = rpt_report_rptprint_new_page (rpt_report, xroot);
+                                                                                       xpage = rpt_report_rptprint_new_page (rpt_report, xdoc);
                                                                                }
                                                                }
                                                }
@@ -1426,7 +1397,7 @@ xmlDoc
                                                                }
 
                                                        cur_y = priv->page->margin->top;
-                                                       xpage = rpt_report_rptprint_new_page (rpt_report, xroot);
+                                                       xpage = rpt_report_rptprint_new_page (rpt_report, xdoc);
 
                                                        if (priv->cur_page > 0 && priv->page_footer != NULL)
                                                                {
@@ -1448,7 +1419,7 @@ xmlDoc
        else
                {
                        cur_y = priv->page->margin->top;
-                       xpage = rpt_report_rptprint_new_page (rpt_report, xroot);
+                       xpage = rpt_report_rptprint_new_page (rpt_report, xdoc);
 
                        if (priv->page_header != NULL)
                                {
@@ -1488,34 +1459,6 @@ xmlDoc
        return xdoc;
 }
 
-static xmlNode
-*rpt_report_rptprint_get_properties_node (xmlDoc *xdoc)
-{
-       xmlNode *xnode;
-
-       xmlXPathContextPtr xpcontext;
-       xmlXPathObjectPtr xpresult;
-       xmlNodeSetPtr xnodeset;
-
-       xnode = NULL;
-
-       xpcontext = xmlXPathNewContext (xdoc);
-
-       /* search for node "properties" */
-       xpcontext->node = xmlDocGetRootElement (xdoc);
-       xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::properties", xpcontext);
-       if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval))
-               {
-                       xnodeset = xpresult->nodesetval;
-                       if (xnodeset->nodeNr > 0)
-                               {
-                                       xnode = xnodeset->nodeTab[0];
-                               }
-               }
-
-       return xnode;
-}
-
 void
 rpt_report_rptprint_set_unit_length (xmlDoc *xdoc, eRptUnitLength unit)
 {
@@ -1604,6 +1547,23 @@ rpt_report_rptprint_set_copies (xmlDoc *xdoc, guint copies)
        xmlAddChild (xnodeprop, xnode);
 }
 
+xmlNode
+*rpt_report_rptprint_page_new (xmlDoc *xdoc, RptSize *size, RptMargin *margin)
+{
+       xmlNode *xroot;
+       xmlNode *xnode;
+
+       xroot = xmlDocGetRootElement (xdoc);
+
+       xnode = xmlNewNode (NULL, "page");
+       xmlAddChild (xroot, xnode);
+
+       rpt_common_set_size (xnode, size);
+       rpt_common_set_margin (xnode, margin);
+
+       return xnode;
+}
+
 /**
  * rpt_report_add_object_to_section:
  * @rpt_report: an #RptReport object.
@@ -2189,33 +2149,42 @@ rpt_report_xml_parse_section (RptReport *rpt_report, xmlNode *xnode, RptReportSe
 }
 
 static xmlNode
-*rpt_report_rptprint_new_page (RptReport *rpt_report, xmlNode *xroot)
+*rpt_report_rptprint_get_properties_node (xmlDoc *xdoc)
 {
        xmlNode *xnode;
 
-       RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report);
+       xmlXPathContextPtr xpcontext;
+       xmlXPathObjectPtr xpresult;
+       xmlNodeSetPtr xnodeset;
 
-       xnode = xmlNewNode (NULL, "page");
-       xmlAddChild (xroot, xnode);
+       xnode = NULL;
 
-       rpt_common_set_size (xnode, priv->page->size);
-       if (priv->page->margin->top != 0.0)
-               {
-                       xmlSetProp (xnode, "margin-top", g_strdup_printf ("%f", priv->page->margin->top));
-               }
-       if (priv->page->margin->right != 0.0)
-               {
-                       xmlSetProp (xnode, "margin-right", g_strdup_printf ("%f", priv->page->margin->right));
-               }
-       if (priv->page->margin->bottom != 0.0)
-               {
-                       xmlSetProp (xnode, "margin-bottom", g_strdup_printf ("%f", priv->page->margin->bottom));
-               }
-       if (priv->page->margin->left != 0.0)
+       xpcontext = xmlXPathNewContext (xdoc);
+
+       /* search for node "properties" */
+       xpcontext->node = xmlDocGetRootElement (xdoc);
+       xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::properties", xpcontext);
+       if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval))
                {
-                       xmlSetProp (xnode, "margin-left", g_strdup_printf ("%f", priv->page->margin->left));
+                       xnodeset = xpresult->nodesetval;
+                       if (xnodeset->nodeNr > 0)
+                               {
+                                       xnode = xnodeset->nodeTab[0];
+                               }
                }
 
+       return xnode;
+}
+
+static xmlNode
+*rpt_report_rptprint_new_page (RptReport *rpt_report, xmlDoc *xdoc)
+{
+       xmlNode *xnode;
+
+       RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report);
+
+       xnode = rpt_report_rptprint_page_new (xdoc, priv->page->size, priv->page->margin);
+
        priv->cur_page++;
 
        return xnode;
index 78fd41b2b97403c671fc22229a39402b476263e6..5d26bb6474f23ea935b6517f41748872443e40f4 100644 (file)
@@ -153,6 +153,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);
+xmlNode *rpt_report_rptprint_page_new (xmlDoc *xdoc, RptSize *size, RptMargin *margin);
 
 
 G_END_DECLS
index 230e209e4437e6ca6cc25927bd992a88afc9e9ee..4574a6d2732b29581ed9216a8624636a7c60eedd 100644 (file)
@@ -6,10 +6,37 @@
     <output-filename>rptreport.pdf</output-filename>
     <copies>1</copies>
   </properties>
-  <page width="595.000000" height="842.000000" margin-top="200.000000" margin-left="100.000000"/>
+  <database>
+    <provider>SQLite</provider>
+    <connection-string>DB_DIR=.;DB_NAME=db_test.db</connection-string>
+    <sql>SELECT * FROM articles ORDER BY name</sql>
+  </database>
+  <page width="595.000000" height="842.000000"/>
   <report>
-    <body height="0.000000">
-      <text name="txt_id" x="50.000000" y="50.000000" width="100.000000" height="50.000000" border-top-width="1.000000" border-top-color="#FF0000FF" font-name="Sans" font-size="12.000000" source="&quot;text with&#10;new line&quot;"/>
+    <report-header height="80.000000">
+      <text name="rephead" x="10.000000" y="10.000000" width="300.000000" height="70.000000" font-name="Verdana" font-size="16.000000" font-bold="y" font-color="#0000FFFF" source="&quot;the report's header&quot;"/>
+    </report-header>
+    <page-header first-page="y" height="80.000000">
+      <text name="title" x="10.000000" y="10.000000" width="300.000000" height="50.000000" font-name="Courier New" font-size="10.000000" font-bold="y" source="&quot;the page's title&quot; &amp; &quot; - &quot; &amp; @Page"/>
+      <line name="line1" x="10.000000" y="65.000000" width="500.000000" height="0.000000" stroke-width="1.000000" stroke-color="#000000FF"/>
+    </page-header>
+    <body height="200.000000">
+      <text name="txt_id" x="50.000000" y="50.000000" width="100.000000" height="50.000000" border-top-width="1.000000" border-top-color="#FF0000FF" font-name="Sans" font-size="12.000000" source="[id]"/>
+      <text name="txt_name" x="200.000000" y="50.000000" width="100.000000" height="50.000000" font-name="Sans" font-size="12.000000" source="[name]"/>
+      <text name="txt_req" x="50.000000" y="100.000000" width="100.000000" height="50.000000" font-name="Sans" font-size="12.000000" source="[nonexistent]"/>
+      <rect name="rect1" x="400.000000" y="10.000000" width="20.000000" height="20.000000" stroke-width="1.000000" stroke-color="#000000FF" fill-color="#00FF00FF"/>
+      <image name="img1" x="450.000000" y="10.000000" width="60.000000" height="60.000000" border-bottom-width="1.000000" border-bottom-color="#FF0000FF" border-bottom-style="10.000000;10.000000;" source="tests/gnome-globe.png"/>
     </body>
+    <report-footer height="50.000000">
+      <line name="line3" x="10.000000" y="10.000000" width="500.000000" height="0.000000" stroke-width="1.000000" stroke-color="#FFFF00FF" stroke-style="50.000000;10.000000;"/>
+      <text name="txt_report_footer" x="10.000000" y="20.000000" width="500.000000" height="30.000000" font-name="Sans" font-size="12.000000" horizontal-align="center" source="&quot;the report's footer&quot;"/>
+      <line name="line4" x="10.000000" y="50.000000" width="500.000000" height="0.000000" stroke-width="1.000000" stroke-color="#FFFF00FF" stroke-style="1.000000;5.000000;"/>
+    </report-footer>
+    <page-footer first-page="y" last-page="y" height="80.000000">
+      <line name="line2" x="10.000000" y="10.000000" width="500.000000" height="0.000000" stroke-width="1.000000" stroke-color="#000000FF"/>
+      <text name="footer" x="10.000000" y="20.000000" width="300.000000" height="50.000000" font-name="Sans" font-size="12.000000" source="&quot;the page's footer&quot;"/>
+      <ellipse name="ellipse1" x="400.000000" y="50.000000" width="20.000000" height="10.000000" stroke-width="1.000000" stroke-color="#FF0000FF" fill-color="#00FF00FF"/>
+      <text name="page_n" x="500.000000" y="20.000000" width="50.000000" height="50.000000" font-name="Sans" font-size="12.000000" source="@Page &amp; &quot;/&quot; &amp; @Pages"/>
+    </page-footer>
   </report>
 </reptool>