OLD | NEW |
---|---|
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_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 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
12 #include "printing/native_metafile_linux.h" | 12 #include "printing/native_metafile.h" |
13 | 13 |
14 typedef struct _cairo_surface cairo_surface_t; | 14 typedef struct _cairo_surface cairo_surface_t; |
15 typedef struct _cairo cairo_t; | |
16 | |
17 namespace base { | |
18 struct FileDescriptor; | |
19 } | |
20 | |
21 class FilePath; | |
22 | 15 |
23 namespace printing { | 16 namespace printing { |
24 | 17 |
25 // This class uses Cairo graphics library to generate PostScript/PDF stream | 18 // This class uses Cairo graphics library to generate PDF stream and stores |
26 // and stores rendering results in a string buffer. | 19 // rendering results in a string buffer. |
27 class PdfPsMetafile : public NativeMetafile { | 20 class PdfPsMetafile : public NativeMetafile { |
28 public: | 21 public: |
29 virtual ~PdfPsMetafile(); | 22 virtual ~PdfPsMetafile(); |
30 | 23 |
31 // Initializes to a fresh new metafile. Returns true on success. | 24 // NativeMetafile methods. |
32 // Note: Only call in the renderer to allocate rendering resources. | |
33 virtual bool Init(); | 25 virtual bool Init(); |
34 | |
35 // Initializes a copy of metafile from PDF stream data. | |
36 // Returns true on success. | |
37 // |src_buffer| should point to the shared memory which stores PDF | |
38 // contents generated in the renderer. | |
39 // Note: Only call in the browser to initialize |data_|. | |
40 virtual bool Init(const void* src_buffer, uint32 src_buffer_size); | 26 virtual bool Init(const void* src_buffer, uint32 src_buffer_size); |
41 | 27 |
42 // Sets raw PDF data for the document. This is used when a cairo drawing | 28 virtual cairo_t* StartPage(const gfx::Size& page_size, |
43 // surface has already been created. This method will cause all subsequent | |
44 // drawing on the surface to be discarded (in Close()). If Init() has not yet | |
45 // been called this method simply calls the second version of Init. | |
46 virtual bool SetRawData(const void* src_buffer, uint32 src_buffer_size); | |
47 | |
48 // Prepares a new cairo surface/context for rendering a new page. | |
49 // The unit is in point (=1/72 in). | |
50 // Returns NULL when failed. | |
51 virtual cairo_t* StartPage(double width_in_points, | |
52 double height_in_points, | |
53 double margin_top_in_points, | 29 double margin_top_in_points, |
54 double margin_right_in_points, | 30 double margin_right_in_points, |
55 double margin_bottom_in_points, | 31 double margin_bottom_in_points, |
56 double margin_left_in_points); | 32 double margin_left_in_points); |
33 virtual bool FinishPage(); | |
34 virtual bool Close(); | |
57 | 35 |
58 // Destroys the surface and the context used in rendering current page. | |
59 // The results of current page will be appended into buffer |data_|. | |
60 // Returns true on success. | |
61 virtual bool FinishPage(); | |
62 | |
63 // Closes resulting PDF file. No further rendering is allowed. | |
64 virtual void Close(); | |
65 | |
66 // Returns size of PDF contents stored in buffer |data_|. | |
67 // This function should ONLY be called after PDF file is closed. | |
68 virtual uint32 GetDataSize() const; | 36 virtual uint32 GetDataSize() const; |
69 | |
70 // Copies PDF contents stored in buffer |data_| into |dst_buffer|. | |
71 // This function should ONLY be called after PDF file is closed. | |
72 // Returns true only when success. | |
73 virtual bool GetData(void* dst_buffer, uint32 dst_buffer_size) const; | 37 virtual bool GetData(void* dst_buffer, uint32 dst_buffer_size) const; |
74 | 38 |
75 // Saves PDF contents stored in buffer |data_| into the file | 39 virtual bool SaveTo(const FilePath& file_path) const; |
76 // associated with |fd|. | 40 |
77 // This function should ONLY be called after PDF file is closed. | 41 virtual gfx::Rect GetPageBounds(unsigned int page_number) const; |
78 virtual bool SaveTo(const base::FileDescriptor& fd) const; | 42 virtual unsigned int GetPageCount() const { return 1; } |
vandebo (ex-Chrome)
2011/03/14 20:24:25
Move the body of this method into the .cc file and
dpapad
2011/03/14 22:15:12
Done.
| |
43 | |
44 virtual gfx::NativeDrawingContext context() const { | |
vandebo (ex-Chrome)
2011/03/14 20:24:25
You can use cairo_t* here.
dpapad
2011/03/14 22:15:12
Done.
| |
45 return context_; | |
46 } | |
47 | |
48 virtual bool SetRawData(const void* src_buffer, uint32 src_buffer_size); | |
49 | |
50 #if defined(OS_CHROMEOS) | |
51 virtual bool SaveToFD(const base::FileDescriptor& fd) const; | |
52 #endif // if defined(OS_CHROMEOS) | |
79 | 53 |
80 // The hardcoded margins, in points. These values are based on 72 dpi, | 54 // 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. | 55 // with 0.25 margins on top, left, and right, and 0.56 on bottom. |
82 static const double kTopMarginInInch; | 56 static const double kTopMarginInInch; |
83 static const double kRightMarginInInch; | 57 static const double kRightMarginInInch; |
84 static const double kBottomMarginInInch; | 58 static const double kBottomMarginInInch; |
85 static const double kLeftMarginInInch; | 59 static const double kLeftMarginInInch; |
86 | 60 |
87 // Returns the PdfPsMetafile object that owns the given context. Returns NULL | 61 // Returns the PdfPsMetafile object that owns the given context. Returns NULL |
88 // if the context was not created by a PdfPsMetafile object. | 62 // if the context was not created by a PdfPsMetafile object. |
(...skipping 17 matching lines...) Expand all Loading... | |
106 std::string data_; | 80 std::string data_; |
107 // Buffer stores raw PDF contents set by SetRawPageData. | 81 // Buffer stores raw PDF contents set by SetRawPageData. |
108 std::string raw_override_data_; | 82 std::string raw_override_data_; |
109 | 83 |
110 DISALLOW_COPY_AND_ASSIGN(PdfPsMetafile); | 84 DISALLOW_COPY_AND_ASSIGN(PdfPsMetafile); |
111 }; | 85 }; |
112 | 86 |
113 } // namespace printing | 87 } // namespace printing |
114 | 88 |
115 #endif // PRINTING_PDF_PS_METAFILE_CAIRO_H_ | 89 #endif // PRINTING_PDF_PS_METAFILE_CAIRO_H_ |
OLD | NEW |