blob: 47c0a636966fcde8384a80dd77d41710f89e3abe [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
initial.commit09911bf2008-07-26 23:55:2920namespace printing {
21
[email protected]675a1ae2013-10-14 20:24:3722// Returns true if |color_mode| is color and not B&W.
23PRINTING_EXPORT bool IsColorModelSelected(int color_mode);
[email protected]63313ae2011-10-13 00:40:3924
[email protected]fa879e512011-11-08 20:39:0125#if defined(USE_CUPS)
26// Get the color model setting name and value for the |color_mode|.
27PRINTING_EXPORT void GetColorModelForMode(int color_mode,
28 std::string* color_setting_name,
29 std::string* color_value);
[email protected]63313ae2011-10-13 00:40:3930#endif
31
halcanary73b63fd2015-11-06 00:02:1432// Inform the printing system that it may embed this user-agent string
33// in its output's metadata.
34PRINTING_EXPORT void SetAgent(const std::string& user_agent);
35PRINTING_EXPORT const std::string& GetAgent();
36
[email protected]69f5b1e62011-09-01 06:34:0437class PRINTING_EXPORT PrintSettings {
initial.commit09911bf2008-07-26 23:55:2938 public:
rbpotter58bc882e2017-02-01 03:44:2439#if defined(OS_WIN)
40 enum PrinterType {
41 TYPE_NONE = 0,
rbpotter0437a1712017-07-14 21:23:2442 TYPE_TEXTONLY,
rbpotter58bc882e2017-02-01 03:44:2443 TYPE_XPS,
44 TYPE_POSTSCRIPT_LEVEL2,
45 TYPE_POSTSCRIPT_LEVEL3
46 };
47#endif
48
[email protected]72ddef92014-06-12 08:08:0649 // Media properties requested by the user. Default instance represents
50 // default media selection.
51 struct RequestedMedia {
52 // Size of the media, in microns.
53 gfx::Size size_microns;
54 // Platform specific id to map it back to the particular media.
55 std::string vendor_id;
56
57 bool IsDefault() const {
58 return size_microns.IsEmpty() && vendor_id.empty();
59 }
60 };
61
initial.commit09911bf2008-07-26 23:55:2962 PrintSettings();
[email protected]20f0487a2010-09-30 20:06:3063 ~PrintSettings();
initial.commit09911bf2008-07-26 23:55:2964
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:1865 // Reinitialize the settings to the default values.
66 void Clear();
67
[email protected]b076a082011-10-20 01:26:3268 void SetCustomMargins(const PageMargins& requested_margins_in_points);
[email protected]c95198b2014-06-12 16:56:5569 const PageMargins& requested_custom_margins_in_points() const {
70 return requested_custom_margins_in_points_;
71 }
[email protected]e5324b52013-10-29 03:16:3772 void set_margin_type(MarginType margin_type) { margin_type_ = margin_type; }
73 MarginType margin_type() const { return margin_type_; }
[email protected]1c23b4e82011-10-15 22:30:4874
[email protected]e5324b52013-10-29 03:16:3775 // Updates the orientation and flip the page if needed.
76 void SetOrientation(bool landscape);
77 bool landscape() const { return landscape_; }
initial.commit09911bf2008-07-26 23:55:2978
[email protected]72ddef92014-06-12 08:08:0679 // Updates user requested media.
80 void set_requested_media(const RequestedMedia& media) {
81 requested_media_ = media;
82 }
83 // Media properties requested by the user. Translated into device media by the
84 // platform specific layers.
Lei Zhang01a1d3c02019-05-21 04:59:1085 const RequestedMedia& requested_media() const { return requested_media_; }
[email protected]72ddef92014-06-12 08:08:0686
[email protected]e5324b52013-10-29 03:16:3787 // Set printer printable area in in device units.
88 // Some platforms already provide flipped area. Set |landscape_needs_flip|
89 // to false on those platforms to avoid double flipping.
Vladislav Kuzkokova3f4af8f2017-11-28 15:20:2690 // This method assumes correct DPI is already set.
[email protected]e5324b52013-10-29 03:16:3791 void SetPrinterPrintableArea(const gfx::Size& physical_size_device_units,
92 const gfx::Rect& printable_area_device_units,
[email protected]e5324b52013-10-29 03:16:3793 bool landscape_needs_flip);
94 const PageSetup& page_setup_device_units() const {
95 return page_setup_device_units_;
96 }
97
[email protected]b5fa4ee2013-10-01 07:19:0798 void set_device_name(const base::string16& device_name) {
initial.commit09911bf2008-07-26 23:55:2999 device_name_ = device_name;
100 }
[email protected]b5fa4ee2013-10-01 07:19:07101 const base::string16& device_name() const { return device_name_; }
[email protected]e5324b52013-10-29 03:16:37102
rbpotter213a4f72017-12-22 22:58:09103 void set_dpi(int dpi) { dpi_ = gfx::Size(dpi, dpi); }
rbpotter116c2e12017-04-04 19:21:28104 void set_dpi_xy(int dpi_horizontal, int dpi_vertical) {
rbpotter213a4f72017-12-22 22:58:09105 dpi_ = gfx::Size(dpi_horizontal, dpi_vertical);
rbpotter116c2e12017-04-04 19:21:28106 }
rbpotter213a4f72017-12-22 22:58:09107
108 int dpi() const { return std::max(dpi_.width(), dpi_.height()); }
109 int dpi_horizontal() const { return dpi_.width(); }
110 int dpi_vertical() const { return dpi_.height(); }
rbpottere33e8e622018-01-25 01:10:33111 const gfx::Size& dpi_size() const { return dpi_; }
[email protected]e5324b52013-10-29 03:16:37112
rbpotter769ffdf2016-10-26 00:53:57113 void set_scale_factor(double scale_factor) { scale_factor_ = scale_factor; }
114 double scale_factor() const { return scale_factor_; }
115
rbpotter0fab356022016-12-28 22:00:23116 void set_rasterize_pdf(bool rasterize_pdf) { rasterize_pdf_ = rasterize_pdf; }
117 bool rasterize_pdf() const { return rasterize_pdf_; }
118
[email protected]b2b0fce2011-01-12 16:34:40119 void set_supports_alpha_blend(bool supports_alpha_blend) {
120 supports_alpha_blend_ = supports_alpha_blend;
121 }
122 bool supports_alpha_blend() const { return supports_alpha_blend_; }
[email protected]e5324b52013-10-29 03:16:37123
[email protected]6ab86ac2010-05-29 07:18:29124 int device_units_per_inch() const {
125#if defined(OS_MACOSX)
126 return 72;
Lei Zhang01a1d3c02019-05-21 04:59:10127#else // defined(OS_MACOSX)
[email protected]6ab86ac2010-05-29 07:18:29128 return dpi();
129#endif // defined(OS_MACOSX)
130 }
initial.commit09911bf2008-07-26 23:55:29131
thestige85e6b62016-08-25 00:00:06132 void set_ranges(const PageRanges& ranges) { ranges_ = ranges; }
133 const PageRanges& ranges() const { return ranges_; }
initial.commit09911bf2008-07-26 23:55:29134
[email protected]e5324b52013-10-29 03:16:37135 void set_selection_only(bool selection_only) {
136 selection_only_ = selection_only;
137 }
138 bool selection_only() const { return selection_only_; }
initial.commit09911bf2008-07-26 23:55:29139
[email protected]e5324b52013-10-29 03:16:37140 void set_should_print_backgrounds(bool should_print_backgrounds) {
141 should_print_backgrounds_ = should_print_backgrounds;
142 }
143 bool should_print_backgrounds() const { return should_print_backgrounds_; }
initial.commit09911bf2008-07-26 23:55:29144
[email protected]e5324b52013-10-29 03:16:37145 void set_display_header_footer(bool display_header_footer) {
146 display_header_footer_ = display_header_footer;
147 }
148 bool display_header_footer() const { return display_header_footer_; }
initial.commit09911bf2008-07-26 23:55:29149
[email protected]e5324b52013-10-29 03:16:37150 void set_title(const base::string16& title) { title_ = title; }
151 const base::string16& title() const { return title_; }
[email protected]c8ad40c2009-06-08 17:05:21152
[email protected]e5324b52013-10-29 03:16:37153 void set_url(const base::string16& url) { url_ = url; }
154 const base::string16& url() const { return url_; }
155
156 void set_collate(bool collate) { collate_ = collate; }
157 bool collate() const { return collate_; }
158
159 void set_color(ColorModel color) { color_ = color; }
160 ColorModel color() const { return color_; }
161
162 void set_copies(int copies) { copies_ = copies; }
163 int copies() const { return copies_; }
164
165 void set_duplex_mode(DuplexMode duplex_mode) { duplex_mode_ = duplex_mode; }
166 DuplexMode duplex_mode() const { return duplex_mode_; }
167
thestige85e6b62016-08-25 00:00:06168#if defined(OS_WIN)
169 void set_print_text_with_gdi(bool use_gdi) { print_text_with_gdi_ = use_gdi; }
170 bool print_text_with_gdi() const { return print_text_with_gdi_; }
thestig1f8436b2016-10-06 01:09:25171
rbpotter58bc882e2017-02-01 03:44:24172 void set_printer_type(PrinterType type) { printer_type_ = type; }
rbpotter0437a1712017-07-14 21:23:24173 bool printer_is_textonly() const {
174 return printer_type_ == PrinterType::TYPE_TEXTONLY;
175 }
Lei Zhang01a1d3c02019-05-21 04:59:10176 bool printer_is_xps() const { return printer_type_ == PrinterType::TYPE_XPS; }
rbpotter58bc882e2017-02-01 03:44:24177 bool printer_is_ps2() const {
178 return printer_type_ == PrinterType::TYPE_POSTSCRIPT_LEVEL2;
179 }
180 bool printer_is_ps3() const {
181 return printer_type_ == PrinterType::TYPE_POSTSCRIPT_LEVEL3;
182 }
thestige85e6b62016-08-25 00:00:06183#endif
184
Wei Li02720a42017-10-25 22:06:48185 void set_is_modifiable(bool is_modifiable) { is_modifiable_ = is_modifiable; }
186 bool is_modifiable() const { return is_modifiable_; }
187
xlou6bd7c2d2018-07-10 01:35:40188 int pages_per_sheet() const { return pages_per_sheet_; }
189 void set_pages_per_sheet(int pages_per_sheet) {
190 pages_per_sheet_ = pages_per_sheet;
xlou194207562018-04-26 23:42:44191 }
192
Vladislav Kuzkokov48b15002019-01-30 17:13:35193#if defined(OS_CHROMEOS)
194 void set_send_user_info(bool send_user_info) {
195 send_user_info_ = send_user_info;
196 }
197 bool send_user_info() const { return send_user_info_; }
198
199 void set_username(const std::string& username) { username_ = username; }
200 const std::string& username() const { return username_; }
Nikita Podguzovc1bf3f82019-03-19 15:23:23201
202 void set_pin_value(const std::string& pin_value) { pin_value_ = pin_value; }
203 const std::string& pin_value() const { return pin_value_; }
Vladislav Kuzkokov48b15002019-01-30 17:13:35204#endif
205
[email protected]d30e8e642008-08-06 12:05:24206 // Cookie generator. It is used to initialize PrintedDocument with its
207 // associated PrintSettings, to be sure that each generated PrintedPage is
208 // correctly associated with its corresponding PrintedDocument.
initial.commit09911bf2008-07-26 23:55:29209 static int NewCookie();
210
[email protected]e5324b52013-10-29 03:16:37211 private:
212 // Multi-page printing. Each PageRange describes a from-to page combination.
213 // This permits printing selected pages only.
214 PageRanges ranges_;
215
[email protected]e5324b52013-10-29 03:16:37216 // Indicates if the user only wants to print the current selection.
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18217 bool selection_only_;
[email protected]e5324b52013-10-29 03:16:37218
219 // Indicates what kind of margins should be applied to the printable area.
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18220 MarginType margin_type_;
[email protected]c48bee22011-03-29 02:36:26221
[email protected]55b23a02011-08-17 23:09:36222 // Strings to be printed as headers and footers if requested by the user.
[email protected]e5324b52013-10-29 03:16:37223 base::string16 title_;
224 base::string16 url_;
[email protected]55b23a02011-08-17 23:09:36225
226 // True if the user wants headers and footers to be displayed.
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18227 bool display_header_footer_;
[email protected]55b23a02011-08-17 23:09:36228
[email protected]19d1c2d2013-01-14 00:59:46229 // True if the user wants to print CSS backgrounds.
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18230 bool should_print_backgrounds_;
[email protected]19d1c2d2013-01-14 00:59:46231
[email protected]e5324b52013-10-29 03:16:37232 // True if the user wants to print with collate.
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18233 bool collate_;
[email protected]e5324b52013-10-29 03:16:37234
235 // True if the user wants to print with collate.
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18236 ColorModel color_;
[email protected]e5324b52013-10-29 03:16:37237
238 // Number of copies user wants to print.
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18239 int copies_;
[email protected]e5324b52013-10-29 03:16:37240
241 // Duplex type user wants to use.
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18242 DuplexMode duplex_mode_;
initial.commit09911bf2008-07-26 23:55:29243
initial.commit09911bf2008-07-26 23:55:29244 // Printer device name as opened by the OS.
[email protected]b5fa4ee2013-10-01 07:19:07245 base::string16 device_name_;
initial.commit09911bf2008-07-26 23:55:29246
[email protected]72ddef92014-06-12 08:08:06247 // Media requested by the user.
248 RequestedMedia requested_media_;
249
[email protected]6ab86ac2010-05-29 07:18:29250 // Page setup in device units.
251 PageSetup page_setup_device_units_;
initial.commit09911bf2008-07-26 23:55:29252
rbpotter116c2e12017-04-04 19:21:28253 // Printer's device effective dots per inch in both axes. The two values will
254 // generally be identical. However, on Windows, there are a few rare printers
255 // that support resolutions with different DPI in different dimensions.
rbpotter213a4f72017-12-22 22:58:09256 gfx::Size dpi_;
initial.commit09911bf2008-07-26 23:55:29257
rbpotter769ffdf2016-10-26 00:53:57258 // Scale factor
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18259 double scale_factor_;
rbpotter769ffdf2016-10-26 00:53:57260
rbpotter0fab356022016-12-28 22:00:23261 // True if PDF should be printed as a raster PDF
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18262 bool rasterize_pdf_;
rbpotter0fab356022016-12-28 22:00:23263
initial.commit09911bf2008-07-26 23:55:29264 // Is the orientation landscape or portrait.
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18265 bool landscape_;
[email protected]b2b0fce2011-01-12 16:34:40266
267 // True if this printer supports AlphaBlend.
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18268 bool supports_alpha_blend_;
[email protected]1c23b4e82011-10-15 22:30:48269
thestige85e6b62016-08-25 00:00:06270#if defined(OS_WIN)
271 // True to print text with GDI.
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18272 bool print_text_with_gdi_;
thestig1f8436b2016-10-06 01:09:25273
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18274 PrinterType printer_type_;
thestige85e6b62016-08-25 00:00:06275#endif
276
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18277 bool is_modifiable_;
Wei Li02720a42017-10-25 22:06:48278
[email protected]b076a082011-10-20 01:26:32279 // If margin type is custom, this is what was requested.
280 PageMargins requested_custom_margins_in_points_;
xlou194207562018-04-26 23:42:44281
282 // Number of pages per sheet.
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18283 int pages_per_sheet_;
Vladislav Kuzkokov48b15002019-01-30 17:13:35284
285#if defined(OS_CHROMEOS)
286 // Whether to send user info.
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18287 bool send_user_info_;
Vladislav Kuzkokov48b15002019-01-30 17:13:35288
289 // Username if it's required by the printer.
290 std::string username_;
Nikita Podguzovc1bf3f82019-03-19 15:23:23291
Vladislav Kuzkokov9f461172019-04-25 13:09:09292 // Job title if it's required by the printer.
293 std::string job_title_;
294
Nikita Podguzovc1bf3f82019-03-19 15:23:23295 // PIN code entered by the user.
296 std::string pin_value_;
Vladislav Kuzkokov48b15002019-01-30 17:13:35297#endif
Vladislav Kuzkokov19998222019-08-12 14:26:09298
299 DISALLOW_COPY_AND_ASSIGN(PrintSettings);
initial.commit09911bf2008-07-26 23:55:29300};
301
302} // namespace printing
303
[email protected]8ff1d422009-07-07 21:31:39304#endif // PRINTING_PRINT_SETTINGS_H_