From: Andrea Zagli Date: Tue, 7 Sep 2010 10:38:43 +0000 (+0200) Subject: Added report and printing property "unit-length". X-Git-Tag: 0.2.0~15 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=5abdea7af8cbe594808679bae5e298761b34eab8;p=reptool%2Flibreptool Added report and printing property "unit-length". --- diff --git a/.gitignore b/.gitignore index 2692962..04c6645 100644 --- a/.gitignore +++ b/.gitignore @@ -47,6 +47,7 @@ tests/test_rptprint tests/test_rptreport tests/test_rptreport_creation tests/test_report_created* +tests/test_rptprint_mm.rptr POTFILES mkinstalldirs stamp-it diff --git a/data/reptool.dtd b/data/reptool.dtd index 013e587..7fa1c7a 100644 --- a/data/reptool.dtd +++ b/data/reptool.dtd @@ -109,7 +109,11 @@ adapt (to-box | to-image | none) #IMPLIED > - + + + + + diff --git a/data/reptool_report.dtd b/data/reptool_report.dtd index 04860f5..e153c73 100644 --- a/data/reptool_report.dtd +++ b/data/reptool_report.dtd @@ -103,7 +103,11 @@ adapt (to-box | to-image | none) #IMPLIED > - + + + + + + * Copyright (C) 2007-2010 Andrea Zagli * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -25,6 +25,165 @@ static GArray *rpt_common_parse_style (const gchar *style); static gchar *rpt_common_style_to_string (const GArray *style); +/** + * rpt_common_value_to_points: + * @unit: unit of length. + * @value: the value to convert. + * + * Returns: the @value converted in points. + */ +gdouble +rpt_common_value_to_points (eRptUnitLength unit, gdouble value) +{ + gdouble ret; + + switch (unit) + { + case RPT_UNIT_POINTS: + ret = value; + break; + + case RPT_UNIT_INCHES: + ret = value * 72; + break; + + case RPT_UNIT_CENTIMETRE: + ret = value / 2.54 * 72; + break; + + case RPT_UNIT_MILLIMETRE: + ret = value / 25.4 * 72; + break; + + default: + g_warning ("Unit length «%d» not available.", unit); + ret = value; + break; + } + + return ret; +} + +/** + * rpt_common_points_to_value: + * @unit: unit of length. + * @value: the value to convert to. + * + * Returns: the points from the @value. + */ +gdouble +rpt_common_points_to_value (eRptUnitLength unit, gdouble value) +{ + gdouble ret; + + switch (unit) + { + case RPT_UNIT_POINTS: + ret = value; + break; + + case RPT_UNIT_INCHES: + ret = value / 72; + break; + + case RPT_UNIT_CENTIMETRE: + ret = value / 72 * 2.54; + break; + + case RPT_UNIT_MILLIMETRE: + ret = value / 72 * 25.4; + break; + + default: + g_warning ("Unit length «%d» not available.", unit); + ret = value; + break; + } + + return ret; +} + +/** + * rpt_common_strunit_to_enum: + * @unit: + * + * Returns: the enum value that match the string @unit. + */ +eRptUnitLength +rpt_common_strunit_to_enum (const gchar *unit) +{ + eRptUnitLength ret; + + gchar *real_unit; + + ret = RPT_UNIT_POINTS; + + if (unit != NULL) + { + real_unit = g_strstrip (g_strdup (unit)); + if (g_ascii_strcasecmp (real_unit, "pt") == 0) + { + /* already setted */ + } + else if (g_ascii_strcasecmp (real_unit, "in") == 0) + { + ret = RPT_UNIT_INCHES; + } + else if (g_ascii_strcasecmp (real_unit, "cm") == 0) + { + ret = RPT_UNIT_CENTIMETRE; + } + else if (g_ascii_strcasecmp (real_unit, "mm") == 0) + { + ret = RPT_UNIT_MILLIMETRE; + } + else + { + g_warning ("Unit length «%s» not available.", real_unit); + } + } + + return ret; +} + +/** + * rpt_common_enum_to_strunit: + * @unit: + * + * Returns: the string value that represents then enum value @unit. + */ +const gchar +*rpt_common_enum_to_strunit (eRptUnitLength unit) +{ + gchar *ret; + + switch (unit) + { + case RPT_UNIT_POINTS: + ret = g_strdup ("pt"); + break; + + case RPT_UNIT_INCHES: + ret = g_strdup ("in"); + break; + + case RPT_UNIT_CENTIMETRE: + ret = g_strdup ("cm"); + break; + + case RPT_UNIT_MILLIMETRE: + ret = g_strdup ("mm"); + break; + + default: + g_warning ("Unit length «%d» not available.", unit); + ret = g_strdup ("pt"); + break; + } + + return ret; +} + /** * rpt_common_rptpoint_new: * diff --git a/src/rptcommon.h b/src/rptcommon.h index dda8f08..1036864 100644 --- a/src/rptcommon.h +++ b/src/rptcommon.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007 Andrea Zagli + * Copyright (C) 2007-2010 Andrea Zagli * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -30,6 +30,14 @@ G_BEGIN_DECLS +typedef enum +{ + RPT_UNIT_POINTS, + RPT_UNIT_INCHES, + RPT_UNIT_CENTIMETRE, + RPT_UNIT_MILLIMETRE +} eRptUnitLength; + /** * RptColor: * @r: the red channel; value from 0 to 1. @@ -157,6 +165,12 @@ struct _RptStroke typedef struct _RptStroke RptStroke; +gdouble rpt_common_value_to_points (eRptUnitLength unit, gdouble value); +gdouble rpt_common_points_to_value (eRptUnitLength unit, gdouble value); + +eRptUnitLength rpt_common_strunit_to_enum (const gchar *unit); +const gchar *rpt_common_enum_to_strunit (eRptUnitLength unit); + RptPoint *rpt_common_rptpoint_new (void); RptPoint *rpt_common_get_position (xmlNode *xnode); void rpt_common_set_position (xmlNode *xnode, diff --git a/src/rptprint.c b/src/rptprint.c index 5a79109..3519702 100644 --- a/src/rptprint.c +++ b/src/rptprint.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006-2007 Andrea Zagli + * Copyright (C) 2006-2010 Andrea Zagli * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -36,6 +36,7 @@ enum { PROP_0, + PROP_UNIT_LENGTH, PROP_OUTPUT_TYPE, PROP_OUTPUT_FILENAME, PROP_PATH_RELATIVES_TO @@ -103,6 +104,8 @@ static void rpt_print_gtk_draw_page (GtkPrintOperation *operation, typedef struct _RptPrintPrivate RptPrintPrivate; struct _RptPrintPrivate { + eRptUnitLength unit; + gdouble width; gdouble height; gdouble margin_top; @@ -162,11 +165,20 @@ rpt_print_class_init (RptPrintClass *klass) object_class->set_property = rpt_print_set_property; object_class->get_property = rpt_print_get_property; + g_object_class_install_property (object_class, PROP_UNIT_LENGTH, + g_param_spec_int ("unit-length", + "Unit length", + "The unit length.", + RPT_UNIT_POINTS, RPT_UNIT_MILLIMETRE, + RPT_UNIT_POINTS, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); + g_object_class_install_property (object_class, PROP_OUTPUT_TYPE, g_param_spec_int ("output-type", "Output Type", "The output type.", - RPTP_OUTPUT_PNG, RPTP_OUTPUT_GTK, RPTP_OUTPUT_PDF, + RPTP_OUTPUT_PNG, RPTP_OUTPUT_GTK, + RPTP_OUTPUT_PDF, G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); g_object_class_install_property (object_class, PROP_OUTPUT_FILENAME, @@ -290,6 +302,10 @@ rpt_print_print (RptPrint *rpt_print) FILE *fout; gchar *prop; + + gdouble width; + gdouble height; + gint npage = 0; RptPrintPrivate *priv = RPT_PRINT_GET_PRIVATE (rpt_print); @@ -311,10 +327,31 @@ rpt_print_print (RptPrint *rpt_print) } } - /* find number of pages */ xpcontext = xmlXPathNewContext (priv->xdoc); - xpcontext->node = xmlDocGetRootElement (priv->xdoc); + /* search for node "properties" */ + xpcontext->node = cur; + xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::properties", xpcontext); + if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval)) + { + xnodeset = xpresult->nodesetval; + if (xnodeset->nodeNr == 1) + { + xmlNode *cur_property = xnodeset->nodeTab[0]->children; + while (cur_property != NULL) + { + if (strcmp (cur_property->name, "unit-length") == 0) + { + g_object_set (G_OBJECT (rpt_print), "unit-length", rpt_common_strunit_to_enum ((const gchar *)xmlNodeGetContent (cur_property)), NULL); + } + + cur_property = cur_property->next; + } + } + } + + /* find number of pages */ + xpcontext->node = cur; xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::page", xpcontext); if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval)) { @@ -389,17 +426,20 @@ rpt_print_print (RptPrint *rpt_print) rpt_print_get_xml_page_attributes (rpt_print, cur); if (priv->width != 0 && priv->height != 0) { + width = rpt_common_value_to_points (priv->unit, priv->width); + height = rpt_common_value_to_points (priv->unit, priv->height); + if (priv->output_type == RPTP_OUTPUT_PNG) { - priv->surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, (int)priv->width, (int)priv->height); + priv->surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, (int)width, (int)height); } else if (priv->output_type == RPTP_OUTPUT_PDF && npage == 0) { - priv->surface = cairo_pdf_surface_create (priv->output_filename, priv->width, priv->height); + priv->surface = cairo_pdf_surface_create (priv->output_filename, width, height); } else if (priv->output_type == RPTP_OUTPUT_PS && npage == 0) { - priv->surface = cairo_ps_surface_create (priv->output_filename, priv->width, priv->height); + priv->surface = cairo_ps_surface_create (priv->output_filename, width, height); } else if (priv->output_type == RPTP_OUTPUT_SVG) { @@ -412,7 +452,7 @@ rpt_print_print (RptPrint *rpt_print) return; } - priv->surface = cairo_svg_surface_create (new_out_filename, priv->width, priv->height); + priv->surface = cairo_svg_surface_create (new_out_filename, width, height); } if (cairo_surface_status (priv->surface) == CAIRO_STATUS_SUCCESS) @@ -502,6 +542,10 @@ rpt_print_set_property (GObject *object, guint property_id, const GValue *value, switch (property_id) { + case PROP_UNIT_LENGTH: + priv->unit = g_value_get_int (value); + break; + case PROP_OUTPUT_TYPE: rpt_print_set_output_type (rpt_print, g_value_get_int (value)); break; @@ -529,6 +573,10 @@ rpt_print_get_property (GObject *object, guint property_id, GValue *value, GPara switch (property_id) { + case PROP_UNIT_LENGTH: + g_value_set_int (value, priv->unit); + break; + case PROP_OUTPUT_TYPE: g_value_set_int (value, priv->output_type); break; @@ -593,38 +641,48 @@ rpt_print_page (RptPrint *rpt_print, xmlNode *xnode) xmlNode *cur = xnode->children; + gdouble width = rpt_common_value_to_points (priv->unit, priv->width); + gdouble height = rpt_common_value_to_points (priv->unit, priv->height); + gdouble margin_left = rpt_common_value_to_points (priv->unit, priv->margin_left); + gdouble margin_right = rpt_common_value_to_points (priv->unit, priv->margin_right); + gdouble margin_top = rpt_common_value_to_points (priv->unit, priv->margin_top); + gdouble margin_bottom = rpt_common_value_to_points (priv->unit, priv->margin_bottom); + /* clipping region for page's margins */ cairo_rectangle (priv->cr, - priv->margin_left, - priv->margin_top, - priv->width - priv->margin_left - priv->margin_right, - priv->height - priv->margin_top - priv->margin_bottom); + margin_left, + margin_top, + width - margin_left - margin_right, + height - margin_top - margin_bottom); cairo_clip (priv->cr); while (cur != NULL) { - cairo_save (priv->cr); - if (strcmp (cur->name, "text") == 0) - { - rpt_print_text_xml (rpt_print, cur); - } - else if (strcmp (cur->name, "line") == 0) - { - rpt_print_line_xml (rpt_print, cur); - } - else if (strcmp (cur->name, "rect") == 0) - { - rpt_print_rect_xml (rpt_print, cur); - } - else if (strcmp (cur->name, "ellipse") == 0) - { - rpt_print_ellipse_xml (rpt_print, cur); - } - else if (strcmp (cur->name, "image") == 0) + if (!xmlNodeIsText (cur)) { - rpt_print_image_xml (rpt_print, cur); + cairo_save (priv->cr); + if (strcmp (cur->name, "text") == 0) + { + rpt_print_text_xml (rpt_print, cur); + } + else if (strcmp (cur->name, "line") == 0) + { + rpt_print_line_xml (rpt_print, cur); + } + else if (strcmp (cur->name, "rect") == 0) + { + rpt_print_rect_xml (rpt_print, cur); + } + else if (strcmp (cur->name, "ellipse") == 0) + { + rpt_print_ellipse_xml (rpt_print, cur); + } + else if (strcmp (cur->name, "image") == 0) + { + rpt_print_image_xml (rpt_print, cur); + } + cairo_restore (priv->cr); } - cairo_restore (priv->cr); cur = cur->next; } @@ -674,22 +732,22 @@ rpt_print_text_xml (RptPrint *rpt_print, xmlNode *xnode) prop = xmlGetProp (xnode, (const xmlChar *)"padding-top"); if (prop != NULL) { - padding_top = atof (prop); + padding_top = rpt_common_value_to_points (priv->unit, atof (prop)); } prop = xmlGetProp (xnode, (const xmlChar *)"padding-right"); if (prop != NULL) { - padding_right= atof (prop); + padding_right = rpt_common_value_to_points (priv->unit, atof (prop)); } prop = xmlGetProp (xnode, (const xmlChar *)"padding-bottom"); if (prop != NULL) { - padding_bottom= atof (prop); + padding_bottom = rpt_common_value_to_points (priv->unit, atof (prop)); } prop = xmlGetProp (xnode, (const xmlChar *)"padding-left"); if (prop != NULL) { - padding_left= atof (prop); + padding_left = rpt_common_value_to_points (priv->unit, atof (prop)); } /* creating pango layout */ @@ -703,7 +761,7 @@ rpt_print_text_xml (RptPrint *rpt_print, xmlNode *xnode) /*}*/ if (size != NULL) { - pango_layout_set_width (playout, (size->width - padding_left - padding_right) * PANGO_SCALE); + pango_layout_set_width (playout, (rpt_common_value_to_points (priv->unit, size->width) - padding_left - padding_right) * PANGO_SCALE); } str_font = g_strdup (font->name); @@ -781,7 +839,10 @@ rpt_print_text_xml (RptPrint *rpt_print, xmlNode *xnode) { color = rpt_common_parse_color (prop); - cairo_rectangle (priv->cr, position->x, position->y, size->width, size->height); + cairo_rectangle (priv->cr, rpt_common_value_to_points (priv->unit, position->x), + rpt_common_value_to_points (priv->unit, position->y), + rpt_common_value_to_points (priv->unit, size->width), + rpt_common_value_to_points (priv->unit, size->height)); cairo_set_source_rgba (priv->cr, color->r, color->g, color->b, color->a); cairo_fill_preserve (priv->cr); } @@ -826,10 +887,10 @@ rpt_print_text_xml (RptPrint *rpt_print, xmlNode *xnode) if (size != NULL) { cairo_rectangle (priv->cr, - position->x + padding_left, - position->y + padding_top, - size->width - padding_left - padding_right, - size->height - padding_top - padding_bottom); + rpt_common_value_to_points (priv->unit, position->x) + padding_left, + rpt_common_value_to_points (priv->unit, position->y) + padding_top, + rpt_common_value_to_points (priv->unit, size->width) - padding_left - padding_right, + rpt_common_value_to_points (priv->unit, size->height) - padding_top - padding_bottom); cairo_clip (priv->cr); } @@ -846,7 +907,8 @@ rpt_print_text_xml (RptPrint *rpt_print, xmlNode *xnode) } } - cairo_move_to (priv->cr, position->x + padding_left, position->y + padding_top); + cairo_move_to (priv->cr, rpt_common_value_to_points (priv->unit, position->x) + padding_left, + rpt_common_value_to_points (priv->unit, position->y) + padding_top); pango_layout_set_text (playout, text, -1); pango_cairo_show_layout (priv->cr, playout); @@ -905,7 +967,7 @@ rpt_print_rect_xml (RptPrint *rpt_print, xmlNode *xnode) if (stroke == NULL) { stroke = (RptStroke *)g_malloc0 (sizeof (RptStroke)); - stroke->width = 1.0; + stroke->width = rpt_common_points_to_value (priv->unit, 1.0); stroke->color = (RptColor *)g_malloc0 (sizeof (RptColor)); stroke->color->a = 1.0; stroke->style = NULL; @@ -924,7 +986,10 @@ rpt_print_rect_xml (RptPrint *rpt_print, xmlNode *xnode) /* TO DO */ /*cairo_set_line_width (priv->cr, stroke.width);*/ - cairo_rectangle (priv->cr, position->x, position->y, size->width, size->height); + cairo_rectangle (priv->cr, rpt_common_value_to_points (priv->unit, position->x), + rpt_common_value_to_points (priv->unit, position->y), + rpt_common_value_to_points (priv->unit, size->width), + rpt_common_value_to_points (priv->unit, size->height)); if (prop != NULL && fill_color != NULL) { @@ -968,7 +1033,7 @@ rpt_print_ellipse_xml (RptPrint *rpt_print, xmlNode *xnode) if (stroke == NULL) { stroke = (RptStroke *)g_malloc0 (sizeof (RptStroke)); - stroke->width = 1.0; + stroke->width = rpt_common_points_to_value (priv->unit, 1.0); stroke->color = (RptColor *)g_malloc0 (sizeof (RptColor)); stroke->color->a = 1.0; stroke->style = NULL; @@ -983,8 +1048,10 @@ rpt_print_ellipse_xml (RptPrint *rpt_print, xmlNode *xnode) 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, rpt_common_value_to_points (priv->unit, position->x), + rpt_common_value_to_points (priv->unit, position->y)); + cairo_scale (priv->cr, rpt_common_value_to_points (priv->unit, size->width), + rpt_common_value_to_points (priv->unit, size->height)); cairo_arc (priv->cr, 0., 0., 1., 0., 2. * M_PI); cairo_restore (priv->cr); @@ -1061,20 +1128,23 @@ 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 / rpt_common_value_to_points (priv->unit, size->width), h / rpt_common_value_to_points (priv->unit, size->height)); } else if (strcmp (adapt, "to-image") == 0) { - size->width = (gdouble)w; - size->height = (gdouble)h; + size->width = rpt_common_points_to_value (priv->unit, (gdouble)w); + size->height = rpt_common_points_to_value (priv->unit, (gdouble)h); } } - cairo_matrix_translate (&matrix, -position->x, -position->y); + cairo_matrix_translate (&matrix, rpt_common_value_to_points (priv->unit, -position->x), rpt_common_value_to_points (priv->unit, -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, rpt_common_value_to_points (priv->unit, position->x), + rpt_common_value_to_points (priv->unit, position->y), + rpt_common_value_to_points (priv->unit, size->width), + rpt_common_value_to_points (priv->unit, size->height)); cairo_fill (priv->cr); rpt_print_border (rpt_print, position, size, border, rotation); @@ -1121,14 +1191,16 @@ rpt_print_line (RptPrint *rpt_print, const RptPoint *from_p, const RptPoint *to_ { RptSize size; - size.width = to_p->x - from_p->x; - size.height = to_p->y - from_p->y; + size.width = rpt_common_value_to_points (priv->unit, to_p->x - from_p->x); + size.height = rpt_common_value_to_points (priv->unit, to_p->y - from_p->y); rpt_print_rotate (rpt_print, from_p, &size, rotation->angle); } - cairo_move_to (priv->cr, from_p->x, from_p->y); - cairo_line_to (priv->cr, to_p->x, to_p->y); + cairo_move_to (priv->cr, rpt_common_value_to_points (priv->unit, from_p->x), + rpt_common_value_to_points (priv->unit, from_p->y)); + cairo_line_to (priv->cr, rpt_common_value_to_points (priv->unit, to_p->x), + rpt_common_value_to_points (priv->unit, to_p->y)); cairo_stroke (priv->cr); if (stroke != NULL && stroke->style != NULL) diff --git a/src/rptreport.c b/src/rptreport.c index ef919f0..55a1d0d 100644 --- a/src/rptreport.c +++ b/src/rptreport.c @@ -99,7 +99,8 @@ typedef struct enum { - PROP_0 + PROP_0, + PROP_UNIT_LENGTH }; static void rpt_report_class_init (RptReportClass *klass); @@ -145,6 +146,8 @@ static void rpt_report_change_specials (RptReport *rpt_report, xmlDoc *xdoc); typedef struct _RptReportPrivate RptReportPrivate; struct _RptReportPrivate { + eRptUnitLength unit; + Database *db; Page *page; @@ -195,6 +198,14 @@ rpt_report_class_init (RptReportClass *klass) object_class->set_property = rpt_report_set_property; object_class->get_property = rpt_report_get_property; + g_object_class_install_property (object_class, PROP_UNIT_LENGTH, + g_param_spec_int ("unit-length", + "Unit length", + "The unit length.", + RPT_UNIT_POINTS, RPT_UNIT_MILLIMETRE, + RPT_UNIT_POINTS, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); + /** * RptReport::field-request: * @rpt_report: an #RptReport object that recieved the signal. @@ -305,6 +316,27 @@ RptReport priv = RPT_REPORT_GET_PRIVATE (rpt_report); xpcontext = xmlXPathNewContext (xdoc); + /* search for node "properties" */ + xpcontext->node = cur; + xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::properties", xpcontext); + if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval)) + { + xnodeset = xpresult->nodesetval; + if (xnodeset->nodeNr == 1) + { + xmlNode *cur_property = xnodeset->nodeTab[0]->children; + while (cur_property != NULL) + { + if (strcmp (cur_property->name, "unit-length") == 0) + { + g_object_set (G_OBJECT (rpt_report), "unit-length", rpt_common_strunit_to_enum ((const gchar *)xmlNodeGetContent (cur_property)), NULL); + } + + cur_property = cur_property->next; + } + } + } + /* search for node "database" */ xpcontext->node = cur; xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::database", xpcontext); @@ -1059,6 +1091,13 @@ xmlDoc xroot = xmlNewNode (NULL, "reptool"); xmlDocSetRootElement (xdoc, xroot); + xmlNode *xnodeprop = xmlNewNode (NULL, "properties"); + xmlAddChild (xroot, xnodeprop); + + xnode = xmlNewNode (NULL, "unit-length"); + xmlNodeSetContent (xnode, rpt_common_enum_to_strunit (priv->unit)); + xmlAddChild (xnodeprop, xnode); + if (priv->db != NULL) { xmlNode *xnodedb = xmlNewNode (NULL, "database"); @@ -1153,6 +1192,14 @@ xmlDoc priv->cur_page = 0; + /* properties */ + xmlNode *xnodeprop = xmlNewNode (NULL, "properties"); + xmlAddChild (xroot, xnodeprop); + + xmlNode *xnode = xmlNewNode (NULL, "unit-length"); + xmlNodeSetContent (xnode, rpt_common_enum_to_strunit (priv->unit)); + xmlAddChild (xnodeprop, xnode); + if (priv->db != NULL) { gint row; @@ -1427,6 +1474,10 @@ rpt_report_set_property (GObject *object, guint property_id, const GValue *value switch (property_id) { + case PROP_UNIT_LENGTH: + priv->unit = g_value_get_int (value); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -1442,6 +1493,10 @@ rpt_report_get_property (GObject *object, guint property_id, GValue *value, GPar switch (property_id) { + case PROP_UNIT_LENGTH: + g_value_set_int (value, priv->unit); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; diff --git a/tests/test_rptreport_creation.c b/tests/test_rptreport_creation.c index 1edca27..f0b17d5 100644 --- a/tests/test_rptreport_creation.c +++ b/tests/test_rptreport_creation.c @@ -35,14 +35,16 @@ main (int argc, char **argv) if (rptr != NULL) { - size.width = 500; - size.height = 500; + g_object_set (G_OBJECT (rptr), "unit-length", 3, NULL); + + size.width = 210; + size.height = 297; rpt_report_set_page_size (rptr, size); point.x = 10; point.y = 10; obj = rpt_obj_text_new ("text1", point); - size.width = 480; + size.width = 210; size.height = 50; g_object_set (obj, "source", "\"The first object inserted.\"", @@ -53,7 +55,7 @@ main (int argc, char **argv) point.x = 10; point.y = 60; obj = rpt_obj_line_new ("line1", point); - size.width = 480; + size.width = 210; size.height = 0; stroke.color = rpt_common_parse_color ("#FF0000"); stroke.style = NULL; @@ -66,8 +68,8 @@ main (int argc, char **argv) point.x = 0; point.y = 0; obj = rpt_obj_line_new ("line2", point); - size.width = 500; - size.height = 500; + size.width = 210; + size.height = 297; stroke.color = rpt_common_parse_color ("#000000AA"); stroke.style = NULL; g_object_set (obj, @@ -76,11 +78,11 @@ main (int argc, char **argv) NULL); rpt_report_add_object_to_section (rptr, obj, RPTREPORT_SECTION_BODY); - point.x = 500; + point.x = 210; point.y = 0; obj = rpt_obj_line_new ("line3", point); - size.width = -500; - size.height = 500; + size.width = -210; + size.height = 297; stroke.color = rpt_common_parse_color ("#000000AA"); g_object_set (obj, "size", &size, @@ -88,11 +90,11 @@ main (int argc, char **argv) NULL); rpt_report_add_object_to_section (rptr, obj, RPTREPORT_SECTION_BODY); - point.x = 250; - point.y = 250; + point.x = 105; + point.y = 148.5; obj = rpt_obj_ellipse_new ("circle1", point); - size.width = 100; - size.height = 100; + size.width = 50; + size.height = 50; color = rpt_common_parse_color ("#00FF0099"); stroke.color = rpt_common_parse_color ("#00FF00AA"); stroke.style = NULL;