From e0c650d288e87b5bc04b853e3f5e7d6ab321b0aa Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Fri, 13 Apr 2007 14:02:33 +0000 Subject: [PATCH] General code adjustments and refactoring. Added special text'source values "@Date" and "@Time". Added new functions to manage RptReport object. Version 0.0.3 git-svn-id: svn+ssh://saetta.homelinux.org/svn/libreptool/trunk@11 3191ed1d-3fce-41bb-ab4a-0cebc0943b59 --- ChangeLog | 28 + configure.ac | 2 +- data/reptool.dtd | 20 +- docs/reference/libreptool-sections.txt | 12 + docs/reference/tmpl/rptcommon.sgml | 17 +- docs/reference/tmpl/rptobjecttext.sgml | 5 + docs/reference/tmpl/rptreport.sgml | 116 +++ src/rptcommon.c | 404 ++++++----- src/rptcommon.h | 55 +- src/rptobject.c | 21 +- src/rptobjectimage.c | 16 +- src/rptobjectline.c | 14 +- src/rptobjectrect.c | 22 +- src/rptobjecttext.c | 72 +- src/rptprint.c | 345 +++++---- src/rptreport.c | 949 +++++++++++++++++++++---- src/rptreport.h | 46 ++ tests/test_report.rpt | 4 +- tests/test_report_db.rpt | 8 +- tests/test_rptprint.rptr | 1 + tests/test_rptreport.c | 3 + 21 files changed, 1579 insertions(+), 581 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6a29833..86684b4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,31 @@ +2007-04-08 Andrea Zagli + + * src/rptreport.h: + * src/rptreport.c: added body's property new-page-after; + added report header's property new-page-after; + added report footer's property new-page-before; + added page header/footer's properties first-page and last-page + +2007-04-07 Andrea Zagli + + * Some general code adjustments and refactorings + * src/rptprint.c: + * src/rptobjtext.c: added text's property background-color + +2007-04-04 Andrea Zagli + + * src/rptreport.h: + * src/rptreport.c: added rpt_report_set_database(), rpt_report_set_section_height(), + rpt_report_set_page_size() + * src/rptreport.c: changed rpt_report_object_is_in_section()'s prototype; + added special source's text objects values @Date and @Time + +2007-04-02 Andrea Zagli + + * src/rptreport.h: + * src/rptreport.c: added rpt_report_new(), rpt_report_add_object_to_section(), + rpt_report_remove_object() and rpt_report_get_object_from_name() + 2007-04-01 Andrea Zagli * src/rptreport.c: added and managed RPT_REPORT_SECTION_REPORT_HEADER and diff --git a/configure.ac b/configure.ac index 10e3d65..83c886f 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.59) -AC_INIT([libreptool], [0.0.2], [azagli@inwind.it]) +AC_INIT([libreptool], [0.0.3], [azagli@inwind.it]) AC_CONFIG_SRCDIR([src/rptprint.c]) AC_CONFIG_HEADER([config.h]) diff --git a/data/reptool.dtd b/data/reptool.dtd index 34ed4ab..874ca70 100644 --- a/data/reptool.dtd +++ b/data/reptool.dtd @@ -101,7 +101,12 @@ adapt (to-box | to-image | none) #IMPLIED > - + + + + + + - - - - - @@ -136,12 +136,14 @@ @@ -151,13 +153,13 @@ diff --git a/docs/reference/libreptool-sections.txt b/docs/reference/libreptool-sections.txt index 44feb8e..7901e43 100644 --- a/docs/reference/libreptool-sections.txt +++ b/docs/reference/libreptool-sections.txt @@ -73,10 +73,22 @@ rpt_object_get_type rptreport RptReport RptReport +RptReportSection +rpt_report_new rpt_report_new_from_xml rpt_report_new_from_file +rpt_report_set_database +rpt_report_set_page_size +rpt_report_set_section_height +rpt_report_set_report_header_new_page_after +rpt_report_set_report_footer_new_page_before +rpt_report_set_page_header_first_last_page +rpt_report_set_page_footer_first_last_page rpt_report_get_xml rpt_report_get_xml_rptprint +rpt_report_add_object_to_section +rpt_report_remove_object +rpt_report_get_object_from_name TYPE_RPT_REPORT RPT_REPORT diff --git a/docs/reference/tmpl/rptcommon.sgml b/docs/reference/tmpl/rptcommon.sgml index 4b9c0e0..082b54d 100644 --- a/docs/reference/tmpl/rptcommon.sgml +++ b/docs/reference/tmpl/rptcommon.sgml @@ -1,10 +1,9 @@ -rptcommon +RptCommon Usefull functions and struct. - @@ -112,7 +111,7 @@ Usefull functions and struct. @xnode: -@position: +@Returns: @@ -130,7 +129,7 @@ Usefull functions and struct. @xnode: -@size: +@Returns: @@ -148,7 +147,7 @@ Usefull functions and struct. @xnode: -@font: +@Returns: @@ -166,7 +165,7 @@ Usefull functions and struct. @xnode: -@border: +@Returns: @@ -184,7 +183,7 @@ Usefull functions and struct. @xnode: -@align: +@Returns: @@ -202,7 +201,7 @@ Usefull functions and struct. @xnode: -@stroke: +@Returns: @@ -220,7 +219,7 @@ Usefull functions and struct. @str_color: -@color: +@Returns: diff --git a/docs/reference/tmpl/rptobjecttext.sgml b/docs/reference/tmpl/rptobjecttext.sgml index 611d4ef..15fc9cd 100644 --- a/docs/reference/tmpl/rptobjecttext.sgml +++ b/docs/reference/tmpl/rptobjecttext.sgml @@ -28,6 +28,11 @@ A textual object. + + + + + diff --git a/docs/reference/tmpl/rptreport.sgml b/docs/reference/tmpl/rptreport.sgml index 211c3f1..df3e7fc 100644 --- a/docs/reference/tmpl/rptreport.sgml +++ b/docs/reference/tmpl/rptreport.sgml @@ -23,6 +23,25 @@ Manage report definition files and produces the xml report/print's file. + + + + + +@RPTREPORT_SECTION_REPORT_HEADER: +@RPTREPORT_SECTION_REPORT_FOOTER: +@RPTREPORT_SECTION_PAGE_HEADER: +@RPTREPORT_SECTION_PAGE_FOOTER: +@RPTREPORT_SECTION_BODY: + + + + + + +@Returns: + + @@ -41,6 +60,74 @@ Manage report definition files and produces the xml report/print's file. @Returns: + + + + + +@rpt_report: +@provider_id: +@connection_string: +@sql: + + + + + + + +@rpt_report: +@size: + + + + + + + +@rpt_report: +@section: +@height: + + + + + + + +@rpt_report: +@new_page_after: + + + + + + + +@rpt_report: +@new_page_before: + + + + + + + +@rpt_report: +@first_page: +@last_page: + + + + + + + +@rpt_report: +@first_page: +@last_page: + + @@ -59,3 +146,32 @@ Manage report definition files and produces the xml report/print's file. @Returns: + + + + + +@rpt_report: +@rpt_object: +@section: + + + + + + + +@rpt_report: +@rpt_object: + + + + + + + +@rpt_report: +@name: +@Returns: + + diff --git a/src/rptcommon.c b/src/rptcommon.c index 5ba8fe2..0ca9437 100644 --- a/src/rptcommon.c +++ b/src/rptcommon.c @@ -24,103 +24,104 @@ /** * rpt_common_get_position: - * @xnode: - * @position: + * @xnode: an #xmlNode. * */ -void -rpt_common_get_position (xmlNode *xnode, RptPoint *position) +RptPoint +*rpt_common_get_position (xmlNode *xnode) { - gchar *prop; + RptPoint *position = NULL; + gchar *x; + gchar *y; - position->x = 0.0; - position->y = 0.0; + x = xmlGetProp (xnode, (const xmlChar *)"x"); + y = xmlGetProp (xnode, (const xmlChar *)"y"); - prop = xmlGetProp (xnode, (const xmlChar *)"x"); - if (prop != NULL) - { - position->x = strtod (prop, NULL); - } - prop = xmlGetProp (xnode, (const xmlChar *)"y"); - if (prop != NULL) + if (x != NULL || y != NULL) { - position->y = strtod (prop, NULL); + position = (RptPoint *)g_malloc0 (sizeof (RptPoint)); + position->x = (x == NULL ? 0.0 : strtod (x, NULL)); + position->y = (y == NULL ? 0.0 : strtod (y, NULL)); } + + return position; } /** * rpt_common_set_position: - * @xnode: + * @xnode: an #xmlNode. * @position: * */ void -rpt_common_set_position (xmlNode *xnode, RptPoint position) +rpt_common_set_position (xmlNode *xnode, const RptPoint *position) { - xmlSetProp (xnode, "x", g_strdup_printf ("%f", position.x)); - xmlSetProp (xnode, "y", g_strdup_printf ("%f", position.y)); + if (position != NULL) + { + xmlSetProp (xnode, "x", g_strdup_printf ("%f", position->x)); + xmlSetProp (xnode, "y", g_strdup_printf ("%f", position->y)); + } } /** * rpt_common_get_size: - * @xnode: - * @size: + * @xnode: an #xmlNode. * */ -void -rpt_common_get_size (xmlNode *xnode, RptSize *size) +RptSize +*rpt_common_get_size (xmlNode *xnode) { - gchar *prop; - - size->width = 0.0; - size->height = 0.0; + RptSize *size = NULL; + gchar *width; + gchar *height; - prop = xmlGetProp (xnode, (const xmlChar *)"width"); - if (prop != NULL) - { - size->width = strtod (prop, NULL); - } - prop = xmlGetProp (xnode, (const xmlChar *)"height"); - if (prop != NULL) + width = xmlGetProp (xnode, (const xmlChar *)"width"); + height = xmlGetProp (xnode, (const xmlChar *)"height"); + if (width != NULL && height != NULL) { - size->height = strtod (prop, NULL); + size = (RptSize *)g_malloc0 (sizeof (RptSize)); + size->width = strtod (width, NULL); + size->height = strtod (height, NULL); } + + return size; } /** * rpt_common_set_size: - * @xnode: + * @xnode: an #xmlNode. * @size: * */ void -rpt_common_set_size (xmlNode *xnode, RptSize size) +rpt_common_set_size (xmlNode *xnode, const RptSize *size) { - xmlSetProp (xnode, "width", g_strdup_printf ("%f", size.width)); - xmlSetProp (xnode, "height", g_strdup_printf ("%f", size.height)); + if (size != NULL) + { + xmlSetProp (xnode, "width", g_strdup_printf ("%f", size->width)); + xmlSetProp (xnode, "height", g_strdup_printf ("%f", size->height)); + } } /** * rpt_common_get_font: - * @xnode: - * @font: + * @xnode: an #xmlNode. * */ -void -rpt_common_get_font (xmlNode *xnode, RptFont *font) +RptFont +*rpt_common_get_font (xmlNode *xnode) { + RptFont *font = NULL; gchar *prop; + font = (RptFont *)g_malloc0 (sizeof (RptFont)); + font->name = g_strdup ("sans"); font->size = 12.0; font->bold = FALSE; font->italic = FALSE; font->underline = PANGO_UNDERLINE_NONE; 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) @@ -178,88 +179,102 @@ rpt_common_get_font (xmlNode *xnode, RptFont *font) prop = xmlGetProp (xnode, "font-color"); if (prop != NULL) { - rpt_common_parse_color (prop, &font->color); + font->color = rpt_common_parse_color (prop); } + + return font; } /** * rpt_common_set_font: - * @xnode: + * @xnode: an #xmlNode. * @font: * */ void -rpt_common_set_font (xmlNode *xnode, RptFont font) +rpt_common_set_font (xmlNode *xnode, const 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 != PANGO_UNDERLINE_NONE) + if (font != NULL) { - switch (font.underline) + xmlSetProp (xnode, "font-name", font->name); + xmlSetProp (xnode, "font-size", g_strdup_printf ("%f", font->size)); + if (font->bold) { - case PANGO_UNDERLINE_SINGLE: - xmlSetProp (xnode, "font-underline", "single"); - break; - - case PANGO_UNDERLINE_DOUBLE: - xmlSetProp (xnode, "font-underline", "double"); - break; - - case PANGO_UNDERLINE_LOW: - xmlSetProp (xnode, "font-underline", "low"); - break; - - case PANGO_UNDERLINE_ERROR: - xmlSetProp (xnode, "font-underline", "error"); - break; + xmlSetProp (xnode, "font-bold", "y"); + } + if (font->italic) + { + xmlSetProp (xnode, "font-italic", "y"); + } + if (font->underline != PANGO_UNDERLINE_NONE) + { + switch (font->underline) + { + case PANGO_UNDERLINE_SINGLE: + xmlSetProp (xnode, "font-underline", "single"); + break; + + case PANGO_UNDERLINE_DOUBLE: + xmlSetProp (xnode, "font-underline", "double"); + break; + + case PANGO_UNDERLINE_LOW: + xmlSetProp (xnode, "font-underline", "low"); + break; + + case PANGO_UNDERLINE_ERROR: + xmlSetProp (xnode, "font-underline", "error"); + break; + } + } + if (font->strike) + { + xmlSetProp (xnode, "font-strike", "y"); + } + if (font->color != NULL) + { + xmlSetProp (xnode, "font-color", rpt_common_convert_to_str_color (font->color)); } } - if (font.strike) - { - xmlSetProp (xnode, "font-strike", "y"); - } - xmlSetProp (xnode, "font-color", rpt_common_convert_to_str_color (font.color)); } /** * rpt_common_get_border: - * @xnode: - * @border: + * @xnode: an #xmlNode. * */ -void -rpt_common_get_border (xmlNode *xnode, RptBorder *border) +RptBorder +*rpt_common_get_border (xmlNode *xnode) { + RptBorder *border = NULL; gchar *prop; + border = (RptBorder *)g_malloc0 (sizeof (RptBorder)); + 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; + border->top_color = (RptColor *)g_malloc0 (sizeof (RptColor)); + 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 = (RptColor *)g_malloc0 (sizeof (RptColor)); + 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 = (RptColor *)g_malloc0 (sizeof (RptColor)); + 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 = (RptColor *)g_malloc0 (sizeof (RptColor)); + 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) @@ -288,70 +303,77 @@ rpt_common_get_border (xmlNode *xnode, RptBorder *border) prop = xmlGetProp (xnode, "border-top-color"); if (prop != NULL) { - rpt_common_parse_color (prop, &border->top_color); + border->top_color = rpt_common_parse_color (prop); } prop = xmlGetProp (xnode, "border-right-color"); if (prop != NULL) { - rpt_common_parse_color (prop, &border->right_color); + border->right_color = rpt_common_parse_color (prop); } prop = xmlGetProp (xnode, "border-bottom-color"); if (prop != NULL) { - rpt_common_parse_color (prop, &border->bottom_color); + border->bottom_color = rpt_common_parse_color (prop); } prop = xmlGetProp (xnode, "border-left-color"); if (prop != NULL) { - rpt_common_parse_color (prop, &border->left_color); + border->left_color = rpt_common_parse_color (prop); } + + return border; } /** * rpt_common_set_border: - * @xnode: + * @xnode: an #xmlNode. * @border: * */ void -rpt_common_set_border (xmlNode *xnode, RptBorder border) +rpt_common_set_border (xmlNode *xnode, const RptBorder *border) { - if (border.top_width > 0.0) + if (border != NULL) { - xmlSetProp (xnode, "border-top-width", g_strdup_printf ("%f", border.top_width)); - xmlSetProp (xnode, "border-top-color", rpt_common_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", rpt_common_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", rpt_common_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", rpt_common_convert_to_str_color (border.left_color)); + if (border->top_width > 0.0 && border->top_color != NULL) + { + xmlSetProp (xnode, "border-top-width", g_strdup_printf ("%f", border->top_width)); + xmlSetProp (xnode, "border-top-color", rpt_common_convert_to_str_color (border->top_color)); + } + if (border->right_width > 0.0 && border->right_color != NULL) + { + xmlSetProp (xnode, "border-right-width", g_strdup_printf ("%f", border->right_width)); + xmlSetProp (xnode, "border-right-color", rpt_common_convert_to_str_color (border->right_color)); + } + if (border->bottom_width > 0.0 && border->bottom_color != NULL) + { + xmlSetProp (xnode, "border-bottom-width", g_strdup_printf ("%f", border->bottom_width)); + xmlSetProp (xnode, "border-bottom-color", rpt_common_convert_to_str_color (border->bottom_color)); + } + if (border->left_width > 0.0 && border->left_color != NULL) + { + xmlSetProp (xnode, "border-left-width", g_strdup_printf ("%f", border->left_width)); + xmlSetProp (xnode, "border-left-color", rpt_common_convert_to_str_color (border->left_color)); + } } } /** * rpt_common_get_align: - * @xnode: - * @align: + * @xnode: an #xmlNode. * */ -void -rpt_common_get_align (xmlNode *xnode, RptAlign *align) +RptAlign +*rpt_common_get_align (xmlNode *xnode) { + RptAlign *align = NULL; gchar *prop; + align = (RptAlign *)g_malloc0 (sizeof (RptAlign)); + align->h_align = RPT_HALIGN_LEFT; align->v_align = RPT_VALIGN_TOP; @@ -384,65 +406,73 @@ rpt_common_get_align (xmlNode *xnode, RptAlign *align) align->v_align = RPT_VALIGN_BOTTOM; } } + + return align; } /** * rpt_common_set_align: - * @xnode: + * @xnode: an #xmlNode. * @align: * */ void -rpt_common_set_align (xmlNode *xnode, RptAlign align) +rpt_common_set_align (xmlNode *xnode, const RptAlign *align) { - if (align.h_align != RPT_HALIGN_LEFT) + if (align != NULL) { - switch (align.h_align) + if (align->h_align != RPT_HALIGN_LEFT) { - case RPT_HALIGN_CENTER: - xmlSetProp (xnode, "horizontal-align", "center"); - break; + 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_RIGHT: + xmlSetProp (xnode, "horizontal-align", "right"); + break; - case RPT_HALIGN_JUSTIFIED: - xmlSetProp (xnode, "horizontal-align", "justified"); - break; + case RPT_HALIGN_JUSTIFIED: + xmlSetProp (xnode, "horizontal-align", "justified"); + break; + } } - } - if (align.v_align != RPT_VALIGN_TOP) - { - switch (align.v_align) + if (align->v_align != RPT_VALIGN_TOP) { - case RPT_VALIGN_CENTER: - xmlSetProp (xnode, "vertical-align", "center"); - break; + switch (align->v_align) + { + case RPT_VALIGN_CENTER: + xmlSetProp (xnode, "vertical-align", "center"); + break; - case RPT_VALIGN_BOTTOM: - xmlSetProp (xnode, "vertical-align", "bottom"); - break; + case RPT_VALIGN_BOTTOM: + xmlSetProp (xnode, "vertical-align", "bottom"); + break; + } } } } /** * rpt_common_get_stroke: - * @xnode: - * @stroke: + * @xnode: an #xmlNode. * */ -void -rpt_common_get_stroke (xmlNode *xnode, RptStroke *stroke) +RptStroke +*rpt_common_get_stroke (xmlNode *xnode) { + RptStroke *stroke = NULL; gchar *prop; + stroke = (RptStroke *)g_malloc0 (sizeof (RptStroke)); stroke->width = 1.0; - stroke->color.r = 0.0; - stroke->color.g = 0.0; - stroke->color.b = 0.0; - stroke->color.a = 1.0; + + stroke->color = (RptColor *)g_malloc0 (sizeof (RptColor)); + 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) @@ -453,37 +483,45 @@ rpt_common_get_stroke (xmlNode *xnode, RptStroke *stroke) prop = xmlGetProp (xnode, "stroke-color"); if (prop != NULL) { - rpt_common_parse_color (prop, &stroke->color); + stroke->color = rpt_common_parse_color (prop); } + + return stroke; } /** * rpt_common_set_stroke: - * @xnode: + * @xnode: an #xmlNode. * @stroke: * */ void -rpt_common_set_stroke (xmlNode *xnode, RptStroke stroke) +rpt_common_set_stroke (xmlNode *xnode, const RptStroke *stroke) { - if (stroke.width != 0.0) + if (stroke != NULL) { - xmlSetProp (xnode, "stroke-width", g_strdup_printf ("%f", stroke.width)); + if (stroke->width != 0.0) + { + xmlSetProp (xnode, "stroke-width", g_strdup_printf ("%f", stroke->width)); + } + xmlSetProp (xnode, "stroke-color", rpt_common_convert_to_str_color (stroke->color)); } - xmlSetProp (xnode, "stroke-color", rpt_common_convert_to_str_color (stroke.color)); } /** * rpt_common_parse_color: * @str_color: - * @color: * */ -void -rpt_common_parse_color (const gchar *str_color, RptColor *color) +RptColor +*rpt_common_parse_color (const gchar *str_color) { + RptColor *color = NULL; gchar *c = g_strstrip (g_strdup (str_color)); + color = (RptColor *)g_malloc0 (sizeof (RptColor)); + color->a = 1.0; + if (c[0] == '#') { if (strlen (c) == 4 || strlen (c) == 5) @@ -525,17 +563,29 @@ rpt_common_parse_color (const gchar *str_color, RptColor *color) } } } + + return color; } -gchar * -rpt_common_convert_to_str_color (RptColor color) +/** + * rpt_common_convert_to_str_color: + * @color: + * + */ +gchar +*rpt_common_convert_to_str_color (const RptColor *color) { - gchar *ret = "#"; + gchar *ret = NULL; - 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); + if (color != NULL) + { + ret = g_strdup ("#"); + + 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; } diff --git a/src/rptcommon.h b/src/rptcommon.h index e3af680..6057130 100644 --- a/src/rptcommon.h +++ b/src/rptcommon.h @@ -64,7 +64,7 @@ typedef struct _RptSize RptSize; * @size: the font's size in pixel. * @bold: if the font is bold. * @italic: if the font is italic. - * @underline: + * @underline: if the font is underline. * @strike: if the font is striked. * @color: an #RptColor. */ @@ -76,7 +76,7 @@ struct _RptFont gboolean italic; PangoUnderline underline; gboolean strike; - RptColor color; + RptColor *color; }; typedef struct _RptFont RptFont; @@ -86,10 +86,10 @@ struct _RptBorder gdouble right_width; gdouble bottom_width; gdouble left_width; - RptColor top_color; - RptColor right_color; - RptColor bottom_color; - RptColor left_color; + RptColor *top_color; + RptColor *right_color; + RptColor *bottom_color; + RptColor *left_color; }; typedef struct _RptBorder RptBorder; @@ -118,38 +118,37 @@ typedef struct _RptAlign RptAlign; struct _RptStroke { gdouble width; - RptColor color; + RptColor *color; }; typedef struct _RptStroke RptStroke; -void rpt_common_get_position (xmlNode *xnode, - RptPoint *position); +RptPoint *rpt_common_get_position (xmlNode *xnode); void rpt_common_set_position (xmlNode *xnode, - RptPoint position); -void rpt_common_get_size (xmlNode *xnode, - RptSize *size); + const RptPoint *position); + +RptSize *rpt_common_get_size (xmlNode *xnode); void rpt_common_set_size (xmlNode *xnode, - RptSize size); -void rpt_common_get_font (xmlNode *xnode, - RptFont *font); + const RptSize *size); + +RptFont *rpt_common_get_font (xmlNode *xnode); void rpt_common_set_font (xmlNode *xnode, - RptFont font); -void rpt_common_get_border (xmlNode *xnode, - RptBorder *border); + const RptFont *font); + +RptBorder *rpt_common_get_border (xmlNode *xnode); void rpt_common_set_border (xmlNode *xnode, - RptBorder border); -void rpt_common_get_align (xmlNode *xnode, - RptAlign *align); + const RptBorder *border); + +RptAlign *rpt_common_get_align (xmlNode *xnode); void rpt_common_set_align (xmlNode *xnode, - RptAlign align); -void rpt_common_get_stroke (xmlNode *xnode, - RptStroke *stroke); + const RptAlign *align); + +RptStroke *rpt_common_get_stroke (xmlNode *xnode); void rpt_common_set_stroke (xmlNode *xnode, - RptStroke stroke); -void rpt_common_parse_color (const gchar *str_color, - RptColor *color); -gchar *rpt_common_convert_to_str_color (RptColor color); + const RptStroke *stroke); + +RptColor *rpt_common_parse_color (const gchar *str_color); +gchar *rpt_common_convert_to_str_color (const RptColor *color); G_END_DECLS diff --git a/src/rptobject.c b/src/rptobject.c index 2abcdfb..d3a888a 100644 --- a/src/rptobject.c +++ b/src/rptobject.c @@ -29,13 +29,13 @@ static void rpt_object_class_init (RptObjectClass *klass); static void rpt_object_init (RptObject *rpt_object); static void rpt_object_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec); + guint property_id, + const GValue *value, + GParamSpec *pspec); static void rpt_object_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec); + guint property_id, + GValue *value, + GParamSpec *pspec); #define RPT_OBJECT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_RPT_OBJECT, RptObjectPrivate)) @@ -103,6 +103,9 @@ rpt_object_class_init (RptObjectClass *klass) static void rpt_object_init (RptObject *rpt_object) { + RptObjectPrivate *priv = RPT_OBJECT_GET_PRIVATE (rpt_object); + + priv->position = NULL; } /** @@ -139,8 +142,10 @@ rpt_object_get_xml (RptObject *rpt_object, xmlNode *xnode) RptObjectPrivate *priv = RPT_OBJECT_GET_PRIVATE (rpt_object); xmlSetProp (xnode, "name", priv->name); - xmlSetProp (xnode, "x", g_strdup_printf ("%f", priv->position->x)); - xmlSetProp (xnode, "y", g_strdup_printf ("%f", priv->position->y)); + if (priv->position != NULL) + { + rpt_common_set_position (xnode, priv->position); + } RPT_OBJECT_GET_CLASS (rpt_object)->get_xml (rpt_object, xnode); } diff --git a/src/rptobjectimage.c b/src/rptobjectimage.c index b847d65..8a81f3d 100644 --- a/src/rptobjectimage.c +++ b/src/rptobjectimage.c @@ -171,19 +171,19 @@ RptObject name = g_strdup ((gchar *)xmlGetProp (xnode, "name")); if (name != NULL && strcmp (g_strstrip (name), "") != 0) { - RptPoint position; + RptPoint *position; RptObjImagePrivate *priv; - rpt_common_get_position (xnode, &position); + position = rpt_common_get_position (xnode); - rpt_obj_image = rpt_obj_image_new ((const gchar *)name, position); + rpt_obj_image = rpt_obj_image_new ((const gchar *)name, *position); if (rpt_obj_image != NULL) { priv = RPT_OBJ_IMAGE_GET_PRIVATE (rpt_obj_image); - rpt_common_get_size (xnode, priv->size); - rpt_common_get_border (xnode, priv->border); + priv->size = rpt_common_get_size (xnode); + priv->border = rpt_common_get_border (xnode); priv->source = (gchar *)xmlGetProp (xnode, "source"); @@ -214,10 +214,8 @@ rpt_obj_image_get_xml (RptObject *rpt_objimage, xmlNode *xnode) xmlNodeSetName (xnode, "image"); - 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, *priv->border); + rpt_common_set_size (xnode, priv->size); + rpt_common_set_border (xnode, priv->border); xmlSetProp (xnode, "source", priv->source); diff --git a/src/rptobjectline.c b/src/rptobjectline.c index 55a5ac7..c07f608 100644 --- a/src/rptobjectline.c +++ b/src/rptobjectline.c @@ -155,19 +155,19 @@ RptObject name = g_strdup ((gchar *)xmlGetProp (xnode, "name")); if (name != NULL && strcmp (g_strstrip (name), "") != 0) { - RptPoint position; + RptPoint *position; RptObjLinePrivate *priv; - rpt_common_get_position (xnode, &position); + position = rpt_common_get_position (xnode); - rpt_obj_line = rpt_obj_line_new ((const gchar *)name, position); + rpt_obj_line = rpt_obj_line_new ((const gchar *)name, *position); if (rpt_obj_line != NULL) { priv = RPT_OBJ_LINE_GET_PRIVATE (rpt_obj_line); - rpt_common_get_size (xnode, priv->size); - rpt_common_get_stroke (xnode, priv->stroke); + priv->size = rpt_common_get_size (xnode); + priv->stroke = rpt_common_get_stroke (xnode); } } @@ -187,8 +187,8 @@ rpt_obj_line_get_xml (RptObject *rpt_objline, xmlNode *xnode) xmlNodeSetName (xnode, "line"); - rpt_common_set_size (xnode, *priv->size); - rpt_common_set_stroke (xnode, *priv->stroke); + rpt_common_set_size (xnode, priv->size); + rpt_common_set_stroke (xnode, priv->stroke); } static void diff --git a/src/rptobjectrect.c b/src/rptobjectrect.c index f158eb5..947d3db 100644 --- a/src/rptobjectrect.c +++ b/src/rptobjectrect.c @@ -144,32 +144,32 @@ RptObject name = g_strdup ((gchar *)xmlGetProp (xnode, "name")); if (name != NULL && strcmp (g_strstrip (name), "") != 0) { - RptPoint position; + RptPoint *position; RptObjRectPrivate *priv; - rpt_common_get_position (xnode, &position); + position = rpt_common_get_position (xnode); - rpt_obj_rect = rpt_obj_rect_new ((const gchar *)name, position); + rpt_obj_rect = rpt_obj_rect_new ((const gchar *)name, *position); if (rpt_obj_rect != NULL) { const gchar *prop; - RptSize size; - RptStroke stroke; + RptSize *size; + RptStroke *stroke; priv = RPT_OBJ_RECT_GET_PRIVATE (rpt_obj_rect); - rpt_common_get_size (xnode, &size); - rpt_common_get_stroke (xnode, &stroke); + size = rpt_common_get_size (xnode); + stroke = rpt_common_get_stroke (xnode); g_object_set (G_OBJECT (rpt_obj_rect), - "size", &size, - "stroke", &stroke, + "size", size, + "stroke", stroke, NULL); prop = (const gchar *)xmlGetProp (xnode, "fill-color"); if (prop != NULL) { - rpt_common_parse_color (prop, priv->fill_color); + priv->fill_color = rpt_common_parse_color (prop); } } } @@ -194,7 +194,7 @@ rpt_obj_rect_get_xml (RptObject *rpt_object, xmlNode *xnode) if (priv->fill_color != NULL) { - xmlSetProp (xnode, "fill-color", rpt_common_convert_to_str_color (*priv->fill_color)); + xmlSetProp (xnode, "fill-color", rpt_common_convert_to_str_color (priv->fill_color)); } } diff --git a/src/rptobjecttext.c b/src/rptobjecttext.c index b88b582..a1c17fc 100644 --- a/src/rptobjecttext.c +++ b/src/rptobjecttext.c @@ -26,7 +26,8 @@ enum PROP_BORDER, PROP_FONT, PROP_ALIGN, - PROP_SOURCE + PROP_SOURCE, + PROP_BACKGROUND_COLOR }; static void rpt_obj_text_class_init (RptObjTextClass *klass); @@ -52,6 +53,7 @@ struct _RptObjTextPrivate RptFont *font; RptAlign *align; gchar *source; + RptColor *background_color; }; GType @@ -121,6 +123,11 @@ rpt_obj_text_class_init (RptObjTextClass *klass) "The source.", "", G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); + g_object_class_install_property (object_class, PROP_BACKGROUND_COLOR, + g_param_spec_pointer ("background-color", + "Background Color", + "The text's background color.", + G_PARAM_READWRITE)); } static void @@ -132,9 +139,10 @@ rpt_obj_text_init (RptObjText *rpt_obj_text) 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)); + priv->border = NULL; + priv->font = NULL; + priv->align = NULL; + priv->background_color = NULL; } /** @@ -176,32 +184,49 @@ RptObject gchar *name; RptObject *rpt_obj_text = NULL; - name = g_strdup ((gchar *)xmlGetProp (xnode, "name")); + name = (gchar *)xmlGetProp (xnode, "name"); if (name != NULL && strcmp (g_strstrip (name), "") != 0) { - RptPoint position; + RptPoint *position; RptObjTextPrivate *priv; - rpt_common_get_position (xnode, &position); + position = rpt_common_get_position (xnode); - rpt_obj_text = rpt_obj_text_new ((const gchar *)name, position); + rpt_obj_text = rpt_obj_text_new ((const gchar *)name, *position); if (rpt_obj_text != NULL) { + gchar *prop; + 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); - rpt_common_get_align (xnode, priv->align); + priv->size = rpt_common_get_size (xnode); + priv->border = rpt_common_get_border (xnode); + priv->font = rpt_common_get_font (xnode); + priv->align = rpt_common_get_align (xnode); g_object_set (rpt_obj_text, "source", xmlGetProp (xnode, "source"), NULL); + + prop = (gchar *)xmlGetProp (xnode, "background-color"); + if (prop != NULL) + { + RptColor *color; + + color = rpt_common_parse_color (g_strstrip (prop)); + g_object_set (rpt_obj_text, "background-color", color, NULL); + } } } return rpt_obj_text; } +/** + * rpt_obj_text_get_xml: + * @rpt_objtext: + * @xnode: + * + */ void rpt_obj_text_get_xml (RptObject *rpt_objtext, xmlNode *xnode) { @@ -209,10 +234,17 @@ rpt_obj_text_get_xml (RptObject *rpt_objtext, xmlNode *xnode) xmlNodeSetName (xnode, "text"); - rpt_common_set_size (xnode, (RptSize)*priv->size); - rpt_common_set_border (xnode, (RptBorder)*priv->border); - rpt_common_set_font (xnode, (RptFont)*priv->font); - rpt_common_set_align (xnode, (RptAlign)*priv->align); + rpt_common_set_size (xnode, priv->size); + rpt_common_set_border (xnode, priv->border); + rpt_common_set_font (xnode, priv->font); + rpt_common_set_align (xnode, priv->align); + + xmlSetProp (xnode, "source", priv->source); + + if (priv->background_color != NULL) + { + xmlSetProp (xnode, "background-color", rpt_common_convert_to_str_color (priv->background_color)); + } } static void @@ -244,6 +276,10 @@ rpt_obj_text_set_property (GObject *object, guint property_id, const GValue *val priv->source = g_strstrip (g_strdup (g_value_get_string (value))); break; + case PROP_BACKGROUND_COLOR: + priv->background_color = g_memdup (g_value_get_pointer (value), sizeof (RptColor)); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -279,6 +315,10 @@ rpt_obj_text_get_property (GObject *object, guint property_id, GValue *value, GP g_value_set_string (value, priv->source); break; + case PROP_BACKGROUND_COLOR: + g_value_set_pointer (value, g_memdup (priv->background_color, sizeof (RptColor))); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; diff --git a/src/rptprint.c b/src/rptprint.c index 1352284..35abb3e 100644 --- a/src/rptprint.c +++ b/src/rptprint.c @@ -60,13 +60,13 @@ static void rpt_print_ellipse_xml (RptPrint *rpt_print, static void rpt_print_image_xml (RptPrint *rpt_print, xmlNode *xnode); static void rpt_print_line (RptPrint *rpt_print, - RptPoint from_p, - RptPoint to_p, - RptStroke stroke); + const RptPoint *from_p, + const RptPoint *to_p, + const RptStroke *stroke); static void rpt_print_border (RptPrint *rpt_print, - RptPoint position, - RptSize size, - RptBorder border); + const RptPoint *position, + const RptSize *size, + const RptBorder *border); #define RPT_PRINT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_RPT_PRINT, RptPrintPrivate)) @@ -211,7 +211,7 @@ RptPrint cairo_surface_destroy (priv->surface); } - if (cairo_status (priv->cr) == CAIRO_STATUS_SUCCESS) + if (cairo_status (priv->cr) == CAIRO_STATUS_SUCCESS) { rpt_print_page (rpt_print, cur); if (output_type == RPTP_OUTPUT_PNG) @@ -225,16 +225,19 @@ RptPrint else { /* TO DO */ + g_warning ("cairo status not sucess: %d",cairo_status (priv->cr)); } } else { /* TO DO */ + g_warning ("cairo surface status not sucess"); } } else { /* TO DO */ + g_warning ("page width or height cannot be zero"); } } else @@ -257,6 +260,7 @@ RptPrint else { /* TO DO */ + g_warning ("Not a valid reptool print report format"); } } @@ -324,6 +328,7 @@ rpt_print_page (RptPrint *rpt_print, xmlNode *xnode) while (cur != NULL) { + cairo_save (priv->cr); if (strcmp (cur->name, "text") == 0) { rpt_print_text_xml (rpt_print, cur); @@ -344,6 +349,7 @@ rpt_print_page (RptPrint *rpt_print, xmlNode *xnode) { rpt_print_image_xml (rpt_print, cur); } + cairo_restore (priv->cr); cur = cur->next; } @@ -354,32 +360,32 @@ rpt_print_text_xml (RptPrint *rpt_print, xmlNode *xnode) { RptPrintPrivate *priv = RPT_PRINT_GET_PRIVATE (rpt_print); - RptPoint position; - RptSize size; - RptAlign align; - RptBorder border; - RptFont font; - RptColor color; + RptPoint *position; + RptSize *size; + RptAlign *align; + RptBorder *border; + RptFont *font; + RptColor *color; PangoLayout *playout; PangoFontDescription *pfdesc; PangoAttribute *pattr; PangoAttrList *lpattr = NULL; - gchar *text = (gchar *)xmlNodeGetContent (xnode), - *prop, - *str_font; + gchar *text = (gchar *)xmlNodeGetContent (xnode); + gchar *prop; + gchar *str_font; - gdouble pad_top, - pad_right, - pad_bottom, - pad_left; + gdouble pad_top; + gdouble pad_right; + gdouble pad_bottom; + gdouble pad_left; - rpt_common_get_position (xnode, &position); - rpt_common_get_size (xnode, &size); - rpt_common_get_align (xnode, &align); - rpt_common_get_border (xnode, &border); - rpt_common_get_font (xnode, &font); + position = rpt_common_get_position (xnode); + size = rpt_common_get_size (xnode); + align = rpt_common_get_align (xnode); + border = rpt_common_get_border (xnode); + font = rpt_common_get_font (xnode); /* padding */ prop = xmlGetProp (xnode, (const xmlChar *)"padding-top"); @@ -405,24 +411,27 @@ rpt_print_text_xml (RptPrint *rpt_print, xmlNode *xnode) /* creating pango layout */ playout = pango_cairo_create_layout (priv->cr); - pango_layout_set_width (playout, size.width * PANGO_SCALE); + if (size != NULL) + { + pango_layout_set_width (playout, size->width * PANGO_SCALE); + } - str_font = g_strdup (font.name); - if (font.bold) + str_font = g_strdup (font->name); + if (font->bold) { - str_font = g_strjoin (NULL, str_font, " bold", NULL); + str_font = g_strconcat (str_font, " bold", NULL); } - if (font.italic) + if (font->italic) { - str_font = g_strjoin (NULL, str_font, " italic", NULL); + str_font = g_strconcat (str_font, " italic", NULL); } - if (font.size > 0) + if (font->size > 0) { - str_font = g_strjoin (NULL, str_font, g_strdup_printf (" %f", font.size), NULL); + str_font = g_strconcat (str_font, g_strdup_printf (" %f", font->size), NULL); } else { - str_font = g_strjoin (NULL, str_font, " 12", NULL); + str_font = g_strconcat (str_font, " 12", NULL); } /* creating pango font description */ @@ -431,11 +440,11 @@ rpt_print_text_xml (RptPrint *rpt_print, xmlNode *xnode) pango_font_description_free (pfdesc); /* setting layout attributes */ - if (font.underline != PANGO_UNDERLINE_NONE) + if (font->underline != PANGO_UNDERLINE_NONE) { PangoAttribute *pattr; - pattr = pango_attr_underline_new (font.underline); + pattr = pango_attr_underline_new (font->underline); pattr->start_index = 0; pattr->end_index = strlen (text) + 1; @@ -445,7 +454,7 @@ rpt_print_text_xml (RptPrint *rpt_print, xmlNode *xnode) } pango_attr_list_insert (lpattr, pattr); } - if (font.strike) + if (font->strike) { PangoAttribute *pattr; @@ -467,16 +476,20 @@ rpt_print_text_xml (RptPrint *rpt_print, xmlNode *xnode) /* background */ prop = xmlGetProp (xnode, (const xmlChar *)"background-color"); - if (prop != NULL) + if (prop != NULL && position != NULL && size != NULL) { - rpt_common_parse_color (prop, &color); + color = rpt_common_parse_color (prop); + + cairo_rectangle (priv->cr, position->x, position->y, size->width, size->height); + cairo_set_source_rgba (priv->cr, color->r, color->g, color->b, color->a); + cairo_fill_preserve (priv->cr); } /* drawing border */ rpt_print_border (rpt_print, position, size, border); /* setting alignment */ - switch (align.h_align) + switch (align->h_align) { case RPT_HALIGN_LEFT: break; @@ -494,7 +507,7 @@ rpt_print_text_xml (RptPrint *rpt_print, xmlNode *xnode) break; } - switch (align.v_align) + switch (align->v_align) { case RPT_VALIGN_TOP: break; @@ -507,35 +520,54 @@ rpt_print_text_xml (RptPrint *rpt_print, xmlNode *xnode) } /* setting clipping region */ - cairo_rectangle (priv->cr, position.x, position.y, size.width, size.height); - cairo_clip (priv->cr); + if (position != NULL && size != NULL) + { + cairo_rectangle (priv->cr, position->x, position->y, size->width, size->height); + cairo_clip (priv->cr); + } /* drawing text */ - cairo_set_source_rgba (priv->cr, font.color.r, font.color.g, font.color.b, font.color.a); - cairo_move_to (priv->cr, position.x, position.y); + if (font != NULL) + { + if (font->color != NULL) + { + cairo_set_source_rgba (priv->cr, font->color->r, font->color->g, font->color->b, font->color->a); + } + else + { + cairo_set_source_rgba (priv->cr, 0.0, 0.0, 0.0, 1.0); + } + } + if (position != NULL) + { + cairo_move_to (priv->cr, position->x, position->y); + } pango_layout_set_text (playout, text, -1); pango_cairo_show_layout (priv->cr, playout); - cairo_reset_clip (priv->cr); + if (position != NULL && size != NULL) + { + cairo_reset_clip (priv->cr); + } } static void rpt_print_line_xml (RptPrint *rpt_print, xmlNode *xnode) { - RptPoint position, - from_p, - to_p; - RptSize size; - RptStroke stroke; + RptPoint *position; + RptPoint *from_p = (RptPoint *)g_malloc0 (sizeof (RptPoint)); + RptPoint *to_p = (RptPoint *)g_malloc0 (sizeof (RptPoint)); + RptSize *size; + RptStroke *stroke; - rpt_common_get_position (xnode, &position); - rpt_common_get_size (xnode, &size); - rpt_common_get_stroke (xnode, &stroke); + position = rpt_common_get_position (xnode); + size = rpt_common_get_size (xnode); + stroke = rpt_common_get_stroke (xnode); - from_p.x = position.x; - from_p.y = position.y; - to_p.x = position.x + size.width; - to_p.y = position.y + size.height; + from_p->x = position->x; + from_p->y = position->y; + to_p->x = position->x + size->width; + to_p->y = position->y + size->height; rpt_print_line (rpt_print, from_p, to_p, stroke); } @@ -543,90 +575,106 @@ rpt_print_line_xml (RptPrint *rpt_print, xmlNode *xnode) static void rpt_print_rect_xml (RptPrint *rpt_print, xmlNode *xnode) { - RptPoint position, - from_p, - to_p; - RptSize size; - RptStroke stroke; - RptColor fill_color; + RptPoint *position; + RptSize *size; + RptStroke *stroke; + RptColor *fill_color; + gchar *prop; RptPrintPrivate *priv = RPT_PRINT_GET_PRIVATE (rpt_print); - rpt_common_get_position (xnode, &position); - rpt_common_get_size (xnode, &size); - rpt_common_get_stroke (xnode, &stroke); + position = rpt_common_get_position (xnode); + size = rpt_common_get_size (xnode); + stroke = rpt_common_get_stroke (xnode); + + if (position == NULL || size == NULL) + { + return; + } + if (stroke == NULL) + { + stroke = (RptStroke *)g_malloc0 (sizeof (RptStroke)); + stroke->width = 1.0; + stroke->color = (RptColor *)g_malloc0 (sizeof (RptColor)); + stroke->color->a = 1.0; + } - gchar *prop = xmlGetProp (xnode, (const xmlChar *)"fill-color"); + prop = xmlGetProp (xnode, (const xmlChar *)"fill-color"); if (prop != NULL) { - fill_color.r = 0.0; - fill_color.g = 0.0; - fill_color.b = 0.0; - fill_color.a = 1.0; - rpt_common_parse_color (prop, &fill_color); + fill_color = rpt_common_parse_color (prop); } /*cairo_set_line_width (priv->cr, stroke.width);*/ - cairo_rectangle (priv->cr, position.x, position.y, size.width, size.height); + cairo_rectangle (priv->cr, position->x, position->y, size->width, size->height); - if (prop != NULL) + if (prop != NULL && fill_color != NULL) { - cairo_set_source_rgba (priv->cr, fill_color.r, fill_color.g, fill_color.b, fill_color.a); + cairo_set_source_rgba (priv->cr, fill_color->r, fill_color->g, fill_color->b, fill_color->a); cairo_fill_preserve (priv->cr); } - cairo_set_source_rgba (priv->cr, stroke.color.r, stroke.color.g, stroke.color.b, stroke.color.a); + cairo_set_source_rgba (priv->cr, stroke->color->r, stroke->color->g, stroke->color->b, stroke->color->a); cairo_stroke (priv->cr); } static void rpt_print_ellipse_xml (RptPrint *rpt_print, xmlNode *xnode) { - RptPoint position; - RptSize size; - RptStroke stroke; - RptColor fill_color; + RptPoint *position; + RptSize *size; + RptStroke *stroke; + RptColor *fill_color; + gchar *prop; RptPrintPrivate *priv = RPT_PRINT_GET_PRIVATE (rpt_print); - rpt_common_get_position (xnode, &position); - rpt_common_get_size (xnode, &size); - rpt_common_get_stroke (xnode, &stroke); + position = rpt_common_get_position (xnode); + size = rpt_common_get_size (xnode); + stroke = rpt_common_get_stroke (xnode); + + if (position == NULL || size == NULL) + { + return; + } + if (stroke == NULL) + { + stroke = (RptStroke *)g_malloc0 (sizeof (RptStroke)); + stroke->width = 1.0; + stroke->color = (RptColor *)g_malloc0 (sizeof (RptColor)); + stroke->color->a = 1.0; + } - gchar *prop = xmlGetProp (xnode, (const xmlChar *)"fill-color"); + prop = xmlGetProp (xnode, (const xmlChar *)"fill-color"); if (prop != NULL) { - fill_color.r = 0.0; - fill_color.g = 0.0; - fill_color.b = 0.0; - fill_color.a = 1.0; - rpt_common_parse_color (prop, &fill_color); + fill_color = rpt_common_parse_color (prop); } cairo_new_path (priv->cr); cairo_save (priv->cr); - cairo_translate (priv->cr, position.x, position.y); - cairo_scale (priv->cr, size.width, size.height); + cairo_translate (priv->cr, position->x, position->y); + cairo_scale (priv->cr, size->width, size->height); cairo_arc (priv->cr, 0., 0., 1., 0., 2. * M_PI); cairo_restore (priv->cr); - if (prop != NULL) + if (prop != NULL && fill_color != NULL) { - cairo_set_source_rgba (priv->cr, fill_color.r, fill_color.g, fill_color.b, fill_color.a); + cairo_set_source_rgba (priv->cr, fill_color->r, fill_color->g, fill_color->b, fill_color->a); cairo_fill_preserve (priv->cr); } - cairo_set_source_rgba (priv->cr, stroke.color.r, stroke.color.g, stroke.color.b, stroke.color.a); + cairo_set_source_rgba (priv->cr, stroke->color->r, stroke->color->g, stroke->color->b, stroke->color->a); cairo_stroke (priv->cr); } static void rpt_print_image_xml (RptPrint *rpt_print, xmlNode *xnode) { - RptPoint position; - RptSize size; - RptBorder border; + RptPoint *position; + RptSize *size; + RptBorder *border; cairo_surface_t *image; cairo_pattern_t *pattern; @@ -653,9 +701,9 @@ rpt_print_image_xml (RptPrint *rpt_print, xmlNode *xnode) g_strstrip (adapt); } - rpt_common_get_position (xnode, &position); - rpt_common_get_size (xnode, &size); - rpt_common_get_border (xnode, &border); + position = rpt_common_get_position (xnode); + size = rpt_common_get_size (xnode); + border = rpt_common_get_border (xnode); image = cairo_image_surface_create_from_png (filename); @@ -669,20 +717,20 @@ rpt_print_image_xml (RptPrint *rpt_print, xmlNode *xnode) if (strcmp (adapt, "to-box") == 0) { - cairo_matrix_scale (&matrix, w / size.width, h / size.height); + cairo_matrix_scale (&matrix, w / size->width, h / size->height); } else if (strcmp (adapt, "to-image") == 0) { - size.width = (gdouble)w; - size.height = (gdouble)h; + size->width = (gdouble)w; + size->height = (gdouble)h; } } - cairo_matrix_translate (&matrix, -position.x, -position.y); + cairo_matrix_translate (&matrix, -position->x, -position->y); cairo_pattern_set_matrix (pattern, &matrix); cairo_set_source (priv->cr, pattern); - cairo_rectangle (priv->cr, position.x, position.y, size.width, size.height); + cairo_rectangle (priv->cr, position->x, position->y, size->width, size->height); cairo_fill (priv->cr); rpt_print_border (rpt_print, position, size, border); @@ -692,64 +740,75 @@ rpt_print_image_xml (RptPrint *rpt_print, xmlNode *xnode) } static void -rpt_print_line (RptPrint *rpt_print, RptPoint from_p, RptPoint to_p, RptStroke stroke) +rpt_print_line (RptPrint *rpt_print, const RptPoint *from_p, const RptPoint *to_p, const RptStroke *stroke) { RptPrintPrivate *priv = RPT_PRINT_GET_PRIVATE (rpt_print); - /*cairo_set_line_width (priv->cr, stroke.width);*/ - cairo_set_source_rgba (priv->cr, stroke.color.r, stroke.color.g, stroke.color.b, stroke.color.a); - cairo_move_to (priv->cr, from_p.x, from_p.y); - cairo_line_to (priv->cr, to_p.x, to_p.y); + if (from_p == NULL || to_p == NULL) return; + + if (stroke != NULL) + { + /*cairo_set_line_width (priv->cr, stroke.width);*/ + cairo_set_source_rgba (priv->cr, stroke->color->r, stroke->color->g, stroke->color->b, stroke->color->a); + } + else + { + cairo_set_source_rgba (priv->cr, 0.0, 0.0, 0.0, 1.0); + } + cairo_move_to (priv->cr, from_p->x, from_p->y); + cairo_line_to (priv->cr, to_p->x, to_p->y); cairo_stroke (priv->cr); } static void -rpt_print_border (RptPrint *rpt_print, RptPoint position, RptSize size, RptBorder border) +rpt_print_border (RptPrint *rpt_print, const RptPoint *position, const RptSize *size, const RptBorder *border) { RptPrintPrivate *priv = RPT_PRINT_GET_PRIVATE (rpt_print); - RptPoint from_p, - to_p; - RptStroke stroke; + if (position == NULL || size == NULL || border == NULL) return; + + RptPoint *from_p = (RptPoint *)g_malloc0 (sizeof (RptPoint)); + RptPoint *to_p = (RptPoint *)g_malloc0 (sizeof (RptPoint)); + RptStroke *stroke = (RptStroke *)g_malloc0 (sizeof (RptStroke)); - if (border.top_width != 0.0) + if (border->top_width != 0.0) { - from_p.x = position.x; - from_p.y = position.y; - to_p.x = position.x + size.width; - to_p.y = position.y; - stroke.width = border.top_width; - stroke.color = border.top_color; + from_p->x = position->x; + from_p->y = position->y; + to_p->x = position->x + size->width; + to_p->y = position->y; + stroke->width = border->top_width; + stroke->color = border->top_color; rpt_print_line (rpt_print, from_p, to_p, stroke); } - if (border.right_width != 0.0) + if (border->right_width != 0.0) { - from_p.x = position.x + size.width; - from_p.y = position.y; - to_p.x = position.x + size.width; - to_p.y = position.y + size.height; - stroke.width = border.right_width; - stroke.color = border.right_color; + from_p->x = position->x + size->width; + from_p->y = position->y; + to_p->x = position->x + size->width; + to_p->y = position->y + size->height; + stroke->width = border->right_width; + stroke->color = border->right_color; rpt_print_line (rpt_print, from_p, to_p, stroke); } - if (border.bottom_width != 0.0) + if (border->bottom_width != 0.0) { - from_p.x = position.x; - from_p.y = position.y + size.height; - to_p.x = position.x + size.width; - to_p.y = position.y + size.height; - stroke.width = border.bottom_width; - stroke.color = border.bottom_color; + from_p->x = position->x; + from_p->y = position->y + size->height; + to_p->x = position->x + size->width; + to_p->y = position->y + size->height; + stroke->width = border->bottom_width; + stroke->color = border->bottom_color; rpt_print_line (rpt_print, from_p, to_p, stroke); } - if (border.left_width != 0.0) + if (border->left_width != 0.0) { - from_p.x = position.x; - from_p.y = position.y; - to_p.x = position.x; - to_p.y = position.y + size.height; - stroke.width = border.left_width; - stroke.color = border.left_color; + from_p->x = position->x; + from_p->y = position->y; + to_p->x = position->x; + to_p->y = position->y + size->height; + stroke->width = border->left_width; + stroke->color = border->left_color; rpt_print_line (rpt_print, from_p, to_p, stroke); } } diff --git a/src/rptreport.c b/src/rptreport.c index 439678e..075ca6c 100644 --- a/src/rptreport.c +++ b/src/rptreport.c @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -28,21 +29,22 @@ #include "rptreport.h" #include "rptcommon.h" -#include "rptobject.h" #include "rptobjecttext.h" #include "rptobjectline.h" #include "rptobjectrect.h" #include "rptobjectellipse.h" #include "rptobjectimage.h" -typedef enum +typedef struct { - RPTREPORT_SECTION_REPORT_HEADER, - RPTREPORT_SECTION_REPORT_FOOTER, - RPTREPORT_SECTION_PAGE_HEADER, - RPTREPORT_SECTION_PAGE_FOOTER, - RPTREPORT_SECTION_BODY -} RptReportSection; + gchar *provider_id; + gchar *connection_string; + gchar *sql; + + GdaClient *gda_client; + GdaConnection *gda_conn; + GdaDataModel *gda_datamodel; +} Database; typedef struct { @@ -53,30 +55,37 @@ typedef struct { gdouble height; GList *objects; + gboolean new_page_after; } ReportHeader; typedef struct { gdouble height; GList *objects; + gboolean new_page_before; } ReportFooter; typedef struct { gdouble height; GList *objects; + gboolean first_page; + gboolean last_page; } PageHeader; typedef struct { gdouble height; GList *objects; + gboolean first_page; + gboolean last_page; } PageFooter; typedef struct { gdouble height; GList *objects; + gboolean new_page_after; } Body; enum @@ -98,9 +107,12 @@ static void rpt_report_get_property (GObject *object, static void rpt_report_xml_parse_section (RptReport *rpt_report, xmlNode *xnode, RptReportSection section); -static RptObject *rpt_report_get_object_from_name (RptReport *rpt_report, const gchar *name); static RptObject *rpt_report_get_object_from_name_in_list (GList *list, const gchar *name); +static RptReportSection rpt_report_get_section_object (RptReport *rpt_report, RptObject *rpt_object); +static gboolean rpt_report_object_is_in_section (RptReport *rpt_report, RptObject *rpt_object, RptReportSection section); +static xmlNode *rpt_report_get_xml_section (RptReport *rpt_report , RptReportSection section); + static xmlNode *rpt_report_rptprint_new_page (RptReport *rpt_report, xmlNode *xroot); static void rpt_report_rptprint_section (RptReport *rpt_report, @@ -120,9 +132,7 @@ static void rpt_report_rptprint_parse_text_source (RptReport *rpt_report, typedef struct _RptReportPrivate RptReportPrivate; struct _RptReportPrivate { - GdaClient *gda_client; - GdaConnection *gda_conn; - GdaDataModel *gda_datamodel; + Database *db; Page *page; ReportHeader *report_header; @@ -178,34 +188,57 @@ rpt_report_init (RptReport *rpt_report) { RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report); - priv->gda_client = NULL; - priv->gda_conn = NULL; - priv->gda_datamodel = NULL; + priv->db = NULL; priv->page = (Page *)g_malloc0 (sizeof (Page)); priv->page->size = (RptSize *)g_malloc0 (sizeof (RptSize)); priv->page->size->width = 0.0; priv->page->size->height = 0.0; - priv->report_header = (ReportHeader *)g_malloc0 (sizeof (ReportHeader)); - priv->report_header->height = 0.0; - priv->report_header->objects = NULL; - - priv->report_footer = (ReportFooter *)g_malloc0 (sizeof (ReportFooter)); - priv->report_footer->height = 0.0; - priv->report_footer->objects = NULL; - - priv->page_header = (PageHeader *)g_malloc0 (sizeof (PageHeader)); - priv->page_header->height = 0.0; - priv->page_header->objects = NULL; - - priv->page_footer = (PageFooter *)g_malloc0 (sizeof (PageFooter)); - priv->page_footer->height = 0.0; - priv->page_footer->objects = NULL; + priv->report_header = NULL; + priv->report_footer = NULL; + priv->page_header = NULL; + priv->page_footer = NULL; priv->body = (Body *)g_malloc0 (sizeof (Body)); priv->body->height = 0.0; priv->body->objects = NULL; + priv->body->new_page_after = FALSE; +} + +/** + * rpt_report_new: + * + * Returns: the newly created #RptReport object. + */ +RptReport +*rpt_report_new () +{ + RptReport *rpt_report; + + rpt_report = RPT_REPORT (g_object_new (rpt_report_get_type (), NULL)); + + return rpt_report; +} + +/** + * rpt_report_new_from_file: + * @filename: the path of the xml file to load. + * + * Returns: the newly created #RptReport object. + */ +RptReport +*rpt_report_new_from_file (const gchar *filename) +{ + RptReport *rpt_report = NULL; + + xmlDoc *xdoc = xmlParseFile (filename); + if (xdoc != NULL) + { + rpt_report = rpt_report_new_from_xml (xdoc); + } + + return rpt_report; } /** @@ -229,37 +262,11 @@ RptReport xmlNodeSetPtr xnodeset; RptReportPrivate *priv; - rpt_report = RPT_REPORT (g_object_new (rpt_report_get_type (), NULL)); + rpt_report = rpt_report_new (); priv = RPT_REPORT_GET_PRIVATE (rpt_report); xpcontext = xmlXPathNewContext (xdoc); - /* search for node "page" */ - xpcontext->node = cur; - xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::page", xpcontext); - if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval)) - { - xnodeset = xpresult->nodesetval; - if (xnodeset->nodeNr == 1) - { - RptSize size; - - rpt_common_get_size (xnodeset->nodeTab[0], &size); - priv->page->size->width = size.width; - priv->page->size->height = size.height; - } - else - { - /* TO DO */ - /* return */ - } - } - else - { - /* TO DO */ - /* return */ - } - /* search for node "database" */ xpcontext->node = cur; xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::database", xpcontext); @@ -268,18 +275,18 @@ RptReport xnodeset = xpresult->nodesetval; if (xnodeset->nodeNr == 1) { - gchar *provider; + gchar *provider_id; gchar *connection_string; gchar *sql; - + xmlNode *cur_database = xnodeset->nodeTab[0]->children; while (cur_database != NULL) { if (strcmp (cur_database->name, "provider") == 0) { - provider = g_strstrip ((gchar *)xmlNodeGetContent (cur_database)); + provider_id = g_strstrip ((gchar *)xmlNodeGetContent (cur_database)); } - else if (strcmp (cur_database->name, "connection_string") == 0) + else if (strcmp (cur_database->name, "connection-string") == 0) { connection_string = g_strstrip ((gchar *)xmlNodeGetContent (cur_database)); } @@ -291,7 +298,7 @@ RptReport cur_database = cur_database->next; } - if (strcmp (provider, "") == 0 || + if (strcmp (provider_id, "") == 0 || strcmp (connection_string, "") == 0 || strcmp (sql, "") == 0) { @@ -299,28 +306,36 @@ RptReport } else { - /* database connection */ - gda_init (PACKAGE_NAME, PACKAGE_VERSION, 0, NULL); - priv->gda_client = gda_client_new (); - priv->gda_conn = gda_client_open_connection_from_string (priv->gda_client, - provider, - connection_string, - 0); - if (priv->gda_conn == NULL) - { - /* TO DO */ - g_warning ("Unable to establish the connection."); - } - else - { - GdaCommand *command = gda_command_new (sql, GDA_COMMAND_TYPE_SQL, GDA_COMMAND_OPTION_STOP_ON_ERRORS); + rpt_report_set_database (rpt_report, provider_id, connection_string, sql); + } + } + } - priv->gda_datamodel = gda_connection_execute_single_command (priv->gda_conn, command, NULL); + /* search for node "page" */ + xpcontext->node = cur; + xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::page", xpcontext); + if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval)) + { + xnodeset = xpresult->nodesetval; + if (xnodeset->nodeNr == 1) + { + RptSize *size; - gda_command_free (command); - } - } + size = rpt_common_get_size (xnodeset->nodeTab[0]); + rpt_report_set_page_size (rpt_report, *size); } + else + { + /* TO DO */ + /* return */ + g_error ("Node \"page\" is missing"); + } + } + else + { + /* TO DO */ + /* return */ + g_error ("Node \"page\" is missing"); } /* search for node "report" */ @@ -336,6 +351,8 @@ RptReport xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::report-header", xpcontext); if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval) && xpresult->nodesetval->nodeNr == 1) { + priv->report_header = (ReportHeader *)g_malloc0 (sizeof (ReportHeader)); + priv->report_header->objects = NULL; rpt_report_xml_parse_section (rpt_report, xpresult->nodesetval->nodeTab[0], RPTREPORT_SECTION_REPORT_HEADER); } @@ -344,6 +361,8 @@ RptReport xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::report-footer", xpcontext); if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval) && xpresult->nodesetval->nodeNr == 1) { + priv->report_footer = (ReportFooter *)g_malloc0 (sizeof (ReportFooter)); + priv->report_footer->objects = NULL; rpt_report_xml_parse_section (rpt_report, xpresult->nodesetval->nodeTab[0], RPTREPORT_SECTION_REPORT_FOOTER); } @@ -352,6 +371,8 @@ RptReport xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::page-header", xpcontext); if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval) && xpresult->nodesetval->nodeNr == 1) { + priv->page_header = (PageHeader *)g_malloc0 (sizeof (PageHeader)); + priv->page_header->objects = NULL; rpt_report_xml_parse_section (rpt_report, xpresult->nodesetval->nodeTab[0], RPTREPORT_SECTION_PAGE_HEADER); } @@ -360,6 +381,8 @@ RptReport xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::page-footer", xpcontext); if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval) && xpresult->nodesetval->nodeNr == 1) { + priv->page_footer = (PageFooter *)g_malloc0 (sizeof (PageFooter)); + priv->page_footer->objects = NULL; rpt_report_xml_parse_section (rpt_report, xpresult->nodesetval->nodeTab[0], RPTREPORT_SECTION_PAGE_FOOTER); } @@ -374,23 +397,27 @@ RptReport { /* TO DO */ /* return */ + g_error ("Node \"body\" is missing"); } } else { /* TO DO */ /* return */ + g_error ("Only one node \"report\" is allowed"); } } else { /* TO DO */ /* return */ + g_error ("Node \"report\" is missing"); } } else { /* TO DO */ + g_warning ("The file is not a valid reptool report definition file"); } } @@ -398,23 +425,156 @@ RptReport } /** - * rpt_report_new_from_file: - * @filename: the path of the xml file to load. + * rpt_report_set_database: + * @rpt_report: an #RptReport object. + * @provider_id: a libgda's provider_id. + * @connection_string: a libgda's connection string. + * @sql: a valid SQL statement. * - * Returns: the newly created #RptReport object. */ -RptReport -*rpt_report_new_from_file (const gchar *filename) +void +rpt_report_set_database (RptReport *rpt_report, + const gchar *provider_id, + const gchar *connection_string, + const gchar *sql) { - RptReport *rpt_report = NULL; + RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report); - xmlDoc *xdoc = xmlParseFile (filename); - if (xdoc != NULL) + if (priv->db != NULL) { - rpt_report = rpt_report_new_from_xml (xdoc); + g_free (priv->db); } + priv->db = (Database *)g_malloc0 (sizeof (Database)); - return rpt_report; + priv->db->provider_id = g_strstrip (g_strdup (provider_id)); + priv->db->connection_string = g_strstrip (g_strdup (connection_string)); + priv->db->sql = g_strstrip (g_strdup (sql)); +} + +/** + * rpt_report_set_page_size: + * @rpt_report: an #RptReport object. + * @size: an #RptSize. + * + */ +void +rpt_report_set_page_size (RptReport *rpt_report, + RptSize size) +{ + RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report); + + priv->page->size->width = size.width; + priv->page->size->height = size.height; +} + +/** + * rpt_report_set_section_height: + * @rpt_report: an #RptReport object. + * @section: + * @height: the section's height. + * + */ +void +rpt_report_set_section_height (RptReport *rpt_report, + RptReportSection section, + gdouble height) +{ + RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report); + + switch (section) + { + case RPTREPORT_SECTION_REPORT_HEADER: + priv->report_header->height = height; + break; + + case RPTREPORT_SECTION_REPORT_FOOTER: + priv->report_footer->height = height; + break; + + case RPTREPORT_SECTION_PAGE_HEADER: + priv->page_header->height = height; + break; + + case RPTREPORT_SECTION_PAGE_FOOTER: + priv->page_footer->height = height; + break; + + case RPTREPORT_SECTION_BODY: + priv->body->height = height; + break; + } +} + +/** + * rpt_report_set_report_header_new_page_after: + * @rpt_report: an #RptReport object. + * @new_page_after: + * + */ +void +rpt_report_set_report_header_new_page_after (RptReport *rpt_report, gboolean new_page_after) +{ + RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report); + + if (priv->report_header != NULL) + { + priv->report_header->new_page_after = new_page_after; + } +} + +/** + * rpt_report_set_report_footer_new_page_before: + * @rpt_report: an #RptReport object. + * @new_page_before: + * + */ +void +rpt_report_set_report_footer_new_page_before (RptReport *rpt_report, gboolean new_page_before) +{ + RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report); + + if (priv->report_footer != NULL) + { + priv->report_footer->new_page_before = new_page_before; + } +} + +/** + * rpt_report_set_page_header_first_last_page: + * @rpt_report: an #RptReport object. + * @first_page: + * @last_page: + * + */ +void +rpt_report_set_page_header_first_last_page (RptReport *rpt_report, gboolean first_page, gboolean last_page) +{ + RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report); + + if (priv->page_header != NULL) + { + priv->page_header->first_page = first_page; + priv->page_header->last_page = last_page; + } +} + +/** + * rpt_report_set_page_footer_first_last_page: + * @rpt_report: an #RptReport object. + * @first_page: + * @last_page: + * + */ +void +rpt_report_set_page_footer_first_last_page (RptReport *rpt_report, gboolean first_page, gboolean last_page) +{ + RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report); + + if (priv->page_footer != NULL) + { + priv->page_footer->first_page = first_page; + priv->page_footer->last_page = last_page; + } } /** @@ -426,11 +586,69 @@ xmlDoc *rpt_report_get_xml (RptReport *rpt_report) { xmlDoc *xdoc = NULL; + xmlNode *xroot; + xmlNode *xreport; + xmlNode *xnode; RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report); /* TO DO */ + xdoc = xmlNewDoc ("1.0"); + + xroot = xmlNewNode (NULL, "reptool"); + xmlDocSetRootElement (xdoc, xroot); + + if (priv->db != NULL) + { + xmlNode *xnodedb = xmlNewNode (NULL, "database"); + xmlAddChild (xroot, xnodedb); + + xnode = xmlNewNode (NULL, "provider"); + xmlNodeSetContent (xnode, priv->db->provider_id); + xmlAddChild (xnodedb, xnode); + + xnode = xmlNewNode (NULL, "connection-string"); + xmlNodeSetContent (xnode, priv->db->connection_string); + xmlAddChild (xnodedb, xnode); + + xnode = xmlNewNode (NULL, "sql"); + xmlNodeSetContent (xnode, priv->db->sql); + xmlAddChild (xnodedb, xnode); + }; + + xnode = xmlNewNode (NULL, "page"); + rpt_common_set_size (xnode, priv->page->size); + xmlAddChild (xroot, xnode); + + xreport = xmlNewNode (NULL, "report"); + xmlAddChild (xroot, xreport); + + if (priv->report_header != NULL) + { + xnode = rpt_report_get_xml_section (rpt_report, RPTREPORT_SECTION_REPORT_HEADER); + xmlAddChild (xreport, xnode); + } + if (priv->page_header != NULL) + { + xnode = rpt_report_get_xml_section (rpt_report, RPTREPORT_SECTION_PAGE_HEADER); + xmlAddChild (xreport, xnode); + } + + xnode = rpt_report_get_xml_section (rpt_report, RPTREPORT_SECTION_BODY); + xmlAddChild (xreport, xnode); + + if (priv->report_footer != NULL) + { + xnode = rpt_report_get_xml_section (rpt_report, RPTREPORT_SECTION_REPORT_FOOTER); + xmlAddChild (xreport, xnode); + } + if (priv->page_footer != NULL) + { + xnode = rpt_report_get_xml_section (rpt_report, RPTREPORT_SECTION_PAGE_FOOTER); + xmlAddChild (xreport, xnode); + } + return xdoc; } @@ -456,36 +674,76 @@ xmlDoc xmlDocSetRootElement (xdoc, xroot); priv->cur_page = 0; - if (priv->gda_datamodel != NULL) + + if (priv->db != NULL) { gint row; gint rows; - rows = gda_data_model_get_n_rows (priv->gda_datamodel); + /* database connection */ + gda_init (PACKAGE_NAME, PACKAGE_VERSION, 0, NULL); + priv->db->gda_client = gda_client_new (); + priv->db->gda_conn = gda_client_open_connection_from_string (priv->db->gda_client, + priv->db->provider_id, + priv->db->connection_string, + 0); + if (priv->db->gda_conn == NULL) + { + /* TO DO */ + g_warning ("Unable to establish the connection."); + return NULL; + } + else + { + GdaCommand *command = gda_command_new (priv->db->sql, GDA_COMMAND_TYPE_SQL, GDA_COMMAND_OPTION_STOP_ON_ERRORS); + + priv->db->gda_datamodel = gda_connection_execute_single_command (priv->db->gda_conn, command, NULL); + if (priv->db->gda_datamodel == NULL) + { + return NULL; + } + + gda_command_free (command); + } + + rows = gda_data_model_get_n_rows (priv->db->gda_datamodel); for (row = 0; row < rows; row++) { if (row == 0 || - (priv->page_footer != NULL && (cur_y + priv->body->height > priv->page->size->height - priv->page_footer->height)) || + priv->body->new_page_after || + (priv->page_footer != NULL && (cur_y + priv->body->height > priv->page->size->height - (priv->page_footer != NULL ? priv->page_footer->height: 0.0))) || cur_y > priv->page->size->height) { if (priv->cur_page > 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, row - 1); + if ((priv->cur_page == 1 && priv->page_footer->first_page) || + priv->cur_page > 1) + { + cur_y = priv->page->size->height - priv->page_footer->height; + rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_PAGE_FOOTER, row - 1); + } } cur_y = 0.0; - priv->cur_page++; xpage = rpt_report_rptprint_new_page (rpt_report, xroot); if (priv->cur_page == 1 && priv->report_header != NULL) { rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_REPORT_HEADER, row); + if (priv->report_header->new_page_after) + { + cur_y = 0.0; + xpage = rpt_report_rptprint_new_page (rpt_report, xroot); + } } if (priv->page_header != NULL) { - rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_PAGE_HEADER, row); + if ((priv->cur_page == 1 && priv->page_header->first_page) || + priv->cur_page > 1) + { + rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_PAGE_HEADER, row); + } } } @@ -494,9 +752,26 @@ xmlDoc if (priv->cur_page > 0 && priv->report_footer != NULL) { + if ((cur_y + priv->report_footer->height > priv->page->size->height - (priv->page_footer != NULL ? priv->page_footer->height : 0.0)) || + priv->report_footer->new_page_before) + { + if (priv->cur_page > 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, row - 1); + } + + cur_y = 0.0; + xpage = rpt_report_rptprint_new_page (rpt_report, xroot); + + if (priv->page_header != NULL) + { + 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_REPORT_FOOTER, row - 1); } - if (priv->cur_page > 0 && priv->page_footer != NULL) + if (priv->cur_page > 0 && priv->page_footer != NULL && priv->page_footer->last_page) { cur_y = priv->page->size->height - priv->page_footer->height; rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_PAGE_FOOTER, row - 1); @@ -532,6 +807,113 @@ xmlDoc return xdoc; } +/** + * rpt_report_add_object_to_section: + * @rpt_report: an #RptReport object. + * @rpt_object: an #RptObject object. + * @section: + * + */ +void +rpt_report_add_object_to_section (RptReport *rpt_report, RptObject *rpt_object, RptReportSection section) +{ + RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report); + + switch (section) + { + case RPTREPORT_SECTION_REPORT_HEADER: + priv->report_header->objects = g_list_append (priv->report_header->objects, rpt_object);; + break; + + case RPTREPORT_SECTION_REPORT_FOOTER: + priv->report_footer->objects = g_list_append (priv->report_footer->objects, rpt_object);; + break; + + case RPTREPORT_SECTION_PAGE_HEADER: + priv->page_header->objects = g_list_append (priv->page_header->objects, rpt_object);; + break; + + case RPTREPORT_SECTION_PAGE_FOOTER: + priv->page_footer->objects = g_list_append (priv->page_footer->objects, rpt_object);; + break; + + case RPTREPORT_SECTION_BODY: + priv->body->objects = g_list_append (priv->body->objects, rpt_object);; + break; + } +} + +/** + * rpt_report_remove_object: + * @rpt_report: an #RptReport object. + * @rpt_object: an #RptObject object. + * + * Removes the @rpt_object from the @rpt_report. + */ +void +rpt_report_remove_object (RptReport *rpt_report, RptObject *rpt_object) +{ + RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report); + + RptReportSection section = rpt_report_get_section_object (rpt_report, rpt_object); + + switch (section) + { + case RPTREPORT_SECTION_REPORT_HEADER: + priv->report_header->objects = g_list_remove (priv->report_header->objects, rpt_object);; + break; + + case RPTREPORT_SECTION_REPORT_FOOTER: + priv->report_footer->objects = g_list_remove (priv->report_footer->objects, rpt_object);; + break; + + case RPTREPORT_SECTION_PAGE_HEADER: + priv->page_header->objects = g_list_remove (priv->page_header->objects, rpt_object);; + break; + + case RPTREPORT_SECTION_PAGE_FOOTER: + priv->page_footer->objects = g_list_remove (priv->page_footer->objects, rpt_object);; + break; + + case RPTREPORT_SECTION_BODY: + priv->body->objects = g_list_remove (priv->body->objects, rpt_object);; + break; + } +} + +/** + * rpt_report_get_object_from_name: + * @rpt_report: an #RptReport object. + * @name: the #RptObject's name. + * + * Returns: the #RptObject object represented by the name @name. + */ +RptObject +*rpt_report_get_object_from_name (RptReport *rpt_report, const gchar *name) +{ + RptObject *obj = NULL; + + RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report); + + if (priv->report_header != NULL && (obj = rpt_report_get_object_from_name_in_list (priv->report_header->objects, name)) != NULL) + { + } + else if (priv->report_footer != NULL && (obj = rpt_report_get_object_from_name_in_list (priv->report_footer->objects, name)) != NULL) + { + } + else if (priv->page_header != NULL && (obj = rpt_report_get_object_from_name_in_list (priv->page_header->objects, name)) != NULL) + { + } + else if (priv->page_footer != NULL && (obj = rpt_report_get_object_from_name_in_list (priv->page_footer->objects, name)) != NULL) + { + } + else if (priv->body != NULL && (obj = rpt_report_get_object_from_name_in_list (priv->body->objects, name)) != NULL) + { + } + + return obj; +} + static void rpt_report_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { @@ -562,6 +944,226 @@ rpt_report_get_property (GObject *object, guint property_id, GValue *value, GPar } } +/** + * rpt_report_get_object_from_name_in_list: + * @list: + * @name: + * + */ +static RptObject +*rpt_report_get_object_from_name_in_list (GList *list, const gchar *name) +{ + gchar *objname; + RptObject *obj = NULL; + + if (list != NULL) + { + list = g_list_first (list); + while (list != NULL) + { + g_object_get ((RptObject *)list->data, "name", &objname, NULL); + if (strcmp (name, objname) == 0) + { + obj = (RptObject *)list->data; + break; + } + + list = g_list_next (list); + } + } + + return obj; +} + +/** + * rpt_report_get_section_object: + * @rpt_report: an #RptReport object. + * @rpt_object: an #RptObject object. + * + * Returns: the #RptReportSection in which @rpt_object is contained. + */ +static RptReportSection +rpt_report_get_section_object (RptReport *rpt_report, RptObject *rpt_object) +{ + RptReportSection section = -1; + + RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report); + + if (rpt_report_object_is_in_section (rpt_report, rpt_object, RPTREPORT_SECTION_REPORT_HEADER)) + { + section = RPTREPORT_SECTION_REPORT_HEADER; + } + else if (rpt_report_object_is_in_section (rpt_report, rpt_object, RPTREPORT_SECTION_REPORT_FOOTER)) + { + section = RPTREPORT_SECTION_REPORT_FOOTER; + } + else if (rpt_report_object_is_in_section (rpt_report, rpt_object, RPTREPORT_SECTION_PAGE_HEADER)) + { + section = RPTREPORT_SECTION_PAGE_HEADER; + } + else if (rpt_report_object_is_in_section (rpt_report, rpt_object, RPTREPORT_SECTION_PAGE_FOOTER)) + { + section = RPTREPORT_SECTION_PAGE_FOOTER; + } + else if (rpt_report_object_is_in_section (rpt_report, rpt_object, RPTREPORT_SECTION_BODY)) + { + section = RPTREPORT_SECTION_BODY; + } + + return section; +} + +/** + * rpt_report_object_is_in_section: + * @rpt_report: an #RptReport object. + * @rpt_object: an #RptObject object. + * @section: + * + * Returns: TRUE if rpt_object is contained into + */ +static gboolean +rpt_report_object_is_in_section (RptReport *rpt_report, RptObject *rpt_object, RptReportSection section) +{ + gboolean ret = FALSE; + GList *list; + + RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report); + + switch (section) + { + case RPTREPORT_SECTION_REPORT_HEADER: + list = priv->report_header->objects; + break; + + case RPTREPORT_SECTION_REPORT_FOOTER: + list = priv->report_footer->objects; + break; + + case RPTREPORT_SECTION_PAGE_HEADER: + list = priv->page_header->objects; + break; + + case RPTREPORT_SECTION_PAGE_FOOTER: + list = priv->page_footer->objects; + break; + + case RPTREPORT_SECTION_BODY: + list = priv->body->objects; + break; + + default: + return FALSE; + } + + list = g_list_first (list); + while (list != NULL) + { + if ((RptObject *)list->data == rpt_object) + { + ret = TRUE; + break; + } + + list = g_list_next (list); + } + + return ret; +} + +/** + * rpt_report_get_xml_section: + * @rpt_report: an #RptReport object. + * @section: + * + */ +static xmlNode +*rpt_report_get_xml_section (RptReport *rpt_report , RptReportSection section) +{ + xmlNode *xnode = NULL; + xmlNode *xnodechild; + gdouble height; + GList *objects; + RptObject *rptobj; + + RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report); + + switch (section) + { + case RPTREPORT_SECTION_REPORT_HEADER: + xnode = xmlNewNode (NULL, "report-header"); + height = priv->report_header->height; + objects = priv->report_header->objects; + if (priv->report_header->new_page_after) + { + xmlSetProp (xnode, "new-page-after", "y"); + } + break; + + case RPTREPORT_SECTION_REPORT_FOOTER: + xnode = xmlNewNode (NULL, "report-footer"); + height = priv->report_footer->height; + objects = priv->report_footer->objects; + if (priv->report_footer->new_page_before) + { + xmlSetProp (xnode, "new-page-before", "y"); + } + break; + + case RPTREPORT_SECTION_PAGE_HEADER: + xnode = xmlNewNode (NULL, "page-header"); + height = priv->page_header->height; + objects = priv->page_header->objects; + if (priv->page_header->first_page) + { + xmlSetProp (xnode, "first-page", "y"); + } + if (priv->page_header->last_page) + { + xmlSetProp (xnode, "last-page", "y"); + } + break; + + case RPTREPORT_SECTION_PAGE_FOOTER: + xnode = xmlNewNode (NULL, "page-footer"); + height = priv->page_footer->height; + objects = priv->page_footer->objects; + if (priv->page_footer->first_page) + { + xmlSetProp (xnode, "first-page", "y"); + } + if (priv->page_footer->last_page) + { + xmlSetProp (xnode, "last-page", "y"); + } + break; + + case RPTREPORT_SECTION_BODY: + xnode = xmlNewNode (NULL, "body"); + height = priv->body->height; + objects = priv->body->objects; + if (priv->body->new_page_after) + { + xmlSetProp (xnode, "new-page-after", "y"); + } + break; + } + xmlSetProp (xnode, "height", g_strdup_printf ("%f", height)); + + objects = g_list_first (objects); + while (objects != NULL) + { + rptobj = (RptObject *)objects->data; + + xnodechild = xmlNewNode (NULL, "object"); + rpt_object_get_xml (rptobj, xnodechild); + xmlAddChild (xnode, xnodechild); + + objects = g_list_next (objects); + } + + return xnode; +} + static void rpt_report_xml_parse_section (RptReport *rpt_report, xmlNode *xnode, RptReportSection section) { @@ -610,7 +1212,7 @@ rpt_report_xml_parse_section (RptReport *rpt_report, xmlNode *xnode, RptReportSe if (rpt_report_get_object_from_name (rpt_report, objname) == NULL) { - objects = g_list_append (objects, rptobj); + rpt_report_add_object_to_section (rpt_report, rptobj, section); } else { @@ -626,79 +1228,87 @@ rpt_report_xml_parse_section (RptReport *rpt_report, xmlNode *xnode, RptReportSe { case RPTREPORT_SECTION_REPORT_HEADER: priv->report_header->height = height; - priv->report_header->objects = objects; + + prop = xmlGetProp (xnode, "new-page-after"); + if (prop != NULL) + { + if (strcasecmp (g_strstrip (prop), "y") == 0) + { + priv->report_header->new_page_after = TRUE; + } + } break; case RPTREPORT_SECTION_REPORT_FOOTER: priv->report_footer->height = height; - priv->report_footer->objects = objects; + + prop = xmlGetProp (xnode, "new-page-before"); + if (prop != NULL) + { + if (strcasecmp (g_strstrip (prop), "y") == 0) + { + priv->report_footer->new_page_before = TRUE; + } + } break; case RPTREPORT_SECTION_PAGE_HEADER: priv->page_header->height = height; - priv->page_header->objects = objects; + + prop = xmlGetProp (xnode, "first-page"); + if (prop != NULL) + { + if (strcasecmp (g_strstrip (prop), "y") == 0) + { + priv->page_header->first_page = TRUE; + } + } + prop = xmlGetProp (xnode, "last-page"); + if (prop != NULL) + { + if (strcasecmp (g_strstrip (prop), "y") == 0) + { + priv->page_header->last_page = TRUE; + } + } break; case RPTREPORT_SECTION_PAGE_FOOTER: priv->page_footer->height = height; - priv->page_footer->objects = objects; + + prop = xmlGetProp (xnode, "first-page"); + if (prop != NULL) + { + if (strcasecmp (g_strstrip (prop), "y") == 0) + { + priv->page_footer->first_page = TRUE; + } + } + prop = xmlGetProp (xnode, "last-page"); + if (prop != NULL) + { + if (strcasecmp (g_strstrip (prop), "y") == 0) + { + priv->page_footer->last_page = TRUE; + } + } break; case RPTREPORT_SECTION_BODY: priv->body->height = height; - priv->body->objects = objects; + + prop = xmlGetProp (xnode, "new-page-after"); + if (prop != NULL) + { + if (strcasecmp (g_strstrip (prop), "y") == 0) + { + priv->body->new_page_after = TRUE; + } + } break; } } -static RptObject -*rpt_report_get_object_from_name (RptReport *rpt_report, const gchar *name) -{ - RptObject *obj = NULL; - - RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report); - - if ((obj = rpt_report_get_object_from_name_in_list (priv->report_header->objects, name)) != NULL) - { - } - else if ((obj = rpt_report_get_object_from_name_in_list (priv->report_footer->objects, name)) != NULL) - { - } - else if ((obj = rpt_report_get_object_from_name_in_list (priv->page_header->objects, name)) != NULL) - { - } - else if ((obj = rpt_report_get_object_from_name_in_list (priv->page_footer->objects, name)) != NULL) - { - } - else if ((obj = rpt_report_get_object_from_name_in_list (priv->body->objects, name)) != NULL) - { - } - - return obj; -} - -static RptObject -*rpt_report_get_object_from_name_in_list (GList *list, const gchar *name) -{ - gchar *objname; - RptObject *obj = NULL; - - list = g_list_first (list); - while (list != NULL) - { - g_object_get ((RptObject *)list->data, "name", &objname, NULL); - if (strcmp (name, objname) == 0) - { - obj = (RptObject *)list->data; - break; - } - - list = g_list_next (list); - } - - return obj; -} - static xmlNode *rpt_report_rptprint_new_page (RptReport *rpt_report, xmlNode *xroot) { @@ -709,7 +1319,9 @@ static xmlNode xnode = xmlNewNode (NULL, "page"); xmlAddChild (xroot, xnode); - rpt_common_set_size (xnode, *priv->page->size); + rpt_common_set_size (xnode, priv->page->size); + + priv->cur_page++; return xnode; } @@ -771,6 +1383,11 @@ 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, row); + attr = xmlHasProp (xnode, "source"); + if (attr != NULL) + { + xmlRemoveProp (attr); + } } else if (IS_RPT_OBJ_IMAGE (rptobj)) { @@ -817,17 +1434,17 @@ rpt_report_rptprint_parse_text_source (RptReport *rpt_report, RptObject *rptobj, g_object_get (G_OBJECT (rptobj), "source", &source, NULL); - if (row > -1 && priv->gda_datamodel != NULL && source[0] == '[' && source[strlen (source) - 1] == ']') + if (row > -1 && priv->db->gda_datamodel != NULL && 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); + col = gda_data_model_get_column_position (priv->db->gda_datamodel, field); if (col > -1) { - source = gda_value_stringify ((GdaValue *)gda_data_model_get_value_at (priv->gda_datamodel, col, row)); + source = gda_value_stringify ((GdaValue *)gda_data_model_get_value_at (priv->db->gda_datamodel, col, row)); } else { @@ -843,12 +1460,28 @@ rpt_report_rptprint_parse_text_source (RptReport *rpt_report, RptObject *rptobj, else if (source[0] == '@') { /* TO DO */ - /* special */ + /* special values */ if (strcmp (source + 1, "Page") == 0) { source = g_strdup_printf ("%d", priv->cur_page); } + else if (strcmp (source + 1, "Date") == 0) + { + char date[11] = "\0"; + time_t now = time (NULL); + struct tm *tm = localtime (&now); + strftime (date, 11, "%F", tm); + source = g_strdup_printf ("%s", &date); + } + else if (strcmp (source + 1, "Time") == 0) + { + char date[6] = ""; + time_t now = time (NULL); + struct tm *tm = localtime (&now); + strftime (date, 6, "%H:%M", tm); + source = g_strdup_printf ("%s", &date); + } } xmlNodeSetContent (xnode, source); diff --git a/src/rptreport.h b/src/rptreport.h index 17a56cb..04d8843 100644 --- a/src/rptreport.h +++ b/src/rptreport.h @@ -24,6 +24,8 @@ #include #include +#include "rptobject.h" + G_BEGIN_DECLS @@ -51,13 +53,57 @@ struct _RptReportClass GType rpt_report_get_type (void) G_GNUC_CONST; +typedef enum +{ + RPTREPORT_SECTION_REPORT_HEADER, + RPTREPORT_SECTION_REPORT_FOOTER, + RPTREPORT_SECTION_PAGE_HEADER, + RPTREPORT_SECTION_PAGE_FOOTER, + RPTREPORT_SECTION_BODY +} RptReportSection; + +RptReport *rpt_report_new (void); + RptReport *rpt_report_new_from_xml (xmlDoc *xdoc); RptReport *rpt_report_new_from_file (const gchar *filename); +void rpt_report_set_database (RptReport *rpt_report, + const gchar *provider_id, + const gchar *connection_string, + const gchar *sql); + +void rpt_report_set_page_size (RptReport *rpt_report, + RptSize size); + +void rpt_report_set_section_height (RptReport *rpt_report, + RptReportSection section, + gdouble height); + +void rpt_report_set_report_header_new_page_after (RptReport *rpt_report, + gboolean new_page_after); +void rpt_report_set_report_footer_new_page_before (RptReport *rpt_report, + gboolean new_page_before); + +void rpt_report_set_page_header_first_last_page (RptReport *rpt_report, + gboolean first_page, + gboolean last_page); +void rpt_report_set_page_footer_first_last_page (RptReport *rpt_report, + gboolean first_page, + gboolean last_page); + xmlDoc *rpt_report_get_xml (RptReport *rpt_report); xmlDoc *rpt_report_get_xml_rptprint (RptReport *rpt_report); +void rpt_report_add_object_to_section (RptReport *rpt_report, + RptObject *rpt_object, + RptReportSection section); +void rpt_report_remove_object (RptReport *rpt_report, + RptObject *rpt_object); + +RptObject *rpt_report_get_object_from_name (RptReport *rpt_report, + const gchar *name); + G_END_DECLS diff --git a/tests/test_report.rpt b/tests/test_report.rpt index d4275f0..41299a2 100644 --- a/tests/test_report.rpt +++ b/tests/test_report.rpt @@ -3,8 +3,10 @@ - + + + diff --git a/tests/test_report_db.rpt b/tests/test_report_db.rpt index c912e1f..1709557 100644 --- a/tests/test_report_db.rpt +++ b/tests/test_report_db.rpt @@ -4,8 +4,8 @@ SQLite - - URI=///home/andreaz/files/c/reptool/libreptool/tests/db_test.db + + URI=///home/andreaz/files/c/reptool/libreptool/tests/db_test.db SELECT * FROM articles ORDER BY name @@ -13,7 +13,7 @@ - + @@ -28,7 +28,7 @@ - + diff --git a/tests/test_rptprint.rptr b/tests/test_rptprint.rptr index 499160f..3f9e7f9 100644 --- a/tests/test_rptprint.rptr +++ b/tests/test_rptprint.rptr @@ -5,6 +5,7 @@ + White on black diff --git a/tests/test_rptreport.c b/tests/test_rptreport.c index ad35069..1b27f07 100644 --- a/tests/test_rptreport.c +++ b/tests/test_rptreport.c @@ -31,6 +31,9 @@ main (int argc, char **argv) if (rptr != NULL) { + xmlDoc *report = rpt_report_get_xml (rptr); + xmlSaveFormatFile ("test_report.rpt", report, 2); + xmlDoc *rptprint = rpt_report_get_xml_rptprint (rptr); xmlSaveFormatFile ("test_report.rptr", rptprint, 2); -- 2.49.0