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

Side by Side Diff: printing/pdf_ps_metafile_cairo.h

Issue 6544028: Create a Factory for NativeMetafile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Minor style fixes 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 | « printing/pdf_metafile_mac.h ('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 #include "printing/native_metafile_factory.h"
12 #include "printing/native_metafile_linux.h"
11 13
12 typedef struct _cairo_surface cairo_surface_t; 14 typedef struct _cairo_surface cairo_surface_t;
13 typedef struct _cairo cairo_t; 15 typedef struct _cairo cairo_t;
14 16
15 namespace base { 17 namespace base {
16 struct FileDescriptor; 18 struct FileDescriptor;
17 } 19 }
18 20
19 class FilePath; 21 class FilePath;
20 22
21 namespace printing { 23 namespace printing {
22 24
23 // This class uses Cairo graphics library to generate PostScript/PDF stream 25 // This class uses Cairo graphics library to generate PostScript/PDF stream
24 // and stores rendering results in a string buffer. 26 // and stores rendering results in a string buffer.
25 class PdfPsMetafile { 27 class PdfPsMetafile : public NativeMetafile {
26 public: 28 public:
dpapad 2011/02/24 20:57:00 Deleted this part because only PDF is supported.
27 enum FileFormat { 29 virtual ~PdfPsMetafile();
28 PDF,
29 PS,
30 };
31
32 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();
41 30
42 // Initializes to a fresh new metafile. Returns true on success. 31 // Initializes to a fresh new metafile. Returns true on success.
43 // Note: Only call in the renderer to allocate rendering resources. 32 // Note: Only call in the renderer to allocate rendering resources.
44 bool Init(); 33 virtual bool Init();
45 34
46 // Initializes a copy of metafile from PDF/PS stream data. 35 // Initializes a copy of metafile from PDF/PS stream data.
47 // Returns true on success. 36 // Returns true on success.
48 // |src_buffer| should point to the shared memory which stores PDF/PS 37 // |src_buffer| should point to the shared memory which stores PDF/PS
49 // contents generated in the renderer. 38 // contents generated in the renderer.
50 // Note: Only call in the browser to initialize |data_|. 39 // Note: Only call in the browser to initialize |data_|.
51 bool Init(const void* src_buffer, uint32 src_buffer_size); 40 virtual bool Init(const void* src_buffer, uint32 src_buffer_size);
52 41
53 // Sets raw PS/PDF data for the document. This is used when a cairo drawing 42 // 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 43 // 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 44 // 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. 45 // been called this method simply calls the second version of Init.
57 bool SetRawData(const void* src_buffer, uint32 src_buffer_size); 46 virtual bool SetRawData(const void* src_buffer, uint32 src_buffer_size);
58 47
59 FileFormat GetFileFormat() const { return format_; } 48 virtual FileFormat GetFileFormat() const { return format_; }
60 49
61 // Prepares a new cairo surface/context for rendering a new page. 50 // Prepares a new cairo surface/context for rendering a new page.
62 // The unit is in point (=1/72 in). 51 // The unit is in point (=1/72 in).
63 // Returns NULL when failed. 52 // Returns NULL when failed.
64 cairo_t* StartPage(double width_in_points, 53 virtual cairo_t* StartPage(double width_in_points,
65 double height_in_points, 54 double height_in_points,
66 double margin_top_in_points, 55 double margin_top_in_points,
67 double margin_right_in_points, 56 double margin_right_in_points,
68 double margin_bottom_in_points, 57 double margin_bottom_in_points,
69 double margin_left_in_points); 58 double margin_left_in_points);
70 59
71 // Destroys the surface and the context used in rendering current page. 60 // Destroys the surface and the context used in rendering current page.
72 // The results of current page will be appended into buffer |data_|. 61 // The results of current page will be appended into buffer |data_|.
73 // Returns true on success. 62 // Returns true on success.
74 bool FinishPage(); 63 virtual bool FinishPage();
75 64
76 // Closes resulting PDF/PS file. No further rendering is allowed. 65 // Closes resulting PDF/PS file. No further rendering is allowed.
77 void Close(); 66 virtual void Close();
78 67
79 // Returns size of PDF/PS contents stored in buffer |data_|. 68 // Returns size of PDF/PS contents stored in buffer |data_|.
80 // This function should ONLY be called after PDF/PS file is closed. 69 // This function should ONLY be called after PDF/PS file is closed.
81 uint32 GetDataSize() const; 70 virtual uint32 GetDataSize() const;
82 71
83 // Copies PDF/PS contents stored in buffer |data_| into |dst_buffer|. 72 // Copies PDF/PS contents stored in buffer |data_| into |dst_buffer|.
84 // This function should ONLY be called after PDF/PS file is closed. 73 // This function should ONLY be called after PDF/PS file is closed.
85 // Returns true only when success. 74 // Returns true only when success.
86 bool GetData(void* dst_buffer, uint32 dst_buffer_size) const; 75 virtual bool GetData(void* dst_buffer, uint32 dst_buffer_size) const;
87 76
88 // Saves PDF/PS contents stored in buffer |data_| into the file 77 // Saves PDF/PS contents stored in buffer |data_| into the file
89 // associated with |fd|. 78 // associated with |fd|.
90 // This function should ONLY be called after PDF/PS file is closed. 79 // This function should ONLY be called after PDF/PS file is closed.
91 bool SaveTo(const base::FileDescriptor& fd) const; 80 virtual bool SaveTo(const base::FileDescriptor& fd) const;
92 81
93 // The hardcoded margins, in points. These values are based on 72 dpi, 82 // 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. 83 // with 0.25 margins on top, left, and right, and 0.56 on bottom.
95 static const double kTopMarginInInch; 84 static const double kTopMarginInInch;
96 static const double kRightMarginInInch; 85 static const double kRightMarginInInch;
97 static const double kBottomMarginInInch; 86 static const double kBottomMarginInInch;
98 static const double kLeftMarginInInch; 87 static const double kLeftMarginInInch;
99 88
100 // Returns the PdfPsMetafile object that owns the given context. Returns NULL 89 // Returns the PdfPsMetafile object that owns the given context. Returns NULL
101 // if the context was not created by a PdfPdMetafile object. 90 // if the context was not created by a PdfPsMetafile object.
102 static PdfPsMetafile* FromCairoContext(cairo_t* context); 91 static PdfPsMetafile* FromCairoContext(cairo_t* context);
103 92
93 protected:
94 PdfPsMetafile();
95
104 private: 96 private:
97 friend class NativeMetafileFactory;
98
105 // Cleans up all resources. 99 // Cleans up all resources.
106 void CleanUpAll(); 100 void CleanUpAll();
107 101
108 FileFormat format_; 102 FileFormat format_;
109 103
110 // Cairo surface and context for entire PDF/PS file. 104 // Cairo surface and context for entire PDF/PS file.
111 cairo_surface_t* surface_; 105 cairo_surface_t* surface_;
112 cairo_t* context_; 106 cairo_t* context_;
113 107
114 // Buffer stores PDF/PS contents for entire PDF/PS file. 108 // Buffer stores PDF/PS contents for entire PDF/PS file.
115 std::string data_; 109 std::string data_;
116 // Buffer stores raw PDF/PS contents set by SetRawPageData. 110 // Buffer stores raw PDF/PS contents set by SetRawPageData.
117 std::string raw_override_data_; 111 std::string raw_override_data_;
118 112
119 DISALLOW_COPY_AND_ASSIGN(PdfPsMetafile); 113 DISALLOW_COPY_AND_ASSIGN(PdfPsMetafile);
120 }; 114 };
121 115
122 } // namespace printing 116 } // namespace printing
123 117
124 #endif // PRINTING_PDF_PS_METAFILE_CAIRO_H_ 118 #endif // PRINTING_PDF_PS_METAFILE_CAIRO_H_
OLDNEW
« no previous file with comments | « printing/pdf_metafile_mac.h ('k') | printing/pdf_ps_metafile_cairo.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698