[email protected] | 71f40a7 | 2012-05-16 07:26:59 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | 8ff1d42 | 2009-07-07 21:31:39 | [diff] [blame] | 5 | #ifndef PRINTING_PRINT_SETTINGS_H_ |
| 6 | #define PRINTING_PRINT_SETTINGS_H_ |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 7 | |
rbpotter | 116c2e1 | 2017-04-04 19:21:28 | [diff] [blame] | 8 | #include <algorithm> |
[email protected] | dcd1e886 | 2011-08-09 06:06:58 | [diff] [blame] | 9 | #include <string> |
| 10 | |
[email protected] | 896d161f | 2013-06-11 22:52:24 | [diff] [blame] | 11 | #include "base/strings/string16.h" |
[email protected] | 8ff1d42 | 2009-07-07 21:31:39 | [diff] [blame] | 12 | #include "printing/page_range.h" |
| 13 | #include "printing/page_setup.h" |
[email protected] | 1c23b4e8 | 2011-10-15 22:30:48 | [diff] [blame] | 14 | #include "printing/print_job_constants.h" |
[email protected] | 63313ae | 2011-10-13 00:40:39 | [diff] [blame] | 15 | #include "printing/printing_export.h" |
tfarina | 3b0452d | 2014-12-31 15:20:09 | [diff] [blame] | 16 | #include "ui/gfx/geometry/rect.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 17 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 18 | namespace printing { |
| 19 | |
[email protected] | 675a1ae | 2013-10-14 20:24:37 | [diff] [blame] | 20 | // Returns true if |color_mode| is color and not B&W. |
| 21 | PRINTING_EXPORT bool IsColorModelSelected(int color_mode); |
[email protected] | 63313ae | 2011-10-13 00:40:39 | [diff] [blame] | 22 | |
[email protected] | fa879e51 | 2011-11-08 20:39:01 | [diff] [blame] | 23 | #if defined(USE_CUPS) |
| 24 | // Get the color model setting name and value for the |color_mode|. |
| 25 | PRINTING_EXPORT void GetColorModelForMode(int color_mode, |
| 26 | std::string* color_setting_name, |
| 27 | std::string* color_value); |
[email protected] | 63313ae | 2011-10-13 00:40:39 | [diff] [blame] | 28 | #endif |
| 29 | |
halcanary | 73b63fd | 2015-11-06 00:02:14 | [diff] [blame] | 30 | // Inform the printing system that it may embed this user-agent string |
| 31 | // in its output's metadata. |
| 32 | PRINTING_EXPORT void SetAgent(const std::string& user_agent); |
| 33 | PRINTING_EXPORT const std::string& GetAgent(); |
| 34 | |
[email protected] | 69f5b1e6 | 2011-09-01 06:34:04 | [diff] [blame] | 35 | class PRINTING_EXPORT PrintSettings { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 36 | public: |
rbpotter | 58bc882e | 2017-02-01 03:44:24 | [diff] [blame] | 37 | #if defined(OS_WIN) |
| 38 | enum PrinterType { |
| 39 | TYPE_NONE = 0, |
rbpotter | 0437a171 | 2017-07-14 21:23:24 | [diff] [blame] | 40 | TYPE_TEXTONLY, |
rbpotter | 58bc882e | 2017-02-01 03:44:24 | [diff] [blame] | 41 | TYPE_XPS, |
| 42 | TYPE_POSTSCRIPT_LEVEL2, |
| 43 | TYPE_POSTSCRIPT_LEVEL3 |
| 44 | }; |
| 45 | #endif |
| 46 | |
[email protected] | 72ddef9 | 2014-06-12 08:08:06 | [diff] [blame] | 47 | // Media properties requested by the user. Default instance represents |
| 48 | // default media selection. |
| 49 | struct RequestedMedia { |
| 50 | // Size of the media, in microns. |
| 51 | gfx::Size size_microns; |
| 52 | // Platform specific id to map it back to the particular media. |
| 53 | std::string vendor_id; |
| 54 | |
| 55 | bool IsDefault() const { |
| 56 | return size_microns.IsEmpty() && vendor_id.empty(); |
| 57 | } |
| 58 | }; |
| 59 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 60 | PrintSettings(); |
vmpstr | 04b8358f | 2016-02-26 01:38:29 | [diff] [blame] | 61 | PrintSettings(const PrintSettings& other); |
[email protected] | 20f0487a | 2010-09-30 20:06:30 | [diff] [blame] | 62 | ~PrintSettings(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 63 | |
| 64 | // Reinitialize the settings to the default values. |
| 65 | void Clear(); |
| 66 | |
[email protected] | b076a08 | 2011-10-20 01:26:32 | [diff] [blame] | 67 | void SetCustomMargins(const PageMargins& requested_margins_in_points); |
[email protected] | c95198b | 2014-06-12 16:56:55 | [diff] [blame] | 68 | const PageMargins& requested_custom_margins_in_points() const { |
| 69 | return requested_custom_margins_in_points_; |
| 70 | } |
[email protected] | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 71 | void set_margin_type(MarginType margin_type) { margin_type_ = margin_type; } |
| 72 | MarginType margin_type() const { return margin_type_; } |
[email protected] | 1c23b4e8 | 2011-10-15 22:30:48 | [diff] [blame] | 73 | |
[email protected] | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 74 | // Updates the orientation and flip the page if needed. |
| 75 | void SetOrientation(bool landscape); |
| 76 | bool landscape() const { return landscape_; } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 77 | |
[email protected] | 72ddef9 | 2014-06-12 08:08:06 | [diff] [blame] | 78 | // Updates user requested media. |
| 79 | void set_requested_media(const RequestedMedia& media) { |
| 80 | requested_media_ = media; |
| 81 | } |
| 82 | // Media properties requested by the user. Translated into device media by the |
| 83 | // platform specific layers. |
| 84 | const RequestedMedia& requested_media() const { |
| 85 | return requested_media_; |
| 86 | } |
| 87 | |
[email protected] | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 88 | // Set printer printable area in in device units. |
| 89 | // Some platforms already provide flipped area. Set |landscape_needs_flip| |
| 90 | // to false on those platforms to avoid double flipping. |
| 91 | void SetPrinterPrintableArea(const gfx::Size& physical_size_device_units, |
| 92 | const gfx::Rect& printable_area_device_units, |
[email protected] | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 93 | bool landscape_needs_flip); |
| 94 | const PageSetup& page_setup_device_units() const { |
| 95 | return page_setup_device_units_; |
| 96 | } |
| 97 | |
[email protected] | b5fa4ee | 2013-10-01 07:19:07 | [diff] [blame] | 98 | void set_device_name(const base::string16& device_name) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 99 | device_name_ = device_name; |
| 100 | } |
[email protected] | b5fa4ee | 2013-10-01 07:19:07 | [diff] [blame] | 101 | const base::string16& device_name() const { return device_name_; } |
[email protected] | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 102 | |
rbpotter | 116c2e1 | 2017-04-04 19:21:28 | [diff] [blame] | 103 | void set_dpi(int dpi) { |
| 104 | dpi_[0] = dpi; |
| 105 | dpi_[1] = dpi; |
| 106 | } |
| 107 | void set_dpi_xy(int dpi_horizontal, int dpi_vertical) { |
| 108 | dpi_[0] = dpi_horizontal; |
| 109 | dpi_[1] = dpi_vertical; |
| 110 | } |
rbpotter | 2fe35484 | 2017-09-11 22:53:41 | [diff] [blame] | 111 | int dpi() const { return std::max(dpi_[0], dpi_[1]); } |
rbpotter | 116c2e1 | 2017-04-04 19:21:28 | [diff] [blame] | 112 | int dpi_horizontal() const { return dpi_[0]; } |
| 113 | int dpi_vertical() const { return dpi_[1]; } |
[email protected] | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 114 | |
rbpotter | 769ffdf | 2016-10-26 00:53:57 | [diff] [blame] | 115 | void set_scale_factor(double scale_factor) { scale_factor_ = scale_factor; } |
| 116 | double scale_factor() const { return scale_factor_; } |
| 117 | |
rbpotter | 0fab35602 | 2016-12-28 22:00:23 | [diff] [blame] | 118 | void set_rasterize_pdf(bool rasterize_pdf) { rasterize_pdf_ = rasterize_pdf; } |
| 119 | bool rasterize_pdf() const { return rasterize_pdf_; } |
| 120 | |
[email protected] | b2b0fce | 2011-01-12 16:34:40 | [diff] [blame] | 121 | void set_supports_alpha_blend(bool supports_alpha_blend) { |
| 122 | supports_alpha_blend_ = supports_alpha_blend; |
| 123 | } |
| 124 | bool supports_alpha_blend() const { return supports_alpha_blend_; } |
[email protected] | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 125 | |
[email protected] | 6ab86ac | 2010-05-29 07:18:29 | [diff] [blame] | 126 | int device_units_per_inch() const { |
| 127 | #if defined(OS_MACOSX) |
| 128 | return 72; |
| 129 | #else // defined(OS_MACOSX) |
| 130 | return dpi(); |
| 131 | #endif // defined(OS_MACOSX) |
| 132 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 133 | |
thestig | e85e6b6 | 2016-08-25 00:00:06 | [diff] [blame] | 134 | void set_ranges(const PageRanges& ranges) { ranges_ = ranges; } |
| 135 | const PageRanges& ranges() const { return ranges_; } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 136 | |
[email protected] | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 137 | void set_selection_only(bool selection_only) { |
| 138 | selection_only_ = selection_only; |
| 139 | } |
| 140 | bool selection_only() const { return selection_only_; } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 141 | |
[email protected] | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 142 | void set_should_print_backgrounds(bool should_print_backgrounds) { |
| 143 | should_print_backgrounds_ = should_print_backgrounds; |
| 144 | } |
| 145 | bool should_print_backgrounds() const { return should_print_backgrounds_; } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 146 | |
[email protected] | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 147 | void set_display_header_footer(bool display_header_footer) { |
| 148 | display_header_footer_ = display_header_footer; |
| 149 | } |
| 150 | bool display_header_footer() const { return display_header_footer_; } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 151 | |
[email protected] | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 152 | void set_title(const base::string16& title) { title_ = title; } |
| 153 | const base::string16& title() const { return title_; } |
[email protected] | c8ad40c | 2009-06-08 17:05:21 | [diff] [blame] | 154 | |
[email protected] | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 155 | void set_url(const base::string16& url) { url_ = url; } |
| 156 | const base::string16& url() const { return url_; } |
| 157 | |
| 158 | void set_collate(bool collate) { collate_ = collate; } |
| 159 | bool collate() const { return collate_; } |
| 160 | |
| 161 | void set_color(ColorModel color) { color_ = color; } |
| 162 | ColorModel color() const { return color_; } |
| 163 | |
| 164 | void set_copies(int copies) { copies_ = copies; } |
| 165 | int copies() const { return copies_; } |
| 166 | |
| 167 | void set_duplex_mode(DuplexMode duplex_mode) { duplex_mode_ = duplex_mode; } |
| 168 | DuplexMode duplex_mode() const { return duplex_mode_; } |
| 169 | |
thestig | e85e6b6 | 2016-08-25 00:00:06 | [diff] [blame] | 170 | #if defined(OS_WIN) |
| 171 | void set_print_text_with_gdi(bool use_gdi) { print_text_with_gdi_ = use_gdi; } |
| 172 | bool print_text_with_gdi() const { return print_text_with_gdi_; } |
thestig | 1f8436b | 2016-10-06 01:09:25 | [diff] [blame] | 173 | |
rbpotter | 58bc882e | 2017-02-01 03:44:24 | [diff] [blame] | 174 | void set_printer_type(PrinterType type) { printer_type_ = type; } |
rbpotter | 0437a171 | 2017-07-14 21:23:24 | [diff] [blame] | 175 | bool printer_is_textonly() const { |
| 176 | return printer_type_ == PrinterType::TYPE_TEXTONLY; |
| 177 | } |
rbpotter | 58bc882e | 2017-02-01 03:44:24 | [diff] [blame] | 178 | bool printer_is_xps() const { return printer_type_ == PrinterType::TYPE_XPS;} |
| 179 | bool printer_is_ps2() const { |
| 180 | return printer_type_ == PrinterType::TYPE_POSTSCRIPT_LEVEL2; |
| 181 | } |
| 182 | bool printer_is_ps3() const { |
| 183 | return printer_type_ == PrinterType::TYPE_POSTSCRIPT_LEVEL3; |
| 184 | } |
thestig | e85e6b6 | 2016-08-25 00:00:06 | [diff] [blame] | 185 | #endif |
| 186 | |
[email protected] | d30e8e64 | 2008-08-06 12:05:24 | [diff] [blame] | 187 | // Cookie generator. It is used to initialize PrintedDocument with its |
| 188 | // associated PrintSettings, to be sure that each generated PrintedPage is |
| 189 | // correctly associated with its corresponding PrintedDocument. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 190 | static int NewCookie(); |
| 191 | |
[email protected] | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 192 | private: |
| 193 | // Multi-page printing. Each PageRange describes a from-to page combination. |
| 194 | // This permits printing selected pages only. |
| 195 | PageRanges ranges_; |
| 196 | |
[email protected] | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 197 | // Indicates if the user only wants to print the current selection. |
| 198 | bool selection_only_; |
| 199 | |
| 200 | // Indicates what kind of margins should be applied to the printable area. |
| 201 | MarginType margin_type_; |
[email protected] | c48bee2 | 2011-03-29 02:36:26 | [diff] [blame] | 202 | |
[email protected] | 55b23a0 | 2011-08-17 23:09:36 | [diff] [blame] | 203 | // Strings to be printed as headers and footers if requested by the user. |
[email protected] | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 204 | base::string16 title_; |
| 205 | base::string16 url_; |
[email protected] | 55b23a0 | 2011-08-17 23:09:36 | [diff] [blame] | 206 | |
| 207 | // True if the user wants headers and footers to be displayed. |
[email protected] | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 208 | bool display_header_footer_; |
[email protected] | 55b23a0 | 2011-08-17 23:09:36 | [diff] [blame] | 209 | |
[email protected] | 19d1c2d | 2013-01-14 00:59:46 | [diff] [blame] | 210 | // True if the user wants to print CSS backgrounds. |
[email protected] | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 211 | bool should_print_backgrounds_; |
[email protected] | 19d1c2d | 2013-01-14 00:59:46 | [diff] [blame] | 212 | |
[email protected] | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 213 | // True if the user wants to print with collate. |
| 214 | bool collate_; |
| 215 | |
| 216 | // True if the user wants to print with collate. |
| 217 | ColorModel color_; |
| 218 | |
| 219 | // Number of copies user wants to print. |
| 220 | int copies_; |
| 221 | |
| 222 | // Duplex type user wants to use. |
| 223 | DuplexMode duplex_mode_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 224 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 225 | // Printer device name as opened by the OS. |
[email protected] | b5fa4ee | 2013-10-01 07:19:07 | [diff] [blame] | 226 | base::string16 device_name_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 227 | |
[email protected] | 72ddef9 | 2014-06-12 08:08:06 | [diff] [blame] | 228 | // Media requested by the user. |
| 229 | RequestedMedia requested_media_; |
| 230 | |
[email protected] | 6ab86ac | 2010-05-29 07:18:29 | [diff] [blame] | 231 | // Page setup in device units. |
| 232 | PageSetup page_setup_device_units_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 233 | |
rbpotter | 116c2e1 | 2017-04-04 19:21:28 | [diff] [blame] | 234 | // Printer's device effective dots per inch in both axes. The two values will |
| 235 | // generally be identical. However, on Windows, there are a few rare printers |
| 236 | // that support resolutions with different DPI in different dimensions. |
| 237 | int dpi_[2]; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 238 | |
rbpotter | 769ffdf | 2016-10-26 00:53:57 | [diff] [blame] | 239 | // Scale factor |
| 240 | double scale_factor_; |
| 241 | |
rbpotter | 0fab35602 | 2016-12-28 22:00:23 | [diff] [blame] | 242 | // True if PDF should be printed as a raster PDF |
| 243 | bool rasterize_pdf_; |
| 244 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 245 | // Is the orientation landscape or portrait. |
| 246 | bool landscape_; |
[email protected] | b2b0fce | 2011-01-12 16:34:40 | [diff] [blame] | 247 | |
| 248 | // True if this printer supports AlphaBlend. |
| 249 | bool supports_alpha_blend_; |
[email protected] | 1c23b4e8 | 2011-10-15 22:30:48 | [diff] [blame] | 250 | |
thestig | e85e6b6 | 2016-08-25 00:00:06 | [diff] [blame] | 251 | #if defined(OS_WIN) |
| 252 | // True to print text with GDI. |
| 253 | bool print_text_with_gdi_; |
thestig | 1f8436b | 2016-10-06 01:09:25 | [diff] [blame] | 254 | |
rbpotter | 58bc882e | 2017-02-01 03:44:24 | [diff] [blame] | 255 | PrinterType printer_type_; |
thestig | e85e6b6 | 2016-08-25 00:00:06 | [diff] [blame] | 256 | #endif |
| 257 | |
[email protected] | b076a08 | 2011-10-20 01:26:32 | [diff] [blame] | 258 | // If margin type is custom, this is what was requested. |
| 259 | PageMargins requested_custom_margins_in_points_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 260 | }; |
| 261 | |
| 262 | } // namespace printing |
| 263 | |
[email protected] | 8ff1d42 | 2009-07-07 21:31:39 | [diff] [blame] | 264 | #endif // PRINTING_PRINT_SETTINGS_H_ |