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_METAFILE_MAC_H_ | 5 #ifndef PRINTING_PDF_METAFILE_MAC_H_ |
6 #define PRINTING_PDF_METAFILE_MAC_H_ | 6 #define PRINTING_PDF_METAFILE_MAC_H_ |
7 | 7 |
8 #include <ApplicationServices/ApplicationServices.h> | 8 #include <ApplicationServices/ApplicationServices.h> |
9 #include <CoreFoundation/CoreFoundation.h> | 9 #include <CoreFoundation/CoreFoundation.h> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
13 #include "base/mac/scoped_cftyperef.h" | 13 #include "base/mac/scoped_cftyperef.h" |
14 #include "printing/native_metafile_mac.h" | 14 #include "printing/native_metafile.h" |
15 | 15 |
16 namespace gfx { | 16 namespace gfx { |
17 class Rect; | 17 class Rect; |
18 class Size; | 18 class Size; |
19 class Point; | 19 class Point; |
20 } | 20 } |
21 | |
21 class FilePath; | 22 class FilePath; |
22 | 23 |
23 namespace printing { | 24 namespace printing { |
24 | 25 |
25 // This class creates a graphics context that renders into a PDF data stream. | 26 // This class creates a graphics context that renders into a PDF data stream. |
26 class PdfMetafile : public NativeMetafile { | 27 class PdfMetafile : public NativeMetafile { |
27 public: | 28 public: |
28 | 29 |
29 virtual ~PdfMetafile(); | 30 virtual ~PdfMetafile(); |
30 | 31 |
31 // Initializes a new metafile, and returns a drawing context for rendering | 32 //NativeMetafile methods. |
32 // into the PDF. Returns NULL on failure. | 33 virtual bool Init(); |
34 virtual bool Init(const void* src_buffer, uint32 src_buffer_size); | |
35 | |
36 virtual CGContextRef StartPage(const gfx::Size& page_size, | |
37 const gfx::Point& content_origin, | |
38 const float& scale_factor); | |
39 virtual bool FinishPage(); | |
40 virtual bool Close(); | |
41 | |
42 // For testing purposes only. | |
vandebo (ex-Chrome)
2011/03/14 20:24:25
Belongs to SaveTo()?
dpapad
2011/03/14 22:15:12
Done.
| |
43 virtual uint32 GetDataSize() const; | |
44 virtual bool GetData(void* dst_buffer, uint32 dst_buffer_size) const; | |
45 | |
46 virtual bool SaveTo(const | |
47 & file_path) const; | |
dpapad
2011/03/14 19:00:35
Accidental break line. I will fix that (along with
dpapad
2011/03/14 22:15:12
Done.
| |
48 | |
49 virtual gfx::Rect GetPageBounds(unsigned int page_number) const; | |
50 virtual unsigned int GetPageCount() const; | |
51 | |
52 virtual CGContextRef context() const { | |
53 return context_.get(); | |
54 } | |
55 | |
56 virtual bool RenderPage(unsigned int page_number, | |
57 CGContextRef context, | |
58 const CGRect rect, | |
59 bool shrink_to_fit, | |
60 bool stretch_to_fit, | |
61 bool center_horizontally, | |
62 bool center_vertically) const; | |
63 | |
33 // Note: The returned context *must not be retained* past Close(). If it is, | 64 // Note: The returned context *must not be retained* past Close(). If it is, |
34 // the data returned from GetData will not be valid PDF data. | 65 // the data returned from GetData will not be valid PDF data. |
35 virtual CGContextRef Init(); | 66 protected: |
36 | |
37 // Initializes a copy of metafile from PDF data. Returns true on success. | |
38 virtual bool Init(const void* src_buffer, uint32 src_buffer_size); | |
39 | |
40 // Prepares a new pdf page at specified |content_origin| with the given | |
41 // |page_size| and a |scale_factor| to use for the drawing. | |
42 virtual CGContextRef StartPage(const gfx::Size& page_size, | |
43 const gfx::Point& content_origin, | |
44 const float& scale_factor); | |
45 | |
46 // Closes the current page. | |
47 virtual void FinishPage(); | |
48 | |
49 // Closes the PDF file; no further rendering is allowed. | |
50 virtual void Close(); | |
51 | |
52 // Renders the given page into |rect| in the given context. | |
53 // Pages use a 1-based index. The rendering uses the following arguments | |
54 // to determine scaling and translation factors. | |
55 // |shrink_to_fit| specifies whether the output should be shrunk to fit the | |
56 // supplied |rect| if the page size is larger than |rect| in any dimension. | |
57 // If this is false, parts of the PDF page that lie outside the bounds will be | |
58 // clipped. | |
59 // |stretch_to_fit| specifies whether the output should be stretched to fit | |
60 // the supplied bounds if the page size is smaller than |rect| in all | |
61 // dimensions. | |
62 // |center_horizontally| specifies whether the final image (after any scaling | |
63 // is done) should be centered horizontally within the given |rect|. | |
64 // |center_vertically| specifies whether the final image (after any scaling | |
65 // is done) should be centered vertically within the given |rect|. | |
66 // Note that all scaling preserves the original aspect ratio of the page. | |
67 virtual bool RenderPage(unsigned int page_number, CGContextRef context, | |
68 const CGRect rect, bool shrink_to_fit, bool stretch_to_fit, | |
69 bool center_horizontally, bool center_vertically) const; | |
70 virtual unsigned int GetPageCount() const; | |
71 | |
72 // Returns the bounds of the given page. | |
73 // Pages use a 1-based index. | |
74 virtual gfx::Rect GetPageBounds(unsigned int page_number) const; | |
75 | |
76 // Returns the size of the underlying PDF data. Only valid after Close() has | |
77 // been called. | |
78 virtual uint32 GetDataSize() const; | |
79 | |
80 // Copies the first |dst_buffer_size| bytes of the PDF data into |dst_buffer|. | |
81 // Only valid after Close() has been called. | |
82 // Returns true if the copy succeeds. | |
83 virtual bool GetData(void* dst_buffer, uint32 dst_buffer_size) const; | |
84 | |
85 // Saves the raw PDF data to the given file. For testing only. | |
86 // Returns true if writing succeeded. | |
87 virtual bool SaveTo(const FilePath& file_path) const; | |
88 | |
89 protected: | |
90 // To create PDF data, callers should call Init() to set up the rendering | 67 // To create PDF data, callers should call Init() to set up the rendering |
91 // context. | 68 // context. |
92 // To create a metafile from existing data, callers should call | 69 // To create a metafile from existing data, callers should call |
93 // Init(const void*, uint32). | 70 // Init(const void*, uint32). |
94 PdfMetafile(); | 71 PdfMetafile(); |
95 | 72 |
96 private: | 73 private: |
97 friend class NativeMetafileFactory; | 74 friend class NativeMetafileFactory; |
98 FRIEND_TEST_ALL_PREFIXES(PdfMetafileTest, Pdf); | 75 FRIEND_TEST_ALL_PREFIXES(PdfMetafileTest, Pdf); |
99 | 76 |
(...skipping 11 matching lines...) Expand all Loading... | |
111 | 88 |
112 // Whether or not a page is currently open. | 89 // Whether or not a page is currently open. |
113 bool page_is_open_; | 90 bool page_is_open_; |
114 | 91 |
115 DISALLOW_COPY_AND_ASSIGN(PdfMetafile); | 92 DISALLOW_COPY_AND_ASSIGN(PdfMetafile); |
116 }; | 93 }; |
117 | 94 |
118 } // namespace printing | 95 } // namespace printing |
119 | 96 |
120 #endif // PRINTING_PDF_METAFILE_MAC_H_ | 97 #endif // PRINTING_PDF_METAFILE_MAC_H_ |
OLD | NEW |