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_EMF_WIN_H_ | 5 #ifndef PRINTING_EMF_WIN_H_ |
6 #define PRINTING_EMF_WIN_H_ | 6 #define PRINTING_EMF_WIN_H_ |
7 | 7 |
8 #include <windows.h> | 8 #include <windows.h> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
13 #include "printing/native_metafile.h" | 13 #include "printing/native_metafile.h" |
14 | 14 |
15 class FilePath; | 15 class FilePath; |
16 | 16 |
17 namespace gfx { | 17 namespace gfx { |
18 class Rect; | 18 class Rect; |
19 } | 19 } |
20 | 20 |
21 namespace printing { | 21 namespace printing { |
22 | 22 |
23 // Simple wrapper class that manage an EMF data stream and its virtual HDC. | 23 // Simple wrapper class that manage an EMF data stream and its virtual HDC. |
24 class Emf : public NativeMetafile { | 24 class Emf : public NativeMetafile { |
25 public: | 25 public: |
26 class Record; | 26 class Record; |
27 class Enumerator; | 27 class Enumerator; |
28 struct EnumerationContext; | 28 struct EnumerationContext; |
29 | 29 |
30 // Generates a virtual HDC that will record every GDI commands and compile | |
31 // it in a EMF data stream. | |
32 Emf(); | |
30 virtual ~Emf(); | 33 virtual ~Emf(); |
31 | 34 |
35 // Initializes the Emf with the data in |metafile_path|. | |
36 virtual bool Init(const FilePath& metafile_path); | |
37 | |
32 // NativeMetafile methods. | 38 // NativeMetafile methods. |
33 virtual bool Init() { return true; } | 39 |
40 // Generates a new metafile that will record every GDI command. | |
41 virtual bool Init(); | |
M-A Ruel
2011/03/17 13:19:21
By style code, we don't allow function overloads.
vandebo (ex-Chrome)
2011/03/17 23:38:06
I was copying the bad existing pattern, Fixed.
An
| |
42 | |
43 // Initializes the Emf with the data in |src_buffer|. Returns true on success. | |
34 virtual bool Init(const void* src_buffer, uint32 src_buffer_size); | 44 virtual bool Init(const void* src_buffer, uint32 src_buffer_size); |
35 | 45 |
36 virtual bool StartPage(); | 46 virtual bool StartPage(); |
37 virtual bool FinishPage(); | 47 virtual bool FinishPage(); |
38 virtual bool Close(); | 48 virtual bool Close(); |
39 | 49 |
40 virtual uint32 GetDataSize() const; | 50 virtual uint32 GetDataSize() const; |
41 virtual bool GetData(void* buffer, uint32 size) const; | 51 virtual bool GetData(void* buffer, uint32 size) const; |
42 | 52 |
43 // Saves the EMF data to a file as-is. It is recommended to use the .emf file | 53 // Saves the EMF data to a file as-is. It is recommended to use the .emf file |
44 // extension but it is not enforced. This function synchronously writes to the | 54 // extension but it is not enforced. This function synchronously writes to the |
45 // file. For testing only. | 55 // file. For testing only. |
46 virtual bool SaveTo(const FilePath& file_path) const; | 56 virtual bool SaveTo(const FilePath& file_path) const; |
47 | 57 |
48 // Should be passed to Playback to keep the exact same size. | 58 // Should be passed to Playback to keep the exact same size. |
49 virtual gfx::Rect GetPageBounds(unsigned int page_number) const; | 59 virtual gfx::Rect GetPageBounds(unsigned int page_number) const; |
50 | 60 |
51 virtual unsigned int GetPageCount() const { | 61 virtual unsigned int GetPageCount() const { |
52 // TODO(dpapad): count the number of times StartPage() is called | 62 // TODO(dpapad): count the number of times StartPage() is called |
53 return 1; | 63 return 1; |
54 } | 64 } |
55 | 65 |
56 virtual HDC context() const { | 66 virtual HDC context() const { |
57 return hdc_; | 67 return hdc_; |
58 } | 68 } |
59 | 69 |
60 virtual bool CreateDc(HDC sibling, const RECT* rect); | |
61 virtual bool CreateFileBackedDc(HDC sibling, | |
62 const RECT* rect, | |
63 const FilePath& path); | |
64 virtual bool CreateFromFile(const FilePath& file_path); | |
65 | |
66 virtual void CloseEmf(); | |
67 | |
68 virtual bool Playback(HDC hdc, const RECT* rect) const; | 70 virtual bool Playback(HDC hdc, const RECT* rect) const; |
69 virtual bool SafePlayback(HDC hdc) const; | 71 virtual bool SafePlayback(HDC hdc) const; |
70 | 72 |
71 virtual bool GetData(std::vector<uint8>* buffer) const; | 73 virtual bool GetData(std::vector<uint8>* buffer) const; |
72 | 74 |
73 virtual HENHMETAFILE emf() const { | 75 virtual HENHMETAFILE emf() const { |
74 return emf_; | 76 return emf_; |
75 } | 77 } |
76 | 78 |
77 protected: | |
78 Emf(); | |
79 | |
80 private: | 79 private: |
81 friend class NativeMetafileFactory; | |
82 FRIEND_TEST_ALL_PREFIXES(EmfTest, DC); | |
83 FRIEND_TEST_ALL_PREFIXES(EmfTest, FileBackedDC); | |
84 FRIEND_TEST_ALL_PREFIXES(EmfPrintingTest, Enumerate); | |
85 FRIEND_TEST_ALL_PREFIXES(EmfPrintingTest, PageBreak); | |
86 | |
87 // Playbacks safely one EMF record. | 80 // Playbacks safely one EMF record. |
88 static int CALLBACK SafePlaybackProc(HDC hdc, | 81 static int CALLBACK SafePlaybackProc(HDC hdc, |
89 HANDLETABLE* handle_table, | 82 HANDLETABLE* handle_table, |
90 const ENHMETARECORD* record, | 83 const ENHMETARECORD* record, |
91 int objects_count, | 84 int objects_count, |
92 LPARAM param); | 85 LPARAM param); |
93 | 86 |
94 // Compiled EMF data handle. | 87 // Compiled EMF data handle. |
95 HENHMETAFILE emf_; | 88 HENHMETAFILE emf_; |
96 | 89 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
164 std::vector<Record> items_; | 157 std::vector<Record> items_; |
165 | 158 |
166 EnumerationContext context_; | 159 EnumerationContext context_; |
167 | 160 |
168 DISALLOW_COPY_AND_ASSIGN(Enumerator); | 161 DISALLOW_COPY_AND_ASSIGN(Enumerator); |
169 }; | 162 }; |
170 | 163 |
171 } // namespace printing | 164 } // namespace printing |
172 | 165 |
173 #endif // PRINTING_EMF_WIN_H_ | 166 #endif // PRINTING_EMF_WIN_H_ |
OLD | NEW |