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

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 pdf_ps_metafile_cairo.h class comment 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"
vandebo (ex-Chrome) 2011/03/08 00:39:35 Still need this, no?
dpapad 2011/03/08 19:39:22 Done.
10 9
11 #if defined(OS_WIN) 10 #if defined(OS_WIN)
12 #include "printing/native_metafile_win.h" 11 #include <windows.h>
12 #include <vector>
13 #elif defined(OS_MACOSX) 13 #elif defined(OS_MACOSX)
14 #include "printing/native_metafile_mac.h" 14 #include <ApplicationServices/ApplicationServices.h>
15 #elif defined(OS_POSIX) 15 #include <CoreFoundation/CoreFoundation.h>
16 #include "printing/native_metafile_linux.h" 16 #include "base/mac/scoped_cftyperef.h"
17 #endif 17 #endif
18 18
19 #if defined(OS_WIN)
20 namespace gfx {
21 class Rect;
22 }
23 #elif defined(OS_MACOSX)
24 namespace gfx {
vandebo (ex-Chrome) 2011/03/08 00:39:35 These can be done outside of a platform ifdef
dpapad 2011/03/08 19:39:22 Done.
25 class Rect;
26 class Size;
27 class Point;
28 }
29 #elif defined(OS_POSIX)
30 typedef struct _cairo_surface cairo_surface_t;
vandebo (ex-Chrome) 2011/03/08 00:39:35 cairo_surface_t isn't used here. What does use it
dpapad 2011/03/08 19:39:22 Done.
31 typedef struct _cairo cairo_t;
vandebo (ex-Chrome) 2011/03/08 00:39:35 Looks like a per platform typedef might be useful.
dpapad 2011/03/08 19:39:22 Done.
32 #endif
33
34 class FilePath;
35
36 namespace printing {
37
38 // This class creates a graphics context that renders into a PDF data stream.
vandebo (ex-Chrome) 2011/03/08 00:39:35 It doesn't always render to a PDF data stream.
dpapad 2011/03/08 19:39:22 Done.
39 class NativeMetafile {
40 public:
41 virtual ~NativeMetafile() {}
42
43 // Initializes a fresh new metafile for rendering. Returns false on failure.
44 // Note: It should only be called from within the renderer process to allocate
45 // rendering resources.
46 virtual bool Init() = 0;
47
48 // Initializes the metafile with the data in |src_buffer|. Returns true
49 // on success.
50 // Note: It should only be called from within the browser process.
51 virtual bool Init(const void* src_buffer, uint32 src_buffer_size) = 0;
52
53 // Returns the size of the underlying data stream. Only valid after Close()
54 // has been called.
55 virtual uint32 GetDataSize() const = 0;
56
57 // Copies the first |dst_buffer_size| bytes of the underlying data stream into
58 // |dst_buffer|. This function should ONLY be called after Close() is invoked.
59 // Returns true if the copy succeeds.
60 virtual bool GetData(void* dst_buffer, uint32 dst_buffer_size) const = 0;
61
62 // Closes the current page and destroys the context used in rendering that
63 // page. The results of current page will be appended into the underlying
64 // data stream. Returns true on success.
65 virtual bool FinishPage() = 0;
66
67 // Closes the metafile. No further rendering is allowed.
vandebo (ex-Chrome) 2011/03/08 00:39:35 Maybe note that this implicitly finishes the curre
dpapad 2011/03/08 19:39:22 Done.
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;
vandebo (ex-Chrome) 2011/03/08 00:39:35 Is this only used by tests? If so, we can make it
dpapad 2011/03/08 19:39:22 No, it is used in non-test code (print_dialog_gtk.
73
74 #if defined(OS_WIN)||defined(OS_MACOSX)
75 // Returns the bounds of the given page. Pages use a 1-based index.
76 virtual gfx::Rect GetPageBounds(unsigned int page_number) const = 0;
vandebo (ex-Chrome) 2011/03/08 00:39:35 Lets make these not platform specific.
dpapad 2011/03/08 19:39:22 Done.
77 virtual unsigned int GetPageCount() const = 0;
78 #endif
79
80 #if defined(OS_WIN)
81 // Generates a virtual HDC that will record every GDI commands and compile it
82 // in a EMF data stream.
83 // hdc is used to setup the default DPI and color settings. hdc is optional.
84 // rect specifies the dimensions (in .01-millimeter units) of the EMF. rect is
85 // optional.
86 virtual bool CreateDc(HDC sibling, const RECT* rect) = 0;
vandebo (ex-Chrome) 2011/03/08 00:39:35 It'd be great to know if these methods are specifi
dpapad 2011/03/08 19:39:22 These functions call internaly CreateEnhMetaFile(.
vandebo (ex-Chrome) 2011/03/08 20:16:53 That makes it sound like they are EMF specific. C
dpapad 2011/03/08 22:17:19 In several places (print_web_view_helper_win.cc, w
87
88 // Similar to the above method but the metafile is backed by a file.
89 virtual bool CreateFileBackedDc(HDC sibling,
90 const RECT* rect,
91 const FilePath& path) = 0;
92
93 // TODO(maruel): CreateFromFile(). If ever used. Maybe users would like to
vandebo (ex-Chrome) 2011/03/08 00:39:35 Is this ever used?
dpapad 2011/03/08 19:39:22 No, it is not used anywhere. Should I remove it?
vandebo (ex-Chrome) 2011/03/08 20:16:53 Yea, we like to remove dead code.
dpapad 2011/03/08 22:17:19 Done.
dpapad 2011/03/10 19:32:34 It turns out that this function is called in servi
94 // have the ability to save web pages to an EMF file? Afterward, it is easy to
95 // convert to PDF or PS.
96 // Load an EMF file.
97 virtual bool CreateFromFile(const FilePath& metafile_path) = 0;
98
99 // Closes the HDC created by CreateDc() and generates the compiled EMF
100 // data.
101 virtual bool CloseDc() = 0;
102
103 // "Plays" the EMF buffer in a HDC. It is the same effect as calling the
104 // original GDI function that were called when recording the EMF. |rect| is in
105 // "logical units" and is optional. If |rect| is NULL, the natural EMF bounds
106 // are used.
107 // Note: Windows has been known to have stack buffer overflow in its GDI
108 // functions, whether used directly or indirectly through precompiled EMF
109 // data. We have to accept the risk here. Since it is used only for printing,
110 // it requires user intervention.
111 virtual bool Playback(HDC hdc, const RECT* rect) const = 0;
112
113 // The slow version of Playback(). It enumerates all the records and play them
114 // back in the HDC. The trick is that it skip over the records known to have
115 // issue with some printers. See Emf::Record::SafePlayback implementation for
116 // details.
117 virtual bool SafePlayback(HDC hdc) const = 0;
vandebo (ex-Chrome) 2011/03/08 00:39:35 Are both of the playback methods still used?
dpapad 2011/03/08 19:39:22 They are both used (but only in emf_win_unittest.c
vandebo (ex-Chrome) 2011/03/08 20:16:53 If only used in emf unit tests, then they can be m
dpapad 2011/03/08 22:17:19 Actually, it turns out that SafePlayback is not on
118
119 // Retrieves the EMF stream. It is a helper function.
120 virtual bool GetData(std::vector<uint8>* buffer) const = 0;
121
122 // Inserts a custom GDICOMMENT records indicating StartPage/EndPage calls
123 // (since StartPage and EndPage do not work in a metafile DC). Only valid
124 // when hdc_ is non-NULL.
125 virtual bool StartPage() = 0;
vandebo (ex-Chrome) 2011/03/08 00:39:35 For methods that are the same on the different pla
dpapad 2011/03/08 19:39:22 Done.
126
127 virtual HENHMETAFILE emf() const = 0;
128 virtual HDC hdc() const = 0;
129 #elif defined(OS_MACOSX)
130 // Prepares a new pdf page at specified |content_origin| with the given
131 // |page_size| and a |scale_factor| to use for the drawing.
132 virtual CGContextRef StartPage(const gfx::Size& page_size,
133 const gfx::Point& content_origin,
134 const float& scale_factor) = 0;
135
136 // Renders the given page into |rect| in the given context.
137 // Pages use a 1-based index. The rendering uses the following arguments
138 // to determine scaling and translation factors.
139 // |shrink_to_fit| specifies whether the output should be shrunk to fit the
140 // supplied |rect| if the page size is larger than |rect| in any dimension.
141 // If this is false, parts of the PDF page that lie outside the bounds will be
142 // clipped.
143 // |stretch_to_fit| specifies whether the output should be stretched to fit
144 // the supplied bounds if the page size is smaller than |rect| in all
145 // dimensions.
146 // |center_horizontally| specifies whether the final image (after any scaling
147 // is done) should be centered horizontally within the given |rect|.
148 // |center_vertically| specifies whether the final image (after any scaling
149 // is done) should be centered vertically within the given |rect|.
150 // Note that all scaling preserves the original aspect ratio of the page.
151 virtual bool RenderPage(unsigned int page_number,
152 CGContextRef context,
153 const CGRect rect,
154 bool shrink_to_fit,
155 bool stretch_to_fit,
156 bool center_horizontally,
157 bool center_vertically) const = 0;
158
159 // Get the context for rendering to the PDF.
160 virtual CGContextRef context() = 0;
161 #elif defined(OS_POSIX)
162 // Sets raw PDF data for the document. This is used when a cairo drawing
163 // surface has already been created. This method will cause all subsequent
164 // drawing on the surface to be discarded (in Close()). If Init() has not yet
165 // been called this method simply calls the second version of Init.
166 virtual bool SetRawData(const void* src_buffer, uint32 src_buffer_size) = 0;
167
168 // Prepares a new cairo surface/context for rendering a new page.
169 // The unit is in point (=1/72 in).
170 // Returns NULL when failed.
171 virtual cairo_t* StartPage(double width_in_points,
vandebo (ex-Chrome) 2011/03/08 00:39:35 These arguments could be turned into two gfx::Size
dpapad 2011/03/08 19:39:22 gfx::Size stores width and height as integers. Her
vandebo (ex-Chrome) 2011/03/08 20:16:53 These are in points, it's ok to round these values
172 double height_in_points,
173 double margin_top_in_points,
174 double margin_right_in_points,
175 double margin_bottom_in_points,
176 double margin_left_in_points) = 0;
177 #endif
178 };
179
180 } // namespace printing
181
19 #endif // PRINTING_NATIVE_METAFILE_H_ 182 #endif // PRINTING_NATIVE_METAFILE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698