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

Side by Side Diff: printing/native_metafile.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: Restored deleted function. Using gfx::NativeDrawingContext instead of PlatformContext. 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
« no previous file with comments | « printing/image_win.cc ('k') | printing/native_metafile_linux.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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_NATIVE_METAFILE_H_ 5 #ifndef PRINTING_NATIVE_METAFILE_H_
6 #define PRINTING_NATIVE_METAFILE_H_ 6 #define PRINTING_NATIVE_METAFILE_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "ui/gfx/native_widget_types.h"
10 11
11 #if defined(OS_WIN) 12 #if defined(OS_WIN)
12 #include "printing/native_metafile_win.h" 13 #include <windows.h>
14 #include <vector>
13 #elif defined(OS_MACOSX) 15 #elif defined(OS_MACOSX)
14 #include "printing/native_metafile_mac.h" 16 #include <ApplicationServices/ApplicationServices.h>
15 #elif defined(OS_POSIX) 17 #include <CoreFoundation/CoreFoundation.h>
16 #include "printing/native_metafile_linux.h" 18 #include "base/mac/scoped_cftyperef.h"
17 #endif 19 #endif
18 20
21 namespace gfx {
22 class Rect;
23 class Size;
24 class Point;
25 }
26
27 class FilePath;
28
29 namespace printing {
30
31 // This class creates a graphics context that renders into a data stream.
32 class NativeMetafile {
33 public:
34 virtual ~NativeMetafile() {}
35
36 // Initializes a fresh new metafile for rendering. Returns false on failure.
37 // Note: It should only be called from within the renderer process to allocate
38 // rendering resources.
39 virtual bool Init() = 0;
40
41 // Initializes the metafile with the data in |src_buffer|. Returns true
42 // on success.
43 // Note: It should only be called from within the browser process.
44 virtual bool Init(const void* src_buffer, uint32 src_buffer_size) = 0;
45
46 // Returns the size of the underlying data stream. Only valid after Close()
47 // has been called.
48 virtual uint32 GetDataSize() const = 0;
49
50 // Copies the first |dst_buffer_size| bytes of the underlying data stream into
51 // |dst_buffer|. This function should ONLY be called after Close() is invoked.
52 // Returns true if the copy succeeds.
53 virtual bool GetData(void* dst_buffer, uint32 dst_buffer_size) const = 0;
54
55 // Closes the current page and destroys the context used in rendering that
56 // page. The results of current page will be appended into the underlying
57 // data stream. Returns true on success.
58 virtual bool FinishPage() = 0;
59
60 // Closes the metafile. No further rendering is allowed (the current page
61 // is implicitly closed).
62 virtual void Close() = 0;
63
64 // Saves the underlying data to the given file. This function should ONLY be
65 // called after the metafile is closed. Returns true if writing succeeded.
66 virtual bool SaveTo(const FilePath& file_path) const = 0;
67
68 // Returns the bounds of the given page. Pages use a 1-based index.
69 virtual gfx::Rect GetPageBounds(unsigned int page_number) const = 0;
70 virtual unsigned int GetPageCount() const = 0;
71
72 #if defined(OS_WIN)
73 // Inserts a custom GDICOMMENT records indicating StartPage/EndPage calls
74 // (since StartPage and EndPage do not work in a metafile DC). Only valid
75 // when hdc_ is non-NULL.
76 virtual bool StartPage() = 0;
77 #elif defined(OS_MACOSX)
78 // Prepares a new pdf page at specified |content_origin| with the given
79 // |page_size| and a |scale_factor| to use for the drawing.
80 virtual gfx::NativeDrawingContext StartPage(const gfx::Size& page_size,
81 const gfx::Point& content_origin,
82 const float& scale_factor) = 0;
83 #elif defined(OS_POSIX)
84 // Prepares a new cairo surface/context for rendering a new page.
85 // The unit is in point (=1/72 in).
86 // Returns NULL when failed.
87 virtual gfx::NativeDrawingContext StartPage(const gfx::Size& page_sixe,
88 double margin_top_in_points,
89 double margin_right_in_points,
90 double margin_bottom_in_points,
91 double margin_left_in_points) = 0;
92 #endif
93
94 #if defined(OS_WIN)
95 // Generates a virtual HDC that will record every GDI commands and compile it
96 // in a EMF data stream.
97 // hdc is used to setup the default DPI and color settings. hdc is optional.
98 // rect specifies the dimensions (in .01-millimeter units) of the EMF. rect is
99 // optional.
100 virtual bool CreateDc(gfx::NativeDrawingContext sibling,
101 const RECT* rect) = 0;
102
103 // Similar to the above method but the metafile is backed by a file.
104 virtual bool CreateFileBackedDc(gfx::NativeDrawingContext sibling,
105 const RECT* rect,
106 const FilePath& path) = 0;
107
108 // TODO(maruel): CreateFromFile(). If ever used. Maybe users would like to
109 // have the ability to save web pages to an EMF file? Afterward, it is easy to
110 // convert to PDF or PS.
111 // Load a metafile fromdisk.
112 virtual bool CreateFromFile(const FilePath& metafile_path) = 0;
dpapad 2011/03/10 19:32:34 Restored this function since it is used (previousl
113
114 // Closes the HDC created by CreateDc() and generates the compiled EMF
115 // data.
116 virtual bool CloseDc() = 0;
117
118 // "Plays" the EMF buffer in a HDC. It is the same effect as calling the
119 // original GDI function that were called when recording the EMF. |rect| is in
120 // "logical units" and is optional. If |rect| is NULL, the natural EMF bounds
121 // are used.
122 // Note: Windows has been known to have stack buffer overflow in its GDI
123 // functions, whether used directly or indirectly through precompiled EMF
124 // data. We have to accept the risk here. Since it is used only for printing,
125 // it requires user intervention.
126 virtual bool Playback(gfx::NativeDrawingContext hdc,
127 const RECT* rect) const = 0;
128
129 // The slow version of Playback(). It enumerates all the records and play them
130 // back in the HDC. The trick is that it skip over the records known to have
131 // issue with some printers. See Emf::Record::SafePlayback implementation for
132 // details.
133 virtual bool SafePlayback(gfx::NativeDrawingContext hdc) const = 0;
134
135 // Retrieves the EMF stream. It is a helper function.
136 virtual bool GetData(std::vector<uint8>* buffer) const = 0;
137
138 virtual HENHMETAFILE emf() const = 0;
139 virtual gfx::NativeDrawingContext hdc() const = 0;
140 #elif defined(OS_MACOSX)
141 // Renders the given page into |rect| in the given context.
142 // Pages use a 1-based index. The rendering uses the following arguments
143 // to determine scaling and translation factors.
144 // |shrink_to_fit| specifies whether the output should be shrunk to fit the
145 // supplied |rect| if the page size is larger than |rect| in any dimension.
146 // If this is false, parts of the PDF page that lie outside the bounds will be
147 // clipped.
148 // |stretch_to_fit| specifies whether the output should be stretched to fit
149 // the supplied bounds if the page size is smaller than |rect| in all
150 // dimensions.
151 // |center_horizontally| specifies whether the final image (after any scaling
152 // is done) should be centered horizontally within the given |rect|.
153 // |center_vertically| specifies whether the final image (after any scaling
154 // is done) should be centered vertically within the given |rect|.
155 // Note that all scaling preserves the original aspect ratio of the page.
156 virtual bool RenderPage(unsigned int page_number,
157 gfx::NativeDrawingContext context,
158 const CGRect rect,
159 bool shrink_to_fit,
160 bool stretch_to_fit,
161 bool center_horizontally,
162 bool center_vertically) const = 0;
163
164 // Get the context for rendering to the PDF.
165 virtual gfx::NativeDrawingContext context() = 0;
166 #elif defined(OS_POSIX)
167 // Sets raw PDF data for the document. This is used when a cairo drawing
168 // surface has already been created. This method will cause all subsequent
169 // drawing on the surface to be discarded (in Close()). If Init() has not yet
170 // been called this method simply calls the second version of Init.
171 virtual bool SetRawData(const void* src_buffer, uint32 src_buffer_size) = 0;
172 #endif
173 };
174
175 } // namespace printing
176
19 #endif // PRINTING_NATIVE_METAFILE_H_ 177 #endif // PRINTING_NATIVE_METAFILE_H_
OLDNEW
« no previous file with comments | « printing/image_win.cc ('k') | printing/native_metafile_linux.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698