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

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: 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
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"
vandebo (ex-Chrome) 2011/03/12 01:21:06 What is this needed for?
dpapad 2011/03/14 18:02:38 This is where the typedef NativeDrawingContext is
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 #if defined(OS_CHROMEOS)
28 namespace base {
29 class FileDescriptor;
30 }
31 #endif
32
33 class FilePath;
34
35 namespace printing {
36
37 // This class creates a graphics context that renders into a data stream.
38 class NativeMetafile {
39 public:
40 virtual ~NativeMetafile() {}
41
42 // Initializes a fresh new metafile for rendering. Returns false on failure.
43 // Note: It should only be called from within the renderer process to allocate
44 // rendering resources.
45 virtual bool Init() = 0;
46
47 // Initializes the metafile with the data in |src_buffer|. Returns true
48 // on success.
49 // Note: It should only be called from within the browser process.
50 virtual bool Init(const void* src_buffer, uint32 src_buffer_size) = 0;
51
52 // Returns the size of the underlying data stream. Only valid after Close()
53 // has been called.
54 virtual uint32 GetDataSize() const = 0;
vandebo (ex-Chrome) 2011/03/12 01:21:06 Move GetDataSize and GetData below Close
dpapad 2011/03/14 18:02:38 Done (Also reordered in emf_win.h, pdf_metafile_ma
55
56 // Copies the first |dst_buffer_size| bytes of the underlying data stream into
57 // |dst_buffer|. This function should ONLY be called after Close() is invoked.
58 // Returns true if the copy succeeds.
59 virtual bool GetData(void* dst_buffer, uint32 dst_buffer_size) const = 0;
60
61 // Closes the current page and destroys the context used in rendering that
62 // page. The results of current page will be appended into the underlying
63 // data stream. Returns true on success.
64 virtual bool FinishPage() = 0;
65
66 // Closes the metafile. No further rendering is allowed (the current page
67 // is implicitly closed).
68 virtual void Close() = 0;
69
70 // Saves the underlying data to the given file. This function should ONLY be
71 // called after the metafile is closed. Returns true if writing succeeded.
72 virtual bool SaveTo(const FilePath& file_path) const = 0;
73
74 // Returns the bounds of the given page. Pages use a 1-based index.
75 virtual gfx::Rect GetPageBounds(unsigned int page_number) const = 0;
76 virtual unsigned int GetPageCount() const = 0;
77
78 #if defined(OS_WIN)
79 // Inserts a custom GDICOMMENT records indicating StartPage/EndPage calls
80 // (since StartPage and EndPage do not work in a metafile DC). Only valid
81 // when hdc_ is non-NULL.
82 virtual bool StartPage() = 0;
vandebo (ex-Chrome) 2011/03/12 01:21:06 Put start page just above FinishPage -- We will sh
dpapad 2011/03/14 18:02:38 Done (Also reordered in emf_win.h, pdf_metafile_ma
83 #elif defined(OS_MACOSX)
84 // Prepares a new pdf page at specified |content_origin| with the given
85 // |page_size| and a |scale_factor| to use for the drawing.
86 virtual gfx::NativeDrawingContext StartPage(const gfx::Size& page_size,
87 const gfx::Point& content_origin,
88 const float& scale_factor) = 0;
89 #elif defined(OS_POSIX)
90 // Prepares a new cairo surface/context for rendering a new page.
91 // The unit is in point (=1/72 in).
92 // Returns NULL when failed.
93 virtual gfx::NativeDrawingContext StartPage(const gfx::Size& page_sixe,
94 double margin_top_in_points,
95 double margin_right_in_points,
96 double margin_bottom_in_points,
97 double margin_left_in_points) = 0;
98 #endif
99
100 #if defined(OS_WIN)
101 // Generates a virtual HDC that will record every GDI commands and compile it
102 // in a EMF data stream.
103 // hdc is used to setup the default DPI and color settings. hdc is optional.
104 // rect specifies the dimensions (in .01-millimeter units) of the EMF. rect is
105 // optional.
106 virtual bool CreateDc(gfx::NativeDrawingContext sibling,
107 const RECT* rect) = 0;
108
109 // Similar to the above method but the metafile is backed by a file.
110 virtual bool CreateFileBackedDc(gfx::NativeDrawingContext sibling,
111 const RECT* rect,
112 const FilePath& path) = 0;
113
114 // TODO(maruel): CreateFromFile(). If ever used. Maybe users would like to
115 // have the ability to save web pages to an EMF file? Afterward, it is easy to
116 // convert to PDF or PS.
117 // Load a metafile fromdisk.
118 virtual bool CreateFromFile(const FilePath& metafile_path) = 0;
119
120 // Closes the HDC created by CreateDc() and generates the compiled EMF
121 // data.
122 virtual bool CloseDc() = 0;
123
124 // "Plays" the EMF buffer in a HDC. It is the same effect as calling the
125 // original GDI function that were called when recording the EMF. |rect| is in
126 // "logical units" and is optional. If |rect| is NULL, the natural EMF bounds
127 // are used.
128 // Note: Windows has been known to have stack buffer overflow in its GDI
129 // functions, whether used directly or indirectly through precompiled EMF
130 // data. We have to accept the risk here. Since it is used only for printing,
131 // it requires user intervention.
132 virtual bool Playback(gfx::NativeDrawingContext hdc,
133 const RECT* rect) const = 0;
134
135 // The slow version of Playback(). It enumerates all the records and play them
136 // back in the HDC. The trick is that it skip over the records known to have
137 // issue with some printers. See Emf::Record::SafePlayback implementation for
138 // details.
139 virtual bool SafePlayback(gfx::NativeDrawingContext hdc) const = 0;
140
141 // Retrieves the EMF stream. It is a helper function.
vandebo (ex-Chrome) 2011/03/12 01:21:06 This is not emf specific, use similar language as
dpapad 2011/03/14 18:02:38 Done.
142 virtual bool GetData(std::vector<uint8>* buffer) const = 0;
vandebo (ex-Chrome) 2011/03/12 01:21:06 For a follow up CL: Should we use this interface a
143
144 virtual HENHMETAFILE emf() const = 0;
145 virtual gfx::NativeDrawingContext hdc() const = 0;
vandebo (ex-Chrome) 2011/03/12 01:21:06 pull this up to the common section and call it con
dpapad 2011/03/14 18:02:38 Done.
146 #elif defined(OS_MACOSX)
147 // Renders the given page into |rect| in the given context.
148 // Pages use a 1-based index. The rendering uses the following arguments
149 // to determine scaling and translation factors.
150 // |shrink_to_fit| specifies whether the output should be shrunk to fit the
151 // supplied |rect| if the page size is larger than |rect| in any dimension.
152 // If this is false, parts of the PDF page that lie outside the bounds will be
153 // clipped.
154 // |stretch_to_fit| specifies whether the output should be stretched to fit
155 // the supplied bounds if the page size is smaller than |rect| in all
156 // dimensions.
157 // |center_horizontally| specifies whether the final image (after any scaling
158 // is done) should be centered horizontally within the given |rect|.
159 // |center_vertically| specifies whether the final image (after any scaling
160 // is done) should be centered vertically within the given |rect|.
161 // Note that all scaling preserves the original aspect ratio of the page.
162 virtual bool RenderPage(unsigned int page_number,
vandebo (ex-Chrome) 2011/03/12 01:21:06 nothing to d, but note: it seems that this method
163 gfx::NativeDrawingContext context,
164 const CGRect rect,
165 bool shrink_to_fit,
166 bool stretch_to_fit,
167 bool center_horizontally,
168 bool center_vertically) const = 0;
169
170 // Get the context for rendering to the PDF.
171 virtual gfx::NativeDrawingContext context() = 0;
vandebo (ex-Chrome) 2011/03/12 01:21:06 To the common section.
dpapad 2011/03/14 18:02:38 Done.
172 #elif defined(OS_POSIX)
173 // Sets raw PDF data for the document. This is used when a cairo drawing
174 // surface has already been created. This method will cause all subsequent
175 // drawing on the surface to be discarded (in Close()). If Init() has not yet
176 // been called this method simply calls the second version of Init.
177 virtual bool SetRawData(const void* src_buffer, uint32 src_buffer_size) = 0;
vandebo (ex-Chrome) 2011/03/12 01:21:06 It looks like this is only used in pdf_ps_metafile
dpapad 2011/03/14 18:02:38 It is also used in webkit/plugins/ppapi/ppapi_plug
178
179 #if defined(OS_CHROMEOS)
180 // Saves the underlying data to the file associated with fd. This function
181 // should ONLY be called after the metafile is closed.
182 // Returns true if writing succeeded.
183 virtual bool SaveToFD(const base::FileDescriptor& fd) const = 0;
184 #endif // if defined(OS_CHROMEOS)
185
186 #endif
187 };
188
189 } // namespace printing
190
19 #endif // PRINTING_NATIVE_METAFILE_H_ 191 #endif // PRINTING_NATIVE_METAFILE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698