Commit a3b07ac9 authored by Marek Kašík's avatar Marek Kašík Committed by Marek Kašík

Bug 339714 - Set printer dpi on cairo ps/pdf surfaces when printing

2008-10-30  Marek Kasik  <mkasik@redhat.com>

	Bug 339714 - Set printer dpi on cairo ps/pdf surfaces when printing

	* gtk/gtk.symbols
	* gtk/gtkprintsettings.c
	* gtk/gtkprintsettings.h
	* docs/reference/gtk/gtk-sections.txt
	* modules/printbackends/file/gtkprintbackendfile.c
	* modules/printbackends/test/gtkprintbackendtest.c
	* modules/printbackends/cups/gtkprintbackendcups.c
	* modules/printbackends/lpr/gtkprintbackendlpr.c:
	Added lpi (lines per inch) setting to GtkPrintSettings and support
	for anamorphic dpi. Surface fallback resolution is set to 2*lpi.

svn path=/trunk/; revision=21733
parent e7b18d2a
2008-10-30 Marek Kasik <mkasik@redhat.com>
Bug 339714 - Set printer dpi on cairo ps/pdf surfaces when printing
* gtk/gtk.symbols
* gtk/gtkprintsettings.c
* gtk/gtkprintsettings.h
* docs/reference/gtk/gtk-sections.txt
* modules/printbackends/file/gtkprintbackendfile.c
* modules/printbackends/test/gtkprintbackendtest.c
* modules/printbackends/cups/gtkprintbackendcups.c
* modules/printbackends/lpr/gtkprintbackendlpr.c:
Added lpi (lines per inch) setting to GtkPrintSettings and support
for anamorphic dpi. Surface fallback resolution is set to 2*lpi.
2008-10-30 Michael Natterer <mitch@imendio.com>
* gtk/*.h: no need to include <gdk/gdk.h> in any widget header,
......
......@@ -6617,6 +6617,14 @@ gtk_print_settings_set_number_up_layout
GTK_PRINT_SETTINGS_RESOLUTION
gtk_print_settings_get_resolution
gtk_print_settings_set_resolution
gtk_print_settings_set_resolution_xy
GTK_PRINT_SETTINGS_RESOLUTION_X
gtk_print_settings_get_resolution_x
GTK_PRINT_SETTINGS_RESOLUTION_Y
gtk_print_settings_get_resolution_y
GTK_PRINT_SETTINGS_PRINTER_LPI
gtk_print_settings_get_printer_lpi
gtk_print_settings_set_printer_lpi
GTK_PRINT_SETTINGS_SCALE
gtk_print_settings_get_scale
gtk_print_settings_set_scale
......
......@@ -2974,6 +2974,11 @@ gtk_print_settings_get_number_up_layout
gtk_print_settings_set_number_up_layout
gtk_print_settings_get_resolution
gtk_print_settings_set_resolution
gtk_print_settings_get_resolution_x
gtk_print_settings_get_resolution_y
gtk_print_settings_set_resolution_xy
gtk_print_settings_get_printer_lpi
gtk_print_settings_set_printer_lpi
gtk_print_settings_get_scale
gtk_print_settings_set_scale
gtk_print_settings_get_print_pages
......
......@@ -1193,7 +1193,9 @@ gtk_print_settings_get_resolution (GtkPrintSettings *settings)
* @settings: a #GtkPrintSettings
* @resolution: the resolution in dpi
*
* Sets the value of %GTK_PRINT_SETTINGS_RESOLUTION.
* Sets the values of %GTK_PRINT_SETTINGS_RESOLUTION,
* %GTK_PRINT_SETTINGS_RESOLUTION_X and
* %GTK_PRINT_SETTINGS_RESOLUTION_Y.
*
* Since: 2.10
*/
......@@ -1203,6 +1205,100 @@ gtk_print_settings_set_resolution (GtkPrintSettings *settings,
{
gtk_print_settings_set_int (settings, GTK_PRINT_SETTINGS_RESOLUTION,
resolution);
gtk_print_settings_set_int (settings, GTK_PRINT_SETTINGS_RESOLUTION_X,
resolution);
gtk_print_settings_set_int (settings, GTK_PRINT_SETTINGS_RESOLUTION_Y,
resolution);
}
/**
* gtk_print_settings_get_resolution_x:
* @settings: a #GtkPrintSettings
*
* Gets the value of %GTK_PRINT_SETTINGS_RESOLUTION_X.
*
* Return value: the horizontal resolution in dpi
*
* Since: 2.16
*/
gint
gtk_print_settings_get_resolution_x (GtkPrintSettings *settings)
{
return gtk_print_settings_get_int (settings, GTK_PRINT_SETTINGS_RESOLUTION_X);
}
/**
* gtk_print_settings_get_resolution_y:
* @settings: a #GtkPrintSettings
*
* Gets the value of %GTK_PRINT_SETTINGS_RESOLUTION_Y.
*
* Return value: the vertical resolution in dpi
*
* Since: 2.16
*/
gint
gtk_print_settings_get_resolution_y (GtkPrintSettings *settings)
{
return gtk_print_settings_get_int (settings, GTK_PRINT_SETTINGS_RESOLUTION_Y);
}
/**
* gtk_print_settings_set_resolution_xy:
* @settings: a #GtkPrintSettings
* @resolution_x: the horizontal resolution in dpi
* @resolution_y: the vertical resolution in dpi
*
* Sets the values of %GTK_PRINT_SETTINGS_RESOLUTION,
* %GTK_PRINT_SETTINGS_RESOLUTION_X and
* %GTK_PRINT_SETTINGS_RESOLUTION_Y.
*
* Since: 2.16
*/
void
gtk_print_settings_set_resolution_xy (GtkPrintSettings *settings,
gint resolution_x,
gint resolution_y)
{
gtk_print_settings_set_int (settings, GTK_PRINT_SETTINGS_RESOLUTION_X,
resolution_x);
gtk_print_settings_set_int (settings, GTK_PRINT_SETTINGS_RESOLUTION_Y,
resolution_y);
gtk_print_settings_set_int (settings, GTK_PRINT_SETTINGS_RESOLUTION,
resolution_x);
}
/**
* gtk_print_settings_get_printer_lpi:
* @settings: a #GtkPrintSettings
*
* Gets the value of %GTK_PRINT_SETTINGS_PRINTER_LPI.
*
* Return value: the resolution in lpi (lines per inch)
*
* Since: 2.16
*/
gdouble
gtk_print_settings_get_printer_lpi (GtkPrintSettings *settings)
{
return gtk_print_settings_get_double (settings, GTK_PRINT_SETTINGS_PRINTER_LPI);
}
/**
* gtk_print_settings_set_printer_lpi:
* @settings: a #GtkPrintSettings
* @resolution: the resolution in lpi (lines per inch)
*
* Sets the value of %GTK_PRINT_SETTINGS_PRINTER_LPI
*
* Since: 2.16
*/
void
gtk_print_settings_set_printer_lpi (GtkPrintSettings *settings,
gdouble lpi)
{
gtk_print_settings_set_double (settings, GTK_PRINT_SETTINGS_PRINTER_LPI,
lpi);
}
/**
......
......@@ -133,6 +133,9 @@ void gtk_print_settings_set_int (GtkPrintSettings
#define GTK_PRINT_SETTINGS_NUMBER_UP "number-up"
#define GTK_PRINT_SETTINGS_NUMBER_UP_LAYOUT "number-up-layout"
#define GTK_PRINT_SETTINGS_OUTPUT_BIN "output-bin"
#define GTK_PRINT_SETTINGS_RESOLUTION_X "resolution-x"
#define GTK_PRINT_SETTINGS_RESOLUTION_Y "resolution-y"
#define GTK_PRINT_SETTINGS_PRINTER_LPI "printer-lpi"
#define GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT "output-file-format"
#define GTK_PRINT_SETTINGS_OUTPUT_URI "output-uri"
......@@ -188,6 +191,14 @@ void gtk_print_settings_set_number_up_layout (GtkPrintSettings
gint gtk_print_settings_get_resolution (GtkPrintSettings *settings);
void gtk_print_settings_set_resolution (GtkPrintSettings *settings,
gint resolution);
gint gtk_print_settings_get_resolution_x (GtkPrintSettings *settings);
gint gtk_print_settings_get_resolution_y (GtkPrintSettings *settings);
void gtk_print_settings_set_resolution_xy (GtkPrintSettings *settings,
gint resolution_x,
gint resolution_y);
gdouble gtk_print_settings_get_printer_lpi (GtkPrintSettings *settings);
void gtk_print_settings_set_printer_lpi (GtkPrintSettings *settings,
gdouble lpi);
gdouble gtk_print_settings_get_scale (GtkPrintSettings *settings);
void gtk_print_settings_set_scale (GtkPrintSettings *settings,
gdouble scale);
......
......@@ -316,6 +316,10 @@ cups_printer_create_cairo_surface (GtkPrinter *printer,
cairo_surface_t *surface;
ppd_file_t *ppd_file = NULL;
ppd_attr_t *ppd_attr = NULL;
ppd_attr_t *ppd_attr_res = NULL;
ppd_attr_t *ppd_attr_screen_freq = NULL;
ppd_attr_t *ppd_attr_res_screen_freq = NULL;
gchar *res_string = NULL;
int level = 2;
/* TODO: check if it is a ps or pdf printer */
......@@ -330,6 +334,57 @@ cups_printer_create_cairo_surface (GtkPrinter *printer,
if (ppd_attr != NULL)
level = atoi (ppd_attr->value);
if (gtk_print_settings_get_resolution (settings) == 0)
{
ppd_attr_res = ppdFindAttr (ppd_file, "DefaultResolution", NULL);
if (ppd_attr_res != NULL)
{
int res, res_x, res_y;
if (sscanf (ppd_attr_res->value, "%dx%ddpi", &res_x, &res_y) == 2)
{
if (res_x != 0 && res_y != 0)
gtk_print_settings_set_resolution_xy (settings, res_x, res_y);
}
else if (sscanf (ppd_attr_res->value, "%ddpi", &res) == 1)
{
if (res != 0)
gtk_print_settings_set_resolution (settings, res);
}
else
gtk_print_settings_set_resolution (settings, 300);
}
}
res_string = g_strdup_printf ("%ddpi",
gtk_print_settings_get_resolution (settings));
ppd_attr_res_screen_freq = ppdFindAttr (ppd_file, "ResScreenFreq", res_string);
g_free (res_string);
if (ppd_attr_res_screen_freq == NULL)
{
res_string = g_strdup_printf ("%dx%ddpi",
gtk_print_settings_get_resolution_x (settings),
gtk_print_settings_get_resolution_y (settings));
ppd_attr_res_screen_freq = ppdFindAttr (ppd_file, "ResScreenFreq", res_string);
g_free (res_string);
}
ppd_attr_screen_freq = ppdFindAttr (ppd_file, "ScreenFreq", NULL);
if (ppd_attr_res_screen_freq != NULL)
gtk_print_settings_set_printer_lpi (settings, atof (ppd_attr_res_screen_freq->value));
else if (ppd_attr_screen_freq != NULL)
gtk_print_settings_set_printer_lpi (settings, atof (ppd_attr_screen_freq->value));
else
gtk_print_settings_set_printer_lpi (settings, 150.0);
}
else
{
gtk_print_settings_set_resolution (settings, 300);
gtk_print_settings_set_printer_lpi (settings, 150.0);
}
if (level == 2)
......@@ -338,8 +393,9 @@ cups_printer_create_cairo_surface (GtkPrinter *printer,
if (level == 3)
cairo_ps_surface_restrict_to_level (surface, CAIRO_PS_LEVEL_3);
/* TODO: DPI from settings object? */
cairo_surface_set_fallback_resolution (surface, 300, 300);
cairo_surface_set_fallback_resolution (surface,
2.0 * gtk_print_settings_get_printer_lpi (settings),
2.0 * gtk_print_settings_get_printer_lpi (settings));
return surface;
}
......@@ -3282,7 +3338,16 @@ set_option_from_settings (GtkPrinterOption *option,
else
{
int res = gtk_print_settings_get_resolution (settings);
if (res != 0)
int res_x = gtk_print_settings_get_resolution_x (settings);
int res_y = gtk_print_settings_get_resolution_y (settings);
if (res_x != res_y)
{
value = g_strdup_printf ("%dx%ddpi", res_x, res_y);
gtk_printer_option_set (option, value);
g_free (value);
}
else if (res != 0)
{
value = g_strdup_printf ("%ddpi", res);
gtk_printer_option_set (option, value);
......@@ -3371,10 +3436,19 @@ foreach_option_get_settings (GtkPrinterOption *option,
settings, GTK_PRINT_SETTINGS_QUALITY, "OutputMode");
else if (strcmp (option->name, "cups-Resolution") == 0)
{
int res = atoi (value);
/* TODO: What if resolution is on XXXxYYYdpi form? */
if (res != 0)
gtk_print_settings_set_resolution (settings, res);
int res, res_x, res_y;
if (sscanf (value, "%dx%ddpi", &res_x, &res_y) == 2)
{
if (res_x != 0 && res_y != 0)
gtk_print_settings_set_resolution_xy (settings, res_x, res_y);
}
else if (sscanf (value, "%ddpi", &res) == 1)
{
if (res != 0)
gtk_print_settings_set_resolution (settings, res);
}
gtk_print_settings_set (settings, option->name, value);
}
else if (strcmp (option->name, "gtk-paper-type") == 0)
......
......@@ -306,8 +306,12 @@ file_printer_create_cairo_surface (GtkPrinter *printer,
else
surface = cairo_pdf_surface_create_for_stream (_cairo_write, cache_io, width, height);
/* TODO: DPI from settings object? */
cairo_surface_set_fallback_resolution (surface, 300, 300);
if (gtk_print_settings_get_printer_lpi (settings) == 0.0)
gtk_print_settings_set_printer_lpi (settings, 150.0);
cairo_surface_set_fallback_resolution (surface,
2.0 * gtk_print_settings_get_printer_lpi (settings),
2.0 * gtk_print_settings_get_printer_lpi (settings));
return surface;
}
......
......@@ -211,8 +211,12 @@ lpr_printer_create_cairo_surface (GtkPrinter *printer,
surface = cairo_ps_surface_create_for_stream (_cairo_write, cache_io, width, height);
/* TODO: DPI from settings object? */
cairo_surface_set_fallback_resolution (surface, 300, 300);
if (gtk_print_settings_get_printer_lpi (settings) == 0.0)
gtk_print_settings_set_printer_lpi (settings, 150.0);
cairo_surface_set_fallback_resolution (surface,
2.0 * gtk_print_settings_get_printer_lpi (settings),
2.0 * gtk_print_settings_get_printer_lpi (settings));
return surface;
}
......
......@@ -306,8 +306,12 @@ test_printer_create_cairo_surface (GtkPrinter *printer,
else
surface = cairo_pdf_surface_create_for_stream (_cairo_write, cache_io, width, height);
/* TODO: DPI from settings object? */
cairo_surface_set_fallback_resolution (surface, 300, 300);
if (gtk_print_settings_get_printer_lpi (settings) == 0.0)
gtk_print_settings_set_printer_lpi (settings, 150.0);
cairo_surface_set_fallback_resolution (surface,
2.0 * gtk_print_settings_get_printer_lpi (settings),
2.0 * gtk_print_settings_get_printer_lpi (settings));
return surface;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment