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

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: Created 9 years, 10 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "printing/metafile_factory.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 {
25
26 friend class MetafileFactory;
27
23 public: 28 public:
24 class Record; 29 class Record;
25 class Enumerator; 30 class Enumerator;
26 struct EnumerationContext; 31 struct EnumerationContext;
27 32
28 Emf(); 33 virtual ~Emf();
29 ~Emf();
30 34
31 // Initializes the Emf with the data in |src_buffer|. Returns true on success. 35 // Initializes the Emf with the data in |src_buffer|. Returns true on success.
32 bool Init(const void* src_buffer, uint32 src_buffer_size); 36 virtual bool Init(const void* src_buffer, uint32 src_buffer_size);
33 37
34 // Generates a virtual HDC that will record every GDI commands and compile it 38 // Generates a virtual HDC that will record every GDI commands and compile it
35 // in a EMF data stream. 39 // in a EMF data stream.
36 // hdc is used to setup the default DPI and color settings. hdc is optional. 40 // 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 41 // rect specifies the dimensions (in .01-millimeter units) of the EMF. rect is
38 // optional. 42 // optional.
39 bool CreateDc(HDC sibling, const RECT* rect); 43 virtual bool CreateDc(HDC sibling, const RECT* rect);
40 44
41 // Similar to the above method but the metafile is backed by a file. 45 // Similar to the above method but the metafile is backed by a file.
42 bool CreateFileBackedDc(HDC sibling, const RECT* rect, const FilePath& path); 46 virtual bool CreateFileBackedDc(HDC sibling, const RECT* rect, const FilePath& path);
Avi (use Gerrit) 2011/02/22 17:33:42 80 col!
dpapad 2011/02/22 18:09:30 Done.
43 47
44 // Load an EMF file. 48 // Load an EMF file.
45 bool CreateFromFile(const FilePath& metafile_path); 49 virtual bool CreateFromFile(const FilePath& metafile_path);
46 50
47 // TODO(maruel): CreateFromFile(). If ever used. Maybe users would like to 51 // 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 52 // have the ability to save web pages to an EMF file? Afterward, it is easy to
49 // convert to PDF or PS. 53 // convert to PDF or PS.
50 54
51 // Closes the HDC created by CreateDc() and generates the compiled EMF 55 // Closes the HDC created by CreateDc() and generates the compiled EMF
52 // data. 56 // data.
53 bool CloseDc(); 57 virtual bool CloseDc();
54 58
55 // Closes the EMF data handle when it is not needed anymore. 59 // Closes the EMF data handle when it is not needed anymore.
56 void CloseEmf(); 60 virtual void CloseEmf();
57 61
58 // "Plays" the EMF buffer in a HDC. It is the same effect as calling the 62 // "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 63 // 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 64 // "logical units" and is optional. If |rect| is NULL, the natural EMF bounds
61 // are used. 65 // are used.
62 // Note: Windows has been known to have stack buffer overflow in its GDI 66 // Note: Windows has been known to have stack buffer overflow in its GDI
63 // functions, whether used directly or indirectly through precompiled EMF 67 // 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, 68 // data. We have to accept the risk here. Since it is used only for printing,
65 // it requires user intervention. 69 // it requires user intervention.
66 bool Playback(HDC hdc, const RECT* rect) const; 70 virtual bool Playback(HDC hdc, const RECT* rect) const;
67 71
68 // The slow version of Playback(). It enumerates all the records and play them 72 // 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 73 // 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 74 // issue with some printers. See Emf::Record::SafePlayback implementation for
71 // details. 75 // details.
72 bool SafePlayback(HDC hdc) const; 76 virtual bool SafePlayback(HDC hdc) const;
73 77
74 // Retrieves the bounds of the painted area by this EMF buffer. This value 78 // 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. 79 // should be passed to Playback to keep the exact same size.
76 gfx::Rect GetBounds() const; 80 virtual gfx::Rect GetBounds() const;
77 81
78 // Retrieves the EMF stream size. 82 // Retrieves the EMF stream size.
79 uint32 GetDataSize() const; 83 virtual uint32 GetDataSize() const;
80 84
81 // Retrieves the EMF stream. 85 // Retrieves the EMF stream.
82 bool GetData(void* buffer, uint32 size) const; 86 virtual bool GetData(void* buffer, uint32 size) const;
83 87
84 // Retrieves the EMF stream. It is an helper function. 88 // Retrieves the EMF stream. It is an helper function.
85 bool GetData(std::vector<uint8>* buffer) const; 89 virtual bool GetData(std::vector<uint8>* buffer) const;
86 90
87 HENHMETAFILE emf() const { 91 virtual HENHMETAFILE emf() const {
88 return emf_; 92 return emf_;
89 } 93 }
90 94
91 HDC hdc() const { 95 virtual HDC hdc() const {
92 return hdc_; 96 return hdc_;
93 } 97 }
94 98
95 // Inserts a custom GDICOMMENT records indicating StartPage/EndPage calls 99 // Inserts a custom GDICOMMENT records indicating StartPage/EndPage calls
96 // (since StartPage and EndPage do not work in a metafile DC). Only valid 100 // (since StartPage and EndPage do not work in a metafile DC). Only valid
97 // when hdc_ is non-NULL. 101 // when hdc_ is non-NULL.
98 bool StartPage(); 102 virtual bool StartPage();
99 bool EndPage(); 103 virtual bool EndPage();
100 104
101 // Saves the EMF data to a file as-is. It is recommended to use the .emf file 105 // 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 106 // extension but it is not enforced. This function synchronously writes to the
103 // file. For testing only. 107 // file. For testing only.
104 bool SaveTo(const std::wstring& filename) const; 108 virtual bool SaveTo(const std::wstring& filename) const;
109
110 protected:
111 Emf();
105 112
106 private: 113 private:
107 // Playbacks safely one EMF record. 114 // Playbacks safely one EMF record.
108 static int CALLBACK SafePlaybackProc(HDC hdc, 115 static int CALLBACK SafePlaybackProc(HDC hdc,
109 HANDLETABLE* handle_table, 116 HANDLETABLE* handle_table,
110 const ENHMETARECORD* record, 117 const ENHMETARECORD* record,
111 int objects_count, 118 int objects_count,
112 LPARAM param); 119 LPARAM param);
113 120
114 // Compiled EMF data handle. 121 // Compiled EMF data handle.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 std::vector<Record> items_; 191 std::vector<Record> items_;
185 192
186 EnumerationContext context_; 193 EnumerationContext context_;
187 194
188 DISALLOW_COPY_AND_ASSIGN(Enumerator); 195 DISALLOW_COPY_AND_ASSIGN(Enumerator);
189 }; 196 };
190 197
191 } // namespace printing 198 } // namespace printing
192 199
193 #endif // PRINTING_EMF_WIN_H_ 200 #endif // PRINTING_EMF_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698