OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_PDF_PS_METAFILE_CAIRO_H_ | 5 #ifndef PRINTING_PDF_PS_METAFILE_CAIRO_H_ |
6 #define PRINTING_PDF_PS_METAFILE_CAIRO_H_ | 6 #define PRINTING_PDF_PS_METAFILE_CAIRO_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 | 11 |
12 typedef struct _cairo_surface cairo_surface_t; | 12 typedef struct _cairo_surface cairo_surface_t; |
13 typedef struct _cairo cairo_t; | 13 typedef struct _cairo cairo_t; |
14 | 14 |
15 namespace base { | 15 namespace base { |
16 struct FileDescriptor; | 16 struct FileDescriptor; |
17 } | 17 } |
18 | 18 |
19 class FilePath; | 19 class FilePath; |
20 | 20 |
21 namespace printing { | 21 namespace printing { |
22 | 22 |
23 // This class uses Cairo graphics library to generate PostScript/PDF stream | 23 // This class uses Cairo graphics library to generate PostScript/PDF stream |
24 // and stores rendering results in a string buffer. | 24 // and stores rendering results in a string buffer. |
25 class PdfPsMetafile { | 25 class PdfPsMetafile { |
26 public: | 26 public: |
27 enum FileFormat { | |
28 PDF, | |
29 PS, | |
30 }; | |
31 | |
32 PdfPsMetafile(); | 27 PdfPsMetafile(); |
33 | |
34 // In the renderer process, callers should also call Init(void) to see if the | |
35 // metafile can obtain all necessary rendering resources. | |
36 // In the browser process, callers should also call Init(const void*, uint32) | |
37 // to initialize the buffer |data_| to use SaveTo(). | |
38 explicit PdfPsMetafile(const FileFormat& format); | |
39 | |
40 ~PdfPsMetafile(); | 28 ~PdfPsMetafile(); |
41 | 29 |
42 // Initializes to a fresh new metafile. Returns true on success. | 30 // Initializes to a fresh new metafile. Returns true on success. |
43 // Note: Only call in the renderer to allocate rendering resources. | 31 // Note: Only call in the renderer to allocate rendering resources. |
44 bool Init(); | 32 bool Init(); |
45 | 33 |
46 // Initializes a copy of metafile from PDF/PS stream data. | 34 // Initializes a copy of metafile from PDF/PS stream data. |
vandebo (ex-Chrome)
2011/02/25 00:10:35
You should update the comments.
dpapad
2011/02/25 02:26:34
Done.
| |
47 // Returns true on success. | 35 // Returns true on success. |
48 // |src_buffer| should point to the shared memory which stores PDF/PS | 36 // |src_buffer| should point to the shared memory which stores PDF/PS |
49 // contents generated in the renderer. | 37 // contents generated in the renderer. |
50 // Note: Only call in the browser to initialize |data_|. | 38 // Note: Only call in the browser to initialize |data_|. |
51 bool Init(const void* src_buffer, uint32 src_buffer_size); | 39 bool Init(const void* src_buffer, uint32 src_buffer_size); |
52 | 40 |
53 // Sets raw PS/PDF data for the document. This is used when a cairo drawing | 41 // Sets raw PS/PDF data for the document. This is used when a cairo drawing |
54 // surface has already been created. This method will cause all subsequent | 42 // surface has already been created. This method will cause all subsequent |
55 // drawing on the surface to be discarded (in Close()). If Init() has not yet | 43 // drawing on the surface to be discarded (in Close()). If Init() has not yet |
56 // been called this method simply calls the second version of Init. | 44 // been called this method simply calls the second version of Init. |
57 bool SetRawData(const void* src_buffer, uint32 src_buffer_size); | 45 bool SetRawData(const void* src_buffer, uint32 src_buffer_size); |
58 | 46 |
59 FileFormat GetFileFormat() const { return format_; } | |
60 | |
61 // Prepares a new cairo surface/context for rendering a new page. | 47 // Prepares a new cairo surface/context for rendering a new page. |
62 // The unit is in point (=1/72 in). | 48 // The unit is in point (=1/72 in). |
63 // Returns NULL when failed. | 49 // Returns NULL when failed. |
64 cairo_t* StartPage(double width_in_points, | 50 cairo_t* StartPage(double width_in_points, |
65 double height_in_points, | 51 double height_in_points, |
66 double margin_top_in_points, | 52 double margin_top_in_points, |
67 double margin_right_in_points, | 53 double margin_right_in_points, |
68 double margin_bottom_in_points, | 54 double margin_bottom_in_points, |
69 double margin_left_in_points); | 55 double margin_left_in_points); |
70 | 56 |
(...skipping 27 matching lines...) Expand all Loading... | |
98 static const double kLeftMarginInInch; | 84 static const double kLeftMarginInInch; |
99 | 85 |
100 // Returns the PdfPsMetafile object that owns the given context. Returns NULL | 86 // Returns the PdfPsMetafile object that owns the given context. Returns NULL |
101 // if the context was not created by a PdfPdMetafile object. | 87 // if the context was not created by a PdfPdMetafile object. |
102 static PdfPsMetafile* FromCairoContext(cairo_t* context); | 88 static PdfPsMetafile* FromCairoContext(cairo_t* context); |
103 | 89 |
104 private: | 90 private: |
105 // Cleans up all resources. | 91 // Cleans up all resources. |
106 void CleanUpAll(); | 92 void CleanUpAll(); |
107 | 93 |
108 FileFormat format_; | |
109 | |
110 // Cairo surface and context for entire PDF/PS file. | 94 // Cairo surface and context for entire PDF/PS file. |
111 cairo_surface_t* surface_; | 95 cairo_surface_t* surface_; |
112 cairo_t* context_; | 96 cairo_t* context_; |
113 | 97 |
114 // Buffer stores PDF/PS contents for entire PDF/PS file. | 98 // Buffer stores PDF/PS contents for entire PDF/PS file. |
115 std::string data_; | 99 std::string data_; |
116 // Buffer stores raw PDF/PS contents set by SetRawPageData. | 100 // Buffer stores raw PDF/PS contents set by SetRawPageData. |
117 std::string raw_override_data_; | 101 std::string raw_override_data_; |
118 | 102 |
119 DISALLOW_COPY_AND_ASSIGN(PdfPsMetafile); | 103 DISALLOW_COPY_AND_ASSIGN(PdfPsMetafile); |
120 }; | 104 }; |
121 | 105 |
122 } // namespace printing | 106 } // namespace printing |
123 | 107 |
124 #endif // PRINTING_PDF_PS_METAFILE_CAIRO_H_ | 108 #endif // PRINTING_PDF_PS_METAFILE_CAIRO_H_ |
OLD | NEW |