Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: printing/emf_win.h

Issue 6544028: Create a Factory for NativeMetafile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ARM compile failure fix Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/renderer_host/render_view_host.cc ('k') | printing/emf_win_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 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"
13 #include "printing/native_metafile_win.h"
12 14
13 class FilePath; 15 class FilePath;
14 16
15 namespace gfx { 17 namespace gfx {
16 class Rect; 18 class Rect;
17 } 19 }
18 20
19 namespace printing { 21 namespace printing {
20 22
21 // 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.
22 class Emf { 24 class Emf : public NativeMetafile {
23 public: 25 public:
24 class Record; 26 class Record;
25 class Enumerator; 27 class Enumerator;
26 struct EnumerationContext; 28 struct EnumerationContext;
27 29
28 Emf(); 30 virtual ~Emf();
29 ~Emf();
30 31
31 // Initializes the Emf with the data in |src_buffer|. Returns true on success. 32 // Initializes the Emf with the data in |src_buffer|. Returns true on success.
32 bool Init(const void* src_buffer, uint32 src_buffer_size); 33 virtual bool Init(const void* src_buffer, uint32 src_buffer_size);
33 34
34 // Generates a virtual HDC that will record every GDI commands and compile it 35 // Generates a virtual HDC that will record every GDI commands and compile it
35 // in a EMF data stream. 36 // in a EMF data stream.
36 // hdc is used to setup the default DPI and color settings. hdc is optional. 37 // hdc is used to setup the default DPI and color settings. hdc is optional.
37 // rect specifies the dimensions (in .01-millimeter units) of the EMF. rect is 38 // rect specifies the dimensions (in .01-millimeter units) of the EMF. rect is
38 // optional. 39 // optional.
39 bool CreateDc(HDC sibling, const RECT* rect); 40 virtual bool CreateDc(HDC sibling, const RECT* rect);
40 41
41 // Similar to the above method but the metafile is backed by a file. 42 // Similar to the above method but the metafile is backed by a file.
42 bool CreateFileBackedDc(HDC sibling, const RECT* rect, const FilePath& path); 43 virtual bool CreateFileBackedDc(HDC sibling,
44 const RECT* rect,
45 const FilePath& path);
43 46
44 // Load an EMF file. 47 // Load an EMF file.
45 bool CreateFromFile(const FilePath& metafile_path); 48 virtual bool CreateFromFile(const FilePath& metafile_path);
46 49
47 // TODO(maruel): CreateFromFile(). If ever used. Maybe users would like to 50 // TODO(maruel): CreateFromFile(). If ever used. Maybe users would like to
48 // have the ability to save web pages to an EMF file? Afterward, it is easy to 51 // have the ability to save web pages to an EMF file? Afterward, it is easy to
49 // convert to PDF or PS. 52 // convert to PDF or PS.
50 53
51 // Closes the HDC created by CreateDc() and generates the compiled EMF 54 // Closes the HDC created by CreateDc() and generates the compiled EMF
52 // data. 55 // data.
53 bool CloseDc(); 56 virtual bool CloseDc();
54 57
55 // Closes the EMF data handle when it is not needed anymore. 58 // Closes the EMF data handle when it is not needed anymore.
56 void CloseEmf(); 59 virtual void CloseEmf();
57 60
58 // "Plays" the EMF buffer in a HDC. It is the same effect as calling the 61 // "Plays" the EMF buffer in a HDC. It is the same effect as calling the
59 // original GDI function that were called when recording the EMF. |rect| is in 62 // original GDI function that were called when recording the EMF. |rect| is in
60 // "logical units" and is optional. If |rect| is NULL, the natural EMF bounds 63 // "logical units" and is optional. If |rect| is NULL, the natural EMF bounds
61 // are used. 64 // are used.
62 // Note: Windows has been known to have stack buffer overflow in its GDI 65 // Note: Windows has been known to have stack buffer overflow in its GDI
63 // functions, whether used directly or indirectly through precompiled EMF 66 // functions, whether used directly or indirectly through precompiled EMF
64 // data. We have to accept the risk here. Since it is used only for printing, 67 // data. We have to accept the risk here. Since it is used only for printing,
65 // it requires user intervention. 68 // it requires user intervention.
66 bool Playback(HDC hdc, const RECT* rect) const; 69 virtual bool Playback(HDC hdc, const RECT* rect) const;
67 70
68 // The slow version of Playback(). It enumerates all the records and play them 71 // The slow version of Playback(). It enumerates all the records and play them
69 // back in the HDC. The trick is that it skip over the records known to have 72 // back in the HDC. The trick is that it skip over the records known to have
70 // issue with some printers. See Emf::Record::SafePlayback implementation for 73 // issue with some printers. See Emf::Record::SafePlayback implementation for
71 // details. 74 // details.
72 bool SafePlayback(HDC hdc) const; 75 virtual bool SafePlayback(HDC hdc) const;
73 76
74 // Retrieves the bounds of the painted area by this EMF buffer. This value 77 // Retrieves the bounds of the painted area by this EMF buffer. This value
75 // should be passed to Playback to keep the exact same size. 78 // should be passed to Playback to keep the exact same size.
76 gfx::Rect GetBounds() const; 79 virtual gfx::Rect GetBounds() const;
77 80
78 // Retrieves the EMF stream size. 81 // Retrieves the EMF stream size.
79 uint32 GetDataSize() const; 82 virtual uint32 GetDataSize() const;
80 83
81 // Retrieves the EMF stream. 84 // Retrieves the EMF stream.
82 bool GetData(void* buffer, uint32 size) const; 85 virtual bool GetData(void* buffer, uint32 size) const;
83 86
84 // Retrieves the EMF stream. It is an helper function. 87 // Retrieves the EMF stream. It is an helper function.
85 bool GetData(std::vector<uint8>* buffer) const; 88 virtual bool GetData(std::vector<uint8>* buffer) const;
86 89
87 HENHMETAFILE emf() const { 90 virtual HENHMETAFILE emf() const {
88 return emf_; 91 return emf_;
89 } 92 }
90 93
91 HDC hdc() const { 94 virtual HDC hdc() const {
92 return hdc_; 95 return hdc_;
93 } 96 }
94 97
95 // Inserts a custom GDICOMMENT records indicating StartPage/EndPage calls 98 // Inserts a custom GDICOMMENT records indicating StartPage/EndPage calls
96 // (since StartPage and EndPage do not work in a metafile DC). Only valid 99 // (since StartPage and EndPage do not work in a metafile DC). Only valid
97 // when hdc_ is non-NULL. 100 // when hdc_ is non-NULL.
98 bool StartPage(); 101 virtual bool StartPage();
99 bool EndPage(); 102 virtual bool EndPage();
100 103
101 // Saves the EMF data to a file as-is. It is recommended to use the .emf file 104 // Saves the EMF data to a file as-is. It is recommended to use the .emf file
102 // extension but it is not enforced. This function synchronously writes to the 105 // extension but it is not enforced. This function synchronously writes to the
103 // file. For testing only. 106 // file. For testing only.
104 bool SaveTo(const std::wstring& filename) const; 107 virtual bool SaveTo(const std::wstring& filename) const;
108
109 protected:
110 Emf();
105 111
106 private: 112 private:
113 friend class NativeMetafileFactory;
114 FRIEND_TEST_ALL_PREFIXES(EmfTest, DC);
115 FRIEND_TEST_ALL_PREFIXES(EmfTest, FileBackedDC);
116 FRIEND_TEST_ALL_PREFIXES(EmfPrintingTest, Enumerate);
117 FRIEND_TEST_ALL_PREFIXES(EmfPrintingTest, PageBreak);
118
107 // Playbacks safely one EMF record. 119 // Playbacks safely one EMF record.
108 static int CALLBACK SafePlaybackProc(HDC hdc, 120 static int CALLBACK SafePlaybackProc(HDC hdc,
109 HANDLETABLE* handle_table, 121 HANDLETABLE* handle_table,
110 const ENHMETARECORD* record, 122 const ENHMETARECORD* record,
111 int objects_count, 123 int objects_count,
112 LPARAM param); 124 LPARAM param);
113 125
114 // Compiled EMF data handle. 126 // Compiled EMF data handle.
115 HENHMETAFILE emf_; 127 HENHMETAFILE emf_;
116 128
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 std::vector<Record> items_; 196 std::vector<Record> items_;
185 197
186 EnumerationContext context_; 198 EnumerationContext context_;
187 199
188 DISALLOW_COPY_AND_ASSIGN(Enumerator); 200 DISALLOW_COPY_AND_ASSIGN(Enumerator);
189 }; 201 };
190 202
191 } // namespace printing 203 } // namespace printing
192 204
193 #endif // PRINTING_EMF_WIN_H_ 205 #endif // PRINTING_EMF_WIN_H_
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_view_host.cc ('k') | printing/emf_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698