OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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.h" | 5 #include "printing/print_settings.h" |
6 | 6 |
7 // TODO(jhawkins): Move platform-specific implementations to their own files. | 7 // TODO(jhawkins): Move platform-specific implementations to their own files. |
8 #if defined(USE_X11) | 8 #if defined(USE_X11) |
9 #include <gtk/gtk.h> | 9 #include <gtk/gtk.h> |
| 10 #include <gtk/gtkprinter.h> |
| 11 #include "printing/native_metafile.h" |
10 #endif // defined(USE_X11) | 12 #endif // defined(USE_X11) |
11 | 13 |
12 #include "base/atomic_sequence_num.h" | 14 #include "base/atomic_sequence_num.h" |
13 #include "base/logging.h" | 15 #include "base/logging.h" |
14 #include "base/string_piece.h" | 16 #include "base/string_piece.h" |
15 #include "base/sys_string_conversions.h" | 17 #include "base/sys_string_conversions.h" |
16 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
17 #include "printing/units.h" | 19 #include "printing/units.h" |
18 | 20 |
19 namespace printing { | 21 namespace printing { |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 gfx::Rect printable_area_device_units( | 124 gfx::Rect printable_area_device_units( |
123 (page_rect.left - paper_rect.left), | 125 (page_rect.left - paper_rect.left), |
124 (page_rect.top - paper_rect.top), | 126 (page_rect.top - paper_rect.top), |
125 (page_rect.right - page_rect.left), | 127 (page_rect.right - page_rect.left), |
126 (page_rect.bottom - page_rect.top)); | 128 (page_rect.bottom - page_rect.top)); |
127 | 129 |
128 SetPrinterPrintableArea(physical_size_device_units, | 130 SetPrinterPrintableArea(physical_size_device_units, |
129 printable_area_device_units, | 131 printable_area_device_units, |
130 72); | 132 72); |
131 } | 133 } |
132 #elif defined(OS_LINUX) | 134 #elif defined(USE_X11) |
133 void PrintSettings::Init(GtkPrintSettings* settings, | 135 void PrintSettings::Init(GtkPrintSettings* settings, |
134 GtkPageSetup* page_setup, | 136 GtkPageSetup* page_setup, |
135 const PageRanges& new_ranges, | 137 const PageRanges& new_ranges, |
136 bool print_selection_only) { | 138 bool print_selection_only) { |
137 // TODO(jhawkins): |printer_name_| and |device_name_| should be string16. | 139 // TODO(jhawkins): |printer_name_| and |device_name_| should be string16. |
138 base::StringPiece name( | 140 base::StringPiece name( |
139 reinterpret_cast<const char*>(gtk_print_settings_get_printer(settings))); | 141 reinterpret_cast<const char*>(gtk_print_settings_get_printer(settings))); |
140 printer_name_ = UTF8ToWide(name); | 142 printer_name_ = UTF8ToWide(name); |
141 device_name_ = printer_name_; | 143 device_name_ = printer_name_; |
142 ranges = new_ranges; | 144 ranges = new_ranges; |
| 145 selection_only = print_selection_only; |
143 | 146 |
144 GtkPageOrientation orientation = gtk_print_settings_get_orientation(settings); | 147 GtkPageOrientation orientation = gtk_print_settings_get_orientation(settings); |
145 landscape_ = orientation == GTK_PAGE_ORIENTATION_LANDSCAPE; | 148 landscape_ = orientation == GTK_PAGE_ORIENTATION_LANDSCAPE; |
146 selection_only = print_selection_only; | |
147 | 149 |
| 150 gfx::Size physical_size_device_units; |
| 151 gfx::Rect printable_area_device_units; |
148 dpi_ = gtk_print_settings_get_resolution(settings); | 152 dpi_ = gtk_print_settings_get_resolution(settings); |
149 | 153 if (dpi_) { |
150 // Initialize page_setup_device_units_. | 154 // Initialize page_setup_device_units_. |
151 gfx::Size physical_size_device_units( | 155 physical_size_device_units.SetSize( |
152 gtk_page_setup_get_paper_width(page_setup, GTK_UNIT_INCH) * dpi_, | 156 gtk_page_setup_get_paper_width(page_setup, GTK_UNIT_INCH) * dpi_, |
153 gtk_page_setup_get_paper_height(page_setup, GTK_UNIT_INCH) * dpi_); | 157 gtk_page_setup_get_paper_height(page_setup, GTK_UNIT_INCH) * dpi_); |
154 gfx::Rect printable_area_device_units( | 158 printable_area_device_units.SetRect( |
155 gtk_page_setup_get_left_margin(page_setup, GTK_UNIT_INCH) * dpi_, | 159 gtk_page_setup_get_left_margin(page_setup, GTK_UNIT_INCH) * dpi_, |
156 gtk_page_setup_get_top_margin(page_setup, GTK_UNIT_INCH) * dpi_, | 160 gtk_page_setup_get_top_margin(page_setup, GTK_UNIT_INCH) * dpi_, |
157 gtk_page_setup_get_page_width(page_setup, GTK_UNIT_INCH) * dpi_, | 161 gtk_page_setup_get_page_width(page_setup, GTK_UNIT_INCH) * dpi_, |
158 gtk_page_setup_get_page_height(page_setup, GTK_UNIT_INCH) * dpi_); | 162 gtk_page_setup_get_page_height(page_setup, GTK_UNIT_INCH) * dpi_); |
159 | 163 } else { |
| 164 // Use dummy values if we cannot get valid values. |
| 165 // TODO(jhawkins) Remove this hack when the Linux printing refactoring |
| 166 // finishes. |
| 167 dpi_ = kPixelsPerInch; |
| 168 double page_width_in_pixel = 8.5 * dpi_; |
| 169 double page_height_in_pixel = 11.0 * dpi_; |
| 170 physical_size_device_units.SetSize( |
| 171 static_cast<int>(page_width_in_pixel), |
| 172 static_cast<int>(page_height_in_pixel)); |
| 173 printable_area_device_units.SetRect( |
| 174 static_cast<int>( |
| 175 NativeMetafile::kLeftMarginInInch * printing::kPixelsPerInch), |
| 176 static_cast<int>( |
| 177 NativeMetafile::kTopMarginInInch * printing::kPixelsPerInch), |
| 178 page_width_in_pixel, |
| 179 page_height_in_pixel); |
| 180 } |
160 SetPrinterPrintableArea(physical_size_device_units, | 181 SetPrinterPrintableArea(physical_size_device_units, |
161 printable_area_device_units, | 182 printable_area_device_units, |
162 dpi_); | 183 dpi_); |
163 } | 184 } |
164 #endif | 185 #endif |
165 | 186 |
166 void PrintSettings::SetPrinterPrintableArea( | 187 void PrintSettings::SetPrinterPrintableArea( |
167 gfx::Size const& physical_size_device_units, | 188 gfx::Size const& physical_size_device_units, |
168 gfx::Rect const& printable_area_device_units, | 189 gfx::Rect const& printable_area_device_units, |
169 int units_per_inch) { | 190 int units_per_inch) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 dpi_ == rhs.dpi_ && | 232 dpi_ == rhs.dpi_ && |
212 landscape_ == rhs.landscape_; | 233 landscape_ == rhs.landscape_; |
213 } | 234 } |
214 | 235 |
215 int PrintSettings::NewCookie() { | 236 int PrintSettings::NewCookie() { |
216 // A cookie of 0 is used to mark a document as unassigned, count from 1. | 237 // A cookie of 0 is used to mark a document as unassigned, count from 1. |
217 return cookie_seq.GetNext() + 1; | 238 return cookie_seq.GetNext() + 1; |
218 } | 239 } |
219 | 240 |
220 } // namespace printing | 241 } // namespace printing |
OLD | NEW |