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.h" | 5 #include "printing/print_settings.h" |
6 | 6 |
7 #include "base/atomic_sequence_num.h" | 7 #include "base/atomic_sequence_num.h" |
| 8 #include "base/logging.h" |
8 #include "printing/print_job_constants.h" | 9 #include "printing/print_job_constants.h" |
9 #include "printing/units.h" | 10 #include "printing/units.h" |
10 | 11 |
11 namespace printing { | 12 namespace printing { |
12 | 13 |
13 #if defined (USE_CUPS) | 14 #if defined (USE_CUPS) |
14 void GetColorModelForMode( | 15 void GetColorModelForMode( |
15 int color_mode, std::string* color_setting_name, std::string* color_value) { | 16 int color_mode, std::string* color_setting_name, std::string* color_value) { |
16 #if defined(OS_MACOSX) | 17 #if defined(OS_MACOSX) |
17 const char kCUPSColorMode[] = "ColorMode"; | 18 const char kCUPSColorMode[] = "ColorMode"; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 } | 108 } |
108 | 109 |
109 // Global SequenceNumber used for generating unique cookie values. | 110 // Global SequenceNumber used for generating unique cookie values. |
110 static base::AtomicSequenceNumber cookie_seq(base::LINKER_INITIALIZED); | 111 static base::AtomicSequenceNumber cookie_seq(base::LINKER_INITIALIZED); |
111 | 112 |
112 PrintSettings::PrintSettings() | 113 PrintSettings::PrintSettings() |
113 : min_shrink(1.25), | 114 : min_shrink(1.25), |
114 max_shrink(2.0), | 115 max_shrink(2.0), |
115 desired_dpi(72), | 116 desired_dpi(72), |
116 selection_only(false), | 117 selection_only(false), |
117 use_overlays(true), | 118 margin_type(DEFAULT_MARGINS), |
118 display_header_footer(false), | 119 display_header_footer(false), |
119 dpi_(0), | 120 dpi_(0), |
120 landscape_(false), | 121 landscape_(false), |
121 supports_alpha_blend_(true) { | 122 supports_alpha_blend_(true) { |
122 } | 123 } |
123 | 124 |
124 PrintSettings::~PrintSettings() { | 125 PrintSettings::~PrintSettings() { |
125 } | 126 } |
126 | 127 |
127 void PrintSettings::Clear() { | 128 void PrintSettings::Clear() { |
(...skipping 11 matching lines...) Expand all Loading... |
139 page_setup_device_units_.Clear(); | 140 page_setup_device_units_.Clear(); |
140 dpi_ = 0; | 141 dpi_ = 0; |
141 landscape_ = false; | 142 landscape_ = false; |
142 supports_alpha_blend_ = true; | 143 supports_alpha_blend_ = true; |
143 } | 144 } |
144 | 145 |
145 void PrintSettings::SetPrinterPrintableArea( | 146 void PrintSettings::SetPrinterPrintableArea( |
146 gfx::Size const& physical_size_device_units, | 147 gfx::Size const& physical_size_device_units, |
147 gfx::Rect const& printable_area_device_units, | 148 gfx::Rect const& printable_area_device_units, |
148 int units_per_inch) { | 149 int units_per_inch) { |
149 | |
150 int header_footer_text_height = 0; | 150 int header_footer_text_height = 0; |
151 int margin_printer_units = 0; | 151 if (display_header_footer) { |
152 if (use_overlays) { | |
153 // Hard-code text_height = 0.5cm = ~1/5 of inch. | 152 // Hard-code text_height = 0.5cm = ~1/5 of inch. |
154 header_footer_text_height = ConvertUnit(kSettingHeaderFooterInterstice, | 153 header_footer_text_height = ConvertUnit(kSettingHeaderFooterInterstice, |
155 kPointsPerInch, units_per_inch); | 154 kPointsPerInch, units_per_inch); |
156 // Default margins 1.0cm = ~2/5 of an inch. | |
157 margin_printer_units = ConvertUnit(1000, kHundrethsMMPerInch, | |
158 units_per_inch); | |
159 } | 155 } |
160 // Start by setting the user configuration | |
161 page_setup_device_units_.Init(physical_size_device_units, | 156 page_setup_device_units_.Init(physical_size_device_units, |
162 printable_area_device_units, | 157 printable_area_device_units, |
163 header_footer_text_height); | 158 header_footer_text_height); |
164 | 159 |
165 | |
166 // Apply default margins (not user configurable just yet). | |
167 // Since the font height is half the margin we put the header and footers at | |
168 // the font height from the margins. | |
169 PageMargins margins; | 160 PageMargins margins; |
170 margins.header = header_footer_text_height; | 161 margins.header = header_footer_text_height; |
171 margins.footer = header_footer_text_height; | 162 margins.footer = header_footer_text_height; |
172 margins.left = margin_printer_units; | 163 switch (margin_type) { |
173 margins.top = margin_printer_units; | 164 case DEFAULT_MARGINS: { |
174 margins.right = margin_printer_units; | 165 // Default margins 1.0cm = ~2/5 of an inch. |
175 margins.bottom = margin_printer_units; | 166 int margin_printer_units = ConvertUnit(1000, kHundrethsMMPerInch, |
176 page_setup_device_units_.SetRequestedMargins(margins); | 167 units_per_inch); |
| 168 margins.top = margin_printer_units; |
| 169 margins.bottom = margin_printer_units; |
| 170 margins.left = margin_printer_units; |
| 171 margins.right = margin_printer_units; |
| 172 break; |
| 173 } |
| 174 case NO_MARGINS: |
| 175 case PRINTABLE_AREA_MARGINS: { |
| 176 margins.top = 0; |
| 177 margins.bottom = 0; |
| 178 margins.left = 0; |
| 179 margins.right = 0; |
| 180 break; |
| 181 } |
| 182 case CUSTOM_MARGINS: { |
| 183 margins.top = ConvertUnitDouble(custom_margins_in_points_.top, |
| 184 printing::kPointsPerInch, |
| 185 units_per_inch); |
| 186 margins.bottom = ConvertUnitDouble(custom_margins_in_points_.bottom, |
| 187 printing::kPointsPerInch, |
| 188 units_per_inch); |
| 189 margins.left = ConvertUnitDouble(custom_margins_in_points_.left, |
| 190 printing::kPointsPerInch, |
| 191 units_per_inch); |
| 192 margins.right = ConvertUnitDouble(custom_margins_in_points_.right, |
| 193 printing::kPointsPerInch, |
| 194 units_per_inch); |
| 195 break; |
| 196 } |
| 197 default: { |
| 198 NOTREACHED(); |
| 199 } |
| 200 } |
| 201 |
| 202 if (margin_type == DEFAULT_MARGINS || margin_type == PRINTABLE_AREA_MARGINS) |
| 203 page_setup_device_units_.SetRequestedMargins(margins); |
| 204 else |
| 205 page_setup_device_units_.ForceRequestedMargins(margins); |
| 206 } |
| 207 |
| 208 void PrintSettings::SetCustomMargins(const PageMargins& margins_in_points) { |
| 209 custom_margins_in_points_ = margins_in_points; |
| 210 margin_type = CUSTOM_MARGINS; |
177 } | 211 } |
178 | 212 |
179 bool PrintSettings::Equals(const PrintSettings& rhs) const { | 213 bool PrintSettings::Equals(const PrintSettings& rhs) const { |
180 // Do not test the display device name (printer_name_) for equality since it | 214 // Do not test the display device name (printer_name_) for equality since it |
181 // may sometimes be chopped off at 30 chars. As long as device_name is the | 215 // may sometimes be chopped off at 30 chars. As long as device_name is the |
182 // same, that's fine. | 216 // same, that's fine. |
183 return ranges == rhs.ranges && | 217 return ranges == rhs.ranges && |
184 min_shrink == rhs.min_shrink && | 218 min_shrink == rhs.min_shrink && |
185 max_shrink == rhs.max_shrink && | 219 max_shrink == rhs.max_shrink && |
186 desired_dpi == rhs.desired_dpi && | 220 desired_dpi == rhs.desired_dpi && |
187 device_name_ == rhs.device_name_ && | 221 device_name_ == rhs.device_name_ && |
188 page_setup_device_units_.Equals(rhs.page_setup_device_units_) && | 222 page_setup_device_units_.Equals(rhs.page_setup_device_units_) && |
189 dpi_ == rhs.dpi_ && | 223 dpi_ == rhs.dpi_ && |
190 landscape_ == rhs.landscape_; | 224 landscape_ == rhs.landscape_; |
191 } | 225 } |
192 | 226 |
193 int PrintSettings::NewCookie() { | 227 int PrintSettings::NewCookie() { |
194 // A cookie of 0 is used to mark a document as unassigned, count from 1. | 228 // A cookie of 0 is used to mark a document as unassigned, count from 1. |
195 return cookie_seq.GetNext() + 1; | 229 return cookie_seq.GetNext() + 1; |
196 } | 230 } |
197 | 231 |
198 void PrintSettings::SetOrientation(bool landscape) { | 232 void PrintSettings::SetOrientation(bool landscape) { |
199 if (landscape_ != landscape) { | 233 if (landscape_ != landscape) { |
200 landscape_ = landscape; | 234 landscape_ = landscape; |
201 page_setup_device_units_.FlipOrientation(); | 235 page_setup_device_units_.FlipOrientation(); |
202 } | 236 } |
203 } | 237 } |
204 | 238 |
205 } // namespace printing | 239 } // namespace printing |
OLD | NEW |