| 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 "SkBitmap.h" | 11 #include "SkBitmap.h" |
| 12 #include "SkPicture.h" | 12 #include "SkPicture.h" |
| 13 #include "SkRect.h" | 13 #include "SkRect.h" |
| 14 #include "SkRefCnt.h" | 14 #include "SkRefCnt.h" |
| 15 #include "SkString.h" |
| 16 #include "SkTime.h" |
| 15 | 17 |
| 16 class SkCanvas; | 18 class SkCanvas; |
| 17 class SkWStream; | 19 class SkWStream; |
| 18 | 20 |
| 19 /** SK_ScalarDefaultDPI is 72 DPI. | 21 /** SK_ScalarDefaultDPI is 72 DPI. |
| 20 */ | 22 */ |
| 21 #define SK_ScalarDefaultRasterDPI 72.0f | 23 #define SK_ScalarDefaultRasterDPI 72.0f |
| 22 | 24 |
| 23 /** | 25 /** |
| 24 * High-level API for creating a document-based canvas. To use.. | 26 * High-level API for creating a document-based canvas. To use.. |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 * Returns true on success or false on failure. | 99 * Returns true on success or false on failure. |
| 98 */ | 100 */ |
| 99 bool close(); | 101 bool close(); |
| 100 | 102 |
| 101 /** | 103 /** |
| 102 * Call abort() to stop producing the document immediately. | 104 * Call abort() to stop producing the document immediately. |
| 103 * The stream output must be ignored, and should not be trusted. | 105 * The stream output must be ignored, and should not be trusted. |
| 104 */ | 106 */ |
| 105 void abort(); | 107 void abort(); |
| 106 | 108 |
| 109 /** |
| 110 * Set the document's metadata, if supported by the document |
| 111 * type. The creationDate and modifiedDate parameters can be |
| 112 * nullptr. For example: |
| 113 * |
| 114 * SkDocument* make_doc(SkWStream* output) { |
| 115 * SkTArray<SkDocument::Attribute> info; |
| 116 * info.emplace_back(SkString("Title"), SkString("...")); |
| 117 * info.emplace_back(SkString("Author"), SkString("...")); |
| 118 * info.emplace_back(SkString("Subject"), SkString("...")); |
| 119 * info.emplace_back(SkString("Keywords"), SkString("...")); |
| 120 * info.emplace_back(SkString("Creator"), SkString("...")); |
| 121 * SkTime::DateTime now; |
| 122 * SkTime::GetDateTime(&now); |
| 123 * SkDocument* doc = SkDocument::CreatePDF(output); |
| 124 * doc->setMetadata(info, &now, &now); |
| 125 * return doc; |
| 126 * } |
| 127 */ |
| 128 struct Attribute { |
| 129 SkString fKey, fValue; |
| 130 Attribute(const SkString& k, const SkString& v) : fKey(k), fValue(v) {} |
| 131 }; |
| 132 virtual void setMetadata(const SkTArray<SkDocument::Attribute>&, |
| 133 const SkTime::DateTime* /* creationDate */, |
| 134 const SkTime::DateTime* /* modifiedDate */) {} |
| 135 |
| 107 protected: | 136 protected: |
| 108 SkDocument(SkWStream*, void (*)(SkWStream*, bool aborted)); | 137 SkDocument(SkWStream*, void (*)(SkWStream*, bool aborted)); |
| 109 | 138 |
| 110 // note: subclasses must call close() in their destructor, as the base class | 139 // note: subclasses must call close() in their destructor, as the base class |
| 111 // cannot do this for them. | 140 // cannot do this for them. |
| 112 virtual ~SkDocument(); | 141 virtual ~SkDocument(); |
| 113 | 142 |
| 114 virtual SkCanvas* onBeginPage(SkScalar width, SkScalar height, | 143 virtual SkCanvas* onBeginPage(SkScalar width, SkScalar height, |
| 115 const SkRect& content) = 0; | 144 const SkRect& content) = 0; |
| 116 virtual void onEndPage() = 0; | 145 virtual void onEndPage() = 0; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 129 | 158 |
| 130 private: | 159 private: |
| 131 SkWStream* fStream; | 160 SkWStream* fStream; |
| 132 void (*fDoneProc)(SkWStream*, bool aborted); | 161 void (*fDoneProc)(SkWStream*, bool aborted); |
| 133 State fState; | 162 State fState; |
| 134 | 163 |
| 135 typedef SkRefCnt INHERITED; | 164 typedef SkRefCnt INHERITED; |
| 136 }; | 165 }; |
| 137 | 166 |
| 138 #endif | 167 #endif |
| OLD | NEW |