blob: de450432949caecb7bcb3f2df973d8982a60d28d [file] [log] [blame]
[email protected]71f40a72012-05-16 07:26:591// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]8ff1d422009-07-07 21:31:395#ifndef PRINTING_PRINT_SETTINGS_H_
6#define PRINTING_PRINT_SETTINGS_H_
initial.commit09911bf2008-07-26 23:55:297
rbpotter116c2e12017-04-04 19:21:288#include <algorithm>
[email protected]dcd1e8862011-08-09 06:06:589#include <string>
10
Vladislav Kuzkokov19998222019-08-12 14:26:0911#include "base/macros.h"
[email protected]896d161f2013-06-11 22:52:2412#include "base/strings/string16.h"
[email protected]8ff1d422009-07-07 21:31:3913#include "printing/page_range.h"
14#include "printing/page_setup.h"
[email protected]1c23b4e82011-10-15 22:30:4815#include "printing/print_job_constants.h"
[email protected]63313ae2011-10-13 00:40:3916#include "printing/printing_export.h"
tfarina3b0452d2014-12-31 15:20:0917#include "ui/gfx/geometry/rect.h"
rbpotter213a4f72017-12-22 22:58:0918#include "ui/gfx/geometry/size.h"
initial.commit09911bf2008-07-26 23:55:2919
Vladislav Kuzkokovd4e4ff32019-09-13 11:55:5620#if defined(OS_CHROMEOS)
21#include <map>
22
23#include "base/values.h"
24#endif // defined(OS_CHROMEOS)
25
initial.commit09911bf2008-07-26 23:55:2926namespace printing {
27
[email protected]675a1ae2013-10-14 20:24:3728// Returns true if |color_mode| is color and not B&W.
29PRINTING_EXPORT bool IsColorModelSelected(int color_mode);
[email protected]63313ae2011-10-13 00:40:3930
[email protected]fa879e512011-11-08 20:39:0131#if defined(USE_CUPS)
32// Get the color model setting name and value for the |color_mode|.
33PRINTING_EXPORT void GetColorModelForMode(int color_mode,
34 std::string* color_setting_name,
35 std::string* color_value);
[email protected]63313ae2011-10-13 00:40:3936#endif
37
halcanary73b63fd2015-11-06 00:02:1438// Inform the printing system that it may embed this user-agent string
39// in its output's metadata.
40PRINTING_EXPORT void SetAgent(const std::string& user_agent);
41PRINTING_EXPORT const std::string& GetAgent();
42
[email protected]69f5b1e62011-09-01 06:34:0443class PRINTING_EXPORT PrintSettings {
initial.commit09911bf2008-07-26 23:55:2944 public:
rbpotter58bc882e2017-02-01 03:44:2445#if defined(OS_WIN)
46 enum PrinterType {
47 TYPE_NONE = 0,
rbpotter0437a1712017-07-14 21:23:2448 TYPE_TEXTONLY,
rbpotter58bc882e2017-02-01 03:44:2449 TYPE_XPS,
50 TYPE_POSTSCRIPT_LEVEL2,
51 TYPE_POSTSCRIPT_LEVEL3
52 };
53#endif
54
[email protected]72ddef92014-06-12 08:08:0655 // Media properties requested by the user. Default instance represents
56 // default media selection.
57 struct RequestedMedia {
58 // Size of the media, in microns.
59 gfx::Size size_microns;
60 // Platform specific id to map it back to the particular media.
61 std::string vendor_id;
62
63 bool IsDefault() const {
64 return size_microns.IsEmpty() && vendor_id.empty();
65 }
66 };
67
Vladislav Kuzkokovd4e4ff32019-09-13 11:55:5668#if defined(OS_CHROMEOS)
69 using AdvancedSettings = std::map<std::string, base::Value>;
70#endif // defined(OS_CHROMEOS)
71
initial.commit09911bf2008-07-26 23:55:2972 PrintSettings();
[email protected]20f0487a2010-09-30 20:06:3073 ~PrintSettings();
initial.commit09911bf2008-07-26 23:55:2974
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:1875 // Reinitialize the settings to the default values.
76 void Clear();
77
[email protected]b076a082011-10-20 01:26:3278 void SetCustomMargins(const PageMargins& requested_margins_in_points);
[email protected]c95198b2014-06-12 16:56:5579 const PageMargins& requested_custom_margins_in_points() const {
80 return requested_custom_margins_in_points_;
81 }
[email protected]e5324b52013-10-29 03:16:3782 void set_margin_type(MarginType margin_type) { margin_type_ = margin_type; }
83 MarginType margin_type() const { return margin_type_; }
[email protected]1c23b4e82011-10-15 22:30:4884
[email protected]e5324b52013-10-29 03:16:3785 // Updates the orientation and flip the page if needed.
86 void SetOrientation(bool landscape);
87 bool landscape() const { return landscape_; }
initial.commit09911bf2008-07-26 23:55:2988
[email protected]72ddef92014-06-12 08:08:0689 // Updates user requested media.
90 void set_requested_media(const RequestedMedia& media) {
91 requested_media_ = media;
92 }
93 // Media properties requested by the user. Translated into device media by the
94 // platform specific layers.
Lei Zhang01a1d3c02019-05-21 04:59:1095 const RequestedMedia& requested_media() const { return requested_media_; }
[email protected]72ddef92014-06-12 08:08:0696
[email protected]e5324b52013-10-29 03:16:3797 // Set printer printable area in in device units.
98 // Some platforms already provide flipped area. Set |landscape_needs_flip|
99 // to false on those platforms to avoid double flipping.
Vladislav Kuzkokova3f4af8f2017-11-28 15:20:26100 // This method assumes correct DPI is already set.
[email protected]e5324b52013-10-29 03:16:37101 void SetPrinterPrintableArea(const gfx::Size& physical_size_device_units,
102 const gfx::Rect& printable_area_device_units,
[email protected]e5324b52013-10-29 03:16:37103 bool landscape_needs_flip);
104 const PageSetup& page_setup_device_units() const {
105 return page_setup_device_units_;
106 }
107
[email protected]b5fa4ee2013-10-01 07:19:07108 void set_device_name(const base::string16& device_name) {
initial.commit09911bf2008-07-26 23:55:29109 device_name_ = device_name;
110 }
[email protected]b5fa4ee2013-10-01 07:19:07111 const base::string16& device_name() const { return device_name_; }
[email protected]e5324b52013-10-29 03:16:37112
rbpotter213a4f72017-12-22 22:58:09113 void set_dpi(int dpi) { dpi_ = gfx::Size(dpi, dpi); }
rbpotter116c2e12017-04-04 19:21:28114 void set_dpi_xy(int dpi_horizontal, int dpi_vertical) {
rbpotter213a4f72017-12-22 22:58:09115 dpi_ = gfx::Size(dpi_horizontal, dpi_vertical);
rbpotter116c2e12017-04-04 19:21:28116 }
rbpotter213a4f72017-12-22 22:58:09117
118 int dpi() const { return std::max(dpi_.width(), dpi_.height()); }
119 int dpi_horizontal() const { return dpi_.width(); }
120 int dpi_vertical() const { return dpi_.height(); }
rbpottere33e8e622018-01-25 01:10:33121 const gfx::Size& dpi_size() const { return dpi_; }
[email protected]e5324b52013-10-29 03:16:37122
rbpotter769ffdf2016-10-26 00:53:57123 void set_scale_factor(double scale_factor) { scale_factor_ = scale_factor; }
124 double scale_factor() const { return scale_factor_; }
125
rbpotter0fab356022016-12-28 22:00:23126 void set_rasterize_pdf(bool rasterize_pdf) { rasterize_pdf_ = rasterize_pdf; }
127 bool rasterize_pdf() const { return rasterize_pdf_; }
128
[email protected]b2b0fce2011-01-12 16:34:40129 void set_supports_alpha_blend(bool supports_alpha_blend) {
130 supports_alpha_blend_ = supports_alpha_blend;
131 }
132 bool supports_alpha_blend() const { return supports_alpha_blend_; }
[email protected]e5324b52013-10-29 03:16:37133
[email protected]6ab86ac2010-05-29 07:18:29134 int device_units_per_inch() const {
135#if defined(OS_MACOSX)
136 return 72;
Lei Zhang01a1d3c02019-05-21 04:59:10137#else // defined(OS_MACOSX)
[email protected]6ab86ac2010-05-29 07:18:29138 return dpi();
139#endif // defined(OS_MACOSX)
140 }
initial.commit09911bf2008-07-26 23:55:29141
thestige85e6b62016-08-25 00:00:06142 void set_ranges(const PageRanges& ranges) { ranges_ = ranges; }
143 const PageRanges& ranges() const { return ranges_; }
initial.commit09911bf2008-07-26 23:55:29144
[email protected]e5324b52013-10-29 03:16:37145 void set_selection_only(bool selection_only) {
146 selection_only_ = selection_only;
147 }
148 bool selection_only() const { return selection_only_; }
initial.commit09911bf2008-07-26 23:55:29149
[email protected]e5324b52013-10-29 03:16:37150 void set_should_print_backgrounds(bool should_print_backgrounds) {
151 should_print_backgrounds_ = should_print_backgrounds;
152 }
153 bool should_print_backgrounds() const { return should_print_backgrounds_; }
initial.commit09911bf2008-07-26 23:55:29154
[email protected]e5324b52013-10-29 03:16:37155 void set_display_header_footer(bool display_header_footer) {
156 display_header_footer_ = display_header_footer;
157 }
158 bool display_header_footer() const { return display_header_footer_; }
initial.commit09911bf2008-07-26 23:55:29159
[email protected]e5324b52013-10-29 03:16:37160 void set_title(const base::string16& title) { title_ = title; }
161 const base::string16& title() const { return title_; }
[email protected]c8ad40c2009-06-08 17:05:21162
[email protected]e5324b52013-10-29 03:16:37163 void set_url(const base::string16& url) { url_ = url; }
164 const base::string16& url() const { return url_; }
165
166 void set_collate(bool collate) { collate_ = collate; }
167 bool collate() const { return collate_; }
168
169 void set_color(ColorModel color) { color_ = color; }
170 ColorModel color() const { return color_; }
171
172 void set_copies(int copies) { copies_ = copies; }
173 int copies() const { return copies_; }
174
175 void set_duplex_mode(DuplexMode duplex_mode) { duplex_mode_ = duplex_mode; }
176 DuplexMode duplex_mode() const { return duplex_mode_; }
177
thestige85e6b62016-08-25 00:00:06178#if defined(OS_WIN)
179 void set_print_text_with_gdi(bool use_gdi) { print_text_with_gdi_ = use_gdi; }
180 bool print_text_with_gdi() const { return print_text_with_gdi_; }
thestig1f8436b2016-10-06 01:09:25181
rbpotter58bc882e2017-02-01 03:44:24182 void set_printer_type(PrinterType type) { printer_type_ = type; }
rbpotter0437a1712017-07-14 21:23:24183 bool printer_is_textonly() const {
184 return printer_type_ == PrinterType::TYPE_TEXTONLY;
185 }
Lei Zhang01a1d3c02019-05-21 04:59:10186 bool printer_is_xps() const { return printer_type_ == PrinterType::TYPE_XPS; }
rbpotter58bc882e2017-02-01 03:44:24187 bool printer_is_ps2() const {
188 return printer_type_ == PrinterType::TYPE_POSTSCRIPT_LEVEL2;
189 }
190 bool printer_is_ps3() const {
191 return printer_type_ == PrinterType::TYPE_POSTSCRIPT_LEVEL3;
192 }
thestige85e6b62016-08-25 00:00:06193#endif
194
Wei Li02720a42017-10-25 22:06:48195 void set_is_modifiable(bool is_modifiable) { is_modifiable_ = is_modifiable; }
196 bool is_modifiable() const { return is_modifiable_; }
197
xlou6bd7c2d2018-07-10 01:35:40198 int pages_per_sheet() const { return pages_per_sheet_; }
199 void set_pages_per_sheet(int pages_per_sheet) {
200 pages_per_sheet_ = pages_per_sheet;
xlou194207562018-04-26 23:42:44201 }
202
Vladislav Kuzkokov48b15002019-01-30 17:13:35203#if defined(OS_CHROMEOS)
204 void set_send_user_info(bool send_user_info) {
205 send_user_info_ = send_user_info;
206 }
207 bool send_user_info() const { return send_user_info_; }
208
209 void set_username(const std::string& username) { username_ = username; }
210 const std::string& username() const { return username_; }
Nikita Podguzovc1bf3f82019-03-19 15:23:23211
212 void set_pin_value(const std::string& pin_value) { pin_value_ = pin_value; }
213 const std::string& pin_value() const { return pin_value_; }
Vladislav Kuzkokovd4e4ff32019-09-13 11:55:56214
215 AdvancedSettings& advanced_settings() { return advanced_settings_; }
216 const AdvancedSettings& advanced_settings() const {
217 return advanced_settings_;
218 }
219#endif // defined(OS_CHROMEOS)
Vladislav Kuzkokov48b15002019-01-30 17:13:35220
[email protected]d30e8e642008-08-06 12:05:24221 // Cookie generator. It is used to initialize PrintedDocument with its
222 // associated PrintSettings, to be sure that each generated PrintedPage is
223 // correctly associated with its corresponding PrintedDocument.
initial.commit09911bf2008-07-26 23:55:29224 static int NewCookie();
225
[email protected]e5324b52013-10-29 03:16:37226 private:
227 // Multi-page printing. Each PageRange describes a from-to page combination.
228 // This permits printing selected pages only.
229 PageRanges ranges_;
230
[email protected]e5324b52013-10-29 03:16:37231 // Indicates if the user only wants to print the current selection.
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18232 bool selection_only_;
[email protected]e5324b52013-10-29 03:16:37233
234 // Indicates what kind of margins should be applied to the printable area.
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18235 MarginType margin_type_;
[email protected]c48bee22011-03-29 02:36:26236
[email protected]55b23a02011-08-17 23:09:36237 // Strings to be printed as headers and footers if requested by the user.
[email protected]e5324b52013-10-29 03:16:37238 base::string16 title_;
239 base::string16 url_;
[email protected]55b23a02011-08-17 23:09:36240
241 // True if the user wants headers and footers to be displayed.
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18242 bool display_header_footer_;
[email protected]55b23a02011-08-17 23:09:36243
[email protected]19d1c2d2013-01-14 00:59:46244 // True if the user wants to print CSS backgrounds.
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18245 bool should_print_backgrounds_;
[email protected]19d1c2d2013-01-14 00:59:46246
[email protected]e5324b52013-10-29 03:16:37247 // True if the user wants to print with collate.
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18248 bool collate_;
[email protected]e5324b52013-10-29 03:16:37249
250 // True if the user wants to print with collate.
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18251 ColorModel color_;
[email protected]e5324b52013-10-29 03:16:37252
253 // Number of copies user wants to print.
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18254 int copies_;
[email protected]e5324b52013-10-29 03:16:37255
256 // Duplex type user wants to use.
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18257 DuplexMode duplex_mode_;
initial.commit09911bf2008-07-26 23:55:29258
initial.commit09911bf2008-07-26 23:55:29259 // Printer device name as opened by the OS.
[email protected]b5fa4ee2013-10-01 07:19:07260 base::string16 device_name_;
initial.commit09911bf2008-07-26 23:55:29261
[email protected]72ddef92014-06-12 08:08:06262 // Media requested by the user.
263 RequestedMedia requested_media_;
264
[email protected]6ab86ac2010-05-29 07:18:29265 // Page setup in device units.
266 PageSetup page_setup_device_units_;
initial.commit09911bf2008-07-26 23:55:29267
rbpotter116c2e12017-04-04 19:21:28268 // Printer's device effective dots per inch in both axes. The two values will
269 // generally be identical. However, on Windows, there are a few rare printers
270 // that support resolutions with different DPI in different dimensions.
rbpotter213a4f72017-12-22 22:58:09271 gfx::Size dpi_;
initial.commit09911bf2008-07-26 23:55:29272
rbpotter769ffdf2016-10-26 00:53:57273 // Scale factor
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18274 double scale_factor_;
rbpotter769ffdf2016-10-26 00:53:57275
rbpotter0fab356022016-12-28 22:00:23276 // True if PDF should be printed as a raster PDF
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18277 bool rasterize_pdf_;
rbpotter0fab356022016-12-28 22:00:23278
initial.commit09911bf2008-07-26 23:55:29279 // Is the orientation landscape or portrait.
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18280 bool landscape_;
[email protected]b2b0fce2011-01-12 16:34:40281
282 // True if this printer supports AlphaBlend.
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18283 bool supports_alpha_blend_;
[email protected]1c23b4e82011-10-15 22:30:48284
thestige85e6b62016-08-25 00:00:06285#if defined(OS_WIN)
286 // True to print text with GDI.
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18287 bool print_text_with_gdi_;
thestig1f8436b2016-10-06 01:09:25288
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18289 PrinterType printer_type_;
thestige85e6b62016-08-25 00:00:06290#endif
291
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18292 bool is_modifiable_;
Wei Li02720a42017-10-25 22:06:48293
[email protected]b076a082011-10-20 01:26:32294 // If margin type is custom, this is what was requested.
295 PageMargins requested_custom_margins_in_points_;
xlou194207562018-04-26 23:42:44296
297 // Number of pages per sheet.
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18298 int pages_per_sheet_;
Vladislav Kuzkokov48b15002019-01-30 17:13:35299
300#if defined(OS_CHROMEOS)
301 // Whether to send user info.
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18302 bool send_user_info_;
Vladislav Kuzkokov48b15002019-01-30 17:13:35303
304 // Username if it's required by the printer.
305 std::string username_;
Nikita Podguzovc1bf3f82019-03-19 15:23:23306
307 // PIN code entered by the user.
308 std::string pin_value_;
Vladislav Kuzkokovd4e4ff32019-09-13 11:55:56309
310 // Advanced settings.
311 AdvancedSettings advanced_settings_;
Vladislav Kuzkokov48b15002019-01-30 17:13:35312#endif
Vladislav Kuzkokov19998222019-08-12 14:26:09313
314 DISALLOW_COPY_AND_ASSIGN(PrintSettings);
initial.commit09911bf2008-07-26 23:55:29315};
316
317} // namespace printing
318
[email protected]8ff1d422009-07-07 21:31:39319#endif // PRINTING_PRINT_SETTINGS_H_