Chromium Code Reviews| OLD | NEW |
|---|---|
| (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_LINUX_H_ | |
| 6 #define PRINTING_NATIVE_METAFILE_LINUX_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 | |
| 12 typedef struct _cairo_surface cairo_surface_t; | |
| 13 typedef struct _cairo cairo_t; | |
| 14 | |
| 15 namespace base { | |
| 16 struct FileDescriptor; | |
| 17 } | |
| 18 | |
| 19 class FilePath; | |
| 20 | |
| 21 namespace printing { | |
| 22 | |
| 23 // This class uses Cairo graphics library to generate PostScript/PDF stream | |
| 24 // and stores rendering results in a string buffer. | |
| 25 class NativeMetafile { | |
| 26 public: | |
| 27 enum FileFormat { | |
| 28 PDF, | |
| 29 PS, | |
| 30 }; | |
| 31 | |
| 32 virtual ~NativeMetafile() {}; | |
| 33 | |
| 34 // Initializes to a fresh new metafile. Returns true on success. | |
| 35 // Note: Only call in the renderer to allocate rendering resources. | |
| 36 virtual bool Init() = 0; | |
| 37 | |
| 38 // Initializes a copy of metafile from PDF/PS stream data. | |
| 39 // Returns true on success. | |
| 40 // |src_buffer| should point to the shared memory which stores PDF/PS | |
| 41 // contents generated in the renderer. | |
| 42 // Note: Only call in the browser to initialize |data_|. | |
| 43 virtual bool Init(const void* src_buffer, uint32 src_buffer_size) = 0; | |
| 44 | |
| 45 // Sets raw PS/PDF data for the document. This is used when a cairo drawing | |
| 46 // surface has already been created. This method will cause all subsequent | |
| 47 // drawing on the surface to be discarded (in Close()). If Init() has not yet | |
| 48 // been called this method simply calls the second version of Init. | |
| 49 virtual bool SetRawData(const void* src_buffer, uint32 src_buffer_size) = 0; | |
| 50 | |
| 51 virtual FileFormat GetFileFormat() const = 0; | |
| 52 | |
| 53 // Prepares a new cairo surface/context for rendering a new page. | |
| 54 // The unit is in point (=1/72 in). | |
| 55 // Returns NULL when failed. | |
| 56 virtual cairo_t* StartPage(double width_in_points, | |
| 57 double height_in_points, | |
| 58 double margin_top_in_points, | |
| 59 double margin_right_in_points, | |
| 60 double margin_bottom_in_points, | |
| 61 double margin_left_in_points) = 0; | |
| 62 | |
| 63 // Destroys the surface and the context used in rendering current page. | |
| 64 // The results of current page will be appended into buffer |data_|. | |
| 65 // Returns true on success. | |
| 66 virtual bool FinishPage() = 0; | |
| 67 | |
| 68 // Closes resulting PDF/PS file. No further rendering is allowed. | |
| 69 virtual void Close() = 0; | |
| 70 | |
| 71 // Returns size of PDF/PS contents stored in buffer |data_|. | |
| 72 // This function should ONLY be called after PDF/PS file is closed. | |
| 73 virtual uint32 GetDataSize() const = 0; | |
| 74 | |
| 75 // Copies PDF/PS contents stored in buffer |data_| into |dst_buffer|. | |
| 76 // This function should ONLY be called after PDF/PS file is closed. | |
| 77 // Returns true only when success. | |
| 78 virtual bool GetData(void* dst_buffer, uint32 dst_buffer_size) const = 0; | |
| 79 | |
| 80 // Saves PDF/PS contents stored in buffer |data_| into the file | |
| 81 // associated with |fd|. | |
| 82 // This function should ONLY be called after PDF/PS file is closed. | |
| 83 virtual bool SaveTo(const base::FileDescriptor& fd) const = 0; | |
| 84 | |
| 85 }; | |
| 86 | |
| 87 } // namespace printing | |
| 88 | |
| 89 #endif /* PRINTING_NATIVE_METAFILE_LINUX_H_ */ | |
|
vandebo (ex-Chrome)
2011/02/23 02:01:41
style
dpapad
2011/02/24 20:56:59
Done.
| |
| OLD | NEW |