blob: 6eac8b326af026956245ef4f689021c2e7641f42 [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"
Jesse Schettler1e5d89d2019-12-07 01:41:5712#include "base/optional.h"
[email protected]896d161f2013-06-11 22:52:2413#include "base/strings/string16.h"
Julie Jeongeun Kime454f2602020-04-30 05:20:0714#include "printing/mojom/print.mojom.h"
[email protected]8ff1d422009-07-07 21:31:3915#include "printing/page_range.h"
16#include "printing/page_setup.h"
[email protected]1c23b4e82011-10-15 22:30:4817#include "printing/print_job_constants.h"
[email protected]63313ae2011-10-13 00:40:3918#include "printing/printing_export.h"
tfarina3b0452d2014-12-31 15:20:0919#include "ui/gfx/geometry/rect.h"
rbpotter213a4f72017-12-22 22:58:0920#include "ui/gfx/geometry/size.h"
initial.commit09911bf2008-07-26 23:55:2921
Vladislav Kuzkokovd4e4ff32019-09-13 11:55:5622#if defined(OS_CHROMEOS)
23#include <map>
24
25#include "base/values.h"
26#endif // defined(OS_CHROMEOS)
27
initial.commit09911bf2008-07-26 23:55:2928namespace printing {
29
Jesse Schettler1e5d89d2019-12-07 01:41:5730// Returns true if |color_mode| is color and not B&W. Must be called with a
31// |color_mode| from printing::ColorModel, excluding UNKNOWN_COLOR_MODEL.
32PRINTING_EXPORT base::Optional<bool> IsColorModelSelected(int color_mode);
[email protected]63313ae2011-10-13 00:40:3933
[email protected]fa879e512011-11-08 20:39:0134#if defined(USE_CUPS)
35// Get the color model setting name and value for the |color_mode|.
36PRINTING_EXPORT void GetColorModelForMode(int color_mode,
37 std::string* color_setting_name,
38 std::string* color_value);
[email protected]63313ae2011-10-13 00:40:3939#endif
40
halcanary73b63fd2015-11-06 00:02:1441// Inform the printing system that it may embed this user-agent string
42// in its output's metadata.
43PRINTING_EXPORT void SetAgent(const std::string& user_agent);
44PRINTING_EXPORT const std::string& GetAgent();
45
[email protected]69f5b1e62011-09-01 06:34:0446class PRINTING_EXPORT PrintSettings {
initial.commit09911bf2008-07-26 23:55:2947 public:
rbpotter58bc882e2017-02-01 03:44:2448#if defined(OS_WIN)
49 enum PrinterType {
50 TYPE_NONE = 0,
rbpotter0437a1712017-07-14 21:23:2451 TYPE_TEXTONLY,
rbpotter58bc882e2017-02-01 03:44:2452 TYPE_XPS,
53 TYPE_POSTSCRIPT_LEVEL2,
54 TYPE_POSTSCRIPT_LEVEL3
55 };
56#endif
57
[email protected]72ddef92014-06-12 08:08:0658 // Media properties requested by the user. Default instance represents
59 // default media selection.
60 struct RequestedMedia {
61 // Size of the media, in microns.
62 gfx::Size size_microns;
63 // Platform specific id to map it back to the particular media.
64 std::string vendor_id;
65
66 bool IsDefault() const {
67 return size_microns.IsEmpty() && vendor_id.empty();
68 }
69 };
70
Vladislav Kuzkokovd4e4ff32019-09-13 11:55:5671#if defined(OS_CHROMEOS)
72 using AdvancedSettings = std::map<std::string, base::Value>;
73#endif // defined(OS_CHROMEOS)
74
initial.commit09911bf2008-07-26 23:55:2975 PrintSettings();
[email protected]20f0487a2010-09-30 20:06:3076 ~PrintSettings();
initial.commit09911bf2008-07-26 23:55:2977
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:1878 // Reinitialize the settings to the default values.
79 void Clear();
80
[email protected]b076a082011-10-20 01:26:3281 void SetCustomMargins(const PageMargins& requested_margins_in_points);
[email protected]c95198b2014-06-12 16:56:5582 const PageMargins& requested_custom_margins_in_points() const {
83 return requested_custom_margins_in_points_;
84 }
[email protected]e5324b52013-10-29 03:16:3785 void set_margin_type(MarginType margin_type) { margin_type_ = margin_type; }
86 MarginType margin_type() const { return margin_type_; }
[email protected]1c23b4e82011-10-15 22:30:4887
[email protected]e5324b52013-10-29 03:16:3788 // Updates the orientation and flip the page if needed.
89 void SetOrientation(bool landscape);
90 bool landscape() const { return landscape_; }
initial.commit09911bf2008-07-26 23:55:2991
[email protected]72ddef92014-06-12 08:08:0692 // Updates user requested media.
93 void set_requested_media(const RequestedMedia& media) {
94 requested_media_ = media;
95 }
96 // Media properties requested by the user. Translated into device media by the
97 // platform specific layers.
Lei Zhang01a1d3c02019-05-21 04:59:1098 const RequestedMedia& requested_media() const { return requested_media_; }
[email protected]72ddef92014-06-12 08:08:0699
[email protected]e5324b52013-10-29 03:16:37100 // Set printer printable area in in device units.
101 // Some platforms already provide flipped area. Set |landscape_needs_flip|
102 // to false on those platforms to avoid double flipping.
Vladislav Kuzkokova3f4af8f2017-11-28 15:20:26103 // This method assumes correct DPI is already set.
[email protected]e5324b52013-10-29 03:16:37104 void SetPrinterPrintableArea(const gfx::Size& physical_size_device_units,
105 const gfx::Rect& printable_area_device_units,
[email protected]e5324b52013-10-29 03:16:37106 bool landscape_needs_flip);
107 const PageSetup& page_setup_device_units() const {
108 return page_setup_device_units_;
109 }
110
[email protected]b5fa4ee2013-10-01 07:19:07111 void set_device_name(const base::string16& device_name) {
initial.commit09911bf2008-07-26 23:55:29112 device_name_ = device_name;
113 }
[email protected]b5fa4ee2013-10-01 07:19:07114 const base::string16& device_name() const { return device_name_; }
[email protected]e5324b52013-10-29 03:16:37115
rbpotter213a4f72017-12-22 22:58:09116 void set_dpi(int dpi) { dpi_ = gfx::Size(dpi, dpi); }
rbpotter116c2e12017-04-04 19:21:28117 void set_dpi_xy(int dpi_horizontal, int dpi_vertical) {
rbpotter213a4f72017-12-22 22:58:09118 dpi_ = gfx::Size(dpi_horizontal, dpi_vertical);
rbpotter116c2e12017-04-04 19:21:28119 }
rbpotter213a4f72017-12-22 22:58:09120
121 int dpi() const { return std::max(dpi_.width(), dpi_.height()); }
122 int dpi_horizontal() const { return dpi_.width(); }
123 int dpi_vertical() const { return dpi_.height(); }
rbpottere33e8e622018-01-25 01:10:33124 const gfx::Size& dpi_size() const { return dpi_; }
[email protected]e5324b52013-10-29 03:16:37125
rbpotter769ffdf2016-10-26 00:53:57126 void set_scale_factor(double scale_factor) { scale_factor_ = scale_factor; }
127 double scale_factor() const { return scale_factor_; }
128
rbpotter0fab356022016-12-28 22:00:23129 void set_rasterize_pdf(bool rasterize_pdf) { rasterize_pdf_ = rasterize_pdf; }
130 bool rasterize_pdf() const { return rasterize_pdf_; }
131
[email protected]b2b0fce2011-01-12 16:34:40132 void set_supports_alpha_blend(bool supports_alpha_blend) {
133 supports_alpha_blend_ = supports_alpha_blend;
134 }
135 bool supports_alpha_blend() const { return supports_alpha_blend_; }
[email protected]e5324b52013-10-29 03:16:37136
[email protected]6ab86ac2010-05-29 07:18:29137 int device_units_per_inch() const {
138#if defined(OS_MACOSX)
139 return 72;
Lei Zhang01a1d3c02019-05-21 04:59:10140#else // defined(OS_MACOSX)
[email protected]6ab86ac2010-05-29 07:18:29141 return dpi();
142#endif // defined(OS_MACOSX)
143 }
initial.commit09911bf2008-07-26 23:55:29144
thestige85e6b62016-08-25 00:00:06145 void set_ranges(const PageRanges& ranges) { ranges_ = ranges; }
146 const PageRanges& ranges() const { return ranges_; }
initial.commit09911bf2008-07-26 23:55:29147
[email protected]e5324b52013-10-29 03:16:37148 void set_selection_only(bool selection_only) {
149 selection_only_ = selection_only;
150 }
151 bool selection_only() const { return selection_only_; }
initial.commit09911bf2008-07-26 23:55:29152
[email protected]e5324b52013-10-29 03:16:37153 void set_should_print_backgrounds(bool should_print_backgrounds) {
154 should_print_backgrounds_ = should_print_backgrounds;
155 }
156 bool should_print_backgrounds() const { return should_print_backgrounds_; }
initial.commit09911bf2008-07-26 23:55:29157
[email protected]e5324b52013-10-29 03:16:37158 void set_display_header_footer(bool display_header_footer) {
159 display_header_footer_ = display_header_footer;
160 }
161 bool display_header_footer() const { return display_header_footer_; }
initial.commit09911bf2008-07-26 23:55:29162
[email protected]e5324b52013-10-29 03:16:37163 void set_title(const base::string16& title) { title_ = title; }
164 const base::string16& title() const { return title_; }
[email protected]c8ad40c2009-06-08 17:05:21165
[email protected]e5324b52013-10-29 03:16:37166 void set_url(const base::string16& url) { url_ = url; }
167 const base::string16& url() const { return url_; }
168
169 void set_collate(bool collate) { collate_ = collate; }
170 bool collate() const { return collate_; }
171
172 void set_color(ColorModel color) { color_ = color; }
173 ColorModel color() const { return color_; }
174
175 void set_copies(int copies) { copies_ = copies; }
176 int copies() const { return copies_; }
177
Julie Jeongeun Kime454f2602020-04-30 05:20:07178 void set_duplex_mode(mojom::DuplexMode duplex_mode) {
179 duplex_mode_ = duplex_mode;
180 }
181 mojom::DuplexMode duplex_mode() const { return duplex_mode_; }
[email protected]e5324b52013-10-29 03:16:37182
thestige85e6b62016-08-25 00:00:06183#if defined(OS_WIN)
184 void set_print_text_with_gdi(bool use_gdi) { print_text_with_gdi_ = use_gdi; }
185 bool print_text_with_gdi() const { return print_text_with_gdi_; }
thestig1f8436b2016-10-06 01:09:25186
rbpotter58bc882e2017-02-01 03:44:24187 void set_printer_type(PrinterType type) { printer_type_ = type; }
rbpotter0437a1712017-07-14 21:23:24188 bool printer_is_textonly() const {
189 return printer_type_ == PrinterType::TYPE_TEXTONLY;
190 }
Lei Zhang01a1d3c02019-05-21 04:59:10191 bool printer_is_xps() const { return printer_type_ == PrinterType::TYPE_XPS; }
rbpotter58bc882e2017-02-01 03:44:24192 bool printer_is_ps2() const {
193 return printer_type_ == PrinterType::TYPE_POSTSCRIPT_LEVEL2;
194 }
195 bool printer_is_ps3() const {
196 return printer_type_ == PrinterType::TYPE_POSTSCRIPT_LEVEL3;
197 }
thestige85e6b62016-08-25 00:00:06198#endif
199
Wei Li02720a42017-10-25 22:06:48200 void set_is_modifiable(bool is_modifiable) { is_modifiable_ = is_modifiable; }
201 bool is_modifiable() const { return is_modifiable_; }
202
xlou6bd7c2d2018-07-10 01:35:40203 int pages_per_sheet() const { return pages_per_sheet_; }
204 void set_pages_per_sheet(int pages_per_sheet) {
205 pages_per_sheet_ = pages_per_sheet;
xlou194207562018-04-26 23:42:44206 }
207
Vladislav Kuzkokov48b15002019-01-30 17:13:35208#if defined(OS_CHROMEOS)
209 void set_send_user_info(bool send_user_info) {
210 send_user_info_ = send_user_info;
211 }
212 bool send_user_info() const { return send_user_info_; }
213
214 void set_username(const std::string& username) { username_ = username; }
215 const std::string& username() const { return username_; }
Nikita Podguzovc1bf3f82019-03-19 15:23:23216
217 void set_pin_value(const std::string& pin_value) { pin_value_ = pin_value; }
218 const std::string& pin_value() const { return pin_value_; }
Vladislav Kuzkokovd4e4ff32019-09-13 11:55:56219
220 AdvancedSettings& advanced_settings() { return advanced_settings_; }
221 const AdvancedSettings& advanced_settings() const {
222 return advanced_settings_;
223 }
224#endif // defined(OS_CHROMEOS)
Vladislav Kuzkokov48b15002019-01-30 17:13:35225
[email protected]d30e8e642008-08-06 12:05:24226 // Cookie generator. It is used to initialize PrintedDocument with its
227 // associated PrintSettings, to be sure that each generated PrintedPage is
228 // correctly associated with its corresponding PrintedDocument.
initial.commit09911bf2008-07-26 23:55:29229 static int NewCookie();
230
[email protected]e5324b52013-10-29 03:16:37231 private:
232 // Multi-page printing. Each PageRange describes a from-to page combination.
233 // This permits printing selected pages only.
234 PageRanges ranges_;
235
[email protected]e5324b52013-10-29 03:16:37236 // Indicates if the user only wants to print the current selection.
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18237 bool selection_only_;
[email protected]e5324b52013-10-29 03:16:37238
239 // Indicates what kind of margins should be applied to the printable area.
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18240 MarginType margin_type_;
[email protected]c48bee22011-03-29 02:36:26241
[email protected]55b23a02011-08-17 23:09:36242 // Strings to be printed as headers and footers if requested by the user.
[email protected]e5324b52013-10-29 03:16:37243 base::string16 title_;
244 base::string16 url_;
[email protected]55b23a02011-08-17 23:09:36245
246 // True if the user wants headers and footers to be displayed.
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18247 bool display_header_footer_;
[email protected]55b23a02011-08-17 23:09:36248
[email protected]19d1c2d2013-01-14 00:59:46249 // True if the user wants to print CSS backgrounds.
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18250 bool should_print_backgrounds_;
[email protected]19d1c2d2013-01-14 00:59:46251
[email protected]e5324b52013-10-29 03:16:37252 // True if the user wants to print with collate.
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18253 bool collate_;
[email protected]e5324b52013-10-29 03:16:37254
255 // True if the user wants to print with collate.
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18256 ColorModel color_;
[email protected]e5324b52013-10-29 03:16:37257
258 // Number of copies user wants to print.
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18259 int copies_;
[email protected]e5324b52013-10-29 03:16:37260
261 // Duplex type user wants to use.
Julie Jeongeun Kime454f2602020-04-30 05:20:07262 mojom::DuplexMode duplex_mode_;
initial.commit09911bf2008-07-26 23:55:29263
initial.commit09911bf2008-07-26 23:55:29264 // Printer device name as opened by the OS.
[email protected]b5fa4ee2013-10-01 07:19:07265 base::string16 device_name_;
initial.commit09911bf2008-07-26 23:55:29266
[email protected]72ddef92014-06-12 08:08:06267 // Media requested by the user.
268 RequestedMedia requested_media_;
269
[email protected]6ab86ac2010-05-29 07:18:29270 // Page setup in device units.
271 PageSetup page_setup_device_units_;
initial.commit09911bf2008-07-26 23:55:29272
rbpotter116c2e12017-04-04 19:21:28273 // Printer's device effective dots per inch in both axes. The two values will
274 // generally be identical. However, on Windows, there are a few rare printers
275 // that support resolutions with different DPI in different dimensions.
rbpotter213a4f72017-12-22 22:58:09276 gfx::Size dpi_;
initial.commit09911bf2008-07-26 23:55:29277
rbpotter769ffdf2016-10-26 00:53:57278 // Scale factor
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18279 double scale_factor_;
rbpotter769ffdf2016-10-26 00:53:57280
rbpotter0fab356022016-12-28 22:00:23281 // True if PDF should be printed as a raster PDF
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18282 bool rasterize_pdf_;
rbpotter0fab356022016-12-28 22:00:23283
initial.commit09911bf2008-07-26 23:55:29284 // Is the orientation landscape or portrait.
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18285 bool landscape_;
[email protected]b2b0fce2011-01-12 16:34:40286
287 // True if this printer supports AlphaBlend.
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18288 bool supports_alpha_blend_;
[email protected]1c23b4e82011-10-15 22:30:48289
thestige85e6b62016-08-25 00:00:06290#if defined(OS_WIN)
291 // True to print text with GDI.
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18292 bool print_text_with_gdi_;
thestig1f8436b2016-10-06 01:09:25293
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18294 PrinterType printer_type_;
thestige85e6b62016-08-25 00:00:06295#endif
296
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18297 bool is_modifiable_;
Wei Li02720a42017-10-25 22:06:48298
[email protected]b076a082011-10-20 01:26:32299 // If margin type is custom, this is what was requested.
300 PageMargins requested_custom_margins_in_points_;
xlou194207562018-04-26 23:42:44301
302 // Number of pages per sheet.
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18303 int pages_per_sheet_;
Vladislav Kuzkokov48b15002019-01-30 17:13:35304
305#if defined(OS_CHROMEOS)
306 // Whether to send user info.
Vladislav Kuzkokov56e6bbbd2019-08-21 18:48:18307 bool send_user_info_;
Vladislav Kuzkokov48b15002019-01-30 17:13:35308
309 // Username if it's required by the printer.
310 std::string username_;
Nikita Podguzovc1bf3f82019-03-19 15:23:23311
312 // PIN code entered by the user.
313 std::string pin_value_;
Vladislav Kuzkokovd4e4ff32019-09-13 11:55:56314
315 // Advanced settings.
316 AdvancedSettings advanced_settings_;
Vladislav Kuzkokov48b15002019-01-30 17:13:35317#endif
Vladislav Kuzkokov19998222019-08-12 14:26:09318
319 DISALLOW_COPY_AND_ASSIGN(PrintSettings);
initial.commit09911bf2008-07-26 23:55:29320};
321
322} // namespace printing
323
[email protected]8ff1d422009-07-07 21:31:39324#endif // PRINTING_PRINT_SETTINGS_H_