OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef PRINTING_NATIVE_METAFILE_WIN_H_ | |
6 #define PRINTING_NATIVE_METAFILE_WIN_H_ | |
7 | |
8 #include <windows.h> | |
9 #include <vector> | |
10 | |
11 #include "base/basictypes.h" | |
12 | |
13 class FilePath; | |
14 | |
15 namespace gfx { | |
16 class Rect; | |
17 } | |
18 | |
19 namespace printing { | |
20 | |
21 // Simple wrapper class that manage an EMF data stream and its virtual HDC. | |
22 class NativeMetafile { | |
23 public: | |
24 | |
vandebo (ex-Chrome)
2011/02/23 02:01:41
extra line.
dpapad
2011/02/24 20:56:59
Done.
| |
25 virtual ~NativeMetafile() {}; | |
26 | |
27 // Initializes the Emf with the data in |src_buffer|. Returns true on success. | |
28 virtual bool Init(const void* src_buffer, uint32 src_buffer_size) = 0; | |
29 | |
30 // Generates a virtual HDC that will record every GDI commands and compile it | |
31 // in a EMF data stream. | |
32 // hdc is used to setup the default DPI and color settings. hdc is optional. | |
33 // rect specifies the dimensions (in .01-millimeter units) of the EMF. rect is | |
34 // optional. | |
35 virtual bool CreateDc(HDC sibling, const RECT* rect) = 0; | |
36 | |
37 // Similar to the above method but the metafile is backed by a file. | |
38 virtual bool CreateFileBackedDc(HDC sibling, | |
39 const RECT* rect, | |
40 const FilePath& path) = 0; | |
41 | |
42 // Load an EMF file. | |
vandebo (ex-Chrome)
2011/02/23 02:01:41
extra spaces
dpapad
2011/02/24 20:56:59
Done.
| |
43 virtual bool CreateFromFile(const FilePath& metafile_path) = 0; | |
44 | |
45 // TODO(maruel): CreateFromFile(). If ever used. Maybe users would like to | |
46 // have the ability to save web pages to an EMF file? Afterward, it is easy to | |
47 // convert to PDF or PS. | |
48 | |
49 // Closes the HDC created by CreateDc() and generates the compiled EMF | |
50 // data. | |
51 virtual bool CloseDc() = 0; | |
52 | |
53 // Closes the EMF data handle when it is not needed anymore. | |
54 virtual void CloseEmf() = 0; | |
55 | |
56 // "Plays" the EMF buffer in a HDC. It is the same effect as calling the | |
57 // original GDI function that were called when recording the EMF. |rect| is in | |
58 // "logical units" and is optional. If |rect| is NULL, the natural EMF bounds | |
59 // are used. | |
60 // Note: Windows has been known to have stack buffer overflow in its GDI | |
61 // functions, whether used directly or indirectly through precompiled EMF | |
62 // data. We have to accept the risk here. Since it is used only for printing, | |
63 // it requires user intervention. | |
64 virtual bool Playback(HDC hdc, const RECT* rect) const = 0; | |
65 | |
66 // The slow version of Playback(). It enumerates all the records and play them | |
67 // back in the HDC. The trick is that it skip over the records known to have | |
68 // issue with some printers. See Emf::Record::SafePlayback implementation for | |
69 // details. | |
70 virtual bool SafePlayback(HDC hdc) const = 0; | |
71 | |
72 // Retrieves the bounds of the painted area by this EMF buffer. This value | |
73 // should be passed to Playback to keep the exact same size. | |
74 virtual gfx::Rect GetBounds() const = 0; | |
75 | |
76 // Retrieves the EMF stream size. | |
77 virtual uint32 GetDataSize() const = 0; | |
78 | |
79 // Retrieves the EMF stream. | |
80 virtual bool GetData(void* buffer, uint32 size) const = 0; | |
81 | |
82 // Retrieves the EMF stream. It is an helper function. | |
83 virtual bool GetData(std::vector<uint8>* buffer) const = 0; | |
84 | |
85 virtual HENHMETAFILE emf() const = 0; | |
86 | |
87 virtual HDC hdc() const = 0; | |
88 | |
89 // Inserts a custom GDICOMMENT records indicating StartPage/EndPage calls | |
90 // (since StartPage and EndPage do not work in a metafile DC). Only valid | |
91 // when hdc_ is non-NULL. | |
92 virtual bool StartPage() = 0; | |
93 virtual bool EndPage() = 0; | |
94 | |
95 // Saves the EMF data to a file as-is. It is recommended to use the .emf file | |
96 // extension but it is not enforced. This function synchronously writes to the | |
97 // file. For testing only. | |
98 virtual bool SaveTo(const std::wstring& filename) const = 0; | |
99 | |
100 }; | |
101 | |
102 } // namespace printing | |
103 | |
104 #endif /* PRINTING_NATIVE_METAFILE_WIN_H_ */ | |
vandebo (ex-Chrome)
2011/02/23 02:01:41
style
dpapad
2011/02/24 20:56:59
Done.
| |
OLD | NEW |