OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef NATIVE_METAFILE_MAC_H_ | |
vandebo (ex-Chrome)
2011/02/22 22:18:16
PRINTING_...
| |
6 #define NATIVE_METAFILE_MAC_H_ | |
7 | |
8 #include <ApplicationServices/ApplicationServices.h> | |
9 #include <CoreFoundation/CoreFoundation.h> | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "base/mac/scoped_cftyperef.h" | |
13 | |
14 namespace gfx { | |
15 class Rect; | |
16 class Size; | |
17 class Point; | |
18 } | |
19 class FilePath; | |
20 | |
21 namespace printing { | |
22 | |
23 // This class creates a graphics context that renders into a PDF data stream. | |
24 class NativeMetafile { | |
25 public: | |
26 | |
27 virtual ~NativeMetafile() {}; | |
28 | |
29 // Initializes a new metafile, and returns a drawing context for rendering | |
30 // into the PDF. Returns NULL on failure. | |
31 // Note: The returned context *must not be retained* past Close(). If it is, | |
32 // the data returned from GetData will not be valid PDF data. | |
33 virtual CGContextRef Init() = 0; | |
34 | |
35 // Initializes a copy of metafile from PDF data. Returns true on success. | |
36 virtual bool Init(const void* src_buffer, uint32 src_buffer_size) = 0; | |
37 | |
38 // Prepares a new pdf page at specified |content_origin| with the given | |
39 // |page_size| and a |scale_factor| to use for the drawing. | |
40 virtual CGContextRef StartPage(const gfx::Size& page_size, | |
41 const gfx::Point& content_origin, | |
42 const float& scale_factor) = 0; | |
43 | |
44 // Closes the current page. | |
45 virtual void FinishPage() = 0; | |
46 | |
47 // Closes the PDF file; no further rendering is allowed. | |
48 virtual void Close() = 0; | |
49 | |
50 // Renders the given page into |rect| in the given context. | |
51 // Pages use a 1-based index. The rendering uses the following arguments | |
52 // to determine scaling and translation factors. | |
53 // |shrink_to_fit| specifies whether the output should be shrunk to fit the | |
54 // supplied |rect| if the page size is larger than |rect| in any dimension. | |
55 // If this is false, parts of the PDF page that lie outside the bounds will be | |
56 // clipped. | |
57 // |stretch_to_fit| specifies whether the output should be stretched to fit | |
58 // the supplied bounds if the page size is smaller than |rect| in all | |
59 // dimensions. | |
60 // |center_horizontally| specifies whether the final image (after any scaling | |
61 // is done) should be centered horizontally within the given |rect|. | |
62 // |center_vertically| specifies whether the final image (after any scaling | |
63 // is done) should be centered vertically within the given |rect|. | |
64 // Note that all scaling preserves the original aspect ratio of the page. | |
65 virtual bool RenderPage(unsigned int page_number, CGContextRef context, | |
66 const CGRect rect, bool shrink_to_fit, bool stretch_to_fit, | |
67 bool center_horizontally, bool center_vertically) const = 0; | |
68 virtual unsigned int GetPageCount() const = 0; | |
69 | |
70 // Returns the bounds of the given page. | |
71 // Pages use a 1-based index. | |
72 virtual gfx::Rect GetPageBounds(unsigned int page_number) const = 0; | |
73 | |
74 // Returns the size of the underlying PDF data. Only valid after Close() has | |
75 // been called. | |
76 virtual uint32 GetDataSize() const = 0; | |
77 | |
78 // Copies the first |dst_buffer_size| bytes of the PDF data into |dst_buffer|. | |
79 // Only valid after Close() has been called. | |
80 // Returns true if the copy succeeds. | |
81 virtual bool GetData(void* dst_buffer, uint32 dst_buffer_size) const = 0; | |
82 | |
83 // Saves the raw PDF data to the given file. For testing only. | |
84 // Returns true if writing succeeded. | |
85 virtual bool SaveTo(const FilePath& file_path) const = 0; | |
86 }; | |
87 | |
88 } // namespace printing | |
89 | |
90 #endif /* NATIVE_METAFILE_MAC_H_ */ | |
OLD | NEW |