blob: 1311ddbeb911f30b9ca39335c0b679ec6f711bab [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
[email protected]dcd1e8862011-08-09 06:06:588#include <string>
9
[email protected]896d161f2013-06-11 22:52:2410#include "base/strings/string16.h"
[email protected]8ff1d422009-07-07 21:31:3911#include "printing/page_range.h"
12#include "printing/page_setup.h"
[email protected]1c23b4e82011-10-15 22:30:4813#include "printing/print_job_constants.h"
[email protected]63313ae2011-10-13 00:40:3914#include "printing/printing_export.h"
tfarina3b0452d2014-12-31 15:20:0915#include "ui/gfx/geometry/rect.h"
initial.commit09911bf2008-07-26 23:55:2916
initial.commit09911bf2008-07-26 23:55:2917namespace printing {
18
[email protected]675a1ae2013-10-14 20:24:3719// Returns true if |color_mode| is color and not B&W.
20PRINTING_EXPORT bool IsColorModelSelected(int color_mode);
[email protected]63313ae2011-10-13 00:40:3921
[email protected]fa879e512011-11-08 20:39:0122#if defined(USE_CUPS)
23// Get the color model setting name and value for the |color_mode|.
24PRINTING_EXPORT void GetColorModelForMode(int color_mode,
25 std::string* color_setting_name,
26 std::string* color_value);
[email protected]63313ae2011-10-13 00:40:3927#endif
28
halcanary73b63fd2015-11-06 00:02:1429// Inform the printing system that it may embed this user-agent string
30// in its output's metadata.
31PRINTING_EXPORT void SetAgent(const std::string& user_agent);
32PRINTING_EXPORT const std::string& GetAgent();
33
initial.commit09911bf2008-07-26 23:55:2934// OS-independent print settings.
[email protected]69f5b1e62011-09-01 06:34:0435class PRINTING_EXPORT PrintSettings {
initial.commit09911bf2008-07-26 23:55:2936 public:
rbpotter58bc882e2017-02-01 03:44:2437#if defined(OS_WIN)
38 enum PrinterType {
39 TYPE_NONE = 0,
40 TYPE_XPS,
41 TYPE_POSTSCRIPT_LEVEL2,
42 TYPE_POSTSCRIPT_LEVEL3
43 };
44#endif
45
[email protected]72ddef92014-06-12 08:08:0646 // Media properties requested by the user. Default instance represents
47 // default media selection.
48 struct RequestedMedia {
49 // Size of the media, in microns.
50 gfx::Size size_microns;
51 // Platform specific id to map it back to the particular media.
52 std::string vendor_id;
53
54 bool IsDefault() const {
55 return size_microns.IsEmpty() && vendor_id.empty();
56 }
57 };
58
initial.commit09911bf2008-07-26 23:55:2959 PrintSettings();
vmpstr04b8358f2016-02-26 01:38:2960 PrintSettings(const PrintSettings& other);
[email protected]20f0487a2010-09-30 20:06:3061 ~PrintSettings();
initial.commit09911bf2008-07-26 23:55:2962
63 // Reinitialize the settings to the default values.
64 void Clear();
65
[email protected]b076a082011-10-20 01:26:3266 void SetCustomMargins(const PageMargins& requested_margins_in_points);
[email protected]c95198b2014-06-12 16:56:5567 const PageMargins& requested_custom_margins_in_points() const {
68 return requested_custom_margins_in_points_;
69 }
[email protected]e5324b52013-10-29 03:16:3770 void set_margin_type(MarginType margin_type) { margin_type_ = margin_type; }
71 MarginType margin_type() const { return margin_type_; }
[email protected]1c23b4e82011-10-15 22:30:4872
[email protected]e5324b52013-10-29 03:16:3773 // Updates the orientation and flip the page if needed.
74 void SetOrientation(bool landscape);
75 bool landscape() const { return landscape_; }
initial.commit09911bf2008-07-26 23:55:2976
[email protected]72ddef92014-06-12 08:08:0677 // Updates user requested media.
78 void set_requested_media(const RequestedMedia& media) {
79 requested_media_ = media;
80 }
81 // Media properties requested by the user. Translated into device media by the
82 // platform specific layers.
83 const RequestedMedia& requested_media() const {
84 return requested_media_;
85 }
86
[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.
90 void SetPrinterPrintableArea(const gfx::Size& physical_size_device_units,
91 const gfx::Rect& printable_area_device_units,
[email protected]e5324b52013-10-29 03:16:3792 bool landscape_needs_flip);
93 const PageSetup& page_setup_device_units() const {
94 return page_setup_device_units_;
95 }
96
[email protected]b5fa4ee2013-10-01 07:19:0797 void set_device_name(const base::string16& device_name) {
initial.commit09911bf2008-07-26 23:55:2998 device_name_ = device_name;
99 }
[email protected]b5fa4ee2013-10-01 07:19:07100 const base::string16& device_name() const { return device_name_; }
[email protected]e5324b52013-10-29 03:16:37101
[email protected]4993f342010-10-26 17:57:52102 void set_dpi(int dpi) { dpi_ = dpi; }
initial.commit09911bf2008-07-26 23:55:29103 int dpi() const { return dpi_; }
[email protected]e5324b52013-10-29 03:16:37104
rbpotter769ffdf2016-10-26 00:53:57105 void set_scale_factor(double scale_factor) { scale_factor_ = scale_factor; }
106 double scale_factor() const { return scale_factor_; }
107
rbpotter0fab356022016-12-28 22:00:23108 void set_rasterize_pdf(bool rasterize_pdf) { rasterize_pdf_ = rasterize_pdf; }
109 bool rasterize_pdf() const { return rasterize_pdf_; }
110
[email protected]b2b0fce2011-01-12 16:34:40111 void set_supports_alpha_blend(bool supports_alpha_blend) {
112 supports_alpha_blend_ = supports_alpha_blend;
113 }
114 bool supports_alpha_blend() const { return supports_alpha_blend_; }
[email protected]e5324b52013-10-29 03:16:37115
[email protected]6ab86ac2010-05-29 07:18:29116 int device_units_per_inch() const {
117#if defined(OS_MACOSX)
118 return 72;
119#else // defined(OS_MACOSX)
120 return dpi();
121#endif // defined(OS_MACOSX)
122 }
initial.commit09911bf2008-07-26 23:55:29123
thestige85e6b62016-08-25 00:00:06124 void set_ranges(const PageRanges& ranges) { ranges_ = ranges; }
125 const PageRanges& ranges() const { return ranges_; }
initial.commit09911bf2008-07-26 23:55:29126
[email protected]e5324b52013-10-29 03:16:37127 void set_selection_only(bool selection_only) {
128 selection_only_ = selection_only;
129 }
130 bool selection_only() const { return selection_only_; }
initial.commit09911bf2008-07-26 23:55:29131
[email protected]e5324b52013-10-29 03:16:37132 void set_should_print_backgrounds(bool should_print_backgrounds) {
133 should_print_backgrounds_ = should_print_backgrounds;
134 }
135 bool should_print_backgrounds() const { return should_print_backgrounds_; }
initial.commit09911bf2008-07-26 23:55:29136
[email protected]e5324b52013-10-29 03:16:37137 void set_display_header_footer(bool display_header_footer) {
138 display_header_footer_ = display_header_footer;
139 }
140 bool display_header_footer() const { return display_header_footer_; }
initial.commit09911bf2008-07-26 23:55:29141
[email protected]e5324b52013-10-29 03:16:37142 void set_title(const base::string16& title) { title_ = title; }
143 const base::string16& title() const { return title_; }
[email protected]c8ad40c2009-06-08 17:05:21144
[email protected]e5324b52013-10-29 03:16:37145 void set_url(const base::string16& url) { url_ = url; }
146 const base::string16& url() const { return url_; }
147
148 void set_collate(bool collate) { collate_ = collate; }
149 bool collate() const { return collate_; }
150
151 void set_color(ColorModel color) { color_ = color; }
152 ColorModel color() const { return color_; }
153
154 void set_copies(int copies) { copies_ = copies; }
155 int copies() const { return copies_; }
156
157 void set_duplex_mode(DuplexMode duplex_mode) { duplex_mode_ = duplex_mode; }
158 DuplexMode duplex_mode() const { return duplex_mode_; }
159
160 int desired_dpi() const { return desired_dpi_; }
161
thestige85e6b62016-08-25 00:00:06162#if defined(OS_WIN)
163 void set_print_text_with_gdi(bool use_gdi) { print_text_with_gdi_ = use_gdi; }
164 bool print_text_with_gdi() const { return print_text_with_gdi_; }
thestig1f8436b2016-10-06 01:09:25165
rbpotter58bc882e2017-02-01 03:44:24166 void set_printer_type(PrinterType type) { printer_type_ = type; }
167 bool printer_is_xps() const { return printer_type_ == PrinterType::TYPE_XPS;}
168 bool printer_is_ps2() const {
169 return printer_type_ == PrinterType::TYPE_POSTSCRIPT_LEVEL2;
170 }
171 bool printer_is_ps3() const {
172 return printer_type_ == PrinterType::TYPE_POSTSCRIPT_LEVEL3;
173 }
thestige85e6b62016-08-25 00:00:06174#endif
175
[email protected]d30e8e642008-08-06 12:05:24176 // Cookie generator. It is used to initialize PrintedDocument with its
177 // associated PrintSettings, to be sure that each generated PrintedPage is
178 // correctly associated with its corresponding PrintedDocument.
initial.commit09911bf2008-07-26 23:55:29179 static int NewCookie();
180
[email protected]e5324b52013-10-29 03:16:37181 private:
182 // Multi-page printing. Each PageRange describes a from-to page combination.
183 // This permits printing selected pages only.
184 PageRanges ranges_;
185
[email protected]e5324b52013-10-29 03:16:37186 // Desired visible dots per inch rendering for output. Printing should be
187 // scaled to ScreenDpi/dpix*desired_dpi.
188 int desired_dpi_;
189
190 // Indicates if the user only wants to print the current selection.
191 bool selection_only_;
192
193 // Indicates what kind of margins should be applied to the printable area.
194 MarginType margin_type_;
[email protected]c48bee22011-03-29 02:36:26195
[email protected]55b23a02011-08-17 23:09:36196 // Strings to be printed as headers and footers if requested by the user.
[email protected]e5324b52013-10-29 03:16:37197 base::string16 title_;
198 base::string16 url_;
[email protected]55b23a02011-08-17 23:09:36199
200 // True if the user wants headers and footers to be displayed.
[email protected]e5324b52013-10-29 03:16:37201 bool display_header_footer_;
[email protected]55b23a02011-08-17 23:09:36202
[email protected]19d1c2d2013-01-14 00:59:46203 // True if the user wants to print CSS backgrounds.
[email protected]e5324b52013-10-29 03:16:37204 bool should_print_backgrounds_;
[email protected]19d1c2d2013-01-14 00:59:46205
[email protected]e5324b52013-10-29 03:16:37206 // True if the user wants to print with collate.
207 bool collate_;
208
209 // True if the user wants to print with collate.
210 ColorModel color_;
211
212 // Number of copies user wants to print.
213 int copies_;
214
215 // Duplex type user wants to use.
216 DuplexMode duplex_mode_;
initial.commit09911bf2008-07-26 23:55:29217
initial.commit09911bf2008-07-26 23:55:29218 // Printer device name as opened by the OS.
[email protected]b5fa4ee2013-10-01 07:19:07219 base::string16 device_name_;
initial.commit09911bf2008-07-26 23:55:29220
[email protected]72ddef92014-06-12 08:08:06221 // Media requested by the user.
222 RequestedMedia requested_media_;
223
[email protected]6ab86ac2010-05-29 07:18:29224 // Page setup in device units.
225 PageSetup page_setup_device_units_;
initial.commit09911bf2008-07-26 23:55:29226
227 // Printer's device effective dots per inch in both axis.
228 int dpi_;
229
rbpotter769ffdf2016-10-26 00:53:57230 // Scale factor
231 double scale_factor_;
232
rbpotter0fab356022016-12-28 22:00:23233 // True if PDF should be printed as a raster PDF
234 bool rasterize_pdf_;
235
initial.commit09911bf2008-07-26 23:55:29236 // Is the orientation landscape or portrait.
237 bool landscape_;
[email protected]b2b0fce2011-01-12 16:34:40238
239 // True if this printer supports AlphaBlend.
240 bool supports_alpha_blend_;
[email protected]1c23b4e82011-10-15 22:30:48241
thestige85e6b62016-08-25 00:00:06242#if defined(OS_WIN)
243 // True to print text with GDI.
244 bool print_text_with_gdi_;
thestig1f8436b2016-10-06 01:09:25245
rbpotter58bc882e2017-02-01 03:44:24246 PrinterType printer_type_;
thestige85e6b62016-08-25 00:00:06247#endif
248
[email protected]b076a082011-10-20 01:26:32249 // If margin type is custom, this is what was requested.
250 PageMargins requested_custom_margins_in_points_;
initial.commit09911bf2008-07-26 23:55:29251};
252
253} // namespace printing
254
[email protected]8ff1d422009-07-07 21:31:39255#endif // PRINTING_PRINT_SETTINGS_H_