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

Side by Side Diff: printing/pdf_ps_metafile_cairo.h

Issue 6576058: Removing PS option from PdfPsMetafile (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated more comments Created 9 years, 10 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
« no previous file with comments | « chrome/renderer/print_web_view_helper_linux.cc ('k') | printing/pdf_ps_metafile_cairo.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 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 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 stream data.
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
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 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
71 // Destroys the surface and the context used in rendering current page. 57 // Destroys the surface and the context used in rendering current page.
72 // The results of current page will be appended into buffer |data_|. 58 // The results of current page will be appended into buffer |data_|.
73 // Returns true on success. 59 // Returns true on success.
74 bool FinishPage(); 60 bool FinishPage();
75 61
76 // Closes resulting PDF/PS file. No further rendering is allowed. 62 // Closes resulting PDF file. No further rendering is allowed.
77 void Close(); 63 void Close();
78 64
79 // Returns size of PDF/PS contents stored in buffer |data_|. 65 // Returns size of PDF contents stored in buffer |data_|.
80 // This function should ONLY be called after PDF/PS file is closed. 66 // This function should ONLY be called after PDF file is closed.
81 uint32 GetDataSize() const; 67 uint32 GetDataSize() const;
82 68
83 // Copies PDF/PS contents stored in buffer |data_| into |dst_buffer|. 69 // Copies PDF contents stored in buffer |data_| into |dst_buffer|.
84 // This function should ONLY be called after PDF/PS file is closed. 70 // This function should ONLY be called after PDF file is closed.
85 // Returns true only when success. 71 // Returns true only when success.
86 bool GetData(void* dst_buffer, uint32 dst_buffer_size) const; 72 bool GetData(void* dst_buffer, uint32 dst_buffer_size) const;
87 73
88 // Saves PDF/PS contents stored in buffer |data_| into the file 74 // Saves PDF contents stored in buffer |data_| into the file
89 // associated with |fd|. 75 // associated with |fd|.
90 // This function should ONLY be called after PDF/PS file is closed. 76 // This function should ONLY be called after PDF file is closed.
91 bool SaveTo(const base::FileDescriptor& fd) const; 77 bool SaveTo(const base::FileDescriptor& fd) const;
92 78
93 // The hardcoded margins, in points. These values are based on 72 dpi, 79 // The hardcoded margins, in points. These values are based on 72 dpi,
94 // with 0.25 margins on top, left, and right, and 0.56 on bottom. 80 // with 0.25 margins on top, left, and right, and 0.56 on bottom.
95 static const double kTopMarginInInch; 81 static const double kTopMarginInInch;
96 static const double kRightMarginInInch; 82 static const double kRightMarginInInch;
97 static const double kBottomMarginInInch; 83 static const double kBottomMarginInInch;
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 PdfPsMetafile 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_; 94 // Cairo surface and context for entire PDF file.
109
110 // 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 contents for entire PDF file.
115 std::string data_; 99 std::string data_;
116 // Buffer stores raw PDF/PS contents set by SetRawPageData. 100 // Buffer stores raw PDF 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_
OLDNEW
« no previous file with comments | « chrome/renderer/print_web_view_helper_linux.cc ('k') | printing/pdf_ps_metafile_cairo.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698