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

Side by Side Diff: printing/native_metafile_win.h

Issue 6611032: Unifying NativeMetafile class interface (as much as possible) for Linux, Mac, Win (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixes for CHROMEOS 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
OLDNEW
(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 manages a data stream and its virtual HDC.
22 class NativeMetafile {
23 public:
24 virtual ~NativeMetafile() {}
25
26 // Initializes the data stream with the data in |src_buffer|. Returns
27 // 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 a data stream from file.
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.
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 data stream size.
77 virtual uint32 GetDataSize() const = 0;
78
79 // Retrieves the data stream.
80 virtual bool GetData(void* buffer, uint32 size) const = 0;
81
82 // Retrieves the data 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 } // namespace printing
102
103 #endif // PRINTING_NATIVE_METAFILE_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698