1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef PRINTING_PRINT_SETTINGS_H_
6 #define PRINTING_PRINT_SETTINGS_H_
11 #include "base/strings/string16.h"
12 #include "printing/page_range.h"
13 #include "printing/page_setup.h"
14 #include "printing/print_job_constants.h"
15 #include "printing/printing_export.h"
16 #include "ui/gfx/geometry/rect.h"
17 #include "ui/gfx/geometry/size.h"
21 // Returns true if |color_mode| is color and not B&W.
22 PRINTING_EXPORT bool IsColorModelSelected(int color_mode);
25 // Get the color model setting name and value for the |color_mode|.
26 PRINTING_EXPORT void GetColorModelForMode(int color_mode,
27 std::string* color_setting_name,
28 std::string* color_value);
31 // Inform the printing system that it may embed this user-agent string
32 // in its output's metadata.
33 PRINTING_EXPORT void SetAgent(const std::string& user_agent);
34 PRINTING_EXPORT const std::string& GetAgent();
36 class PRINTING_EXPORT PrintSettings {
43 TYPE_POSTSCRIPT_LEVEL2,
44 TYPE_POSTSCRIPT_LEVEL3
48 // 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;
56 bool IsDefault() const {
57 return size_microns.IsEmpty() && vendor_id.empty();
62 PrintSettings(const PrintSettings& other);
65 // Reinitialize the settings to the default values.
68 void SetCustomMargins(const PageMargins& requested_margins_in_points);
69 const PageMargins& requested_custom_margins_in_points() const {
70 return requested_custom_margins_in_points_;
72 void set_margin_type(MarginType margin_type) { margin_type_ = margin_type; }
73 MarginType margin_type() const { return margin_type_; }
75 // Updates the orientation and flip the page if needed.
76 void SetOrientation(bool landscape);
77 bool landscape() const { return landscape_; }
79 // Updates user requested media.
80 void set_requested_media(const RequestedMedia& media) {
81 requested_media_ = media;
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_;
89 // 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.
92 // This method assumes correct DPI is already set.
93 void SetPrinterPrintableArea(const gfx::Size& physical_size_device_units,
94 const gfx::Rect& printable_area_device_units,
95 bool landscape_needs_flip);
96 const PageSetup& page_setup_device_units() const {
97 return page_setup_device_units_;
100 void set_device_name(const base::string16& device_name) {
101 device_name_ = device_name;
103 const base::string16& device_name() const { return device_name_; }
105 void set_dpi(int dpi) { dpi_ = gfx::Size(dpi, dpi); }
106 void set_dpi_xy(int dpi_horizontal, int dpi_vertical) {
107 dpi_ = gfx::Size(dpi_horizontal, dpi_vertical);
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(); }
113 const gfx::Size& dpi_size() const { return dpi_; }
115 void set_scale_factor(double scale_factor) { scale_factor_ = scale_factor; }
116 double scale_factor() const { return scale_factor_; }
118 void set_rasterize_pdf(bool rasterize_pdf) { rasterize_pdf_ = rasterize_pdf; }
119 bool rasterize_pdf() const { return rasterize_pdf_; }
121 void set_supports_alpha_blend(bool supports_alpha_blend) {
122 supports_alpha_blend_ = supports_alpha_blend;
124 bool supports_alpha_blend() const { return supports_alpha_blend_; }
126 int device_units_per_inch() const {
127 #if defined(OS_MACOSX)
129 #else // defined(OS_MACOSX)
131 #endif // defined(OS_MACOSX)
134 void set_ranges(const PageRanges& ranges) { ranges_ = ranges; }
135 const PageRanges& ranges() const { return ranges_; }
137 void set_selection_only(bool selection_only) {
138 selection_only_ = selection_only;
140 bool selection_only() const { return selection_only_; }
142 void set_should_print_backgrounds(bool should_print_backgrounds) {
143 should_print_backgrounds_ = should_print_backgrounds;
145 bool should_print_backgrounds() const { return should_print_backgrounds_; }
147 void set_display_header_footer(bool display_header_footer) {
148 display_header_footer_ = display_header_footer;
150 bool display_header_footer() const { return display_header_footer_; }
152 void set_title(const base::string16& title) { title_ = title; }
153 const base::string16& title() const { return title_; }
155 void set_url(const base::string16& url) { url_ = url; }
156 const base::string16& url() const { return url_; }
158 void set_collate(bool collate) { collate_ = collate; }
159 bool collate() const { return collate_; }
161 void set_color(ColorModel color) { color_ = color; }
162 ColorModel color() const { return color_; }
164 void set_copies(int copies) { copies_ = copies; }
165 int copies() const { return copies_; }
167 void set_duplex_mode(DuplexMode duplex_mode) { duplex_mode_ = duplex_mode; }
168 DuplexMode duplex_mode() const { return duplex_mode_; }
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_; }
174 void set_printer_type(PrinterType type) { printer_type_ = type; }
175 bool printer_is_textonly() const {
176 return printer_type_ == PrinterType::TYPE_TEXTONLY;
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;
182 bool printer_is_ps3() const {
183 return printer_type_ == PrinterType::TYPE_POSTSCRIPT_LEVEL3;
187 void set_is_modifiable(bool is_modifiable) { is_modifiable_ = is_modifiable; }
188 bool is_modifiable() const { return is_modifiable_; }
190 int pages_per_sheet() const { return pages_per_sheet_; }
191 void set_pages_per_sheet(int pages_per_sheet) {
192 pages_per_sheet_ = pages_per_sheet;
195 // Cookie generator. It is used to initialize PrintedDocument with its
196 // associated PrintSettings, to be sure that each generated PrintedPage is
197 // correctly associated with its corresponding PrintedDocument.
198 static int NewCookie();
201 // Multi-page printing. Each PageRange describes a from-to page combination.
202 // This permits printing selected pages only.
205 // Indicates if the user only wants to print the current selection.
206 bool selection_only_;
208 // Indicates what kind of margins should be applied to the printable area.
209 MarginType margin_type_;
211 // Strings to be printed as headers and footers if requested by the user.
212 base::string16 title_;
215 // True if the user wants headers and footers to be displayed.
216 bool display_header_footer_;
218 // True if the user wants to print CSS backgrounds.
219 bool should_print_backgrounds_;
221 // True if the user wants to print with collate.
224 // True if the user wants to print with collate.
227 // Number of copies user wants to print.
230 // Duplex type user wants to use.
231 DuplexMode duplex_mode_;
233 // Printer device name as opened by the OS.
234 base::string16 device_name_;
236 // Media requested by the user.
237 RequestedMedia requested_media_;
239 // Page setup in device units.
240 PageSetup page_setup_device_units_;
242 // Printer's device effective dots per inch in both axes. The two values will
243 // generally be identical. However, on Windows, there are a few rare printers
244 // that support resolutions with different DPI in different dimensions.
248 double scale_factor_;
250 // True if PDF should be printed as a raster PDF
253 // Is the orientation landscape or portrait.
256 // True if this printer supports AlphaBlend.
257 bool supports_alpha_blend_;
260 // True to print text with GDI.
261 bool print_text_with_gdi_;
263 PrinterType printer_type_;
268 // If margin type is custom, this is what was requested.
269 PageMargins requested_custom_margins_in_points_;
271 // Number of pages per sheet.
272 int pages_per_sheet_;
275 } // namespace printing
277 #endif // PRINTING_PRINT_SETTINGS_H_