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

Side by Side Diff: printing/pdf_metafile_mac.h

Issue 6544028: Create a Factory for NativeMetafile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed styling issues (naming, 80cols) 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/mac/scoped_cftyperef.h" 12 #include "base/mac/scoped_cftyperef.h"
13 #include "printing/metafile_factory.h"
14 #include "printing/native_metafile_mac.h"
13 15
14 namespace gfx { 16 namespace gfx {
15 class Rect; 17 class Rect;
16 class Size; 18 class Size;
17 class Point; 19 class Point;
18 } 20 }
19 class FilePath; 21 class FilePath;
20 22
21 namespace printing { 23 namespace printing {
22 24
23 // This class creates a graphics context that renders into a PDF data stream. 25 // This class creates a graphics context that renders into a PDF data stream.
24 class PdfMetafile { 26 class PdfMetafile: public NativeMetafile {
27
28 friend class MetafileFactory;
Avi (use Gerrit) 2011/02/22 19:00:07 friends are private.
dpapad 2011/02/22 19:29:10 Done.
29
25 public: 30 public:
26 // To create PDF data, callers should also call Init() to set up the
27 // rendering context.
28 // To create a metafile from existing Data, callers should also call
29 // Init(const void*, uint32).
30 PdfMetafile();
31 31
32 ~PdfMetafile(); 32 virtual ~PdfMetafile();
33 33
34 // Initializes a new metafile, and returns a drawing context for rendering 34 // Initializes a new metafile, and returns a drawing context for rendering
35 // into the PDF. Returns NULL on failure. 35 // into the PDF. Returns NULL on failure.
36 // Note: The returned context *must not be retained* past Close(). If it is, 36 // Note: The returned context *must not be retained* past Close(). If it is,
37 // the data returned from GetData will not be valid PDF data. 37 // the data returned from GetData will not be valid PDF data.
38 CGContextRef Init(); 38 virtual CGContextRef Init();
39 39
40 // Initializes a copy of metafile from PDF data. Returns true on success. 40 // Initializes a copy of metafile from PDF data. Returns true on success.
41 bool Init(const void* src_buffer, uint32 src_buffer_size); 41 virtual bool Init(const void* src_buffer, uint32 src_buffer_size);
42 42
43 // Prepares a new pdf page at specified |content_origin| with the given 43 // Prepares a new pdf page at specified |content_origin| with the given
44 // |page_size| and a |scale_factor| to use for the drawing. 44 // |page_size| and a |scale_factor| to use for the drawing.
45 CGContextRef StartPage(const gfx::Size& page_size, 45 virtual CGContextRef StartPage(const gfx::Size& page_size,
46 const gfx::Point& content_origin, 46 const gfx::Point& content_origin,
47 const float& scale_factor); 47 const float& scale_factor);
48 48
49 // Closes the current page. 49 // Closes the current page.
50 void FinishPage(); 50 virtual void FinishPage();
51 51
52 // Closes the PDF file; no further rendering is allowed. 52 // Closes the PDF file; no further rendering is allowed.
53 void Close(); 53 virtual void Close();
54 54
55 // Renders the given page into |rect| in the given context. 55 // Renders the given page into |rect| in the given context.
56 // Pages use a 1-based index. The rendering uses the following arguments 56 // Pages use a 1-based index. The rendering uses the following arguments
57 // to determine scaling and translation factors. 57 // to determine scaling and translation factors.
58 // |shrink_to_fit| specifies whether the output should be shrunk to fit the 58 // |shrink_to_fit| specifies whether the output should be shrunk to fit the
59 // supplied |rect| if the page size is larger than |rect| in any dimension. 59 // supplied |rect| if the page size is larger than |rect| in any dimension.
60 // If this is false, parts of the PDF page that lie outside the bounds will be 60 // If this is false, parts of the PDF page that lie outside the bounds will be
61 // clipped. 61 // clipped.
62 // |stretch_to_fit| specifies whether the output should be stretched to fit 62 // |stretch_to_fit| specifies whether the output should be stretched to fit
63 // the supplied bounds if the page size is smaller than |rect| in all 63 // the supplied bounds if the page size is smaller than |rect| in all
64 // dimensions. 64 // dimensions.
65 // |center_horizontally| specifies whether the final image (after any scaling 65 // |center_horizontally| specifies whether the final image (after any scaling
66 // is done) should be centered horizontally within the given |rect|. 66 // is done) should be centered horizontally within the given |rect|.
67 // |center_vertically| specifies whether the final image (after any scaling 67 // |center_vertically| specifies whether the final image (after any scaling
68 // is done) should be centered vertically within the given |rect|. 68 // is done) should be centered vertically within the given |rect|.
69 // Note that all scaling preserves the original aspect ratio of the page. 69 // Note that all scaling preserves the original aspect ratio of the page.
70 bool RenderPage(unsigned int page_number, CGContextRef context, 70 virtual bool RenderPage(unsigned int page_number, CGContextRef context,
71 const CGRect rect, bool shrink_to_fit, bool stretch_to_fit, 71 const CGRect rect, bool shrink_to_fit, bool stretch_to_fit,
72 bool center_horizontally, bool center_vertically) const; 72 bool center_horizontally, bool center_vertically) const;
73 unsigned int GetPageCount() const; 73 virtual unsigned int GetPageCount() const;
74 74
75 // Returns the bounds of the given page. 75 // Returns the bounds of the given page.
76 // Pages use a 1-based index. 76 // Pages use a 1-based index.
77 gfx::Rect GetPageBounds(unsigned int page_number) const; 77 virtual gfx::Rect GetPageBounds(unsigned int page_number) const;
78 78
79 // Returns the size of the underlying PDF data. Only valid after Close() has 79 // Returns the size of the underlying PDF data. Only valid after Close() has
80 // been called. 80 // been called.
81 uint32 GetDataSize() const; 81 virtual uint32 GetDataSize() const;
82 82
83 // Copies the first |dst_buffer_size| bytes of the PDF data into |dst_buffer|. 83 // Copies the first |dst_buffer_size| bytes of the PDF data into |dst_buffer|.
84 // Only valid after Close() has been called. 84 // Only valid after Close() has been called.
85 // Returns true if the copy succeeds. 85 // Returns true if the copy succeeds.
86 bool GetData(void* dst_buffer, uint32 dst_buffer_size) const; 86 virtual bool GetData(void* dst_buffer, uint32 dst_buffer_size) const;
87 87
88 // Saves the raw PDF data to the given file. For testing only. 88 // Saves the raw PDF data to the given file. For testing only.
89 // Returns true if writing succeeded. 89 // Returns true if writing succeeded.
90 bool SaveTo(const FilePath& file_path) const; 90 virtual bool SaveTo(const FilePath& file_path) const;
91
92 protected:
93 // To create PDF data, callers should also call Init() to set up the
94 // rendering context.
95 // To create a metafile from existing Data, callers should also call
96 // Init(const void*, uint32).
97 PdfMetafile();
91 98
92 private: 99 private:
93 // Returns a CGPDFDocumentRef version of pdf_data_. 100 // Returns a CGPDFDocumentRef version of pdf_data_.
94 CGPDFDocumentRef GetPDFDocument() const; 101 virtual CGPDFDocumentRef GetPDFDocument() const;
95 102
96 // Context for rendering to the pdf. 103 // Context for rendering to the pdf.
97 base::mac::ScopedCFTypeRef<CGContextRef> context_; 104 base::mac::ScopedCFTypeRef<CGContextRef> context_;
98 105
99 // PDF backing store. 106 // PDF backing store.
100 base::mac::ScopedCFTypeRef<CFMutableDataRef> pdf_data_; 107 base::mac::ScopedCFTypeRef<CFMutableDataRef> pdf_data_;
101 108
102 // Lazily-created CGPDFDocument representation of pdf_data_. 109 // Lazily-created CGPDFDocument representation of pdf_data_.
103 mutable base::mac::ScopedCFTypeRef<CGPDFDocumentRef> pdf_doc_; 110 mutable base::mac::ScopedCFTypeRef<CGPDFDocumentRef> pdf_doc_;
104 111
105 // Whether or not a page is currently open. 112 // Whether or not a page is currently open.
106 bool page_is_open_; 113 bool page_is_open_;
107 114
108 DISALLOW_COPY_AND_ASSIGN(PdfMetafile); 115 DISALLOW_COPY_AND_ASSIGN(PdfMetafile);
109 }; 116 };
110 117
111 } // namespace printing 118 } // namespace printing
112 119
113 #endif // PRINTING_PDF_METAFILE_MAC_H_ 120 #endif // PRINTING_PDF_METAFILE_MAC_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698