• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2015 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 #include "include/core/SkTypes.h"
8 
9 #if defined(SK_SUPPORT_PDF)
10 #include "include/core/SkData.h"
11 #include "include/core/SkDocument.h"
12 #include "include/core/SkRefCnt.h"
13 #include "include/core/SkStream.h"
14 #include "include/core/SkString.h"
15 #include "include/docs/SkPDFDocument.h"
16 #include "include/docs/SkPDFJpegHelpers.h"
17 #include "src/pdf/SkPDFUtils.h"
18 #include "tests/Test.h"
19 
20 #include <cstdint>
21 #include <cstring>
22 
DEF_TEST(SkPDF_Metadata,r)23 DEF_TEST(SkPDF_Metadata, r) {
24     REQUIRE_PDF_DOCUMENT(SkPDF_Metadata, r);
25     SkPDF::DateTime now;
26     SkPDFUtils::GetDateTime(&now);
27     SkPDF::Metadata metadata;
28     metadata.fTitle = "A1";
29     metadata.fAuthor = "A2";
30     metadata.fSubject = "A3";
31     metadata.fKeywords = "A4";
32     metadata.fCreator = "A5";
33     metadata.fCreation = now;
34     metadata.fModified = now;
35     metadata.jpegDecoder = SkPDF::JPEG::Decode;
36     metadata.jpegEncoder = SkPDF::JPEG::Encode;
37 
38     SkDynamicMemoryWStream pdf;
39     auto doc = SkPDF::MakeDocument(&pdf, metadata);
40     doc->beginPage(612.0f, 792.0f);
41     doc->close();
42     sk_sp<SkData> data = pdf.detachAsData();
43     static const char* expectations[] = {
44         "/Title (A1)",
45         "/Author (A2)",
46         "/Subject (A3)",
47         "/Keywords (A4)",
48         "/Creator (A5)",
49         "/Producer (Skia/PDF ",
50         "/CreationDate (D:",
51         "/ModDate (D:"
52     };
53     const uint8_t* bytes = data->bytes();
54     for (const char* expectation : expectations) {
55         size_t len = strlen(expectation);
56         bool found = false;
57         size_t N = 1 + data->size() - len;
58         for (size_t i = 0; i < N; ++i) {
59             if (0 == memcmp(bytes + i, expectation, len)) {
60                 found = true;
61                 break;
62             }
63         }
64         if (!found) {
65             ERRORF(r, "expectation missing: '%s'.", expectation);
66         }
67     }
68 }
69 #endif
70