OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef PRINTING_PDF_RENDER_SETTINGS_H_ | 5 #ifndef PRINTING_PDF_RENDER_SETTINGS_H_ |
6 #define PRINTING_PDF_RENDER_SETTINGS_H_ | 6 #define PRINTING_PDF_RENDER_SETTINGS_H_ |
7 | 7 |
8 #include "ipc/ipc_message_utils.h" | 8 #include "ipc/ipc_message_utils.h" |
9 #include "ipc/ipc_param_traits.h" | 9 #include "ipc/ipc_param_traits.h" |
10 #include "printing/printing_export.h" | 10 #include "printing/printing_export.h" |
11 #include "ui/gfx/geometry/rect.h" | 11 #include "ui/gfx/geometry/rect.h" |
12 #include "ui/gfx/ipc/geometry/gfx_param_traits.h" | 12 #include "ui/gfx/ipc/geometry/gfx_param_traits.h" |
13 #include "ui/gfx/ipc/skia/gfx_skia_param_traits.h" | 13 #include "ui/gfx/ipc/skia/gfx_skia_param_traits.h" |
14 | 14 |
15 namespace printing { | 15 namespace printing { |
16 | 16 |
17 // Defining PDF rendering settings. | 17 // Defining PDF rendering settings. |
18 struct PdfRenderSettings { | 18 struct PdfRenderSettings { |
19 PdfRenderSettings() : dpi(0), autorotate(false) {} | 19 enum class Mode : uint8_t { |
20 PdfRenderSettings(gfx::Rect area, int dpi, bool autorotate) | 20 NORMAL = 0, |
21 : area(area), dpi(dpi), autorotate(autorotate) {} | 21 #if defined(OS_WIN) |
22 GDI_TEXT, | |
23 #endif | |
24 }; | |
25 | |
26 PdfRenderSettings() : dpi(0), autorotate(false), mode(Mode::NORMAL) {} | |
27 PdfRenderSettings(gfx::Rect area, int dpi, bool autorotate, Mode mode) | |
28 : area(area), dpi(dpi), autorotate(autorotate), mode(mode) {} | |
22 ~PdfRenderSettings() {} | 29 ~PdfRenderSettings() {} |
23 | 30 |
24 gfx::Rect area; | 31 gfx::Rect area; |
25 int dpi; | 32 int dpi; |
26 bool autorotate; | 33 bool autorotate; |
34 Mode mode; | |
27 }; | 35 }; |
28 | 36 |
29 } // namespace printing | 37 } // namespace printing |
30 | 38 |
31 namespace IPC { | 39 namespace IPC { |
32 template <> | 40 template <> |
33 struct ParamTraits<printing::PdfRenderSettings> { | 41 struct ParamTraits<printing::PdfRenderSettings> { |
34 typedef printing::PdfRenderSettings param_type; | 42 using param_type = printing::PdfRenderSettings; |
35 static void Write(base::Pickle* m, const param_type& p) { | 43 static void Write(base::Pickle* m, const param_type& p) { |
36 WriteParam(m, p.area); | 44 WriteParam(m, p.area); |
37 WriteParam(m, p.dpi); | 45 WriteParam(m, p.dpi); |
38 WriteParam(m, p.autorotate); | 46 WriteParam(m, p.autorotate); |
47 WriteParam(m, static_cast<uint8_t>(p.mode)); | |
39 } | 48 } |
40 | 49 |
41 static bool Read(const base::Pickle* m, | 50 static bool Read(const base::Pickle* m, |
42 base::PickleIterator* iter, | 51 base::PickleIterator* iter, |
43 param_type* r) { | 52 param_type* r) { |
44 return ReadParam(m, iter, &r->area) && | 53 uint8_t mode = 0; |
45 ReadParam(m, iter, &r->dpi) && | 54 bool ret = ReadParam(m, iter, &r->area) && |
46 ReadParam(m, iter, &r->autorotate); | 55 ReadParam(m, iter, &r->dpi) && |
56 ReadParam(m, iter, &r->autorotate) && | |
57 ReadParam(m, iter, &mode); | |
58 if (ret) | |
59 r->mode = static_cast<printing::PdfRenderSettings::Mode>(mode); | |
Tom Sepez
2017/01/23 21:14:08
Need to validate that mode is in range here or use
Vitaly Buka (NO REVIEWS)
2017/01/23 22:03:30
Better to use IPC macros
rbpotter
2017/01/24 02:22:01
Done.
I switched the entire structure to use the
| |
60 return ret; | |
47 } | 61 } |
48 | 62 |
49 static void Log(const param_type& p, std::string* l) { | 63 static void Log(const param_type& p, std::string* l) { |
50 LogParam(p.area, l); | 64 LogParam(p.area, l); |
51 l->append(", "); | 65 l->append(", "); |
52 LogParam(p.dpi, l); | 66 LogParam(p.dpi, l); |
53 l->append(", "); | 67 l->append(", "); |
54 LogParam(p.autorotate, l); | 68 LogParam(p.autorotate, l); |
69 l->append(", "); | |
70 LogParam(static_cast<uint8_t>(p.mode), l); | |
55 } | 71 } |
56 }; | 72 }; |
57 | 73 |
58 } // namespace IPC | 74 } // namespace IPC |
59 | 75 |
60 #endif // PRINTING_PDF_RENDER_SETTINGS_H_ | 76 #endif // PRINTING_PDF_RENDER_SETTINGS_H_ |
OLD | NEW |