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

Bug 535158 – can't rearrange the order of multi pages per side

2008-08-21  Marek Kasik  <mkasik@redhat.com>

	Bug 535158 – can't rearrange the order of multi pages per side

	* gtk/gtkprinter.c
	* gtk/gtkprinter.h
	* gtk/gtkprintunixdialog.c
	* gtk/gtkprintsettings.c
	* gtk/gtkprintsettings.h
	* gtk/gtkenums.h
	* modules/printbackends/cups/gtkprintbackendcups.c: Allow user to
	specify layout of pages per sheet in number-up mode

svn path=/trunk/; revision=21175
parent 0f942a3c
......@@ -487,6 +487,18 @@ typedef enum
GTK_PAGE_SET_ODD
} GtkPageSet;
typedef enum
{
GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM,
GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_BOTTOM_TO_TOP,
GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_TOP_TO_BOTTOM,
GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_BOTTOM_TO_TOP,
GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_LEFT_TO_RIGHT,
GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_RIGHT_TO_LEFT,
GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_LEFT_TO_RIGHT,
GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_RIGHT_TO_LEFT
} GtkNumberUpLayout;
typedef enum
{
GTK_PAGE_ORIENTATION_PORTRAIT,
......
......@@ -1224,6 +1224,7 @@ gtk_print_capabilities_get_type (void)
{ GTK_PRINT_CAPABILITY_GENERATE_PS, "GTK_PRINT_CAPABILITY_GENERATE_PS", "generate-ps" },
{ GTK_PRINT_CAPABILITY_PREVIEW, "GTK_PRINT_CAPABILITY_PREVIEW", "preview" },
{ GTK_PRINT_CAPABILITY_NUMBER_UP, "GTK_PRINT_CAPABILITY_NUMBER_UP", "number-up"},
{ GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT, "GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT", "number-up-layout" },
{ 0, NULL, NULL }
};
......
......@@ -36,15 +36,16 @@ G_BEGIN_DECLS
*/
typedef enum
{
GTK_PRINT_CAPABILITY_PAGE_SET = 1 << 0,
GTK_PRINT_CAPABILITY_COPIES = 1 << 1,
GTK_PRINT_CAPABILITY_COLLATE = 1 << 2,
GTK_PRINT_CAPABILITY_REVERSE = 1 << 3,
GTK_PRINT_CAPABILITY_SCALE = 1 << 4,
GTK_PRINT_CAPABILITY_GENERATE_PDF = 1 << 5,
GTK_PRINT_CAPABILITY_GENERATE_PS = 1 << 6,
GTK_PRINT_CAPABILITY_PREVIEW = 1 << 7,
GTK_PRINT_CAPABILITY_NUMBER_UP = 1 << 8
GTK_PRINT_CAPABILITY_PAGE_SET = 1 << 0,
GTK_PRINT_CAPABILITY_COPIES = 1 << 1,
GTK_PRINT_CAPABILITY_COLLATE = 1 << 2,
GTK_PRINT_CAPABILITY_REVERSE = 1 << 3,
GTK_PRINT_CAPABILITY_SCALE = 1 << 4,
GTK_PRINT_CAPABILITY_GENERATE_PDF = 1 << 5,
GTK_PRINT_CAPABILITY_GENERATE_PS = 1 << 6,
GTK_PRINT_CAPABILITY_PREVIEW = 1 << 7,
GTK_PRINT_CAPABILITY_NUMBER_UP = 1 << 8,
GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT = 1 << 9
} GtkPrintCapabilities;
GType gtk_print_capabilities_get_type (void) G_GNUC_CONST;
......
......@@ -25,6 +25,7 @@
#include "gtkprintsettings.h"
#include "gtkprintutils.h"
#include "gtkalias.h"
#include <gtk/gtk.h>
typedef struct _GtkPrintSettingsClass GtkPrintSettingsClass;
......@@ -1038,6 +1039,108 @@ gtk_print_settings_set_page_set (GtkPrintSettings *settings,
gtk_print_settings_set (settings, GTK_PRINT_SETTINGS_PAGE_SET, str);
}
/**
* gtk_print_settings_get_number_up_layout:
* @settings: a #GtkPrintSettings
*
* Gets the value of %GTK_PRINT_SETTINGS_NUMBER_UP_LAYOUT.
*
* Return value: layout of page in number-up mode
*
* Since: 2.14
*/
GtkNumberUpLayout
gtk_print_settings_get_number_up_layout (GtkPrintSettings *settings)
{
GtkNumberUpLayout layout;
GtkTextDirection text_direction;
const gchar *val;
val = gtk_print_settings_get (settings, GTK_PRINT_SETTINGS_NUMBER_UP_LAYOUT);
text_direction = gtk_widget_get_default_direction ();
if (text_direction == GTK_TEXT_DIR_LTR)
layout = GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM;
else
layout = GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_TOP_TO_BOTTOM;
if (val == NULL)
return layout;
if (strcmp (val, "lrtb") == 0)
return GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM;
if (strcmp (val, "lrbt") == 0)
return GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_BOTTOM_TO_TOP;
if (strcmp (val, "rltb") == 0)
return GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_TOP_TO_BOTTOM;
if (strcmp (val, "rlbt") == 0)
return GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_BOTTOM_TO_TOP;
if (strcmp (val, "tblr") == 0)
return GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_LEFT_TO_RIGHT;
if (strcmp (val, "tbrl") == 0)
return GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_RIGHT_TO_LEFT;
if (strcmp (val, "btlr") == 0)
return GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_LEFT_TO_RIGHT;
if (strcmp (val, "btrl") == 0)
return GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_RIGHT_TO_LEFT;
return layout;
}
/**
* gtk_print_settings_set_number_up_layout:
* @settings: a #GtkPrintSettings
* @number_up_layout: a #GtkNumberUpLayout value
*
* Sets the value of %GTK_PRINT_SETTINGS_NUMBER_UP_LAYOUT.
*
* Since: 2.14
*/
void
gtk_print_settings_set_number_up_layout (GtkPrintSettings *settings,
GtkNumberUpLayout number_up_layout)
{
const gchar *str;
switch (number_up_layout)
{
default:
case GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM:
str = "lrtb";
break;
case GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_BOTTOM_TO_TOP:
str = "lrbt";
break;
case GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_TOP_TO_BOTTOM:
str = "rltb";
break;
case GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_BOTTOM_TO_TOP:
str = "rlbt";
break;
case GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_LEFT_TO_RIGHT:
str = "tblr";
break;
case GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_RIGHT_TO_LEFT:
str = "tbrl";
break;
case GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_LEFT_TO_RIGHT:
str = "btlr";
break;
case GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_RIGHT_TO_LEFT:
str = "btrl";
break;
}
gtk_print_settings_set (settings, GTK_PRINT_SETTINGS_NUMBER_UP_LAYOUT, str);
}
/**
* gtk_print_settings_get_n_copies:
* @settings: a #GtkPrintSettings
......
......@@ -46,8 +46,8 @@ struct _GtkPageRange
gint end;
};
GType gtk_print_settings_get_type (void) G_GNUC_CONST;
GtkPrintSettings *gtk_print_settings_new (void);
GType gtk_print_settings_get_type (void) G_GNUC_CONST;
GtkPrintSettings *gtk_print_settings_new (void);
GtkPrintSettings *gtk_print_settings_copy (GtkPrintSettings *other);
......@@ -71,7 +71,7 @@ void gtk_print_settings_to_key_file (GtkPrintSettings
const gchar *group_name);
gboolean gtk_print_settings_has_key (GtkPrintSettings *settings,
const gchar *key);
G_CONST_RETURN gchar *gtk_print_settings_get (GtkPrintSettings *settings,
G_CONST_RETURN gchar *gtk_print_settings_get (GtkPrintSettings *settings,
const gchar *key);
void gtk_print_settings_set (GtkPrintSettings *settings,
const gchar *key,
......@@ -110,28 +110,29 @@ void gtk_print_settings_set_int (GtkPrintSettings
const gchar *key,
gint value);
#define GTK_PRINT_SETTINGS_PRINTER "printer"
#define GTK_PRINT_SETTINGS_ORIENTATION "orientation"
#define GTK_PRINT_SETTINGS_PAPER_FORMAT "paper-format"
#define GTK_PRINT_SETTINGS_PAPER_WIDTH "paper-width"
#define GTK_PRINT_SETTINGS_PAPER_HEIGHT "paper-height"
#define GTK_PRINT_SETTINGS_N_COPIES "n-copies"
#define GTK_PRINT_SETTINGS_DEFAULT_SOURCE "default-source"
#define GTK_PRINT_SETTINGS_QUALITY "quality"
#define GTK_PRINT_SETTINGS_RESOLUTION "resolution"
#define GTK_PRINT_SETTINGS_USE_COLOR "use-color"
#define GTK_PRINT_SETTINGS_DUPLEX "duplex"
#define GTK_PRINT_SETTINGS_COLLATE "collate"
#define GTK_PRINT_SETTINGS_REVERSE "reverse"
#define GTK_PRINT_SETTINGS_MEDIA_TYPE "media-type"
#define GTK_PRINT_SETTINGS_DITHER "dither"
#define GTK_PRINT_SETTINGS_SCALE "scale"
#define GTK_PRINT_SETTINGS_PRINT_PAGES "print-pages"
#define GTK_PRINT_SETTINGS_PAGE_RANGES "page-ranges"
#define GTK_PRINT_SETTINGS_PAGE_SET "page-set"
#define GTK_PRINT_SETTINGS_FINISHINGS "finishings"
#define GTK_PRINT_SETTINGS_NUMBER_UP "number-up"
#define GTK_PRINT_SETTINGS_OUTPUT_BIN "output-bin"
#define GTK_PRINT_SETTINGS_PRINTER "printer"
#define GTK_PRINT_SETTINGS_ORIENTATION "orientation"
#define GTK_PRINT_SETTINGS_PAPER_FORMAT "paper-format"
#define GTK_PRINT_SETTINGS_PAPER_WIDTH "paper-width"
#define GTK_PRINT_SETTINGS_PAPER_HEIGHT "paper-height"
#define GTK_PRINT_SETTINGS_N_COPIES "n-copies"
#define GTK_PRINT_SETTINGS_DEFAULT_SOURCE "default-source"
#define GTK_PRINT_SETTINGS_QUALITY "quality"
#define GTK_PRINT_SETTINGS_RESOLUTION "resolution"
#define GTK_PRINT_SETTINGS_USE_COLOR "use-color"
#define GTK_PRINT_SETTINGS_DUPLEX "duplex"
#define GTK_PRINT_SETTINGS_COLLATE "collate"
#define GTK_PRINT_SETTINGS_REVERSE "reverse"
#define GTK_PRINT_SETTINGS_MEDIA_TYPE "media-type"
#define GTK_PRINT_SETTINGS_DITHER "dither"
#define GTK_PRINT_SETTINGS_SCALE "scale"
#define GTK_PRINT_SETTINGS_PRINT_PAGES "print-pages"
#define GTK_PRINT_SETTINGS_PAGE_RANGES "page-ranges"
#define GTK_PRINT_SETTINGS_PAGE_SET "page-set"
#define GTK_PRINT_SETTINGS_FINISHINGS "finishings"
#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_OUTPUT_FILE_FORMAT "output-file-format"
#define GTK_PRINT_SETTINGS_OUTPUT_URI "output-uri"
......@@ -141,78 +142,81 @@ void gtk_print_settings_set_int (GtkPrintSettings
/* Helpers: */
G_CONST_RETURN gchar *gtk_print_settings_get_printer (GtkPrintSettings *settings);
void gtk_print_settings_set_printer (GtkPrintSettings *settings,
const gchar *printer);
GtkPageOrientation gtk_print_settings_get_orientation (GtkPrintSettings *settings);
void gtk_print_settings_set_orientation (GtkPrintSettings *settings,
GtkPageOrientation orientation);
GtkPaperSize * gtk_print_settings_get_paper_size (GtkPrintSettings *settings);
void gtk_print_settings_set_paper_size (GtkPrintSettings *settings,
GtkPaperSize *paper_size);
gdouble gtk_print_settings_get_paper_width (GtkPrintSettings *settings,
GtkUnit unit);
void gtk_print_settings_set_paper_width (GtkPrintSettings *settings,
gdouble width,
GtkUnit unit);
gdouble gtk_print_settings_get_paper_height (GtkPrintSettings *settings,
GtkUnit unit);
void gtk_print_settings_set_paper_height (GtkPrintSettings *settings,
gdouble height,
GtkUnit unit);
gboolean gtk_print_settings_get_use_color (GtkPrintSettings *settings);
void gtk_print_settings_set_use_color (GtkPrintSettings *settings,
gboolean use_color);
gboolean gtk_print_settings_get_collate (GtkPrintSettings *settings);
void gtk_print_settings_set_collate (GtkPrintSettings *settings,
gboolean collate);
gboolean gtk_print_settings_get_reverse (GtkPrintSettings *settings);
void gtk_print_settings_set_reverse (GtkPrintSettings *settings,
gboolean reverse);
GtkPrintDuplex gtk_print_settings_get_duplex (GtkPrintSettings *settings);
void gtk_print_settings_set_duplex (GtkPrintSettings *settings,
GtkPrintDuplex duplex);
GtkPrintQuality gtk_print_settings_get_quality (GtkPrintSettings *settings);
void gtk_print_settings_set_quality (GtkPrintSettings *settings,
GtkPrintQuality quality);
gint gtk_print_settings_get_n_copies (GtkPrintSettings *settings);
void gtk_print_settings_set_n_copies (GtkPrintSettings *settings,
gint num_copies);
gint gtk_print_settings_get_number_up (GtkPrintSettings *settings);
void gtk_print_settings_set_number_up (GtkPrintSettings *settings,
gint number_up);
gint gtk_print_settings_get_resolution (GtkPrintSettings *settings);
void gtk_print_settings_set_resolution (GtkPrintSettings *settings,
gint resolution);
gdouble gtk_print_settings_get_scale (GtkPrintSettings *settings);
void gtk_print_settings_set_scale (GtkPrintSettings *settings,
gdouble scale);
GtkPrintPages gtk_print_settings_get_print_pages (GtkPrintSettings *settings);
void gtk_print_settings_set_print_pages (GtkPrintSettings *settings,
GtkPrintPages pages);
GtkPageRange * gtk_print_settings_get_page_ranges (GtkPrintSettings *settings,
gint *num_ranges);
void gtk_print_settings_set_page_ranges (GtkPrintSettings *settings,
GtkPageRange *page_ranges,
gint num_ranges);
GtkPageSet gtk_print_settings_get_page_set (GtkPrintSettings *settings);
void gtk_print_settings_set_page_set (GtkPrintSettings *settings,
GtkPageSet page_set);
G_CONST_RETURN gchar *gtk_print_settings_get_default_source (GtkPrintSettings *settings);
void gtk_print_settings_set_default_source (GtkPrintSettings *settings,
const gchar *default_source);
G_CONST_RETURN gchar *gtk_print_settings_get_media_type (GtkPrintSettings *settings);
void gtk_print_settings_set_media_type (GtkPrintSettings *settings,
const gchar *media_type);
G_CONST_RETURN gchar *gtk_print_settings_get_dither (GtkPrintSettings *settings);
void gtk_print_settings_set_dither (GtkPrintSettings *settings,
const gchar *dither);
G_CONST_RETURN gchar *gtk_print_settings_get_finishings (GtkPrintSettings *settings);
void gtk_print_settings_set_finishings (GtkPrintSettings *settings,
const gchar *finishings);
G_CONST_RETURN gchar *gtk_print_settings_get_output_bin (GtkPrintSettings *settings);
void gtk_print_settings_set_output_bin (GtkPrintSettings *settings,
const gchar *output_bin);
G_CONST_RETURN gchar *gtk_print_settings_get_printer (GtkPrintSettings *settings);
void gtk_print_settings_set_printer (GtkPrintSettings *settings,
const gchar *printer);
GtkPageOrientation gtk_print_settings_get_orientation (GtkPrintSettings *settings);
void gtk_print_settings_set_orientation (GtkPrintSettings *settings,
GtkPageOrientation orientation);
GtkPaperSize * gtk_print_settings_get_paper_size (GtkPrintSettings *settings);
void gtk_print_settings_set_paper_size (GtkPrintSettings *settings,
GtkPaperSize *paper_size);
gdouble gtk_print_settings_get_paper_width (GtkPrintSettings *settings,
GtkUnit unit);
void gtk_print_settings_set_paper_width (GtkPrintSettings *settings,
gdouble width,
GtkUnit unit);
gdouble gtk_print_settings_get_paper_height (GtkPrintSettings *settings,
GtkUnit unit);
void gtk_print_settings_set_paper_height (GtkPrintSettings *settings,
gdouble height,
GtkUnit unit);
gboolean gtk_print_settings_get_use_color (GtkPrintSettings *settings);
void gtk_print_settings_set_use_color (GtkPrintSettings *settings,
gboolean use_color);
gboolean gtk_print_settings_get_collate (GtkPrintSettings *settings);
void gtk_print_settings_set_collate (GtkPrintSettings *settings,
gboolean collate);
gboolean gtk_print_settings_get_reverse (GtkPrintSettings *settings);
void gtk_print_settings_set_reverse (GtkPrintSettings *settings,
gboolean reverse);
GtkPrintDuplex gtk_print_settings_get_duplex (GtkPrintSettings *settings);
void gtk_print_settings_set_duplex (GtkPrintSettings *settings,
GtkPrintDuplex duplex);
GtkPrintQuality gtk_print_settings_get_quality (GtkPrintSettings *settings);
void gtk_print_settings_set_quality (GtkPrintSettings *settings,
GtkPrintQuality quality);
gint gtk_print_settings_get_n_copies (GtkPrintSettings *settings);
void gtk_print_settings_set_n_copies (GtkPrintSettings *settings,
gint num_copies);
gint gtk_print_settings_get_number_up (GtkPrintSettings *settings);
void gtk_print_settings_set_number_up (GtkPrintSettings *settings,
gint number_up);
GtkNumberUpLayout gtk_print_settings_get_number_up_layout (GtkPrintSettings *settings);
void gtk_print_settings_set_number_up_layout (GtkPrintSettings *settings,
GtkNumberUpLayout number_up_layout);
gint gtk_print_settings_get_resolution (GtkPrintSettings *settings);
void gtk_print_settings_set_resolution (GtkPrintSettings *settings,
gint resolution);
gdouble gtk_print_settings_get_scale (GtkPrintSettings *settings);
void gtk_print_settings_set_scale (GtkPrintSettings *settings,
gdouble scale);
GtkPrintPages gtk_print_settings_get_print_pages (GtkPrintSettings *settings);
void gtk_print_settings_set_print_pages (GtkPrintSettings *settings,
GtkPrintPages pages);
GtkPageRange * gtk_print_settings_get_page_ranges (GtkPrintSettings *settings,
gint *num_ranges);
void gtk_print_settings_set_page_ranges (GtkPrintSettings *settings,
GtkPageRange *page_ranges,
gint num_ranges);
GtkPageSet gtk_print_settings_get_page_set (GtkPrintSettings *settings);
void gtk_print_settings_set_page_set (GtkPrintSettings *settings,
GtkPageSet page_set);
G_CONST_RETURN gchar *gtk_print_settings_get_default_source (GtkPrintSettings *settings);
void gtk_print_settings_set_default_source (GtkPrintSettings *settings,
const gchar *default_source);
G_CONST_RETURN gchar *gtk_print_settings_get_media_type (GtkPrintSettings *settings);
void gtk_print_settings_set_media_type (GtkPrintSettings *settings,
const gchar *media_type);
G_CONST_RETURN gchar *gtk_print_settings_get_dither (GtkPrintSettings *settings);
void gtk_print_settings_set_dither (GtkPrintSettings *settings,
const gchar *dither);
G_CONST_RETURN gchar *gtk_print_settings_get_finishings (GtkPrintSettings *settings);
void gtk_print_settings_set_finishings (GtkPrintSettings *settings,
const gchar *finishings);
G_CONST_RETURN gchar *gtk_print_settings_get_output_bin (GtkPrintSettings *settings);
void gtk_print_settings_set_output_bin (GtkPrintSettings *settings,
const gchar *output_bin);
G_END_DECLS
......
......@@ -168,6 +168,7 @@ struct GtkPrintUnixDialogPrivate
GtkPrinterOptionWidget *billing_info;
GtkPrinterOptionWidget *cover_before;
GtkPrinterOptionWidget *cover_after;
GtkPrinterOptionWidget *number_up_layout;
GtkWidget *conflicts_widget;
......@@ -189,6 +190,9 @@ struct GtkPrintUnixDialogPrivate
* is changed by the user it is cleared.
*/
GtkPrintSettings *initial_settings;
GtkPrinterOption *number_up_layout_n_option;
GtkPrinterOption *number_up_layout_2_option;
/* This is the initial printer set by set_settings. We look for it in the
* added printers. We clear this whenever the user manually changes
......@@ -415,6 +419,8 @@ gtk_print_unix_dialog_init (GtkPrintUnixDialog *dialog)
priv = dialog->priv = GTK_PRINT_UNIX_DIALOG_GET_PRIVATE (dialog);
priv->print_backends = NULL;
priv->current_page = -1;
priv->number_up_layout_n_option = NULL;
priv->number_up_layout_2_option = NULL;
priv->page_setup = gtk_page_setup_new ();
priv->page_setup_set = FALSE;
......@@ -509,6 +515,24 @@ gtk_print_unix_dialog_finalize (GObject *object)
priv->options = NULL;
}
if (priv->number_up_layout_2_option)
{
priv->number_up_layout_2_option->choices[0] = NULL;
priv->number_up_layout_2_option->choices[1] = NULL;
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_display[0] = NULL;
priv->number_up_layout_2_option->choices_display[1] = NULL;
g_object_unref (priv->number_up_layout_2_option);
priv->number_up_layout_2_option = NULL;
}
if (priv->number_up_layout_n_option)
{
g_object_unref (priv->number_up_layout_n_option);
priv->number_up_layout_n_option = NULL;
}
if (priv->page_setup)
{
g_object_unref (priv->page_setup);
......@@ -1149,6 +1173,7 @@ update_dialog_from_settings (GtkPrintUnixDialog *dialog)
}
setup_option (dialog, "gtk-n-up", priv->pages_per_sheet);
setup_option (dialog, "gtk-n-up-layout", priv->number_up_layout);
setup_option (dialog, "gtk-duplex", priv->duplex);
setup_option (dialog, "gtk-paper-type", priv->paper_type);
setup_option (dialog, "gtk-paper-source", priv->paper_source);
......@@ -2095,6 +2120,59 @@ dialog_get_pages_per_sheet (GtkPrintUnixDialog *dialog)
return num;
}
static GtkNumberUpLayout
dialog_get_number_up_layout (GtkPrintUnixDialog *dialog)
{
GtkPrintUnixDialogPrivate *priv = dialog->priv;
GtkPrintCapabilities caps;
GtkNumberUpLayout layout;
GtkTextDirection text_direction;
const gchar *val;
val = gtk_printer_option_widget_get_value (priv->number_up_layout);
text_direction = gtk_widget_get_default_direction ();
caps = priv->manual_capabilities | priv->printer_capabilities;
if (caps & GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT)
{
if (text_direction == GTK_TEXT_DIR_LTR)
layout = GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM;
else
layout = GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_TOP_TO_BOTTOM;
}
else
layout = GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM;
if (val == NULL)
return layout;
if (strcmp (val, "lrtb") == 0)
return GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM;
if (strcmp (val, "lrbt") == 0)
return GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_BOTTOM_TO_TOP;
if (strcmp (val, "rltb") == 0)
return GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_TOP_TO_BOTTOM;
if (strcmp (val, "rlbt") == 0)
return GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_BOTTOM_TO_TOP;
if (strcmp (val, "tblr") == 0)
return GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_LEFT_TO_RIGHT;
if (strcmp (val, "tbrl") == 0)
return GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_RIGHT_TO_LEFT;
if (strcmp (val, "btlr") == 0)
return GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_LEFT_TO_RIGHT;
if (strcmp (val, "btrl") == 0)
return GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_RIGHT_TO_LEFT;
return layout;
}
static gboolean
draw_page_cb (GtkWidget *widget,
......@@ -2113,11 +2191,17 @@ draw_page_cb (GtkWidget *widget,
PangoFontDescription *font;
gchar *text;
GdkColor *color;
GtkNumberUpLayout number_up_layout;
gint start_x, end_x, start_y, end_y;
gint dx, dy;
gboolean horizontal;
orientation = gtk_page_setup_get_orientation (priv->page_setup);
landscape =
(orientation == GTK_PAGE_ORIENTATION_LANDSCAPE) ||
(orientation == GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE);
number_up_layout = dialog_get_number_up_layout (dialog);
cr = gdk_cairo_create (widget->window);
......@@ -2196,25 +2280,120 @@ draw_page_cb (GtkWidget *widget,
pango_layout_set_width (layout, page_width * PANGO_SCALE);
pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
for (y = 0; y < pages_y; y++)
switch (number_up_layout)
{
for (x = 0; x < pages_x; x++)
{
text = g_strdup_printf ("%d", i++);
pango_layout_set_text (layout, text, -1);
g_free (text);
pango_layout_get_size (layout, &layout_w, &layout_h);
cairo_save (cr);
cairo_translate (cr,
x * page_width,
y * page_height + (page_height - layout_h / 1024.0) / 2
);
pango_cairo_show_layout (cr, layout);
cairo_restore (cr);
}
default:
case GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM:
start_x = 0;
end_x = pages_x - 1;
start_y = 0;
end_y = pages_y - 1;
dx = 1;
dy = 1;
horizontal = TRUE;
break;
case GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_BOTTOM_TO_TOP:
start_x = 0;
end_x = pages_x - 1;
start_y = pages_y - 1;
end_y = 0;
dx = 1;
dy = - 1;
horizontal = TRUE;
break;
case GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_TOP_TO_BOTTOM:
start_x = pages_x - 1;
end_x = 0;
start_y = 0;
end_y = pages_y - 1;
dx = - 1;
dy = 1;
horizontal = TRUE;
break;
case GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_BOTTOM_TO_TOP:
start_x = pages_x - 1;
end_x = 0;
start_y = pages_y - 1;
end_y = 0;
dx = - 1;
dy = - 1;
horizontal = TRUE;
break;
case GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_LEFT_TO_RIGHT:
start_x = 0;
end_x = pages_x - 1;
start_y = 0;
end_y = pages_y - 1;
dx = 1;
dy = 1;
horizontal = FALSE;
break;
case GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_RIGHT_TO_LEFT:
start_x = pages_x - 1;
end_x = 0;
start_y = 0;
end_y = pages_y - 1;
dx = - 1;
dy = 1;
horizontal = FALSE;
break;
case GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_LEFT_TO_RIGHT:
start_x = 0;
end_x = pages_x - 1;
start_y = pages_y - 1;
end_y = 0;
dx = 1;
dy = - 1;
horizontal = FALSE;
break;
case GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_RIGHT_TO_LEFT:
start_x = pages_x - 1;
end_x = 0;
start_y = pages_y - 1;
end_y = 0;
dx = - 1;
dy = - 1;
horizontal = FALSE;
break;
}
if (horizontal)
for (y = start_y; y != end_y + dy; y += dy)
{
for (x = start_x; x != end_x + dx; x += dx)
{
text = g_strdup_printf ("%d", i++);
pango_layout_set_text (layout, text, -1);
g_free (text);
pango_layout_get_size (layout, &layout_w, &layout_h);
cairo_save (cr);
cairo_translate (cr,
x * page_width,
y * page_height + (page_height - layout_h / 1024.0) / 2);
pango_cairo_show_layout (cr, layout);
cairo_restore (cr);
}
}
else
for (x = start_x; x != end_x + dx; x += dx)
{
for (y = start_y; y != end_y + dy; y += dy)
{
text = g_strdup_printf ("%d", i++);
pango_layout_set_text (layout, text, -1);
g_free (text);
pango_layout_get_size (layout, &layout_w, &layout_h);
cairo_save (cr);
cairo_translate (cr,
x * page_width,
y * page_height + (page_height - layout_h / 1024.0) / 2);
pango_cairo_show_layout (cr, layout);
cairo_restore (cr);
}
}
g_object_unref (layout);
cairo_destroy (cr);
......@@ -2230,6 +2409,103 @@ redraw_page_layout_preview (GtkPrintUnixDialog *dialog)
gtk_widget_queue_draw (priv->page_layout_preview);
}
static void
update_number_up_layout (GtkPrintUnixDialog *dialog)
{
GtkPrintUnixDialogPrivate *priv = dialog->priv;
GtkPrintCapabilities caps;
GtkPrinterOptionSet *set;
GtkNumberUpLayout layout;
GtkPrinterOption *option;
GtkPrinterOption *old_option;
set = priv->options;
caps = priv->manual_capabilities | priv->printer_capabilities;
if (caps & GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT)
{
if (priv->number_up_layout_n_option == NULL)
{
priv->number_up_layout_n_option = gtk_printer_option_set_lookup (set, "gtk-n-up-layout");
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"));
}
layout = dialog_get_number_up_layout (dialog);
old_option = gtk_printer_option_set_lookup (set, "gtk-n-up-layout");
if (old_option != NULL)
gtk_printer_option_set_remove (set, old_option);
if (dialog_get_pages_per_sheet (dialog) != 1)
{
if (dialog_get_pages_per_sheet (dialog) == 2)
{
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)
gtk_printer_option_set (option, "lrtb");