blob: 354b5377d773e855bcfbfc5792d98604aa1e5fad [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
[email protected]896d161f2013-06-11 22:52:2411#include "base/strings/string16.h"
[email protected]8ff1d422009-07-07 21:31:3912#include "printing/page_range.h"
13#include "printing/page_setup.h"
[email protected]1c23b4e82011-10-15 22:30:4814#include "printing/print_job_constants.h"
[email protected]63313ae2011-10-13 00:40:3915#include "printing/printing_export.h"
tfarina3b0452d2014-12-31 15:20:0916#include "ui/gfx/geometry/rect.h"
rbpotter213a4f72017-12-22 22:58:0917#include "ui/gfx/geometry/size.h"
initial.commit09911bf2008-07-26 23:55:2918
initial.commit09911bf2008-07-26 23:55:2919namespace printing {
20
[email protected]675a1ae2013-10-14 20:24:3721// Returns true if |color_mode| is color and not B&W.
22PRINTING_EXPORT bool IsColorModelSelected(int color_mode);
[email protected]63313ae2011-10-13 00:40:3923
[email protected]fa879e512011-11-08 20:39:0124#if defined(USE_CUPS)
25// Get the color model setting name and value for the |color_mode|.
26PRINTING_EXPORT void GetColorModelForMode(int color_mode,
27 std::string* color_setting_name,
28 std::string* color_value);
[email protected]63313ae2011-10-13 00:40:3929#endif
30
halcanary73b63fd2015-11-06 00:02:1431// Inform the printing system that it may embed this user-agent string
32// in its output's metadata.
33PRINTING_EXPORT void SetAgent(const std::string& user_agent);
34PRINTING_EXPORT const std::string& GetAgent();
35
[email protected]69f5b1e62011-09-01 06:34:0436class PRINTING_EXPORT PrintSettings {
initial.commit09911bf2008-07-26 23:55:2937 public:
rbpotter58bc882e2017-02-01 03:44:2438#if defined(OS_WIN)
39 enum PrinterType {
40 TYPE_NONE = 0,
rbpotter0437a1712017-07-14 21:23:2441 TYPE_TEXTONLY,
rbpotter58bc882e2017-02-01 03:44:2442 TYPE_XPS,
43 TYPE_POSTSCRIPT_LEVEL2,
44 TYPE_POSTSCRIPT_LEVEL3
45 };
46#endif
47
[email protected]72ddef92014-06-12 08:08:0648 // Media properties requested by the user. Default instance represents
49 // default media selection.
50 struct RequestedMedia {
51 // Size of the media, in microns.
52 gfx::Size size_microns;
53 // Platform specific id to map it back to the particular media.
54 std::string vendor_id;
55
56 bool IsDefault() const {
57 return size_microns.IsEmpty() && vendor_id.empty();
58 }
59 };
60
initial.commit09911bf2008-07-26 23:55:2961 PrintSettings();
vmpstr04b8358f2016-02-26 01:38:2962 PrintSettings(const PrintSettings& other);
[email protected]20f0487a2010-09-30 20:06:3063 ~PrintSettings();
initial.commit09911bf2008-07-26 23:55:2964
65 // 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.
85 const RequestedMedia& requested_media() const {
86 return requested_media_;
87 }
88
[email protected]e5324b52013-10-29 03:16:3789 // Set printer printable area in in device units.
90 // Some platforms already provide flipped area. Set |landscape_needs_flip|
91 // to false on those platforms to avoid double flipping.
Vladislav Kuzkokova3f4af8f2017-11-28 15:20:2692 // This method assumes correct DPI is already set.
[email protected]e5324b52013-10-29 03:16:3793 void SetPrinterPrintableArea(const gfx::Size& physical_size_device_units,
94 const gfx::Rect& printable_area_device_units,
[email protected]e5324b52013-10-29 03:16:3795 bool landscape_needs_flip);
96 const PageSetup& page_setup_device_units() const {
97 return page_setup_device_units_;
98 }
99
[email protected]b5fa4ee2013-10-01 07:19:07100 void set_device_name(const base::string16& device_name) {
initial.commit09911bf2008-07-26 23:55:29101 device_name_ = device_name;
102 }
[email protected]b5fa4ee2013-10-01 07:19:07103 const base::string16& device_name() const { return device_name_; }
[email protected]e5324b52013-10-29 03:16:37104
rbpotter213a4f72017-12-22 22:58:09105 void set_dpi(int dpi) { dpi_ = gfx::Size(dpi, dpi); }
rbpotter116c2e12017-04-04 19:21:28106 void set_dpi_xy(int dpi_horizontal, int dpi_vertical) {
rbpotter213a4f72017-12-22 22:58:09107 dpi_ = gfx::Size(dpi_horizontal, dpi_vertical);
rbpotter116c2e12017-04-04 19:21:28108 }
rbpotter213a4f72017-12-22 22:58:09109
110 int dpi() const { return std::max(dpi_.width(), dpi_.height()); }
111 int dpi_horizontal() const { return dpi_.width(); }
112 int dpi_vertical() const { return dpi_.height(); }
[email protected]e5324b52013-10-29 03:16:37113
rbpotter769ffdf2016-10-26 00:53:57114 void set_scale_factor(double scale_factor) { scale_factor_ = scale_factor; }
115 double scale_factor() const { return scale_factor_; }
116
rbpotter0fab356022016-12-28 22:00:23117 void set_rasterize_pdf(bool rasterize_pdf) { rasterize_pdf_ = rasterize_pdf; }
118 bool rasterize_pdf() const { return rasterize_pdf_; }
119
[email protected]b2b0fce2011-01-12 16:34:40120 void set_supports_alpha_blend(bool supports_alpha_blend) {
121 supports_alpha_blend_ = supports_alpha_blend;
122 }
123 bool supports_alpha_blend() const { return supports_alpha_blend_; }
[email protected]e5324b52013-10-29 03:16:37124
[email protected]6ab86ac2010-05-29 07:18:29125 int device_units_per_inch() const {
126#if defined(OS_MACOSX)
127 return 72;
128#else // defined(OS_MACOSX)
129 return dpi();
130#endif // defined(OS_MACOSX)
131 }
initial.commit09911bf2008-07-26 23:55:29132
thestige85e6b62016-08-25 00:00:06133 void set_ranges(const PageRanges& ranges) { ranges_ = ranges; }
134 const PageRanges& ranges() const { return ranges_; }
initial.commit09911bf2008-07-26 23:55:29135
[email protected]e5324b52013-10-29 03:16:37136 void set_selection_only(bool selection_only) {
137 selection_only_ = selection_only;
138 }
139 bool selection_only() const { return selection_only_; }
initial.commit09911bf2008-07-26 23:55:29140
[email protected]e5324b52013-10-29 03:16:37141 void set_should_print_backgrounds(bool should_print_backgrounds) {
142 should_print_backgrounds_ = should_print_backgrounds;
143 }
144 bool should_print_backgrounds() const { return should_print_backgrounds_; }
initial.commit09911bf2008-07-26 23:55:29145
[email protected]e5324b52013-10-29 03:16:37146 void set_display_header_footer(bool display_header_footer) {
147 display_header_footer_ = display_header_footer;
148 }
149 bool display_header_footer() const { return display_header_footer_; }
initial.commit09911bf2008-07-26 23:55:29150
[email protected]e5324b52013-10-29 03:16:37151 void set_title(const base::string16& title) { title_ = title; }
152 const base::string16& title() const { return title_; }
[email protected]c8ad40c2009-06-08 17:05:21153
[email protected]e5324b52013-10-29 03:16:37154 void set_url(const base::string16& url) { url_ = url; }
155 const base::string16& url() const { return url_; }
156
157 void set_collate(bool collate) { collate_ = collate; }
158 bool collate() const { return collate_; }
159
160 void set_color(ColorModel color) { color_ = color; }
161 ColorModel color() const { return color_; }
162
163 void set_copies(int copies) { copies_ = copies; }
164 int copies() const { return copies_; }
165
166 void set_duplex_mode(DuplexMode duplex_mode) { duplex_mode_ = duplex_mode; }
167 DuplexMode duplex_mode() const { return duplex_mode_; }
168
thestige85e6b62016-08-25 00:00:06169#if defined(OS_WIN)
170 void set_print_text_with_gdi(bool use_gdi) { print_text_with_gdi_ = use_gdi; }
171 bool print_text_with_gdi() const { return print_text_with_gdi_; }
thestig1f8436b2016-10-06 01:09:25172
rbpotter58bc882e2017-02-01 03:44:24173 void set_printer_type(PrinterType type) { printer_type_ = type; }
rbpotter0437a1712017-07-14 21:23:24174 bool printer_is_textonly() const {
175 return printer_type_ == PrinterType::TYPE_TEXTONLY;
176 }
rbpotter58bc882e2017-02-01 03:44:24177 bool printer_is_xps() const { return printer_type_ == PrinterType::TYPE_XPS;}
178 bool printer_is_ps2() const {
179 return printer_type_ == PrinterType::TYPE_POSTSCRIPT_LEVEL2;
180 }
181 bool printer_is_ps3() const {
182 return printer_type_ == PrinterType::TYPE_POSTSCRIPT_LEVEL3;
183 }
thestige85e6b62016-08-25 00:00:06184#endif
185
Wei Li02720a42017-10-25 22:06:48186 void set_is_modifiable(bool is_modifiable) { is_modifiable_ = is_modifiable; }
187 bool is_modifiable() const { return is_modifiable_; }
188
[email protected]d30e8e642008-08-06 12:05:24189 // Cookie generator. It is used to initialize PrintedDocument with its
190 // associated PrintSettings, to be sure that each generated PrintedPage is
191 // correctly associated with its corresponding PrintedDocument.
initial.commit09911bf2008-07-26 23:55:29192 static int NewCookie();
193
[email protected]e5324b52013-10-29 03:16:37194 private:
195 // Multi-page printing. Each PageRange describes a from-to page combination.
196 // This permits printing selected pages only.
197 PageRanges ranges_;
198
[email protected]e5324b52013-10-29 03:16:37199 // Indicates if the user only wants to print the current selection.
200 bool selection_only_;
201
202 // Indicates what kind of margins should be applied to the printable area.
203 MarginType margin_type_;
[email protected]c48bee22011-03-29 02:36:26204
[email protected]55b23a02011-08-17 23:09:36205 // Strings to be printed as headers and footers if requested by the user.
[email protected]e5324b52013-10-29 03:16:37206 base::string16 title_;
207 base::string16 url_;
[email protected]55b23a02011-08-17 23:09:36208
209 // True if the user wants headers and footers to be displayed.
[email protected]e5324b52013-10-29 03:16:37210 bool display_header_footer_;
[email protected]55b23a02011-08-17 23:09:36211
[email protected]19d1c2d2013-01-14 00:59:46212 // True if the user wants to print CSS backgrounds.
[email protected]e5324b52013-10-29 03:16:37213 bool should_print_backgrounds_;
[email protected]19d1c2d2013-01-14 00:59:46214
[email protected]e5324b52013-10-29 03:16:37215 // True if the user wants to print with collate.
216 bool collate_;
217
218 // True if the user wants to print with collate.
219 ColorModel color_;
220
221 // Number of copies user wants to print.
222 int copies_;
223
224 // Duplex type user wants to use.
225 DuplexMode duplex_mode_;
initial.commit09911bf2008-07-26 23:55:29226
initial.commit09911bf2008-07-26 23:55:29227 // Printer device name as opened by the OS.
[email protected]b5fa4ee2013-10-01 07:19:07228 base::string16 device_name_;
initial.commit09911bf2008-07-26 23:55:29229
[email protected]72ddef92014-06-12 08:08:06230 // Media requested by the user.
231 RequestedMedia requested_media_;
232
[email protected]6ab86ac2010-05-29 07:18:29233 // Page setup in device units.
234 PageSetup page_setup_device_units_;
initial.commit09911bf2008-07-26 23:55:29235
rbpotter116c2e12017-04-04 19:21:28236 // Printer's device effective dots per inch in both axes. The two values will
237 // generally be identical. However, on Windows, there are a few rare printers
238 // that support resolutions with different DPI in different dimensions.
rbpotter213a4f72017-12-22 22:58:09239 gfx::Size dpi_;
initial.commit09911bf2008-07-26 23:55:29240
rbpotter769ffdf2016-10-26 00:53:57241 // Scale factor
242 double scale_factor_;
243
rbpotter0fab356022016-12-28 22:00:23244 // True if PDF should be printed as a raster PDF
245 bool rasterize_pdf_;
246
initial.commit09911bf2008-07-26 23:55:29247 // Is the orientation landscape or portrait.
248 bool landscape_;
[email protected]b2b0fce2011-01-12 16:34:40249
250 // True if this printer supports AlphaBlend.
251 bool supports_alpha_blend_;
[email protected]1c23b4e82011-10-15 22:30:48252
thestige85e6b62016-08-25 00:00:06253#if defined(OS_WIN)
254 // True to print text with GDI.
255 bool print_text_with_gdi_;
thestig1f8436b2016-10-06 01:09:25256
rbpotter58bc882e2017-02-01 03:44:24257 PrinterType printer_type_;
thestige85e6b62016-08-25 00:00:06258#endif
259
Wei Li02720a42017-10-25 22:06:48260 bool is_modifiable_;
261
[email protected]b076a082011-10-20 01:26:32262 // If margin type is custom, this is what was requested.
263 PageMargins requested_custom_margins_in_points_;
initial.commit09911bf2008-07-26 23:55:29264};
265
266} // namespace printing
267
[email protected]8ff1d422009-07-07 21:31:39268#endif // PRINTING_PRINT_SETTINGS_H_