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. 4 5 #ifndef PRINTING_PRINT_SETTINGS_H_ 6 #define PRINTING_PRINT_SETTINGS_H_ 7 8 #include <string> 9 10 #include "base/strings/string16.h" 11 #include "printing/page_range.h" 12 #include "printing/page_setup.h" 13 #include "printing/print_job_constants.h" 14 #include "printing/printing_export.h" 15 #include "ui/gfx/rect.h" 16 17 namespace printing { 18 19 // Returns true if |color_mode| is color and not B&W. 20 PRINTING_EXPORT bool IsColorModelSelected(int color_mode); 21 22 #if defined(USE_CUPS) 23 // Get the color model setting name and value for the |color_mode|. 24 PRINTING_EXPORT void GetColorModelForMode(int color_mode, 25 std::string* color_setting_name, 26 std::string* color_value); 27 #endif 28 29 // OS-independent print settings. 30 class PRINTING_EXPORT PrintSettings { 31 public: 32 PrintSettings(); 33 ~PrintSettings(); 34 35 // Reinitialize the settings to the default values. 36 void Clear(); 37 38 void SetCustomMargins(const PageMargins& requested_margins_in_points); 39 void set_margin_type(MarginType margin_type) { margin_type_ = margin_type; } 40 MarginType margin_type() const { return margin_type_; } 41 42 // Updates the orientation and flip the page if needed. 43 void SetOrientation(bool landscape); 44 bool landscape() const { return landscape_; } 45 46 // Set printer printable area in in device units. 47 // Some platforms already provide flipped area. Set |landscape_needs_flip| 48 // to false on those platforms to avoid double flipping. 49 void SetPrinterPrintableArea(const gfx::Size& physical_size_device_units, 50 const gfx::Rect& printable_area_device_units, 51 bool landscape_needs_flip); 52 const PageSetup& page_setup_device_units() const { 53 return page_setup_device_units_; 54 } 55 56 void set_device_name(const base::string16& device_name) { 57 device_name_ = device_name; 58 } 59 const base::string16& device_name() const { return device_name_; } 60 61 void set_dpi(int dpi) { dpi_ = dpi; } 62 int dpi() const { return dpi_; } 63 64 void set_supports_alpha_blend(bool supports_alpha_blend) { 65 supports_alpha_blend_ = supports_alpha_blend; 66 } 67 bool supports_alpha_blend() const { return supports_alpha_blend_; } 68 69 int device_units_per_inch() const { 70 #if defined(OS_MACOSX) 71 return 72; 72 #else // defined(OS_MACOSX) 73 return dpi(); 74 #endif // defined(OS_MACOSX) 75 } 76 77 void set_ranges(const PageRanges& ranges) { ranges_ = ranges; }; 78 const PageRanges& ranges() const { return ranges_; }; 79 80 void set_selection_only(bool selection_only) { 81 selection_only_ = selection_only; 82 } 83 bool selection_only() const { return selection_only_; } 84 85 void set_should_print_backgrounds(bool should_print_backgrounds) { 86 should_print_backgrounds_ = should_print_backgrounds; 87 } 88 bool should_print_backgrounds() const { return should_print_backgrounds_; } 89 90 void set_display_header_footer(bool display_header_footer) { 91 display_header_footer_ = display_header_footer; 92 } 93 bool display_header_footer() const { return display_header_footer_; } 94 95 void set_title(const base::string16& title) { title_ = title; } 96 const base::string16& title() const { return title_; } 97 98 void set_url(const base::string16& url) { url_ = url; } 99 const base::string16& url() const { return url_; } 100 101 void set_collate(bool collate) { collate_ = collate; } 102 bool collate() const { return collate_; } 103 104 void set_color(ColorModel color) { color_ = color; } 105 ColorModel color() const { return color_; } 106 107 void set_copies(int copies) { copies_ = copies; } 108 int copies() const { return copies_; } 109 110 void set_duplex_mode(DuplexMode duplex_mode) { duplex_mode_ = duplex_mode; } 111 DuplexMode duplex_mode() const { return duplex_mode_; } 112 113 int desired_dpi() const { return desired_dpi_; } 114 115 double max_shrink() const { return max_shrink_; } 116 117 double min_shrink() const { return min_shrink_; } 118 119 // Cookie generator. It is used to initialize PrintedDocument with its 120 // associated PrintSettings, to be sure that each generated PrintedPage is 121 // correctly associated with its corresponding PrintedDocument. 122 static int NewCookie(); 123 124 private: 125 // Multi-page printing. Each PageRange describes a from-to page combination. 126 // This permits printing selected pages only. 127 PageRanges ranges_; 128 129 // By imaging to a width a little wider than the available pixels, thin pages 130 // will be scaled down a little, matching the way they print in IE and Camino. 131 // This lets them use fewer sheets than they would otherwise, which is 132 // presumably why other browsers do this. Wide pages will be scaled down more 133 // than this. 134 double min_shrink_; 135 136 // This number determines how small we are willing to reduce the page content 137 // in order to accommodate the widest line. If the page would have to be 138 // reduced smaller to make the widest line fit, we just clip instead (this 139 // behavior matches MacIE and Mozilla, at least) 140 double max_shrink_; 141 142 // Desired visible dots per inch rendering for output. Printing should be 143 // scaled to ScreenDpi/dpix*desired_dpi. 144 int desired_dpi_; 145 146 // Indicates if the user only wants to print the current selection. 147 bool selection_only_; 148 149 // Indicates what kind of margins should be applied to the printable area. 150 MarginType margin_type_; 151 152 // Strings to be printed as headers and footers if requested by the user. 153 base::string16 title_; 154 base::string16 url_; 155 156 // True if the user wants headers and footers to be displayed. 157 bool display_header_footer_; 158 159 // True if the user wants to print CSS backgrounds. 160 bool should_print_backgrounds_; 161 162 // True if the user wants to print with collate. 163 bool collate_; 164 165 // True if the user wants to print with collate. 166 ColorModel color_; 167 168 // Number of copies user wants to print. 169 int copies_; 170 171 // Duplex type user wants to use. 172 DuplexMode duplex_mode_; 173 174 // Printer device name as opened by the OS. 175 base::string16 device_name_; 176 177 // Page setup in device units. 178 PageSetup page_setup_device_units_; 179 180 // Printer's device effective dots per inch in both axis. 181 int dpi_; 182 183 // Is the orientation landscape or portrait. 184 bool landscape_; 185 186 // True if this printer supports AlphaBlend. 187 bool supports_alpha_blend_; 188 189 // If margin type is custom, this is what was requested. 190 PageMargins requested_custom_margins_in_points_; 191 }; 192 193 } // namespace printing 194 195 #endif // PRINTING_PRINT_SETTINGS_H_ 196