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" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 // |src_buffer| should point to the shared memory which stores PDF/PS | 46 // |src_buffer| should point to the shared memory which stores PDF/PS |
47 // contents generated in the renderer. | 47 // contents generated in the renderer. |
48 // Note: Only call in the browser to initialize |data_|. | 48 // Note: Only call in the browser to initialize |data_|. |
49 bool Init(const void* src_buffer, uint32 src_buffer_size); | 49 bool Init(const void* src_buffer, uint32 src_buffer_size); |
50 | 50 |
51 FileFormat GetFileFormat() const { return format_; } | 51 FileFormat GetFileFormat() const { return format_; } |
52 | 52 |
53 // Prepares a new cairo surface/context for rendering a new page. | 53 // Prepares a new cairo surface/context for rendering a new page. |
54 // The unit is in point (=1/72 in). | 54 // The unit is in point (=1/72 in). |
55 // Returns NULL when failed. | 55 // Returns NULL when failed. |
56 cairo_t* StartPage(double width, double height); | 56 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); |
57 | 62 |
58 // Destroys the surface and the context used in rendering current page. | 63 // Destroys the surface and the context used in rendering current page. |
59 // The results of current page will be appended into buffer |data_|. | 64 // The results of current page will be appended into buffer |data_|. |
60 // Returns true on success. | 65 // Returns true on success. |
61 bool FinishPage(); | 66 bool FinishPage(); |
62 | 67 |
63 // Closes resulting PDF/PS file. No further rendering is allowed. | 68 // Closes resulting PDF/PS file. No further rendering is allowed. |
64 void Close(); | 69 void Close(); |
65 | 70 |
66 // Returns size of PDF/PS contents stored in buffer |data_|. | 71 // Returns size of PDF/PS contents stored in buffer |data_|. |
67 // This function should ONLY be called after PDF/PS file is closed. | 72 // This function should ONLY be called after PDF/PS file is closed. |
68 uint32 GetDataSize() const; | 73 uint32 GetDataSize() const; |
69 | 74 |
70 // Copies PDF/PS contents stored in buffer |data_| into |dst_buffer|. | 75 // Copies PDF/PS contents stored in buffer |data_| into |dst_buffer|. |
71 // This function should ONLY be called after PDF/PS file is closed. | 76 // This function should ONLY be called after PDF/PS file is closed. |
72 // Returns true only when success. | 77 // Returns true only when success. |
73 bool GetData(void* dst_buffer, uint32 dst_buffer_size) const; | 78 bool GetData(void* dst_buffer, uint32 dst_buffer_size) const; |
74 | 79 |
75 // Saves PDF/PS contents stored in buffer |data_| into the file | 80 // Saves PDF/PS contents stored in buffer |data_| into the file |
76 // associated with |fd|. | 81 // associated with |fd|. |
77 // This function should ONLY be called after PDF/PS file is closed. | 82 // This function should ONLY be called after PDF/PS file is closed. |
78 bool SaveTo(const base::FileDescriptor& fd) const; | 83 bool SaveTo(const base::FileDescriptor& fd) const; |
79 | 84 |
80 // The hardcoded margins, in points. These values are based on 72 dpi, | 85 // The hardcoded margins, in points. These values are based on 72 dpi, |
81 // with 0.25 margins on top, left, and right, and 0.56 on bottom. | 86 // with 0.25 margins on top, left, and right, and 0.56 on bottom. |
82 static const double kTopMargin; | 87 static const double kTopMarginInInch; |
83 static const double kRightMargin; | 88 static const double kRightMarginInInch; |
84 static const double kBottomMargin; | 89 static const double kBottomMarginInInch; |
85 static const double kLeftMargin; | 90 static const double kLeftMarginInInch; |
86 | 91 |
87 private: | 92 private: |
88 // Cleans up all resources. | 93 // Cleans up all resources. |
89 void CleanUpAll(); | 94 void CleanUpAll(); |
90 | 95 |
91 FileFormat format_; | 96 FileFormat format_; |
92 | 97 |
93 // Cairo surface and context for entire PDF/PS file. | 98 // Cairo surface and context for entire PDF/PS file. |
94 cairo_surface_t* surface_; | 99 cairo_surface_t* surface_; |
95 cairo_t* context_; | 100 cairo_t* context_; |
96 | 101 |
97 // Buffer stores PDF/PS contents for entire PDF/PS file. | 102 // Buffer stores PDF/PS contents for entire PDF/PS file. |
98 std::string data_; | 103 std::string data_; |
99 | 104 |
100 DISALLOW_COPY_AND_ASSIGN(PdfPsMetafile); | 105 DISALLOW_COPY_AND_ASSIGN(PdfPsMetafile); |
101 }; | 106 }; |
102 | 107 |
103 } // namespace printing | 108 } // namespace printing |
104 | 109 |
105 #endif // PRINTING_PDF_PS_METAFILE_CAIRO_H_ | 110 #endif // PRINTING_PDF_PS_METAFILE_CAIRO_H_ |
OLD | NEW |