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

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: Fixed NativeMetafileFactory class comments 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/native_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 {
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
107 // Playbacks safely one EMF record. 115 // Playbacks safely one EMF record.
108 static int CALLBACK SafePlaybackProc(HDC hdc, 116 static int CALLBACK SafePlaybackProc(HDC hdc,
109 HANDLETABLE* handle_table, 117 HANDLETABLE* handle_table,
110 const ENHMETARECORD* record, 118 const ENHMETARECORD* record,
111 int objects_count, 119 int objects_count,
112 LPARAM param); 120 LPARAM param);
113 121
114 // Compiled EMF data handle. 122 // Compiled EMF data handle.
115 HENHMETAFILE emf_; 123 HENHMETAFILE emf_;
116 124
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 std::vector<Record> items_; 192 std::vector<Record> items_;
185 193
186 EnumerationContext context_; 194 EnumerationContext context_;
187 195
188 DISALLOW_COPY_AND_ASSIGN(Enumerator); 196 DISALLOW_COPY_AND_ASSIGN(Enumerator);
189 }; 197 };
190 198
191 } // namespace printing 199 } // namespace printing
192 200
193 #endif // PRINTING_EMF_WIN_H_ 201 #endif // PRINTING_EMF_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698