Commit 91190ce2 authored by Marek Kasik's avatar Marek Kasik

Add ability to print in number-up mode for file backend and lpr backend

GtkPrintOperation is now able to render multiple pages per sheet by its
own. The most important changes are in these functions:
  * increment_page_sequence
  * prepare_data
  * common_render_page
  * print_pages_idle
Patch also changes set of choices for 2 pages per sheet mode when
landscape orientation is used to "Top to bottom" and "Bottom to top".
parent 26c10075
......@@ -205,6 +205,8 @@ gtk_print_job_init (GtkPrintJob *job)
job->scale = 1.0;
job->page_set = GTK_PAGE_SET_ALL;
job->rotate_to_orientation = FALSE;
job->number_up = 1;
job->number_up_layout = GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM;
}
......
......@@ -66,6 +66,8 @@ struct _GtkPrintJob
guint GSEAL (rotate_to_orientation) : 1;
guint GSEAL (collate) : 1;
guint GSEAL (reverse) : 1;
guint GSEAL (number_up);
GtkNumberUpLayout GSEAL (number_up_layout);
};
struct _GtkPrintJobClass
......
......@@ -43,6 +43,8 @@ struct _GtkPrintOperationPrivate
GtkPrintSettings *print_settings;
gchar *job_name;
gint nr_of_pages;
gint nr_of_pages_to_print;
gint page_position;
gint current_page;
GtkUnit unit;
gchar *export_filename;
......@@ -70,6 +72,9 @@ struct _GtkPrintOperationPrivate
guint manual_orientation : 1;
double manual_scale;
GtkPageSet manual_page_set;
guint manual_number_up;
GtkNumberUpLayout manual_number_up_layout;
GtkWidget *custom_widget;
gchar *custom_tab_label;
......
......@@ -87,10 +87,14 @@ unix_start_page (GtkPrintOperation *op,
type = cairo_surface_get_type (op_unix->surface);
if (type == CAIRO_SURFACE_TYPE_PS)
cairo_ps_surface_set_size (op_unix->surface, w, h);
else if (type == CAIRO_SURFACE_TYPE_PDF)
cairo_pdf_surface_set_size (op_unix->surface, w, h);
if ((op->priv->manual_number_up < 2) ||
(op->priv->page_position % op->priv->manual_number_up == 0))
{
if (type == CAIRO_SURFACE_TYPE_PS)
cairo_ps_surface_set_size (op_unix->surface, w, h);
else if (type == CAIRO_SURFACE_TYPE_PDF)
cairo_pdf_surface_set_size (op_unix->surface, w, h);
}
}
static void
......@@ -100,7 +104,11 @@ unix_end_page (GtkPrintOperation *op,
cairo_t *cr;
cr = gtk_print_context_get_cairo_context (print_context);
cairo_show_page (cr);
if ((op->priv->manual_number_up < 2) ||
((op->priv->page_position + 1) % op->priv->manual_number_up == 0) ||
(op->priv->page_position == op->priv->nr_of_pages_to_print - 1))
cairo_show_page (cr);
}
static void
......@@ -399,7 +407,9 @@ get_print_dialog (GtkPrintOperation *op,
GTK_PRINT_CAPABILITY_COLLATE |
GTK_PRINT_CAPABILITY_REVERSE |
GTK_PRINT_CAPABILITY_SCALE |
GTK_PRINT_CAPABILITY_PREVIEW);
GTK_PRINT_CAPABILITY_PREVIEW |
GTK_PRINT_CAPABILITY_NUMBER_UP |
GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT);
if (priv->print_settings)
gtk_print_unix_dialog_set_settings (GTK_PRINT_UNIX_DIALOG (pd),
......@@ -523,6 +533,8 @@ finish_print (PrintResponseData *rdata,
priv->manual_page_set = job->page_set;
priv->manual_scale = job->scale;
priv->manual_orientation = job->rotate_to_orientation;
priv->manual_number_up = job->number_up;
priv->manual_number_up_layout = job->number_up_layout;
}
}
out:
......
......@@ -1598,6 +1598,8 @@ gtk_print_operation_run_without_dialog (GtkPrintOperation *op,
op->priv->manual_orientation = FALSE;
op->priv->manual_scale = 1.0;
op->priv->manual_page_set = GTK_PAGE_SET_ALL;
op->priv->manual_number_up = 1;
op->priv->manual_number_up_layout = GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM;
op->priv->start_page = win32_start_page;
op->priv->end_page = win32_end_page;
......@@ -1821,6 +1823,8 @@ gtk_print_operation_run_with_dialog (GtkPrintOperation *op,
op->priv->manual_orientation = FALSE;
op->priv->manual_scale = 1.0;
op->priv->manual_page_set = GTK_PAGE_SET_ALL;
op->priv->manual_number_up = 1;
op->priv->manual_number_up_layout = GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM;
}
op->priv->start_page = win32_start_page;
......
This diff is collapsed.
......@@ -2428,6 +2428,7 @@ update_number_up_layout (GtkPrintUnixDialog *dialog)
GtkNumberUpLayout layout;
GtkPrinterOption *option;
GtkPrinterOption *old_option;
GtkPageOrientation page_orientation;
set = priv->options;
......@@ -2438,17 +2439,64 @@ update_number_up_layout (GtkPrintUnixDialog *dialog)
if (priv->number_up_layout_n_option == NULL)
{
priv->number_up_layout_n_option = gtk_printer_option_set_lookup (set, "gtk-n-up-layout");
if (priv->number_up_layout_n_option == NULL)
{
char *n_up_layout[] = { "lrtb", "lrbt", "rltb", "rlbt", "tblr", "tbrl", "btlr", "btrl" };
/* Translators: These strings name the possible arrangements of
* multiple pages on a sheet when printing (same as in gtkprintbackendcups.c)
*/
char *n_up_layout_display[] = { N_("Left to right, top to bottom"), N_("Left to right, bottom to top"),
N_("Right to left, top to bottom"), N_("Right to left, bottom to top"),
N_("Top to bottom, left to right"), N_("Top to bottom, right to left"),
N_("Bottom to top, left to right"), N_("Bottom to top, right to left") };
int i;
priv->number_up_layout_n_option = gtk_printer_option_new ("gtk-n-up-layout",
_("Page Ordering"),
GTK_PRINTER_OPTION_TYPE_PICKONE);
gtk_printer_option_allocate_choices (priv->number_up_layout_n_option, 8);
for (i = 0; i < G_N_ELEMENTS (n_up_layout_display); i++)
{
priv->number_up_layout_n_option->choices[i] = g_strdup (n_up_layout[i]);
priv->number_up_layout_n_option->choices_display[i] = g_strdup (_(n_up_layout_display[i]));
}
}
g_object_ref (priv->number_up_layout_n_option);
priv->number_up_layout_2_option = gtk_printer_option_new ("gtk-n-up-layout",
_("Page Ordering"),
GTK_PRINTER_OPTION_TYPE_PICKONE);
gtk_printer_option_allocate_choices (priv->number_up_layout_2_option, 2);
}
priv->number_up_layout_2_option->choices[0] = priv->number_up_layout_n_option->choices[0];
priv->number_up_layout_2_option->choices[1] = priv->number_up_layout_n_option->choices[2];
priv->number_up_layout_2_option->choices_display[0] = g_strdup ( _("Left to right"));
priv->number_up_layout_2_option->choices_display[1] = g_strdup ( _("Right to left"));
page_orientation = gtk_page_setup_get_orientation (priv->page_setup);
if (page_orientation == GTK_PAGE_ORIENTATION_PORTRAIT ||
page_orientation == GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT)
{
if (! (priv->number_up_layout_2_option->choices[0] == priv->number_up_layout_n_option->choices[0] &&
priv->number_up_layout_2_option->choices[1] == priv->number_up_layout_n_option->choices[2]))
{
g_free (priv->number_up_layout_2_option->choices_display[0]);
g_free (priv->number_up_layout_2_option->choices_display[1]);
priv->number_up_layout_2_option->choices[0] = priv->number_up_layout_n_option->choices[0];
priv->number_up_layout_2_option->choices[1] = priv->number_up_layout_n_option->choices[2];
priv->number_up_layout_2_option->choices_display[0] = g_strdup ( _("Left to right"));
priv->number_up_layout_2_option->choices_display[1] = g_strdup ( _("Right to left"));
}
}
else
{
if (! (priv->number_up_layout_2_option->choices[0] == priv->number_up_layout_n_option->choices[0] &&
priv->number_up_layout_2_option->choices[1] == priv->number_up_layout_n_option->choices[1]))
{
g_free (priv->number_up_layout_2_option->choices_display[0]);
g_free (priv->number_up_layout_2_option->choices_display[1]);
priv->number_up_layout_2_option->choices[0] = priv->number_up_layout_n_option->choices[0];
priv->number_up_layout_2_option->choices[1] = priv->number_up_layout_n_option->choices[1];
priv->number_up_layout_2_option->choices_display[0] = g_strdup ( _("Top to bottom"));
priv->number_up_layout_2_option->choices_display[1] = g_strdup ( _("Bottom to top"));
}
}
layout = dialog_get_number_up_layout (dialog);
......@@ -2468,12 +2516,20 @@ update_number_up_layout (GtkPrintUnixDialog *dialog)
option = priv->number_up_layout_2_option;
if (layout == GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM ||
layout == GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_BOTTOM_TO_TOP ||
layout == GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_LEFT_TO_RIGHT ||
layout == GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_LEFT_TO_RIGHT)
layout == GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_LEFT_TO_RIGHT)
enum_value = g_enum_get_value (enum_class, GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM);
else
if (layout == GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_BOTTOM_TO_TOP ||
layout == GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_LEFT_TO_RIGHT)
enum_value = g_enum_get_value (enum_class, GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_BOTTOM_TO_TOP);
if (layout == GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_TOP_TO_BOTTOM ||
layout == GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_RIGHT_TO_LEFT)
enum_value = g_enum_get_value (enum_class, GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_TOP_TO_BOTTOM);
if (layout == GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_BOTTOM_TO_TOP ||
layout == GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_RIGHT_TO_LEFT)
enum_value = g_enum_get_value (enum_class, GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_BOTTOM_TO_TOP);
}
else
{
......
......@@ -383,7 +383,8 @@ static const ipp_option_t ipp_options[] = {
{ "saturation", IPP_TAG_INTEGER },
{ "scaling", IPP_TAG_INTEGER },
{ "sides", IPP_TAG_KEYWORD },
{ "wrap", IPP_TAG_BOOLEAN }
{ "wrap", IPP_TAG_BOOLEAN },
{ "number-up-layout", IPP_TAG_INTEGER }
};
......
......@@ -647,6 +647,10 @@ file_printer_get_settings_from_options (GtkPrinter *printer,
option = gtk_printer_option_set_lookup (options, "gtk-n-up");
if (option)
gtk_print_settings_set (settings, GTK_PRINT_SETTINGS_NUMBER_UP, option->value);
option = gtk_printer_option_set_lookup (options, "gtk-n-up-layout");
if (option)
gtk_print_settings_set (settings, GTK_PRINT_SETTINGS_NUMBER_UP_LAYOUT, option->value);
}
static void
......@@ -669,6 +673,8 @@ file_printer_prepare_for_print (GtkPrinter *printer,
print_job->collate = gtk_print_settings_get_collate (settings);
print_job->reverse = gtk_print_settings_get_reverse (settings);
print_job->num_copies = gtk_print_settings_get_n_copies (settings);
print_job->number_up = gtk_print_settings_get_number_up (settings);
print_job->number_up_layout = gtk_print_settings_get_number_up_layout (settings);
scale = gtk_print_settings_get_scale (settings);
if (scale != 100.0)
......
......@@ -450,7 +450,16 @@ lpr_printer_get_settings_from_options (GtkPrinter *printer,
GtkPrinterOption *option;
option = gtk_printer_option_set_lookup (options, "gtk-main-page-custom-input");
gtk_print_settings_set (settings, "lpr-commandline", option->value);
if (option)
gtk_print_settings_set (settings, "lpr-commandline", option->value);
option = gtk_printer_option_set_lookup (options, "gtk-n-up");
if (option)
gtk_print_settings_set (settings, GTK_PRINT_SETTINGS_NUMBER_UP, option->value);
option = gtk_printer_option_set_lookup (options, "gtk-n-up-layout");
if (option)
gtk_print_settings_set (settings, GTK_PRINT_SETTINGS_NUMBER_UP_LAYOUT, option->value);
}
static void
......@@ -473,6 +482,8 @@ lpr_printer_prepare_for_print (GtkPrinter *printer,
print_job->collate = gtk_print_settings_get_collate (settings);
print_job->reverse = gtk_print_settings_get_reverse (settings);
print_job->num_copies = gtk_print_settings_get_n_copies (settings);
print_job->number_up = gtk_print_settings_get_number_up (settings);
print_job->number_up_layout = gtk_print_settings_get_number_up_layout (settings);
scale = gtk_print_settings_get_scale (settings);
if (scale != 100.0)
......
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