| 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;
|
| +}
|
|
|