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_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 | 9 |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
| 15 #include "base/memory/scoped_ptr.h" |
15 #include "printing/metafile.h" | 16 #include "printing/metafile.h" |
16 | 17 |
17 namespace base { | 18 namespace base { |
18 class FilePath; | 19 class FilePath; |
19 } | 20 } |
20 | 21 |
21 namespace gfx { | 22 namespace gfx { |
22 class Rect; | 23 class Rect; |
23 class Size; | 24 class Size; |
24 } | 25 } |
(...skipping 15 matching lines...) Expand all Loading... |
40 // Generates a virtual HDC that will record every GDI commands and compile | 41 // Generates a virtual HDC that will record every GDI commands and compile |
41 // it in a EMF data stream. | 42 // it in a EMF data stream. |
42 Emf(); | 43 Emf(); |
43 virtual ~Emf(); | 44 virtual ~Emf(); |
44 | 45 |
45 // Closes metafile. | 46 // Closes metafile. |
46 void Close(); | 47 void Close(); |
47 | 48 |
48 // Generates a new metafile that will record every GDI command, and will | 49 // Generates a new metafile that will record every GDI command, and will |
49 // be saved to |metafile_path|. | 50 // be saved to |metafile_path|. |
50 virtual bool InitToFile(const base::FilePath& metafile_path); | 51 bool InitToFile(const base::FilePath& metafile_path); |
51 | 52 |
52 // Initializes the Emf with the data in |metafile_path|. | 53 // Initializes the Emf with the data in |metafile_path|. |
53 virtual bool InitFromFile(const base::FilePath& metafile_path); | 54 bool InitFromFile(const base::FilePath& metafile_path); |
54 | 55 |
55 // Metafile methods. | 56 // Metafile methods. |
56 virtual bool Init() OVERRIDE; | 57 virtual bool Init() OVERRIDE; |
57 virtual bool InitFromData(const void* src_buffer, | 58 virtual bool InitFromData(const void* src_buffer, |
58 uint32 src_buffer_size) OVERRIDE; | 59 uint32 src_buffer_size) OVERRIDE; |
59 | 60 |
60 virtual SkBaseDevice* StartPageForVectorCanvas( | 61 virtual SkBaseDevice* StartPageForVectorCanvas( |
61 const gfx::Size& page_size, const gfx::Rect& content_area, | 62 const gfx::Size& page_size, const gfx::Rect& content_area, |
62 const float& scale_factor) OVERRIDE; | 63 const float& scale_factor) OVERRIDE; |
63 // Inserts a custom GDICOMMENT records indicating StartPage/EndPage calls | 64 // Inserts a custom GDICOMMENT records indicating StartPage/EndPage calls |
64 // (since StartPage and EndPage do not work in a metafile DC). Only valid | 65 // (since StartPage and EndPage do not work in a metafile DC). Only valid |
65 // when hdc_ is non-NULL. |page_size|, |content_area|, and |scale_factor| are | 66 // when hdc_ is non-NULL. |page_size|, |content_area|, and |scale_factor| are |
66 // ignored. | 67 // ignored. |
67 virtual bool StartPage(const gfx::Size& page_size, | 68 virtual bool StartPage(const gfx::Size& page_size, |
68 const gfx::Rect& content_area, | 69 const gfx::Rect& content_area, |
69 const float& scale_factor) OVERRIDE; | 70 const float& scale_factor) OVERRIDE; |
70 virtual bool FinishPage() OVERRIDE; | 71 virtual bool FinishPage() OVERRIDE; |
71 virtual bool FinishDocument() OVERRIDE; | 72 virtual bool FinishDocument() OVERRIDE; |
72 | 73 |
73 virtual uint32 GetDataSize() const OVERRIDE; | 74 virtual uint32 GetDataSize() const OVERRIDE; |
74 virtual bool GetData(void* buffer, uint32 size) const OVERRIDE; | 75 virtual bool GetData(void* buffer, uint32 size) const OVERRIDE; |
75 | 76 |
76 // Saves the EMF data to a file as-is. It is recommended to use the .emf file | |
77 // extension but it is not enforced. This function synchronously writes to the | |
78 // file. For testing only. | |
79 virtual bool SaveTo(const base::FilePath& file_path) const OVERRIDE; | |
80 | |
81 // Should be passed to Playback to keep the exact same size. | 77 // Should be passed to Playback to keep the exact same size. |
82 virtual gfx::Rect GetPageBounds(unsigned int page_number) const OVERRIDE; | 78 virtual gfx::Rect GetPageBounds(unsigned int page_number) const OVERRIDE; |
83 | 79 |
84 virtual unsigned int GetPageCount() const OVERRIDE { | 80 virtual unsigned int GetPageCount() const OVERRIDE { |
85 return page_count_; | 81 return page_count_; |
86 } | 82 } |
87 | 83 |
88 virtual HDC context() const OVERRIDE { | 84 virtual HDC context() const OVERRIDE { |
89 return hdc_; | 85 return hdc_; |
90 } | 86 } |
91 | 87 |
92 virtual bool Playback(HDC hdc, const RECT* rect) const OVERRIDE; | 88 virtual bool Playback(HDC hdc, const RECT* rect) const OVERRIDE; |
93 virtual bool SafePlayback(HDC hdc) const OVERRIDE; | 89 virtual bool SafePlayback(HDC hdc) const OVERRIDE; |
94 | 90 |
95 virtual HENHMETAFILE emf() const OVERRIDE { | 91 HENHMETAFILE emf() const { return emf_; } |
96 return emf_; | |
97 } | |
98 | 92 |
99 // Returns true if metafile contains alpha blend. | 93 // Returns true if metafile contains alpha blend. |
100 bool IsAlphaBlendUsed() const; | 94 bool IsAlphaBlendUsed() const; |
101 | 95 |
102 // Returns new metafile with only bitmap created by playback of the current | 96 // Returns new metafile with only bitmap created by playback of the current |
103 // metafile. Returns NULL if fails. | 97 // metafile. Returns NULL if fails. |
104 Emf* RasterizeMetafile(int raster_area_in_pixels) const; | 98 scoped_ptr<Emf> RasterizeMetafile(int raster_area_in_pixels) const; |
105 | 99 |
106 // Returns new metafile where AlphaBlend replaced by bitmaps. Returns NULL | 100 // Returns new metafile where AlphaBlend replaced by bitmaps. Returns NULL |
107 // if fails. | 101 // if fails. |
108 Emf* RasterizeAlphaBlend() const; | 102 scoped_ptr<Emf> RasterizeAlphaBlend() const; |
109 | 103 |
110 private: | 104 private: |
111 FRIEND_TEST_ALL_PREFIXES(EmfTest, DC); | 105 FRIEND_TEST_ALL_PREFIXES(EmfTest, DC); |
112 FRIEND_TEST_ALL_PREFIXES(EmfPrintingTest, PageBreak); | 106 FRIEND_TEST_ALL_PREFIXES(EmfPrintingTest, PageBreak); |
113 FRIEND_TEST_ALL_PREFIXES(EmfTest, FileBackedEmf); | 107 FRIEND_TEST_ALL_PREFIXES(EmfTest, FileBackedEmf); |
114 | 108 |
115 // Retrieves the underlying data stream. It is a helper function. | |
116 bool GetDataAsVector(std::vector<uint8>* buffer) const; | |
117 | |
118 // Playbacks safely one EMF record. | 109 // Playbacks safely one EMF record. |
119 static int CALLBACK SafePlaybackProc(HDC hdc, | 110 static int CALLBACK SafePlaybackProc(HDC hdc, |
120 HANDLETABLE* handle_table, | 111 HANDLETABLE* handle_table, |
121 const ENHMETARECORD* record, | 112 const ENHMETARECORD* record, |
122 int objects_count, | 113 int objects_count, |
123 LPARAM param); | 114 LPARAM param); |
124 | 115 |
125 // Compiled EMF data handle. | 116 // Compiled EMF data handle. |
126 HENHMETAFILE emf_; | 117 HENHMETAFILE emf_; |
127 | 118 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 std::vector<Record> items_; | 192 std::vector<Record> items_; |
202 | 193 |
203 EnumerationContext context_; | 194 EnumerationContext context_; |
204 | 195 |
205 DISALLOW_COPY_AND_ASSIGN(Enumerator); | 196 DISALLOW_COPY_AND_ASSIGN(Enumerator); |
206 }; | 197 }; |
207 | 198 |
208 } // namespace printing | 199 } // namespace printing |
209 | 200 |
210 #endif // PRINTING_EMF_WIN_H_ | 201 #endif // PRINTING_EMF_WIN_H_ |
OLD | NEW |