]> saetta.ns0.it Git - reptool/libreptool/commitdiff
Adjustments to RptReport::new_from_gtktreeview.
authorAndrea Zagli <azagli@libero.it>
Sat, 8 Oct 2011 15:35:31 +0000 (17:35 +0200)
committerAndrea Zagli <azagli@libero.it>
Sat, 8 Oct 2011 15:35:31 +0000 (17:35 +0200)
Retrieved font from GtkTreeView's style.

src/rptreport.c
tests/rptreport_gtktreeview.c
tests/test_report.rpt

index be3afabb68abff33ce9a07a83ac33c36a410af6a..1e0b4e306eadad58961e357940ea30b38375d7c1 100644 (file)
@@ -533,6 +533,9 @@ RptReport
 {
        RptReport *ret;
 
+       GtkStyle *style;
+       PangoFontDescription *pango_font;
+
        GList *columns;
        GHashTable *columns_names;
 
@@ -540,6 +543,8 @@ RptReport
 
        RptPoint *point;
        RptSize *size;
+       RptFont *font;
+       RptAlign *align;
        RptObject *obj;
 
        guint x;
@@ -552,6 +557,9 @@ RptReport
 
        g_return_val_if_fail (GTK_IS_TREE_VIEW (view), NULL);
 
+       style = gtk_widget_get_style (GTK_WIDGET (view));
+       pango_font = style->font_desc;
+
        ret = rpt_report_new ();
 
        columns = gtk_tree_view_get_columns (view);
@@ -564,10 +572,10 @@ RptReport
 
        rpt_report_set_page_margins (ret, 10, 10, 10, 10);
 
-       rpt_report_set_section_height (ret, RPTREPORT_SECTION_PAGE_HEADER, 30);
+       rpt_report_set_section_height (ret, RPTREPORT_SECTION_PAGE_HEADER, 27);
        rpt_report_set_page_header_first_last_page (ret, TRUE, TRUE);
 
-       rpt_report_set_section_height (ret, RPTREPORT_SECTION_BODY, 30);
+       rpt_report_set_section_height (ret, RPTREPORT_SECTION_BODY, 15);
 
        if (title != NULL)
                {
@@ -575,14 +583,19 @@ RptReport
                        obj = rpt_obj_text_new ("title", *point);
 
                        size = rpt_common_rptsize_new_with_values (page_size->width - 20, 10);
+                       font = rpt_common_rptfont_from_pango_description (pango_font);
+                       font->size += 2;
+                       font->bold = TRUE;
 
                        g_object_set (obj,
                                      "source", title,
                                      "size", size,
+                                     "font", font,
                                      NULL);
 
                        g_free (point);
                        g_free (size);
+                       g_free (font);
 
                        rpt_report_add_object_to_section (ret, obj, RPTREPORT_SECTION_PAGE_HEADER);
                }
@@ -596,32 +609,43 @@ RptReport
                        col = (GtkTreeViewColumn *)columns->data;
 
                        col_title = g_strdup_printf ("\"%s\"", gtk_tree_view_column_get_title (col));
-                       col_width = gtk_tree_view_column_get_width (col) / 96 * 25.4;
+                       col_width = rpt_common_points_to_value (RPT_UNIT_MILLIMETRE, gtk_tree_view_column_get_width (col) / 96 * 72);
 
-                       point = rpt_common_rptpoint_new_with_values (x, 20);
+                       point = rpt_common_rptpoint_new_with_values (x, 15);
                        size = rpt_common_rptsize_new_with_values (col_width, 10);
+                       font = rpt_common_rptfont_from_pango_description (pango_font);
+                       font->bold = TRUE;
 
                        obj = rpt_obj_text_new (g_strdup_printf ("title_%d", idx), *point);
 
                        g_object_set (obj,
                                      "source", col_title,
                                      "size", size,
+                                     "font", font,
                                      NULL);
 
                        rpt_report_add_object_to_section (ret, obj, RPTREPORT_SECTION_PAGE_HEADER);
 
+                       g_free (point);
+                       g_free (font);
+
+                       point = rpt_common_rptpoint_new_with_values (x, 0);
+                       font = rpt_common_rptfont_from_pango_description (pango_font);
+
                        field_name = g_strdup_printf ("field_%d", idx);
                        obj = rpt_obj_text_new (field_name, *point);
 
                        g_object_set (obj,
                                      "source", g_strdup_printf ("[%s]", field_name),
                                      "size", size,
+                                     "font", font,
                                      NULL);
 
                        rpt_report_add_object_to_section (ret, obj, RPTREPORT_SECTION_BODY);
 
                        g_free (point);
                        g_free (size);
+                       g_free (font);
 
                        g_hash_table_insert (columns_names, field_name, g_strdup_printf ("%d", idx));
 
@@ -631,7 +655,7 @@ RptReport
                        columns = g_list_next (columns);
                }
 
-       point = rpt_common_rptpoint_new_with_values (0, 10);
+       point = rpt_common_rptpoint_new_with_values (0, 25);
        obj = rpt_obj_line_new ("line1", *point);
 
        size = rpt_common_rptsize_new_with_values (page_size->width - 20, 0);
@@ -645,7 +669,7 @@ RptReport
 
        rpt_report_add_object_to_section (ret, obj, RPTREPORT_SECTION_PAGE_HEADER);
 
-       rpt_report_set_section_height (ret, RPTREPORT_SECTION_PAGE_FOOTER, 15);
+       rpt_report_set_section_height (ret, RPTREPORT_SECTION_PAGE_FOOTER, 12);
 
        point = rpt_common_rptpoint_new_with_values (0, 0);
        obj = rpt_obj_line_new ("line2", *point);
@@ -662,18 +686,25 @@ RptReport
        rpt_report_add_object_to_section (ret, obj, RPTREPORT_SECTION_PAGE_FOOTER);
        rpt_report_set_page_footer_first_last_page (ret, TRUE, TRUE);
 
-       point = rpt_common_rptpoint_new_with_values (0, 0);
+       point = rpt_common_rptpoint_new_with_values (0, 2);
        obj = rpt_obj_text_new ("pages", *point);
 
        size = rpt_common_rptsize_new_with_values (page_size->width - 20, 10);
+       align = rpt_common_rptalign_new ();
+       align->h_align = RPT_HALIGN_RIGHT;
+       font = rpt_common_rptfont_from_pango_description (pango_font);
+       font->size -= 1;
 
        g_object_set (obj,
                      "source", "\"Page \" & @Page & \" of \" & @Pages",
                      "size", size,
+                     "font", font,
+                     "align", align,
                      NULL);
 
        g_free (point);
        g_free (size);
+       g_free (font);
 
        rpt_report_add_object_to_section (ret, obj, RPTREPORT_SECTION_PAGE_FOOTER);
 
index b5394110d4c296d5a304503d4221ae218059e463..fe922651bba16d5ac7e0bdb8ddce1ceb575babfe 100644 (file)
@@ -50,6 +50,13 @@ main (int argc, char **argv)
                            CHECKED_COLUMN, FALSE,
                            -1);
 
+       gtk_list_store_append (store, &iter);
+       gtk_list_store_set (store, &iter,
+                           TITLE_COLUMN, "The Art of Computer Programming",
+                           AUTHOR_COLUMN, "Donald E. Knuth",
+                           CHECKED_COLUMN, FALSE,
+                           -1);
+
        GtkWidget *tree;
 
        tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
index b539beb6acc1776144e510ce8c25944288f61515..74588112431493576329dc02c0e1c169591074d2 100644 (file)
@@ -1,9 +1,9 @@
 <?xml version="1.0"?>
 <reptool>
   <properties>
-    <unit-length>pt</unit-length>
-    <output-type>png</output-type>
-    <output-filename>test.png</output-filename>
+    <unit-length>mm</unit-length>
+    <output-type>pdf</output-type>
+    <output-filename>rptreport.pdf</output-filename>
     <copies>1</copies>
   </properties>
   <database>
     <connection-string/>
     <sql/>
   </database>
-  <page width="595.000000" height="842.000000"/>
+  <page width="297,000000" height="210,000000" margin-top="10,000000" margin-right="10,000000" margin-bottom="10,000000" margin-left="10,000000"/>
   <report>
-    <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 first-page="y" last-page="y" height="27,000000">
+      <text name="title" x="0,000000" y="0,000000" width="277,000000" height="10,000000" font-name="Droid Sans" font-size="11,000000" font-bold="y" font-color="#000000FF" source="&quot;Report's Title&quot;"/>
+      <text name="title_0" x="0,000000" y="15,000000" width="50,000000" height="10,000000" font-name="Droid Sans" font-size="9,000000" font-bold="y" font-color="#000000FF" source="&quot;Book's title&quot;"/>
+      <text name="title_1" x="55,000000" y="15,000000" width="76,000000" height="10,000000" font-name="Droid Sans" font-size="9,000000" font-bold="y" font-color="#000000FF" source="&quot;Author&quot;"/>
+      <line name="line1" x="0,000000" y="25,000000" width="277,000000" height="0,000000"/>
     </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 height="15,000000">
+      <text name="field_0" x="0,000000" y="0,000000" width="50,000000" height="10,000000" font-name="Droid Sans" font-size="9,000000" font-color="#000000FF" source="[field_0]"/>
+      <text name="field_1" x="55,000000" y="0,000000" width="76,000000" height="10,000000" font-name="Droid Sans" font-size="9,000000" font-color="#000000FF" source="[field_1]"/>
     </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 first-page="y" last-page="y" height="12,000000">
+      <line name="line2" x="0,000000" y="0,000000" width="277,000000" height="0,000000"/>
+      <text name="pages" x="0,000000" y="2,000000" width="277,000000" height="10,000000" font-name="Droid Sans" font-size="8,000000" font-color="#000000FF" horizontal-align="right" source="&quot;Page &quot; &amp; @Page &amp; &quot; of &quot; &amp; @Pages"/>
     </page-footer>
   </report>
 </reptool>