OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "printing/print_settings_initializer_gtk.h" | 5 #include "printing/print_settings_initializer_gtk.h" |
6 | 6 |
7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
8 #include <gtk/gtkunixprint.h> | 8 #include <gtk/gtkunixprint.h> |
9 | 9 |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "printing/print_settings.h" | 12 #include "printing/print_settings.h" |
13 #include "printing/units.h" | 13 #include "printing/units.h" |
14 | 14 |
15 namespace printing { | 15 namespace printing { |
16 | 16 |
17 // static | 17 // static |
18 void PrintSettingsInitializerGtk::InitPrintSettings( | 18 void PrintSettingsInitializerGtk::InitPrintSettings( |
19 GtkPrintSettings* settings, | 19 GtkPrintSettings* settings, |
20 GtkPageSetup* page_setup, | 20 GtkPageSetup* page_setup, |
21 const PageRanges& new_ranges, | |
22 bool print_selection_only, | |
23 PrintSettings* print_settings) { | 21 PrintSettings* print_settings) { |
24 DCHECK(settings); | 22 DCHECK(settings); |
25 DCHECK(page_setup); | 23 DCHECK(page_setup); |
26 DCHECK(print_settings); | 24 DCHECK(print_settings); |
27 | 25 |
28 base::string16 name(base::UTF8ToUTF16(static_cast<const char*>( | 26 base::string16 name(base::UTF8ToUTF16(static_cast<const char*>( |
29 gtk_print_settings_get_printer(settings)))); | 27 gtk_print_settings_get_printer(settings)))); |
30 print_settings->set_device_name(name); | 28 print_settings->set_device_name(name); |
31 print_settings->ranges = new_ranges; | |
32 print_settings->selection_only = print_selection_only; | |
33 | 29 |
34 gfx::Size physical_size_device_units; | 30 gfx::Size physical_size_device_units; |
35 gfx::Rect printable_area_device_units; | 31 gfx::Rect printable_area_device_units; |
36 int dpi = gtk_print_settings_get_resolution(settings); | 32 int dpi = gtk_print_settings_get_resolution(settings); |
37 if (dpi) { | 33 if (dpi) { |
38 // Initialize page_setup_device_units_. | 34 // Initialize page_setup_device_units_. |
39 physical_size_device_units.SetSize( | 35 physical_size_device_units.SetSize( |
40 gtk_page_setup_get_paper_width(page_setup, GTK_UNIT_INCH) * dpi, | 36 gtk_page_setup_get_paper_width(page_setup, GTK_UNIT_INCH) * dpi, |
41 gtk_page_setup_get_paper_height(page_setup, GTK_UNIT_INCH) * dpi); | 37 gtk_page_setup_get_paper_height(page_setup, GTK_UNIT_INCH) * dpi); |
42 printable_area_device_units.SetRect( | 38 printable_area_device_units.SetRect( |
(...skipping 10 matching lines...) Expand all Loading... |
53 static_cast<int>(page_width_in_pixel), | 49 static_cast<int>(page_width_in_pixel), |
54 static_cast<int>(page_height_in_pixel)); | 50 static_cast<int>(page_height_in_pixel)); |
55 printable_area_device_units.SetRect( | 51 printable_area_device_units.SetRect( |
56 static_cast<int>(kLeftMarginInInch * dpi), | 52 static_cast<int>(kLeftMarginInInch * dpi), |
57 static_cast<int>(kTopMarginInInch * dpi), | 53 static_cast<int>(kTopMarginInInch * dpi), |
58 page_width_in_pixel - (kLeftMarginInInch + kRightMarginInInch) * dpi, | 54 page_width_in_pixel - (kLeftMarginInInch + kRightMarginInInch) * dpi, |
59 page_height_in_pixel - (kTopMarginInInch + kBottomMarginInInch) * dpi); | 55 page_height_in_pixel - (kTopMarginInInch + kBottomMarginInInch) * dpi); |
60 } | 56 } |
61 | 57 |
62 print_settings->set_dpi(dpi); | 58 print_settings->set_dpi(dpi); |
63 print_settings->SetPrinterPrintableArea(physical_size_device_units, | |
64 printable_area_device_units, | |
65 dpi); | |
66 | 59 |
67 // Note: With the normal GTK print dialog, when the user selects the landscape | 60 // Note: With the normal GTK print dialog, when the user selects the landscape |
68 // orientation, all that does is change the paper size. Which seems to be | 61 // orientation, all that does is change the paper size. Which seems to be |
69 // enough to render the right output and send it to the printer. | 62 // enough to render the right output and send it to the printer. |
70 // The orientation value stays as portrait and does not actually affect | 63 // The orientation value stays as portrait and does not actually affect |
71 // printing. | 64 // printing. |
72 // Thus this is only useful in print preview mode, where we manually set the | 65 // Thus this is only useful in print preview mode, where we manually set the |
73 // orientation and change the paper size ourselves. | 66 // orientation and change the paper size ourselves. |
74 GtkPageOrientation orientation = gtk_print_settings_get_orientation(settings); | 67 GtkPageOrientation orientation = gtk_print_settings_get_orientation(settings); |
| 68 // Set before SetPrinterPrintableArea to make it flip area if necessary. |
75 print_settings->SetOrientation(orientation == GTK_PAGE_ORIENTATION_LANDSCAPE); | 69 print_settings->SetOrientation(orientation == GTK_PAGE_ORIENTATION_LANDSCAPE); |
| 70 |
| 71 print_settings->SetPrinterPrintableArea(physical_size_device_units, |
| 72 printable_area_device_units, |
| 73 dpi, true); |
76 } | 74 } |
77 | 75 |
78 const double PrintSettingsInitializerGtk::kTopMarginInInch = 0.25; | 76 const double PrintSettingsInitializerGtk::kTopMarginInInch = 0.25; |
79 const double PrintSettingsInitializerGtk::kBottomMarginInInch = 0.56; | 77 const double PrintSettingsInitializerGtk::kBottomMarginInInch = 0.56; |
80 const double PrintSettingsInitializerGtk::kLeftMarginInInch = 0.25; | 78 const double PrintSettingsInitializerGtk::kLeftMarginInInch = 0.25; |
81 const double PrintSettingsInitializerGtk::kRightMarginInInch = 0.25; | 79 const double PrintSettingsInitializerGtk::kRightMarginInInch = 0.25; |
82 | 80 |
83 } // namespace printing | 81 } // namespace printing |
OLD | NEW |