SkPDF: metadata first

Motivation: while experimenting with serializing images immediately, I would like to keep serializing metadata first.

TBR=djsollen@google.com
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1780463008

Review URL: https://codereview.chromium.org/1780463008
This commit is contained in:
halcanary 2016-03-20 07:07:11 -07:00 committed by Commit bot
parent ee0fa00427
commit 2c9c469cc9
2 changed files with 25 additions and 24 deletions

View File

@ -4,15 +4,24 @@ Using Skia's PDF Backend
Here is an example of using Skia's PDF backend in the recommended way:
via the SkDocument and SkCanvas APIs.
<!--?prettify?-->
<!--?prettify lang=cc?-->
#include "SkDocument.h"
bool WritePDF() {
SkWStream* outputStream = ....;
SkAutoTUnref<SkDocument> pdfDocument(
SkDocument::CreatePDF(outputStream));
bool WritePDF(SkWStream* outputStream) {
sk_sp<SkDocument> pdfDocument(SkDocument::CreatePDF(outputStream));
typedef SkDocument::Attribute Attr;
Attr info[] = {
Attr(SkString("Title"), SkString("....")),
Attr(SkString("Author"), SkString("....")),
Attr(SkString("Subject"), SkString("....")),
Attr(SkString("Keywords"), SkString("....")),
Attr(SkString("Creator"), SkString("....")),
};
int infoCount = sizeof(info) / sizeof(info[0]);
SkTime::DateTime now;
SkTime::GetDateTime(&now);
pdfDocument->setMetadata(info, infoCount, &now, &now);
int numberOfPages = ....;
for (int page = 0; page < numberOfPages; ++page) {
@ -25,16 +34,5 @@ via the SkDocument and SkCanvas APIs.
pdfDocument->endPage();
}
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);
pdfDocument->setMetadata(info, &now, &now);
return pdfDocument->close();
}

View File

@ -13,15 +13,18 @@ DEF_TEST(SkPDF_MetadataAttribute, r) {
REQUIRE_PDF_DOCUMENT(SkPDF_MetadataAttribute, r);
SkDynamicMemoryWStream pdf;
SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&pdf));
SkTArray<SkDocument::Attribute> info;
info.emplace_back(SkString("Title"), SkString("A1"));
info.emplace_back(SkString("Author"), SkString("A2"));
info.emplace_back(SkString("Subject"), SkString("A3"));
info.emplace_back(SkString("Keywords"), SkString("A4"));
info.emplace_back(SkString("Creator"), SkString("A5"));
typedef SkDocument::Attribute Attr;
Attr info[] = {
Attr(SkString("Title"), SkString("A1")),
Attr(SkString("Author"), SkString("A2")),
Attr(SkString("Subject"), SkString("A3")),
Attr(SkString("Keywords"), SkString("A4")),
Attr(SkString("Creator"), SkString("A5")),
};
int infoCount = sizeof(info) / sizeof(info[0]);
SkTime::DateTime now;
SkTime::GetDateTime(&now);
doc->setMetadata(&info[0], info.count(), &now, &now);
doc->setMetadata(&info[0], infoCount, &now, &now);
doc->beginPage(612.0f, 792.0f);
doc->close();
SkAutoTUnref<SkData> data(pdf.copyToData());