OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkDocument_DEFINED | 8 #ifndef SkDocument_DEFINED |
9 #define SkDocument_DEFINED | 9 #define SkDocument_DEFINED |
10 | 10 |
11 #include "SkPDFCallbacks.h" | |
bungeman-skia
2013/09/26 19:52:39
core should not depend on PDF.
edisonn
2013/10/04 19:40:37
Done.
| |
11 #include "SkRect.h" | 12 #include "SkRect.h" |
12 #include "SkRefCnt.h" | 13 #include "SkRefCnt.h" |
14 #include "SkBitmap.h" | |
15 #include "SkRect.h" | |
13 | 16 |
14 class SkCanvas; | 17 class SkCanvas; |
15 class SkWStream; | 18 class SkWStream; |
16 | 19 |
17 /** | 20 /** |
18 * High-level API for creating a document-based canvas. To use.. | 21 * High-level API for creating a document-based canvas. To use.. |
19 * | 22 * |
20 * 1. Create a document, specifying a stream to store the output. | 23 * 1. Create a document, specifying a stream to store the output. |
21 * 2. For each "page" of content: | 24 * 2. For each "page" of content: |
22 * a. canvas = doc->beginPage(...) | 25 * a. canvas = doc->beginPage(...) |
23 * b. draw_my_content(canvas); | 26 * b. draw_my_content(canvas); |
24 * c. doc->endPage(); | 27 * c. doc->endPage(); |
25 * 3. Close the document with doc->close(). | 28 * 3. Close the document with doc->close(). |
26 */ | 29 */ |
27 class SkDocument : public SkRefCnt { | 30 class SkDocument : public SkRefCnt { |
28 public: | 31 public: |
29 SK_DECLARE_INST_COUNT(SkDocument) | 32 SK_DECLARE_INST_COUNT(SkDocument) |
30 | 33 |
31 /** | 34 /** |
32 * Create a PDF-backed document, writing the results into a file. | 35 * Create a PDF-backed document, writing the results into a file. |
33 * If there is an error trying to create the doc, returns NULL. | 36 * If there is an error trying to create the doc, returns NULL. |
37 * encoder sets the DCTEncoder for images, to encode a bitmap | |
38 * as JPEG (DCT). | |
34 */ | 39 */ |
35 static SkDocument* CreatePDF(const char filename[]); | 40 static SkDocument* CreatePDF(const char filename[], |
41 EncodeToDCTStream encoder = NULL); | |
36 | 42 |
37 /** | 43 /** |
38 * Create a PDF-backed document, writing the results into a stream. | 44 * Create a PDF-backed document, writing the results into a stream. |
39 * If there is an error trying to create the doc, returns NULL. | 45 * If there is an error trying to create the doc, returns NULL. |
40 * | 46 * |
41 * The document may write to the stream at anytime during its lifetime, | 47 * The document may write to the stream at anytime during its lifetime, |
42 * until either close() is called or the document is deleted. Once close() | 48 * until either close() is called or the document is deleted. Once close() |
43 * has been called, and all of the data has been written to the stream, | 49 * has been called, and all of the data has been written to the stream, |
44 * if there is a Done proc provided, it will be called with the stream. | 50 * if there is a Done proc provided, it will be called with the stream. |
45 * The proc can delete the stream, or whatever it needs to do. | 51 * The proc can delete the stream, or whatever it needs to do. |
52 * encoder sets the DCTEncoder for images, to encode a bitmap | |
53 * as JPEG (DCT). | |
46 */ | 54 */ |
47 static SkDocument* CreatePDF(SkWStream*, void (*Done)(SkWStream*) = NULL); | 55 static SkDocument* CreatePDF(SkWStream*, void (*Done)(SkWStream*) = NULL, |
56 EncodeToDCTStream encoder = NULL); | |
48 | 57 |
49 /** | 58 /** |
50 * Begin a new page for the document, returning the canvas that will draw | 59 * Begin a new page for the document, returning the canvas that will draw |
51 * into the page. The document owns this canvas, and it will go out of | 60 * into the page. The document owns this canvas, and it will go out of |
52 * scope when endPage() or close() is called, or the document is deleted. | 61 * scope when endPage() or close() is called, or the document is deleted. |
62 * If mediaBox is null, then we set the mediabox to the trim rectangle. | |
vandebo (ex-Chrome)
2013/09/27 15:50:17
Please document the args better. What affect does
edisonn
2013/10/04 19:40:37
Done.
| |
53 */ | 63 */ |
54 SkCanvas* beginPage(SkScalar width, SkScalar height, | 64 SkCanvas* beginPage(const SkSize& trimSize, |
55 const SkRect* content = NULL); | 65 const SkRect* mediaBox = NULL); |
56 | 66 |
57 /** | 67 /** |
58 * Call endPage() when the content for the current page has been drawn | 68 * Call endPage() when the content for the current page has been drawn |
59 * (into the canvas returned by beginPage()). After this call the canvas | 69 * (into the canvas returned by beginPage()). After this call the canvas |
60 * returned by beginPage() will be out-of-scope. | 70 * returned by beginPage() will be out-of-scope. |
61 */ | 71 */ |
62 void endPage(); | 72 void endPage(); |
63 | 73 |
64 /** | 74 /** |
65 * Call close() when all pages have been drawn. This will close the file | 75 * Call close() when all pages have been drawn. This will close the file |
66 * or stream holding the document's contents. After close() the document | 76 * or stream holding the document's contents. After close() the document |
67 * can no longer add new pages. Deleting the document will automatically | 77 * can no longer add new pages. Deleting the document will automatically |
68 * call close() if need be. | 78 * call close() if need be. |
79 * Returns true on success or false on failure. | |
69 */ | 80 */ |
70 void close(); | 81 bool close(); |
82 | |
83 /** | |
84 * Call abort() to stop producing the document immediately. | |
85 * The stream output must be ignored, and should not be trusted. | |
86 */ | |
87 void abort(); | |
71 | 88 |
72 protected: | 89 protected: |
73 SkDocument(SkWStream*, void (*)(SkWStream*)); | 90 SkDocument(SkWStream*, void (*)(SkWStream*)); |
74 // note: subclasses must call close() in their destructor, as the base class | 91 // note: subclasses must call close() in their destructor, as the base class |
75 // cannot do this for them. | 92 // cannot do this for them. |
76 virtual ~SkDocument(); | 93 virtual ~SkDocument(); |
77 | 94 |
78 virtual SkCanvas* onBeginPage(SkScalar width, SkScalar height, | 95 virtual SkCanvas* onBeginPage(const SkSize& trimSize, |
79 const SkRect& content) = 0; | 96 const SkRect* mediaBox) = 0; |
80 virtual void onEndPage() = 0; | 97 virtual void onEndPage() = 0; |
81 virtual void onClose(SkWStream*) = 0; | 98 virtual bool onClose(SkWStream*) = 0; |
99 virtual void onAbort() = 0; | |
82 | 100 |
83 enum State { | 101 enum State { |
84 kBetweenPages_State, | 102 kBetweenPages_State, |
85 kInPage_State, | 103 kInPage_State, |
86 kClosed_State | 104 kClosed_State |
87 }; | 105 }; |
88 State getState() const { return fState; } | 106 State getState() const { return fState; } |
89 | 107 |
90 private: | 108 private: |
91 SkWStream* fStream; | 109 SkWStream* fStream; |
92 void (*fDoneProc)(SkWStream*); | 110 void (*fDoneProc)(SkWStream*); |
93 State fState; | 111 State fState; |
94 | 112 |
95 typedef SkRefCnt INHERITED; | 113 typedef SkRefCnt INHERITED; |
96 }; | 114 }; |
97 | 115 |
98 #endif | 116 #endif |
OLD | NEW |