/*
- * Copyright (C) 2006-2007 Andrea Zagli <azagli@inwind.it>
+ * Copyright (C) 2006-2010 Andrea Zagli <azagli@libero.it>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
enum
{
PROP_0,
+ PROP_UNIT_LENGTH,
PROP_OUTPUT_TYPE,
PROP_OUTPUT_FILENAME,
PROP_PATH_RELATIVES_TO
typedef struct _RptPrintPrivate RptPrintPrivate;
struct _RptPrintPrivate
{
+ eRptUnitLength unit;
+
gdouble width;
gdouble height;
gdouble margin_top;
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,
FILE *fout;
gchar *prop;
+
+ gdouble width;
+ gdouble height;
+
gint npage = 0;
RptPrintPrivate *priv = RPT_PRINT_GET_PRIVATE (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))
{
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)
{
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)
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;
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;
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;
}
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 */
/*}*/
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);
{
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);
}
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);
}
}
}
- 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);
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;
/* 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)
{
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;
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);
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);
{
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)
enum
{
- PROP_0
+ PROP_0,
+ PROP_UNIT_LENGTH
};
static void rpt_report_class_init (RptReportClass *klass);
typedef struct _RptReportPrivate RptReportPrivate;
struct _RptReportPrivate
{
+ eRptUnitLength unit;
+
Database *db;
Page *page;
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.
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);
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");
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;
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;
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;