and print definition.
Added functions RptCommon::stroutputtype_to_enum, RptCommon::enum_to_stroutputtype,
RptPrint::set_output_type, RptPrint::set_output_filename, RptPrint::set_copies,
RptReport::set_output_type, RptReport::set_output_filename, RptReport::set_copies.
Renamed RPTP_OUTPUT* to RPT_OUTPUT*.
docs/reference/version.xml
docs/reference/html/
docs/reference/xml/
+docs/reference/libreptool-decl-list.txt
+docs/reference/libreptool-decl.txt
+docs/reference/libreptool-scan.c
libtool
stamp-h1
tests/test*.png
<!ELEMENT reptool (properties?, database?, page, report)>
-<!ELEMENT properties (unit-length?)>
+<!ELEMENT properties (unit-length?, output-type?, output-filename?, copies?)>
<!ELEMENT unit-length (pt | in | cm | mm) #IMPLIED>
+<!ELEMENT output-type (png, pdf, ps, svg, gtk, gtk-default) #IMPLIED>
+<!ELEMENT output-filename CDATA #IMPLIED>
+<!ELEMENT copies CDATA #IMPLIED>
<!ELEMENT database (provider, connection-string, sql)>
<!ELEMENT provider (#PCDATA)>
<!ELEMENT reptool_report (properties?, page*)>
-<!ELEMENT properties (unit-length?)>
+<!ELEMENT properties (unit-length?, output-type?, output-filename?, copies?)>
<!ELEMENT unit-length (pt | in | cm | mm) #IMPLIED>
+<!ELEMENT output-type (png, pdf, ps, svg, gtk, gtk-default) #IMPLIED>
+<!ELEMENT output-filename CDATA #IMPLIED>
+<!ELEMENT copies CDATA #IMPLIED>
<!ELEMENT page (%objects;)>
<!ATTLIST page
return ret;
}
+/**
+ * rpt_common_stroutputtype_to_enum:
+ * @output_type:
+ *
+ * Returns: the enum value that match the string @output_type.
+ */
+eRptOutputType
+rpt_common_stroutputtype_to_enum (const gchar *output_type)
+{
+ eRptOutputType ret;
+
+ gchar *real_outputtype;
+
+ ret = RPT_OUTPUT_PDF;
+
+ if (output_type != NULL)
+ {
+ real_outputtype = g_strstrip (g_strdup (output_type));
+ if (g_ascii_strcasecmp (real_outputtype, "pdf") == 0)
+ {
+ /* already setted */
+ }
+ else if (g_ascii_strcasecmp (real_outputtype, "png") == 0)
+ {
+ ret = RPT_OUTPUT_PNG;
+ }
+ else if (g_ascii_strcasecmp (real_outputtype, "ps") == 0)
+ {
+ ret = RPT_OUTPUT_PS;
+ }
+ else if (g_ascii_strcasecmp (real_outputtype, "svg") == 0)
+ {
+ ret = RPT_OUTPUT_SVG;
+ }
+ else if (g_ascii_strcasecmp (real_outputtype, "gtk") == 0)
+ {
+ ret = RPT_OUTPUT_GTK;
+ }
+ else if (g_ascii_strcasecmp (real_outputtype, "gtk-default") == 0)
+ {
+ ret = RPT_OUTPUT_GTK_DEFAULT_PRINTER;
+ }
+ else
+ {
+ g_warning ("Output type «%s» not available.", real_outputtype);
+ }
+ }
+
+ return ret;
+}
+
+/**
+ * rpt_common_enum_to_stroutputtype:
+ * @output_type:
+ *
+ * Returns: the string value that represents then enum value @output_type.
+ */
+const gchar
+*rpt_common_enum_to_stroutputtype (eRptOutputType output_type)
+{
+ gchar *ret;
+
+ switch (output_type)
+ {
+ case RPT_OUTPUT_PDF:
+ ret = g_strdup ("df");
+ break;
+
+ case RPT_OUTPUT_PNG:
+ ret = g_strdup ("png");
+ break;
+
+ case RPT_OUTPUT_PS:
+ ret = g_strdup ("ps");
+ break;
+
+ case RPT_OUTPUT_SVG:
+ ret = g_strdup ("svg");
+ break;
+
+ case RPT_OUTPUT_GTK:
+ ret = g_strdup ("gtk");
+ break;
+
+ case RPT_OUTPUT_GTK_DEFAULT_PRINTER:
+ ret = g_strdup ("gtk-default");
+ break;
+
+ default:
+ g_warning ("Output type «%d» not available.", output_type);
+ ret = g_strdup ("pdf");
+ break;
+ }
+
+ return ret;
+}
+
/**
* rpt_common_rptpoint_new:
*
RPT_UNIT_MILLIMETRE
} eRptUnitLength;
+typedef enum
+{
+ RPT_OUTPUT_PNG,
+ RPT_OUTPUT_PDF,
+ RPT_OUTPUT_PS,
+ RPT_OUTPUT_SVG,
+ RPT_OUTPUT_GTK,
+ RPT_OUTPUT_GTK_DEFAULT_PRINTER
+} eRptOutputType;
+
/**
* RptColor:
* @r: the red channel; value from 0 to 1.
eRptUnitLength rpt_common_strunit_to_enum (const gchar *unit);
const gchar *rpt_common_enum_to_strunit (eRptUnitLength unit);
+eRptOutputType rpt_common_stroutputtype_to_enum (const gchar *output_type);
+const gchar *rpt_common_enum_to_stroutputtype (eRptOutputType output_type);
+
RptPoint *rpt_common_rptpoint_new (void);
RptPoint *rpt_common_get_position (xmlNode *xnode);
void rpt_common_set_position (xmlNode *xnode,
PROP_UNIT_LENGTH,
PROP_OUTPUT_TYPE,
PROP_OUTPUT_FILENAME,
+ PROP_COPIES,
PROP_PATH_RELATIVES_TO
};
{
eRptUnitLength unit;
+ eRptOutputType output_type;
+ gchar *output_filename;
+
+ guint copies;
+
gdouble width;
gdouble height;
gdouble margin_top;
xmlDoc *xdoc;
- RptPrintOutputType output_type;
- gchar *output_filename;
-
gchar *path_relatives_to;
xmlNodeSet *pages;
g_param_spec_int ("output-type",
"Output Type",
"The output type.",
- RPTP_OUTPUT_PNG, RPTP_OUTPUT_GTK,
- RPTP_OUTPUT_PDF,
+ RPT_OUTPUT_PNG, RPT_OUTPUT_GTK,
+ RPT_OUTPUT_PDF,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_OUTPUT_FILENAME,
g_param_spec_string ("output-filename",
"Output File Name",
"The output file's name.",
- "",
+ "rptreport.pdf",
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+ g_object_class_install_property (object_class, PROP_COPIES,
+ g_param_spec_uint ("copies",
+ "Copies",
+ "The number of copies to print.",
+ 1, G_MAXUINT,
+ 1,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
g_object_class_install_property (object_class, PROP_PATH_RELATIVES_TO,
g_param_spec_string ("path-relatives-to",
"Path are relatives to",
*
*/
void
-rpt_print_set_output_type (RptPrint *rpt_print, RptPrintOutputType output_type)
+rpt_print_set_output_type (RptPrint *rpt_print, eRptOutputType output_type)
{
+ g_return_if_fail (IS_RPT_PRINT (rpt_print));
+
RptPrintPrivate *priv = RPT_PRINT_GET_PRIVATE (rpt_print);
priv->output_type = output_type;
void
rpt_print_set_output_filename (RptPrint *rpt_print, const gchar *output_filename)
{
+ g_return_if_fail (IS_RPT_PRINT (rpt_print));
+
RptPrintPrivate *priv = RPT_PRINT_GET_PRIVATE (rpt_print);
priv->output_filename = g_strdup (output_filename);
+ if (g_strcmp0 (priv->output_filename, "") == 0)
+ {
+ g_warning ("It's not possible to set an empty output filename.");
+ priv->output_filename = g_strdup ("rptreport.pdf");
+ }
+}
+
+/**
+ * rpt_print_set_copies:
+ * @rpt_print: an #RptPrint object.
+ * @copies: number of copies.
+ *
+ */
+void
+rpt_print_set_copies (RptPrint *rpt_print, guint copies)
+{
+ g_return_if_fail (IS_RPT_PRINT (rpt_print));
+
+ RptPrintPrivate *priv = RPT_PRINT_GET_PRIVATE (rpt_print);
+
+ priv->copies = copies;
}
/**
{
g_object_set (G_OBJECT (rpt_print), "unit-length", rpt_common_strunit_to_enum ((const gchar *)xmlNodeGetContent (cur_property)), NULL);
}
+ else if (strcmp (cur_property->name, "output-type") == 0)
+ {
+ rpt_print_set_output_type (rpt_print, rpt_common_stroutputtype_to_enum ((const gchar *)xmlNodeGetContent (cur_property)));
+ }
+ else if (strcmp (cur_property->name, "output-filename") == 0)
+ {
+ rpt_print_set_output_filename (rpt_print, (const gchar *)xmlNodeGetContent (cur_property));
+ }
+ else if (strcmp (cur_property->name, "copies") == 0)
+ {
+ rpt_print_set_copies (rpt_print, strtol ((const gchar *)xmlNodeGetContent (cur_property), NULL, 10));
+ }
cur_property = cur_property->next;
}
return;
}
- if (priv->output_type == RPTP_OUTPUT_GTK
- || priv->output_type == RPTP_OUTPUT_GTK_DEFAULT_PRINTER)
+ if (priv->output_type == RPT_OUTPUT_GTK
+ || priv->output_type == RPT_OUTPUT_GTK_DEFAULT_PRINTER)
{
gchar *locale_old;
gchar *locale_num;
locale_num = setlocale (LC_NUMERIC, "C");
gtk_print_operation_run (operation,
- (priv->output_type == RPTP_OUTPUT_GTK ? GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG : GTK_PRINT_OPERATION_ACTION_PRINT),
+ (priv->output_type == RPT_OUTPUT_GTK ? GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG : GTK_PRINT_OPERATION_ACTION_PRINT),
NULL, NULL);
setlocale (LC_NUMERIC, locale_num);
setlocale (LC_ALL, locale_old);
{
switch (priv->output_type)
{
- case RPTP_OUTPUT_PNG:
+ case RPT_OUTPUT_PNG:
priv->output_filename = g_strdup ("reptool.png");
break;
- case RPTP_OUTPUT_PDF:
+ case RPT_OUTPUT_PDF:
priv->output_filename = g_strdup ("reptool.pdf");
break;
- case RPTP_OUTPUT_PS:
+ case RPT_OUTPUT_PS:
priv->output_filename = g_strdup ("reptool.ps");
break;
- case RPTP_OUTPUT_SVG:
+ case RPT_OUTPUT_SVG:
priv->output_filename = g_strdup ("reptool.svg");
break;
}
}
- if (priv->output_type != RPTP_OUTPUT_PNG && priv->output_type != RPTP_OUTPUT_SVG)
+ if (priv->output_type != RPT_OUTPUT_PNG && priv->output_type != RPT_OUTPUT_SVG)
{
fout = fopen (priv->output_filename, "w");
if (fout == NULL)
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)
+ if (priv->output_type == RPT_OUTPUT_PNG)
{
priv->surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, (int)width, (int)height);
}
- else if (priv->output_type == RPTP_OUTPUT_PDF && npage == 0)
+ else if (priv->output_type == RPT_OUTPUT_PDF && npage == 0)
{
priv->surface = cairo_pdf_surface_create (priv->output_filename, width, height);
}
- else if (priv->output_type == RPTP_OUTPUT_PS && npage == 0)
+ else if (priv->output_type == RPT_OUTPUT_PS && npage == 0)
{
priv->surface = cairo_ps_surface_create (priv->output_filename, width, height);
}
- else if (priv->output_type == RPTP_OUTPUT_SVG)
+ else if (priv->output_type == RPT_OUTPUT_SVG)
{
gchar *new_out_filename = rpt_print_new_numbered_filename (priv->output_filename, npage + 1);
fout = fopen (new_out_filename, "w");
if (cairo_surface_status (priv->surface) == CAIRO_STATUS_SUCCESS)
{
- if (priv->output_type == RPTP_OUTPUT_PNG || priv->output_type == RPTP_OUTPUT_SVG)
+ if (priv->output_type == RPT_OUTPUT_PNG || priv->output_type == RPT_OUTPUT_SVG)
{
priv->cr = cairo_create (priv->surface);
}
priv->cr = cairo_create (priv->surface);
}
- if (priv->output_type != RPTP_OUTPUT_PNG && priv->output_type != RPTP_OUTPUT_SVG && npage == 0)
+ if (priv->output_type != RPT_OUTPUT_PNG && priv->output_type != RPT_OUTPUT_SVG && npage == 0)
{
cairo_surface_destroy (priv->surface);
}
{
rpt_print_page (rpt_print, cur);
- if (priv->output_type == RPTP_OUTPUT_PNG)
+ if (priv->output_type == RPT_OUTPUT_PNG)
{
gchar *new_out_filename = rpt_print_new_numbered_filename (priv->output_filename, npage + 1);
cairo_show_page (priv->cr);
}
- if (priv->output_type == RPTP_OUTPUT_SVG)
+ if (priv->output_type == RPT_OUTPUT_SVG)
{
cairo_surface_destroy (priv->surface);
cairo_destroy (priv->cr);
{
cairo_destroy (priv->cr);
}
- if (priv->output_type != RPTP_OUTPUT_PNG && priv->output_type != RPTP_OUTPUT_SVG)
+ if (priv->output_type != RPT_OUTPUT_PNG && priv->output_type != RPT_OUTPUT_SVG)
{
fclose (fout);
}
rpt_print_set_output_filename (rpt_print, g_value_get_string (value));
break;
+ case PROP_COPIES:
+ rpt_print_set_copies (rpt_print, g_value_get_uint (value));
+ break;
+
case PROP_PATH_RELATIVES_TO:
priv->path_relatives_to = g_strstrip (g_strdup (g_value_get_string (value)));
break;
g_value_set_string (value, priv->output_filename);
break;
+ case PROP_COPIES:
+ g_value_set_uint (value, priv->copies);
+ break;
+
case PROP_PATH_RELATIVES_TO:
g_value_set_string (value, priv->path_relatives_to);
break;
gtk_print_operation_set_default_page_setup (operation, page_set);
gtk_print_operation_set_unit (operation, GTK_UNIT_POINTS);
gtk_print_operation_set_n_pages (operation, priv->pages->nodeNr);
+
+ GtkPrintSettings *settings = gtk_print_operation_get_print_settings (operation);
+ if (settings == NULL)
+ {
+ settings = gtk_print_settings_new ();
+ }
+ gtk_print_settings_set_n_copies (settings, priv->copies);
+ gtk_print_operation_set_print_settings (operation, settings);
}
static void
/*
- * Copyright (C) 2006-2007 Andrea Zagli <azagli@inwind.it>
+ * Copyright (C) 2006-2010 Andrea Zagli <azagli@inwind.it>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
#include <glib-object.h>
#include <libxml/tree.h>
+#include "rptcommon.h"
+
G_BEGIN_DECLS
GType rpt_print_get_type (void) G_GNUC_CONST;
-typedef enum
-{
- RPTP_OUTPUT_PNG,
- RPTP_OUTPUT_PDF,
- RPTP_OUTPUT_PS,
- RPTP_OUTPUT_SVG,
- RPTP_OUTPUT_GTK,
- RPTP_OUTPUT_GTK_DEFAULT_PRINTER
-} RptPrintOutputType;
-
RptPrint *rpt_print_new_from_xml (xmlDoc *xdoc);
RptPrint *rpt_print_new_from_file (const gchar *filename);
-void rpt_print_set_output_type (RptPrint *rpt_print, RptPrintOutputType output_type);
+void rpt_print_set_output_type (RptPrint *rpt_print, eRptOutputType output_type);
void rpt_print_set_output_filename (RptPrint *rpt_print, const gchar *output_filename);
+void rpt_print_set_copies (RptPrint *rpt_print, guint copies);
+
void rpt_print_print (RptPrint *rpt_print);
gdouble *cur_y,
RptReportSection section,
gint row);
-
+
static void rpt_report_rptprint_parse_text_source (RptReport *rpt_report,
RptObject *rptobj,
xmlNode *xnode,
{
eRptUnitLength unit;
+ eRptOutputType output_type;
+ gchar *output_filename;
+
+ guint copies;
+
Database *db;
Page *page;
priv->body->height = 0.0;
priv->body->objects = NULL;
priv->body->new_page_after = FALSE;
+
+ priv->output_type = RPT_OUTPUT_PDF;
+ priv->output_filename = g_strdup ("rptreport.pdf");
+ priv->copies = 1;
}
/**
{
g_object_set (G_OBJECT (rpt_report), "unit-length", rpt_common_strunit_to_enum ((const gchar *)xmlNodeGetContent (cur_property)), NULL);
}
+ else if (strcmp (cur_property->name, "output-type") == 0)
+ {
+ rpt_report_set_output_type (rpt_report, rpt_common_stroutputtype_to_enum ((const gchar *)xmlNodeGetContent (cur_property)));
+ }
+ else if (strcmp (cur_property->name, "output-filename") == 0)
+ {
+ rpt_report_set_output_filename (rpt_report, (const gchar *)xmlNodeGetContent (cur_property));
+ }
+ else if (strcmp (cur_property->name, "copies") == 0)
+ {
+ rpt_report_set_copies (rpt_report, strtol ((const gchar *)xmlNodeGetContent (cur_property), NULL, 10));
+ }
cur_property = cur_property->next;
}
return rpt_report;
}
+/**
+ * rpt_report_set_output_type:
+ * @rpt_report:
+ * @output_type:
+ *
+ */
+void
+rpt_report_set_output_type (RptReport *rpt_report, eRptOutputType output_type)
+{
+ g_return_if_fail (IS_RPT_REPORT (rpt_report));
+
+ RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report);
+
+ priv->output_type = output_type;
+}
+
+/**
+ * rpt_report_set_output_filename:
+ * @rpt_report:
+ * @output_filename:
+ *
+ */
+void
+rpt_report_set_output_filename (RptReport *rpt_report, const gchar *output_filename)
+{
+ g_return_if_fail (IS_RPT_REPORT (rpt_report));
+
+ RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report);
+
+ priv->output_filename = g_strstrip (g_strdup (output_filename));
+ if (g_strcmp0 (priv->output_filename, "") == 0)
+ {
+ g_warning ("It's not possible to set an empty output filename.");
+ priv->output_filename = g_strdup ("rptreport.pdf");
+ }
+}
+
+/**
+ * rpt_report_set_copies:
+ * @rpt_report:
+ * @copies:
+ *
+ */
+void
+rpt_report_set_copies (RptReport *rpt_report, guint copies)
+{
+ g_return_if_fail (IS_RPT_REPORT (rpt_report));
+
+ RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report);
+
+ priv->copies = copies;
+}
+
/**
* rpt_report_database_get_provider:
* @rpt_report:
xmlNodeSetContent (xnode, rpt_common_enum_to_strunit (priv->unit));
xmlAddChild (xnodeprop, xnode);
+ xnode = xmlNewNode (NULL, "output-type");
+ xmlNodeSetContent (xnode, rpt_common_enum_to_stroutputtype (priv->output_type));
+ xmlAddChild (xnodeprop, xnode);
+
+ xnode = xmlNewNode (NULL, "output-filename");
+ xmlNodeSetContent (xnode, priv->output_filename);
+ xmlAddChild (xnodeprop, xnode);
+
+ xnode = xmlNewNode (NULL, "copies");
+ xmlNodeSetContent (xnode, g_strdup_printf ("%d", priv->copies));
+ xmlAddChild (xnodeprop, xnode);
+
if (priv->db != NULL)
{
xmlNode *xnodedb = xmlNewNode (NULL, "database");
xmlNodeSetContent (xnode, rpt_common_enum_to_strunit (priv->unit));
xmlAddChild (xnodeprop, xnode);
+ xnode = xmlNewNode (NULL, "output-type");
+ xmlNodeSetContent (xnode, rpt_common_enum_to_stroutputtype (priv->output_type));
+ xmlAddChild (xnodeprop, xnode);
+
+ xnode = xmlNewNode (NULL, "output-filename");
+ xmlNodeSetContent (xnode, priv->output_filename);
+ xmlAddChild (xnodeprop, xnode);
+
+ xnode = xmlNewNode (NULL, "copies");
+ xmlNodeSetContent (xnode, g_strdup_printf ("%d", priv->copies));
+ xmlAddChild (xnodeprop, xnode);
+
if (priv->db != NULL)
{
gint row;
/*
- * Copyright (C) 2007 Andrea Zagli <azagli@inwind.it>
+ * Copyright (C) 2007-2010 Andrea Zagli <azagli@inwind.it>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
RptReport *rpt_report_new_from_xml (xmlDoc *xdoc);
RptReport *rpt_report_new_from_file (const gchar *filename);
+void rpt_report_set_output_type (RptReport *rpt_report, eRptOutputType output_type);
+void rpt_report_set_output_filename (RptReport *rpt_report, const gchar *output_filename);
+
+void rpt_report_set_copies (RptReport *rpt_report, guint copies);
+
const gchar *rpt_report_database_get_provider (RptReport *rpt_report);
const gchar *rpt_report_database_get_connection_string (RptReport *rpt_report);
const gchar *rpt_report_database_get_sql (RptReport *rpt_report);
gboolean rpt_report_get_report_header_new_page_after (RptReport *rpt_report);
void rpt_report_set_report_header_new_page_after (RptReport *rpt_report,
gboolean new_page_after);
-
+
gboolean rpt_report_get_report_footer_new_page_before (RptReport *rpt_report);
void rpt_report_set_report_footer_new_page_before (RptReport *rpt_report,
gboolean new_page_before);
/*
- * Copyright (C) 2006-2007 Andrea Zagli <azagli@inwind.it>
+ * Copyright (C) 2006-2010 Andrea Zagli <azagli@inwind.it>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
if (rptp != NULL)
{
- rpt_print_set_output_type (rptp, RPTP_OUTPUT_PNG);
+ rpt_print_set_output_type (rptp, RPT_OUTPUT_PNG);
rpt_print_set_output_filename (rptp, "test.png");
rpt_print_print (rptp);
}
rptp = rpt_print_new_from_xml (rptprint);
if (rptp != NULL)
{
- rpt_print_set_output_type (rptp, RPTP_OUTPUT_PDF);
+ rpt_print_set_output_type (rptp, RPT_OUTPUT_PDF);
rpt_print_set_output_filename (rptp, "test.pdf");
rpt_print_print (rptp);
}
rptp = rpt_print_new_from_xml (rptprint);
if (rptp != NULL)
{
- rpt_print_set_output_type (rptp, RPTP_OUTPUT_PDF);
+ rpt_print_set_output_type (rptp, RPT_OUTPUT_PDF);
rpt_print_set_output_filename (rptp, "test_report_created.pdf");
rpt_print_print (rptp);
}