| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 #include "SkPDFCanon.h" | 8 #include "SkPDFCanon.h" |
| 9 #include "SkPDFCanvas.h" | 9 #include "SkPDFCanvas.h" |
| 10 #include "SkPDFDevice.h" | 10 #include "SkPDFDevice.h" |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 | 492 |
| 493 sk_sp<SkDocument> SkPDFMakeDocument(SkWStream* stream, | 493 sk_sp<SkDocument> SkPDFMakeDocument(SkWStream* stream, |
| 494 void (*proc)(SkWStream*, bool), | 494 void (*proc)(SkWStream*, bool), |
| 495 SkScalar dpi, | 495 SkScalar dpi, |
| 496 SkPixelSerializer* jpeg, | 496 SkPixelSerializer* jpeg, |
| 497 bool pdfa) { | 497 bool pdfa) { |
| 498 return stream ? sk_make_sp<SkPDFDocument>(stream, proc, dpi, jpeg, pdfa) | 498 return stream ? sk_make_sp<SkPDFDocument>(stream, proc, dpi, jpeg, pdfa) |
| 499 : nullptr; | 499 : nullptr; |
| 500 } | 500 } |
| 501 | 501 |
| 502 #ifdef SK_PDF_GENERATE_PDFA | |
| 503 static const bool kPDFA = true; | |
| 504 #else | |
| 505 static const bool kPDFA = false; | |
| 506 #endif | |
| 507 | |
| 508 SkDocument* SkDocument::CreatePDF(SkWStream* stream, SkScalar dpi) { | 502 SkDocument* SkDocument::CreatePDF(SkWStream* stream, SkScalar dpi) { |
| 509 return SkPDFMakeDocument(stream, nullptr, dpi, nullptr, kPDFA).release(); | 503 return SkPDFMakeDocument(stream, nullptr, dpi, nullptr, false).release(); |
| 510 } | 504 } |
| 511 | 505 |
| 512 SkDocument* SkDocument::CreatePDF(SkWStream* stream, | 506 SkDocument* SkDocument::CreatePDF(SkWStream* stream, |
| 513 SkScalar dpi, | 507 SkScalar dpi, |
| 514 SkPixelSerializer* jpegEncoder) { | 508 SkPixelSerializer* jpegEncoder) { |
| 515 return SkPDFMakeDocument(stream, nullptr, dpi, | 509 return SkPDFMakeDocument(stream, nullptr, dpi, |
| 516 jpegEncoder, kPDFA).release(); | 510 jpegEncoder, false).release(); |
| 517 } | 511 } |
| 518 | 512 |
| 519 SkDocument* SkDocument::CreatePDF(const char path[], SkScalar dpi) { | 513 SkDocument* SkDocument::CreatePDF(const char path[], SkScalar dpi) { |
| 520 auto delete_wstream = [](SkWStream* stream, bool) { delete stream; }; | 514 auto delete_wstream = [](SkWStream* stream, bool) { delete stream; }; |
| 521 std::unique_ptr<SkFILEWStream> stream(new SkFILEWStream(path)); | 515 std::unique_ptr<SkFILEWStream> stream(new SkFILEWStream(path)); |
| 522 return stream->isValid() | 516 return stream->isValid() |
| 523 ? SkPDFMakeDocument(stream.release(), delete_wstream, dpi, | 517 ? SkPDFMakeDocument(stream.release(), delete_wstream, dpi, |
| 524 nullptr, kPDFA).release() | 518 nullptr, false).release() |
| 525 : nullptr; | 519 : nullptr; |
| 526 } | 520 } |
| 521 |
| 522 static const SkTime::DateTime* optional_timestamp_to_ptr( |
| 523 const SkDocument::OptionalTimestamp& ts) { |
| 524 return ts.enabled ? &ts.dateTime : nullptr; |
| 525 } |
| 526 |
| 527 sk_sp<SkDocument> SkDocument::MakePDF( |
| 528 SkWStream* stream, |
| 529 SkScalar dpi, |
| 530 const SkDocument::PDFMetadata& metadata, |
| 531 SkPixelSerializer* jpegEncoder, |
| 532 bool pdfa) { |
| 533 auto doc = SkPDFMakeDocument(stream, nullptr, dpi, |
| 534 jpegEncoder, pdfa); |
| 535 // For now, we translate new-style metadata |
| 536 // (SkDocument::PDFMetadata) into old-style metadata |
| 537 // (SkDocument::Attribute) so that we can support both APIs. We |
| 538 // will change this once all clients are moved to the new API. |
| 539 SkTArray<SkDocument::Attribute> attributes; |
| 540 if (metadata.title.size() > 0) { |
| 541 attributes.emplace_back(SkString("Title"), metadata.title); |
| 542 } |
| 543 if (metadata.author.size() > 0) { |
| 544 attributes.emplace_back(SkString("Author"), metadata.author); |
| 545 } |
| 546 if (metadata.subject.size() > 0) { |
| 547 attributes.emplace_back(SkString("Subject"), metadata.subject); |
| 548 } |
| 549 if (metadata.keywords.size() > 0) { |
| 550 attributes.emplace_back(SkString("Keywords"), metadata.keywords); |
| 551 } |
| 552 if (metadata.creator.size() > 0) { |
| 553 attributes.emplace_back(SkString("Creator"), metadata.creator); |
| 554 } |
| 555 doc->setMetadata( |
| 556 &attributes[0], attributes.count(), |
| 557 optional_timestamp_to_ptr(metadata.creation), |
| 558 optional_timestamp_to_ptr(metadata.modified)); |
| 559 return doc; |
| 560 } |
| OLD | NEW |