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

Side by Side Diff: printing/pdf_metafile_mac.h

Issue 6594121: Revert 76553 - Applying factory pattern (through NativeMetafileFactory class)... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 9 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/native_metafile_win.h ('k') | printing/pdf_metafile_mac_unittest.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) 2011 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/gtest_prod_util.h"
13 #include "base/mac/scoped_cftyperef.h" 12 #include "base/mac/scoped_cftyperef.h"
14 #include "printing/native_metafile_mac.h"
15 13
16 namespace gfx { 14 namespace gfx {
17 class Rect; 15 class Rect;
18 class Size; 16 class Size;
19 class Point; 17 class Point;
20 } 18 }
21 class FilePath; 19 class FilePath;
22 20
23 namespace printing { 21 namespace printing {
24 22
25 // This class creates a graphics context that renders into a PDF data stream. 23 // This class creates a graphics context that renders into a PDF data stream.
26 class PdfMetafile : public NativeMetafile { 24 class PdfMetafile {
27 public: 25 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();
28 31
29 virtual ~PdfMetafile(); 32 ~PdfMetafile();
30 33
31 // Initializes a new metafile, and returns a drawing context for rendering 34 // Initializes a new metafile, and returns a drawing context for rendering
32 // into the PDF. Returns NULL on failure. 35 // into the PDF. Returns NULL on failure.
33 // 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,
34 // the data returned from GetData will not be valid PDF data. 37 // the data returned from GetData will not be valid PDF data.
35 virtual CGContextRef Init(); 38 CGContextRef Init();
36 39
37 // 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.
38 virtual bool Init(const void* src_buffer, uint32 src_buffer_size); 41 bool Init(const void* src_buffer, uint32 src_buffer_size);
39 42
40 // 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
41 // |page_size| and a |scale_factor| to use for the drawing. 44 // |page_size| and a |scale_factor| to use for the drawing.
42 virtual CGContextRef StartPage(const gfx::Size& page_size, 45 CGContextRef StartPage(const gfx::Size& page_size,
43 const gfx::Point& content_origin, 46 const gfx::Point& content_origin,
44 const float& scale_factor); 47 const float& scale_factor);
45 48
46 // Closes the current page. 49 // Closes the current page.
47 virtual void FinishPage(); 50 void FinishPage();
48 51
49 // Closes the PDF file; no further rendering is allowed. 52 // Closes the PDF file; no further rendering is allowed.
50 virtual void Close(); 53 void Close();
51 54
52 // Renders the given page into |rect| in the given context. 55 // Renders the given page into |rect| in the given context.
53 // 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
54 // to determine scaling and translation factors. 57 // to determine scaling and translation factors.
55 // |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
56 // 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.
57 // 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
58 // clipped. 61 // clipped.
59 // |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
60 // 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
61 // dimensions. 64 // dimensions.
62 // |center_horizontally| specifies whether the final image (after any scaling 65 // |center_horizontally| specifies whether the final image (after any scaling
63 // is done) should be centered horizontally within the given |rect|. 66 // is done) should be centered horizontally within the given |rect|.
64 // |center_vertically| specifies whether the final image (after any scaling 67 // |center_vertically| specifies whether the final image (after any scaling
65 // is done) should be centered vertically within the given |rect|. 68 // is done) should be centered vertically within the given |rect|.
66 // 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.
67 virtual bool RenderPage(unsigned int page_number, CGContextRef context, 70 bool RenderPage(unsigned int page_number, CGContextRef context,
68 const CGRect rect, bool shrink_to_fit, bool stretch_to_fit, 71 const CGRect rect, bool shrink_to_fit, bool stretch_to_fit,
69 bool center_horizontally, bool center_vertically) const; 72 bool center_horizontally, bool center_vertically) const;
70 virtual unsigned int GetPageCount() const; 73 unsigned int GetPageCount() const;
71 74
72 // Returns the bounds of the given page. 75 // Returns the bounds of the given page.
73 // Pages use a 1-based index. 76 // Pages use a 1-based index.
74 virtual gfx::Rect GetPageBounds(unsigned int page_number) const; 77 gfx::Rect GetPageBounds(unsigned int page_number) const;
75 78
76 // 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
77 // been called. 80 // been called.
78 virtual uint32 GetDataSize() const; 81 uint32 GetDataSize() const;
79 82
80 // 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|.
81 // Only valid after Close() has been called. 84 // Only valid after Close() has been called.
82 // Returns true if the copy succeeds. 85 // Returns true if the copy succeeds.
83 virtual bool GetData(void* dst_buffer, uint32 dst_buffer_size) const; 86 bool GetData(void* dst_buffer, uint32 dst_buffer_size) const;
84 87
85 // 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.
86 // Returns true if writing succeeded. 89 // Returns true if writing succeeded.
87 virtual bool SaveTo(const FilePath& file_path) const; 90 bool SaveTo(const FilePath& file_path) const;
88
89 protected:
90 // To create PDF data, callers should call Init() to set up the rendering
91 // context.
92 // To create a metafile from existing data, callers should call
93 // Init(const void*, uint32).
94 PdfMetafile();
95 91
96 private: 92 private:
97 friend class NativeMetafileFactory;
98 FRIEND_TEST_ALL_PREFIXES(PdfMetafileTest, Pdf);
99
100 // Returns a CGPDFDocumentRef version of pdf_data_. 93 // Returns a CGPDFDocumentRef version of pdf_data_.
101 CGPDFDocumentRef GetPDFDocument() const; 94 CGPDFDocumentRef GetPDFDocument() const;
102 95
103 // Context for rendering to the pdf. 96 // Context for rendering to the pdf.
104 base::mac::ScopedCFTypeRef<CGContextRef> context_; 97 base::mac::ScopedCFTypeRef<CGContextRef> context_;
105 98
106 // PDF backing store. 99 // PDF backing store.
107 base::mac::ScopedCFTypeRef<CFMutableDataRef> pdf_data_; 100 base::mac::ScopedCFTypeRef<CFMutableDataRef> pdf_data_;
108 101
109 // Lazily-created CGPDFDocument representation of pdf_data_. 102 // Lazily-created CGPDFDocument representation of pdf_data_.
110 mutable base::mac::ScopedCFTypeRef<CGPDFDocumentRef> pdf_doc_; 103 mutable base::mac::ScopedCFTypeRef<CGPDFDocumentRef> pdf_doc_;
111 104
112 // Whether or not a page is currently open. 105 // Whether or not a page is currently open.
113 bool page_is_open_; 106 bool page_is_open_;
114 107
115 DISALLOW_COPY_AND_ASSIGN(PdfMetafile); 108 DISALLOW_COPY_AND_ASSIGN(PdfMetafile);
116 }; 109 };
117 110
118 } // namespace printing 111 } // namespace printing
119 112
120 #endif // PRINTING_PDF_METAFILE_MAC_H_ 113 #endif // PRINTING_PDF_METAFILE_MAC_H_
OLDNEW
« no previous file with comments | « printing/native_metafile_win.h ('k') | printing/pdf_metafile_mac_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698