Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(850)

Unified Diff: src/pdf/SkPDFDocument.cpp

Issue 1916093002: SkDocument/PDF: new API (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2016-04-25 (Monday) 14:51:30 EDT Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« include/core/SkDocument.h ('K') | « include/core/SkDocument.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pdf/SkPDFDocument.cpp
diff --git a/src/pdf/SkPDFDocument.cpp b/src/pdf/SkPDFDocument.cpp
index 28602ed17681bbb1e6f0821ea81637bf40ac9e91..c2fa5f9d2463ec6ac12c6f32405f37a52ca3908c 100644
--- a/src/pdf/SkPDFDocument.cpp
+++ b/src/pdf/SkPDFDocument.cpp
@@ -499,21 +499,15 @@ sk_sp<SkDocument> SkPDFMakeDocument(SkWStream* stream,
: nullptr;
}
-#ifdef SK_PDF_GENERATE_PDFA
- static const bool kPDFA = true;
-#else
- static const bool kPDFA = false;
-#endif
-
SkDocument* SkDocument::CreatePDF(SkWStream* stream, SkScalar dpi) {
- return SkPDFMakeDocument(stream, nullptr, dpi, nullptr, kPDFA).release();
+ return SkPDFMakeDocument(stream, nullptr, dpi, nullptr, false).release();
}
SkDocument* SkDocument::CreatePDF(SkWStream* stream,
SkScalar dpi,
SkPixelSerializer* jpegEncoder) {
return SkPDFMakeDocument(stream, nullptr, dpi,
- jpegEncoder, kPDFA).release();
+ jpegEncoder, false).release();
}
SkDocument* SkDocument::CreatePDF(const char path[], SkScalar dpi) {
@@ -521,6 +515,46 @@ SkDocument* SkDocument::CreatePDF(const char path[], SkScalar dpi) {
std::unique_ptr<SkFILEWStream> stream(new SkFILEWStream(path));
return stream->isValid()
? SkPDFMakeDocument(stream.release(), delete_wstream, dpi,
- nullptr, kPDFA).release()
+ nullptr, false).release()
: nullptr;
}
+
+static const SkTime::DateTime* optional_timestamp_to_ptr(
+ const SkDocument::OptionalTimestamp& ts) {
+ return ts.enabled ? &ts.dateTime : nullptr;
+}
+
+sk_sp<SkDocument> SkDocument::MakePDF(
+ SkWStream* stream,
+ SkScalar dpi,
+ const SkDocument::PDFMetadata& metadata,
+ SkPixelSerializer* jpegEncoder,
+ bool pdfa) {
+ auto doc = SkPDFMakeDocument(stream, nullptr, dpi,
+ jpegEncoder, pdfa);
+ // For now, we translate new-style metadata
+ // (SkDocument::PDFMetadata) into old-style metadata
+ // (SkDocument::Attribute) so that we can support both APIs. We
+ // will change this once all clients are moved to the new API.
+ SkTArray<SkDocument::Attribute> attributes;
+ if (metadata.title.size() > 0) {
+ attributes.emplace_back(SkString("Title"), metadata.title);
+ }
+ if (metadata.author.size() > 0) {
+ attributes.emplace_back(SkString("Author"), metadata.author);
+ }
+ if (metadata.subject.size() > 0) {
+ attributes.emplace_back(SkString("Subject"), metadata.subject);
+ }
+ if (metadata.keywords.size() > 0) {
+ attributes.emplace_back(SkString("Keywords"), metadata.keywords);
+ }
+ if (metadata.creator.size() > 0) {
+ attributes.emplace_back(SkString("Creator"), metadata.creator);
+ }
+ doc->setMetadata(
+ &attributes[0], attributes.count(),
+ optional_timestamp_to_ptr(metadata.creation),
+ optional_timestamp_to_ptr(metadata.modified));
+ return doc;
+}
« include/core/SkDocument.h ('K') | « include/core/SkDocument.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698