diff options
author | Matthias Clasen <matthiasc@src.gnome.org> | 2008-05-21 02:17:30 +0000 |
---|---|---|
committer | Matthias Clasen <matthiasc@src.gnome.org> | 2008-05-21 02:17:30 +0000 |
commit | 59ae44d00ee7876b3c69fd462d515a4f50c55b6a (patch) | |
tree | 76c8f2df967022569c134fa9e177663ffb07b27f /modules | |
parent | 75a9722aa14784e70c49b988ce28589eceb752e3 (diff) | |
download | gtk+-59ae44d00ee7876b3c69fd462d515a4f50c55b6a.tar.gz |
RH bug 204621 - "GtkPrint" asks for "Letter" size paper when "A4" size
was chosen
Patch by Marek Kasik.
* gtk/gtk.symbols:
* gtk/gtkprinter.[hc]: Add gtk_printer_get_default_page_size.
* gtk/gtkprintbackend.[hc]: Add fallback implementation.
* modules/printbackends/file/gtkprintbackendfile.c:
* modules/printbackends/cups/gtkprintbackendcups.c: Implement
get_default_page_size.
* gtk/gtkpagesetupunixdialog.c: When selecting a different printer,
select its default paper size.
* gtk/gtkprintunixdialog.c: If no explicit page setup has been set,
use the printer default.
* gtk/gtkprintoperation-unix.c: Don't create an empty page setup
if we don't have a default page setup.
svn path=/trunk/; revision=20120
Diffstat (limited to 'modules')
-rw-r--r-- | modules/printbackends/cups/gtkprintbackendcups.c | 94 | ||||
-rw-r--r-- | modules/printbackends/file/gtkprintbackendfile.c | 10 |
2 files changed, 74 insertions, 30 deletions
diff --git a/modules/printbackends/cups/gtkprintbackendcups.c b/modules/printbackends/cups/gtkprintbackendcups.c index 7277e42b21..5261e13c3e 100644 --- a/modules/printbackends/cups/gtkprintbackendcups.c +++ b/modules/printbackends/cups/gtkprintbackendcups.c @@ -136,6 +136,7 @@ static void cups_printer_prepare_for_print (GtkPrinter GtkPrintSettings *settings, GtkPageSetup *page_setup); static GList * cups_printer_list_papers (GtkPrinter *printer); +static GtkPageSetup * cups_printer_get_default_page_size (GtkPrinter *printer); static void cups_printer_request_details (GtkPrinter *printer); static void cups_request_default_printer (GtkPrintBackendCups *print_backend); static void cups_request_ppd (GtkPrinter *printer); @@ -255,6 +256,7 @@ gtk_print_backend_cups_class_init (GtkPrintBackendCupsClass *class) backend_class->printer_get_settings_from_options = cups_printer_get_settings_from_options; backend_class->printer_prepare_for_print = cups_printer_prepare_for_print; backend_class->printer_list_papers = cups_printer_list_papers; + backend_class->printer_get_default_page_size = cups_printer_get_default_page_size; backend_class->printer_get_hard_margins = cups_printer_get_hard_margins; backend_class->printer_get_capabilities = cups_printer_get_capabilities; } @@ -1437,6 +1439,8 @@ cups_request_ppd_cb (GtkPrintBackendCups *print_backend, /* let ppdOpenFd take over the ownership of the open file */ g_io_channel_seek_position (data->ppd_io, 0, G_SEEK_SET, NULL); data->printer->ppd_file = ppdOpenFd (dup (g_io_channel_unix_get_fd (data->ppd_io))); + + ppdMarkDefaults (data->printer->ppd_file); gtk_printer_set_has_details (printer, TRUE); g_signal_emit_by_name (printer, "details-acquired", TRUE); @@ -3121,16 +3125,52 @@ cups_printer_prepare_for_print (GtkPrinter *printer, print_job->rotate_to_orientation = TRUE; } +static GtkPageSetup * +create_page_setup (ppd_file_t *ppd_file, + ppd_size_t *size) + { + char *display_name; + GtkPageSetup *page_setup; + GtkPaperSize *paper_size; + ppd_option_t *option; + ppd_choice_t *choice; + + display_name = NULL; + option = ppdFindOption (ppd_file, "PageSize"); + if (option) + { + choice = ppdFindChoice (option, size->name); + if (choice) + display_name = ppd_text_to_utf8 (ppd_file, choice->text); + } + + if (display_name == NULL) + display_name = g_strdup (size->name); + + page_setup = gtk_page_setup_new (); + paper_size = gtk_paper_size_new_from_ppd (size->name, + display_name, + size->width, + size->length); + gtk_page_setup_set_paper_size (page_setup, paper_size); + gtk_paper_size_free (paper_size); + + gtk_page_setup_set_top_margin (page_setup, size->length - size->top, GTK_UNIT_POINTS); + gtk_page_setup_set_bottom_margin (page_setup, size->bottom, GTK_UNIT_POINTS); + gtk_page_setup_set_left_margin (page_setup, size->left, GTK_UNIT_POINTS); + gtk_page_setup_set_right_margin (page_setup, size->width - size->right, GTK_UNIT_POINTS); + + g_free (display_name); + + return page_setup; +} + static GList * cups_printer_list_papers (GtkPrinter *printer) { ppd_file_t *ppd_file; ppd_size_t *size; - char *display_name; GtkPageSetup *page_setup; - GtkPaperSize *paper_size; - ppd_option_t *option; - ppd_choice_t *choice; GList *l; int i; @@ -3142,33 +3182,9 @@ cups_printer_list_papers (GtkPrinter *printer) for (i = 0; i < ppd_file->num_sizes; i++) { - size = &ppd_file->sizes[i]; + size = &ppd_file->sizes[i]; - display_name = NULL; - option = ppdFindOption (ppd_file, "PageSize"); - if (option) - { - choice = ppdFindChoice (option, size->name); - if (choice) - display_name = ppd_text_to_utf8 (ppd_file, choice->text); - } - if (display_name == NULL) - display_name = g_strdup (size->name); - - page_setup = gtk_page_setup_new (); - paper_size = gtk_paper_size_new_from_ppd (size->name, - display_name, - size->width, - size->length); - gtk_page_setup_set_paper_size (page_setup, paper_size); - gtk_paper_size_free (paper_size); - - gtk_page_setup_set_top_margin (page_setup, size->length - size->top, GTK_UNIT_POINTS); - gtk_page_setup_set_bottom_margin (page_setup, size->bottom, GTK_UNIT_POINTS); - gtk_page_setup_set_left_margin (page_setup, size->left, GTK_UNIT_POINTS); - gtk_page_setup_set_right_margin (page_setup, size->width - size->right, GTK_UNIT_POINTS); - - g_free (display_name); + page_setup = create_page_setup (ppd_file, size); l = g_list_prepend (l, page_setup); } @@ -3176,6 +3192,24 @@ cups_printer_list_papers (GtkPrinter *printer) return g_list_reverse (l); } +static GtkPageSetup * +cups_printer_get_default_page_size (GtkPrinter *printer) +{ + ppd_file_t *ppd_file; + ppd_size_t *size; + ppd_option_t *option; + + + ppd_file = gtk_printer_cups_get_ppd (GTK_PRINTER_CUPS (printer)); + if (ppd_file == NULL) + return NULL; + + option = ppdFindOption (ppd_file, "PageSize"); + size = ppdPageSize (ppd_file, option->defchoice); + + return create_page_setup (ppd_file, size); +} + static void cups_printer_get_hard_margins (GtkPrinter *printer, gdouble *top, diff --git a/modules/printbackends/file/gtkprintbackendfile.c b/modules/printbackends/file/gtkprintbackendfile.c index a83d5bc05d..58b787919c 100644 --- a/modules/printbackends/file/gtkprintbackendfile.c +++ b/modules/printbackends/file/gtkprintbackendfile.c @@ -104,6 +104,7 @@ static cairo_surface_t * file_printer_create_cairo_surface (GtkPrinter GIOChannel *cache_io); static GList * file_printer_list_papers (GtkPrinter *printer); +static GtkPageSetup * file_printer_get_default_page_size (GtkPrinter *printer); static void gtk_print_backend_file_register_type (GTypeModule *module) @@ -182,6 +183,7 @@ gtk_print_backend_file_class_init (GtkPrintBackendFileClass *class) backend_class->printer_get_settings_from_options = file_printer_get_settings_from_options; backend_class->printer_prepare_for_print = file_printer_prepare_for_print; backend_class->printer_list_papers = file_printer_list_papers; + backend_class->printer_get_default_page_size = file_printer_get_default_page_size; } /* return N_FORMATS if no explicit format in the settings */ @@ -697,3 +699,11 @@ file_printer_list_papers (GtkPrinter *printer) return g_list_reverse (result); } + +static GtkPageSetup * +file_printer_get_default_page_size (GtkPrinter *printer) +{ + GtkPageSetup *result = NULL; + + return result; +} |