2015-09-23 19:45:49 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
#include "SkDocument.h"
|
|
|
|
#include "SkStream.h"
|
|
|
|
#include "SkData.h"
|
|
|
|
#include "Test.h"
|
|
|
|
|
2016-04-27 14:45:18 +00:00
|
|
|
DEF_TEST(SkPDF_Metadata, r) {
|
|
|
|
REQUIRE_PDF_DOCUMENT(SkPDF_Metadata, r);
|
2015-09-23 19:45:49 +00:00
|
|
|
SkTime::DateTime now;
|
|
|
|
SkTime::GetDateTime(&now);
|
2016-04-27 14:45:18 +00:00
|
|
|
SkDocument::PDFMetadata metadata;
|
|
|
|
metadata.fTitle = "A1";
|
|
|
|
metadata.fAuthor = "A2";
|
|
|
|
metadata.fSubject = "A3";
|
|
|
|
metadata.fKeywords = "A4";
|
|
|
|
metadata.fCreator = "A5";
|
|
|
|
metadata.fCreation.fEnabled = true;
|
|
|
|
metadata.fCreation.fDateTime = now;
|
|
|
|
metadata.fModified.fEnabled = true;
|
|
|
|
metadata.fModified.fDateTime = now;
|
|
|
|
|
|
|
|
SkDynamicMemoryWStream pdf;
|
|
|
|
sk_sp<SkDocument> doc = SkDocument::MakePDF(&pdf, SK_ScalarDefaultRasterDPI,
|
|
|
|
metadata, nullptr, false);
|
2015-09-23 19:45:49 +00:00
|
|
|
doc->beginPage(612.0f, 792.0f);
|
|
|
|
doc->close();
|
2016-09-12 19:01:44 +00:00
|
|
|
sk_sp<SkData> data = pdf.detachAsData();
|
2015-09-23 19:45:49 +00:00
|
|
|
static const char* expectations[] = {
|
|
|
|
"/Title (A1)",
|
|
|
|
"/Author (A2)",
|
|
|
|
"/Subject (A3)",
|
|
|
|
"/Keywords (A4)",
|
|
|
|
"/Creator (A5)",
|
2016-03-29 16:09:29 +00:00
|
|
|
"/Producer (Skia/PDF ",
|
2015-09-23 19:45:49 +00:00
|
|
|
"/CreationDate (D:",
|
|
|
|
"/ModDate (D:"
|
|
|
|
};
|
2016-04-27 14:45:18 +00:00
|
|
|
const uint8_t* bytes = data->bytes();
|
2015-09-23 19:45:49 +00:00
|
|
|
for (const char* expectation : expectations) {
|
2016-04-27 14:45:18 +00:00
|
|
|
size_t len = strlen(expectation);
|
2015-09-23 19:45:49 +00:00
|
|
|
bool found = false;
|
2016-04-27 14:45:18 +00:00
|
|
|
size_t N = 1 + data->size() - len;
|
2015-09-23 19:45:49 +00:00
|
|
|
for (size_t i = 0; i < N; ++i) {
|
2016-04-27 14:45:18 +00:00
|
|
|
if (0 == memcmp(bytes + i, expectation, len)) {
|
2015-09-23 19:45:49 +00:00
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found) {
|
|
|
|
ERRORF(r, "expectation missing: '%s'.", expectation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|