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