OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef NATIVE_METAFILE_WIN_H_ | |
6 #define 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 | |
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, const RECT* rect, const FilePath& path) = 0; | |
Avi (use Gerrit)
2011/02/22 17:33:42
80 col!
dpapad
2011/02/22 18:09:30
Done.
| |
39 | |
40 // Load an EMF file. | |
41 virtual bool CreateFromFile(const FilePath& metafile_path) = 0; | |
42 | |
43 // TODO(maruel): CreateFromFile(). If ever used. Maybe users would like to | |
44 // have the ability to save web pages to an EMF file? Afterward, it is easy to | |
45 // convert to PDF or PS. | |
46 | |
47 // Closes the HDC created by CreateDc() and generates the compiled EMF | |
48 // data. | |
49 virtual bool CloseDc() = 0; | |
50 | |
51 // Closes the EMF data handle when it is not needed anymore. | |
52 virtual void CloseEmf() = 0; | |
53 | |
54 // "Plays" the EMF buffer in a HDC. It is the same effect as calling the | |
55 // original GDI function that were called when recording the EMF. |rect| is in | |
56 // "logical units" and is optional. If |rect| is NULL, the natural EMF bounds | |
57 // are used. | |
58 // Note: Windows has been known to have stack buffer overflow in its GDI | |
59 // functions, whether used directly or indirectly through precompiled EMF | |
60 // data. We have to accept the risk here. Since it is used only for printing, | |
61 // it requires user intervention. | |
62 virtual bool Playback(HDC hdc, const RECT* rect) const = 0; | |
63 | |
64 // The slow version of Playback(). It enumerates all the records and play them | |
65 // back in the HDC. The trick is that it skip over the records known to have | |
66 // issue with some printers. See Emf::Record::SafePlayback implementation for | |
67 // details. | |
68 virtual bool SafePlayback(HDC hdc) const = 0; | |
69 | |
70 // Retrieves the bounds of the painted area by this EMF buffer. This value | |
71 // should be passed to Playback to keep the exact same size. | |
72 virtual gfx::Rect GetBounds() const = 0; | |
73 | |
74 // Retrieves the EMF stream size. | |
75 virtual uint32 GetDataSize() const = 0; | |
76 | |
77 // Retrieves the EMF stream. | |
78 virtual bool GetData(void* buffer, uint32 size) const = 0; | |
79 | |
80 // Retrieves the EMF stream. It is an helper function. | |
81 virtual bool GetData(std::vector<uint8>* buffer) const = 0; | |
82 | |
83 virtual HENHMETAFILE emf() const = 0; | |
84 | |
85 virtual HDC hdc() const = 0; | |
86 | |
87 // Inserts a custom GDICOMMENT records indicating StartPage/EndPage calls | |
88 // (since StartPage and EndPage do not work in a metafile DC). Only valid | |
89 // when hdc_ is non-NULL. | |
90 virtual bool StartPage() = 0; | |
91 virtual bool EndPage() = 0; | |
92 | |
93 // Saves the EMF data to a file as-is. It is recommended to use the .emf file | |
94 // extension but it is not enforced. This function synchronously writes to the | |
95 // file. For testing only. | |
96 virtual bool SaveTo(const std::wstring& filename) const = 0; | |
97 | |
98 }; | |
99 | |
100 } // namespace printing | |
101 | |
102 #endif /* NATIVE_METAFILE_WIN_H_ */ | |
OLD | NEW |