initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1 | // Copyright 2008, Google Inc. |
| 2 | // All rights reserved. |
| 3 | // |
| 4 | // Redistribution and use in source and binary forms, with or without |
| 5 | // modification, are permitted provided that the following conditions are |
| 6 | // met: |
| 7 | // |
| 8 | // * Redistributions of source code must retain the above copyright |
| 9 | // notice, this list of conditions and the following disclaimer. |
| 10 | // * Redistributions in binary form must reproduce the above |
| 11 | // copyright notice, this list of conditions and the following disclaimer |
| 12 | // in the documentation and/or other materials provided with the |
| 13 | // distribution. |
| 14 | // * Neither the name of Google Inc. nor the names of its |
| 15 | // contributors may be used to endorse or promote products derived from |
| 16 | // this software without specific prior written permission. |
| 17 | // |
| 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | |
| 30 | #ifndef CHROME_BROWSER_PRINTING_PRINT_SETTINGS_H__ |
| 31 | #define CHROME_BROWSER_PRINTING_PRINT_SETTINGS_H__ |
| 32 | |
| 33 | #include "base/gfx/rect.h" |
| 34 | #include "chrome/browser/printing/page_overlays.h" |
| 35 | #include "chrome/browser/printing/page_range.h" |
| 36 | #include "chrome/browser/printing/page_setup.h" |
| 37 | |
| 38 | struct ViewMsg_Print_Params; |
| 39 | typedef struct HDC__* HDC; |
| 40 | typedef struct _devicemodeW DEVMODE; |
| 41 | |
| 42 | namespace printing { |
| 43 | |
| 44 | // OS-independent print settings. |
| 45 | class PrintSettings { |
| 46 | public: |
| 47 | PrintSettings(); |
| 48 | |
| 49 | // Reinitialize the settings to the default values. |
| 50 | void Clear(); |
| 51 | |
| 52 | #ifdef WIN32 |
| 53 | // Reads the settings from the selected device context. Calculates derived |
| 54 | // values like printable_area_. |
| 55 | void Init(HDC hdc, |
| 56 | const DEVMODE& dev_mode, |
| 57 | const PageRanges& new_ranges, |
| 58 | const std::wstring& new_device_name); |
| 59 | #endif |
| 60 | |
| 61 | // Sets margins in 0.01 millimeter unit. |
| 62 | void UpdateMarginsMetric(const PageMargins& new_margins); |
| 63 | |
| 64 | // Sets margins in thousandth of inch. |
| 65 | void UpdateMarginsMilliInch(const PageMargins& new_margins); |
| 66 | |
| 67 | // Initializes the print parameters that needs to be sent to the renderer |
| 68 | // process. |
| 69 | void RenderParams(ViewMsg_Print_Params* params) const; |
| 70 | |
| 71 | // Equality operator. |
| 72 | // NOTE: printer_name is NOT tested for equality since it doesn't affect the |
| 73 | // output. |
| 74 | bool Equals(const PrintSettings& rhs) const; |
| 75 | |
| 76 | const std::wstring& printer_name() const { return printer_name_; } |
| 77 | void set_device_name(const std::wstring& device_name) { |
| 78 | device_name_ = device_name; |
| 79 | } |
| 80 | const std::wstring& device_name() const { return device_name_; } |
| 81 | int dpi() const { return dpi_; } |
| 82 | const PageSetup& page_setup_cmm() const { return page_setup_cmm_; } |
| 83 | const PageSetup& page_setup_pixels() const { return page_setup_pixels_; } |
| 84 | |
| 85 | // Multipage printing. Each PageRange describes a from-to page combinaison. |
| 86 | // This permits printing some selected pages only. |
| 87 | PageRanges ranges; |
| 88 | |
| 89 | // By imaging to a width a little wider than the available pixels, thin pages |
| 90 | // will be scaled down a little, matching the way they print in IE and Camino. |
| 91 | // This lets them use fewer sheets than they would otherwise, which is |
| 92 | // presumably why other browsers do this. Wide pages will be scaled down more |
| 93 | // than this. |
| 94 | double min_shrink; |
| 95 | |
| 96 | // This number determines how small we are willing to reduce the page content |
| 97 | // in order to accommodate the widest line. If the page would have to be |
| 98 | // reduced smaller to make the widest line fit, we just clip instead (this |
| 99 | // behavior matches MacIE and Mozilla, at least) |
| 100 | double max_shrink; |
| 101 | |
| 102 | // Desired visible dots per inch rendering for output. Printing should be |
| 103 | // scaled to ScreenDpi/dpix*desired_dpi. |
| 104 | int desired_dpi; |
| 105 | |
| 106 | // The various overlays (headers and footers). |
| 107 | PageOverlays overlays; |
| 108 | |
[email protected] | d30e8e64 | 2008-08-06 12:05:24 | [diff] [blame^] | 109 | // Cookie generator. It is used to initialize PrintedDocument with its |
| 110 | // associated PrintSettings, to be sure that each generated PrintedPage is |
| 111 | // correctly associated with its corresponding PrintedDocument. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 112 | static int NewCookie(); |
| 113 | |
| 114 | private: |
| 115 | ////////////////////////////////////////////////////////////////////////////// |
| 116 | // Settings that can't be changed without side-effects. |
| 117 | |
| 118 | // Printer name as shown to the user. |
| 119 | std::wstring printer_name_; |
| 120 | |
| 121 | // Printer device name as opened by the OS. |
| 122 | std::wstring device_name_; |
| 123 | |
| 124 | // Page setup in centimillimeter (0.01 mm) units. |
| 125 | PageSetup page_setup_cmm_; |
| 126 | |
| 127 | // Page setup in pixel units, dpi adjusted. |
| 128 | PageSetup page_setup_pixels_; |
| 129 | |
| 130 | // Printer's device effective dots per inch in both axis. |
| 131 | int dpi_; |
| 132 | |
| 133 | // Is the orientation landscape or portrait. |
| 134 | bool landscape_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 135 | }; |
| 136 | |
| 137 | } // namespace printing |
| 138 | |
| 139 | #endif // CHROME_BROWSER_PRINTING_PRINT_SETTINGS_H__ |