Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2013 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #ifndef SkDocument_DEFINED | |
| 9 #define SkDocument_DEFINED | |
| 10 | |
| 11 #include "SkRect.h" | |
| 12 #include "SkRefCnt.h" | |
| 13 | |
| 14 class SkCanvas; | |
| 15 class SkWStream; | |
| 16 | |
| 17 /** | |
| 18 * High-level API for creating a document-based canvas. To use.. | |
| 19 * | |
| 20 * 1. Create a document, specifying a stream to store the output. | |
| 21 * 2. For each "page" of content: | |
| 22 * a. canvas = doc->beginPage(...) | |
| 23 * b. draw_my_content(canvas); | |
| 24 * c. doc->endPage(); | |
| 25 * 3. Close the document with doc->close(). | |
| 26 */ | |
| 27 class SkDocument : public SkRefCnt { | |
| 28 public: | |
| 29 /** | |
| 30 * Create a PDF-backed document, writing the results into a file. If there | |
| 31 * is an error trying to create the doc, returns NULL. | |
| 32 */ | |
| 33 static SkDocument* CreatePDF(const char filename[]); | |
| 34 | |
| 35 /** | |
| 36 * Create a PDF-backed document, writing the results into a stream. | |
| 37 * there is an error trying to create the doc, returns NULL. | |
|
scroggo
2013/06/07 20:12:32
If got lost here.
| |
| 38 * | |
| 39 * The document may write to the stream at anytime during its lifetime, | |
| 40 * until either close() is called or the document is deleted. Thus the | |
| 41 * caller must ensure that the stream remains in scope. | |
| 42 */ | |
| 43 static SkDocument* CreatePDF(SkWStream*); | |
| 44 | |
| 45 /** | |
| 46 * Begin a new page for the document, returning the canvas that will draw | |
| 47 * into the page. The document owns this canvas, and it will go out of | |
| 48 * scope when endPage() or close() is called, or the document is deleted. | |
| 49 */ | |
| 50 SkCanvas* beginPage(SkScalar width, SkScalar height, | |
| 51 const SkRect* content = NULL); | |
| 52 | |
| 53 /** | |
| 54 * Call endPage() when the content for the current page has been drawn | |
| 55 * (into the canvas returned by beginPage()). After this call the canvas | |
| 56 * returned by beginPage() will be out-of-scope. | |
| 57 */ | |
| 58 void endPage(); | |
| 59 | |
| 60 /** | |
| 61 * Call close() when all pages have been drawn. This will close the file | |
| 62 * or stream holding the document's contents. After close() the document | |
| 63 * can no longer add new pages. Deleting the document will automatically | |
| 64 * call close() if need be. | |
| 65 */ | |
| 66 void close(); | |
| 67 | |
| 68 protected: | |
| 69 SkDocument(SkWStream*); | |
| 70 virtual ~SkDocument(); | |
| 71 | |
| 72 virtual SkCanvas* onBeginPage(SkScalar width, SkScalar height, | |
| 73 const SkRect& content) = 0; | |
| 74 virtual void onEndPage() = 0; | |
| 75 virtual void onClose(SkWStream*) = 0; | |
| 76 | |
| 77 enum State { | |
| 78 kBetweenPages_State, | |
| 79 kInPage_State, | |
| 80 kClosed_State | |
| 81 }; | |
| 82 State getState() const { return fState; } | |
| 83 | |
| 84 private: | |
| 85 SkWStream* fStream; | |
| 86 State fState; | |
| 87 }; | |
| 88 | |
| 89 #endif | |
| OLD | NEW |