OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_METAFILE_H_ | 5 #ifndef PRINTING_METAFILE_H_ |
6 #define PRINTING_METAFILE_H_ | 6 #define PRINTING_METAFILE_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
14 #include "printing/native_drawing_context.h" | 14 #include "printing/native_drawing_context.h" |
15 #include "printing/printing_export.h" | 15 #include "printing/printing_export.h" |
16 | 16 |
17 #if defined(OS_WIN) | 17 #if defined(OS_WIN) |
18 #include <windows.h> | 18 #include <windows.h> |
19 #elif defined(OS_MACOSX) | |
20 #include <ApplicationServices/ApplicationServices.h> | |
21 #include <CoreFoundation/CoreFoundation.h> | |
22 #include "base/mac/scoped_cftyperef.h" | |
23 #endif | 19 #endif |
24 | 20 |
25 namespace base { | 21 namespace base { |
26 class File; | 22 class File; |
27 } | 23 } |
28 | 24 |
29 namespace gfx { | 25 namespace gfx { |
30 class Rect; | 26 class Rect; |
31 class Size; | 27 class Size; |
32 } | 28 } |
33 | 29 |
34 namespace printing { | 30 namespace printing { |
35 | 31 |
36 // This class plays metafiles from data stream (usually PDF or EMF). | 32 // This class plays metafiles from data stream (usually PDF or EMF). |
37 class PRINTING_EXPORT MetafilePlayer { | 33 class PRINTING_EXPORT MetafilePlayer { |
38 public: | 34 public: |
39 #if defined(OS_MACOSX) | |
40 // |shrink_to_fit| specifies whether the output should be shrunk to fit a | |
41 // destination page if the source PDF is bigger than the destination page in | |
42 // any dimension. If this is false, parts of the source PDF page that lie | |
43 // outside the bounds will be clipped. | |
44 // |stretch_to_fit| specifies whether the output should be stretched to fit | |
45 // the destination page if the source page size is smaller in all dimensions. | |
46 // |center_horizontally| specifies whether the output (after any scaling is | |
47 // done) should be centered horizontally within the destination page. | |
48 // |center_vertically| specifies whether the output (after any scaling is | |
49 // done) should be centered vertically within the destination page. | |
50 // Note that all scaling preserves the original aspect ratio of the page. | |
51 // |autorotate| specifies whether the source PDF should be autorotated to fit | |
52 // on the destination page. | |
53 struct MacRenderPageParams { | |
54 MacRenderPageParams() | |
55 : shrink_to_fit(false), | |
56 stretch_to_fit(false), | |
57 center_horizontally(false), | |
58 center_vertically(false), | |
59 autorotate(false) { | |
60 } | |
61 | |
62 bool shrink_to_fit; | |
63 bool stretch_to_fit; | |
64 bool center_horizontally; | |
65 bool center_vertically; | |
66 bool autorotate; | |
67 }; | |
68 #endif // defined(OS_MACOSX) | |
69 MetafilePlayer(); | 35 MetafilePlayer(); |
70 virtual ~MetafilePlayer(); | 36 virtual ~MetafilePlayer(); |
71 | 37 |
72 #if defined(OS_WIN) | 38 #if defined(OS_WIN) |
73 // The slow version of Playback(). It enumerates all the records and play them | 39 // The slow version of Playback(). It enumerates all the records and play them |
74 // back in the HDC. The trick is that it skip over the records known to have | 40 // back in the HDC. The trick is that it skip over the records known to have |
75 // issue with some printers. See Emf::Record::SafePlayback implementation for | 41 // issue with some printers. See Emf::Record::SafePlayback implementation for |
76 // details. | 42 // details. |
77 virtual bool SafePlayback(skia::NativeDrawingContext hdc) const = 0; | 43 virtual bool SafePlayback(skia::NativeDrawingContext hdc) const = 0; |
78 | |
79 #elif defined(OS_MACOSX) | |
80 // Renders the given page into |rect| in the given context. | |
81 // Pages use a 1-based index. The rendering uses the arguments in | |
82 // |params| to determine scaling, translation, and rotation. | |
83 virtual bool RenderPage(unsigned int page_number, | |
84 skia::NativeDrawingContext context, | |
85 const CGRect rect, | |
86 const MacRenderPageParams& params) const = 0; | |
87 #endif // if defined(OS_WIN) | 44 #endif // if defined(OS_WIN) |
88 | 45 |
89 // Populates the buffer with the underlying data. This function should ONLY be | 46 // Populates the buffer with the underlying data. This function should ONLY be |
90 // called after the metafile is closed. Returns true if writing succeeded. | 47 // called after the metafile is closed. Returns true if writing succeeded. |
91 virtual bool GetDataAsVector(std::vector<char>* buffer) const = 0; | 48 virtual bool GetDataAsVector(std::vector<char>* buffer) const = 0; |
92 | 49 |
93 // Saves the underlying data to the given file. This function should ONLY be | 50 // Saves the underlying data to the given file. This function should ONLY be |
94 // called after the metafile is closed. Returns true if writing succeeded. | 51 // called after the metafile is closed. Returns true if writing succeeded. |
95 virtual bool SaveTo(base::File* file) const = 0; | 52 virtual bool SaveTo(base::File* file) const = 0; |
96 | 53 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 bool GetDataAsVector(std::vector<char>* buffer) const override; | 120 bool GetDataAsVector(std::vector<char>* buffer) const override; |
164 bool SaveTo(base::File* file) const override; | 121 bool SaveTo(base::File* file) const override; |
165 | 122 |
166 private: | 123 private: |
167 DISALLOW_COPY_AND_ASSIGN(Metafile); | 124 DISALLOW_COPY_AND_ASSIGN(Metafile); |
168 }; | 125 }; |
169 | 126 |
170 } // namespace printing | 127 } // namespace printing |
171 | 128 |
172 #endif // PRINTING_METAFILE_H_ | 129 #endif // PRINTING_METAFILE_H_ |
OLD | NEW |