aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core
diff options
context:
space:
mode:
Diffstat (limited to 'include/core')
-rw-r--r--include/core/SkDocument.h29
-rw-r--r--include/core/SkTArray.h8
2 files changed, 37 insertions, 0 deletions
diff --git a/include/core/SkDocument.h b/include/core/SkDocument.h
index a35f448208..316d15a253 100644
--- a/include/core/SkDocument.h
+++ b/include/core/SkDocument.h
@@ -12,6 +12,8 @@
#include "SkPicture.h"
#include "SkRect.h"
#include "SkRefCnt.h"
+#include "SkString.h"
+#include "SkTime.h"
class SkCanvas;
class SkWStream;
@@ -104,6 +106,33 @@ public:
*/
void abort();
+ /**
+ * Set the document's metadata, if supported by the document
+ * type. The creationDate and modifiedDate parameters can be
+ * nullptr. For example:
+ *
+ * SkDocument* make_doc(SkWStream* output) {
+ * SkTArray<SkDocument::Attribute> info;
+ * info.emplace_back(SkString("Title"), SkString("..."));
+ * info.emplace_back(SkString("Author"), SkString("..."));
+ * info.emplace_back(SkString("Subject"), SkString("..."));
+ * info.emplace_back(SkString("Keywords"), SkString("..."));
+ * info.emplace_back(SkString("Creator"), SkString("..."));
+ * SkTime::DateTime now;
+ * SkTime::GetDateTime(&now);
+ * SkDocument* doc = SkDocument::CreatePDF(output);
+ * doc->setMetadata(info, &now, &now);
+ * return doc;
+ * }
+ */
+ struct Attribute {
+ SkString fKey, fValue;
+ Attribute(const SkString& k, const SkString& v) : fKey(k), fValue(v) {}
+ };
+ virtual void setMetadata(const SkTArray<SkDocument::Attribute>&,
+ const SkTime::DateTime* /* creationDate */,
+ const SkTime::DateTime* /* modifiedDate */) {}
+
protected:
SkDocument(SkWStream*, void (*)(SkWStream*, bool aborted));
diff --git a/include/core/SkTArray.h b/include/core/SkTArray.h
index d67956be32..401f7084d6 100644
--- a/include/core/SkTArray.h
+++ b/include/core/SkTArray.h
@@ -194,6 +194,14 @@ public:
}
/**
+ * Construct a new T at the back of this array.
+ */
+ template<class... Args> T& emplace_back(Args&&... args) {
+ T* newT = reinterpret_cast<T*>(this->push_back_raw(1));
+ return *new (newT) T(skstd::forward<Args>(args)...);
+ }
+
+ /**
* Allocates n more default-initialized T values, and returns the address of
* the start of that new range. Note: this address is only valid until the
* next API call made on the array that might add or remove elements.