Flutter Engine
The Flutter Engine
third_party
skia
tests
PDFMetadataAttributeTest.cpp
Go to the documentation of this file.
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
#ifdef 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 "
src/pdf/SkPDFUtils.h
"
17
#include "
tests/Test.h
"
18
19
#include <cstdint>
20
#include <cstring>
21
22
DEF_TEST
(SkPDF_Metadata, r) {
23
REQUIRE_PDF_DOCUMENT
(SkPDF_Metadata, r);
24
SkPDF::DateTime
now;
25
SkPDFUtils::GetDateTime
(&now);
26
SkPDF::Metadata
metadata;
27
metadata.
fTitle
=
"A1"
;
28
metadata.
fAuthor
=
"A2"
;
29
metadata.
fSubject
=
"A3"
;
30
metadata.
fKeywords
=
"A4"
;
31
metadata.
fCreator
=
"A5"
;
32
metadata.
fCreation
= now;
33
metadata.
fModified
= now;
34
35
SkDynamicMemoryWStream
pdf;
36
auto
doc =
SkPDF::MakeDocument
(&pdf, metadata);
37
doc->beginPage(612.0f, 792.0f);
38
doc->close();
39
sk_sp<SkData>
data
= pdf.
detachAsData
();
40
static
const
char
* expectations[] = {
41
"/Title (A1)"
,
42
"/Author (A2)"
,
43
"/Subject (A3)"
,
44
"/Keywords (A4)"
,
45
"/Creator (A5)"
,
46
"/Producer (Skia/PDF "
,
47
"/CreationDate (D:"
,
48
"/ModDate (D:"
49
};
50
const
uint8_t* bytes =
data
->bytes();
51
for
(
const
char
*
expectation
: expectations) {
52
size_t
len
= strlen(
expectation
);
53
bool
found =
false
;
54
size_t
N
= 1 +
data
->size() -
len
;
55
for
(
size_t
i
= 0;
i
<
N
; ++
i
) {
56
if
(0 == memcmp(bytes +
i
,
expectation
,
len
)) {
57
found =
true
;
58
break
;
59
}
60
}
61
if
(!found) {
62
ERRORF
(r,
"expectation missing: '%s'."
,
expectation
);
63
}
64
}
65
}
66
#endif
SkData.h
SkDocument.h
SkPDFDocument.h
SkPDFUtils.h
SkRefCnt.h
SkStream.h
SkString.h
SkTypes.h
Test.h
DEF_TEST
#define DEF_TEST(name, reporter)
Definition:
Test.h:312
REQUIRE_PDF_DOCUMENT
#define REQUIRE_PDF_DOCUMENT(TEST_NAME, REPORTER)
Definition:
Test.h:485
ERRORF
#define ERRORF(r,...)
Definition:
Test.h:293
N
#define N
Definition:
beziers.cpp:19
SkDynamicMemoryWStream
Definition:
SkStream.h:455
SkDynamicMemoryWStream::detachAsData
sk_sp< SkData > detachAsData()
Definition:
SkStream.cpp:707
sk_sp< SkData >
i
int i
Definition:
fl_socket_accessible.cc:18
SkPDFUtils::GetDateTime
void GetDateTime(SkPDF::DateTime *)
Definition:
SkPDFUtils.cpp:431
SkPDF::MakeDocument
SK_API sk_sp< SkDocument > MakeDocument(SkWStream *stream, const Metadata &metadata)
Definition:
SkDocument_PDF_None.cpp:14
gn.find_headers.len
len
Definition:
find_headers.py:30
import_conformance_tests.expectation
tuple expectation
Definition:
import_conformance_tests.py:54
SkPDF::DateTime
Definition:
SkPDFDocument.h:69
SkPDF::Metadata
Definition:
SkPDFDocument.h:85
SkPDF::Metadata::fCreator
SkString fCreator
Definition:
SkPDFDocument.h:107
SkPDF::Metadata::fTitle
SkString fTitle
Definition:
SkPDFDocument.h:88
SkPDF::Metadata::fSubject
SkString fSubject
Definition:
SkPDFDocument.h:96
SkPDF::Metadata::fAuthor
SkString fAuthor
Definition:
SkPDFDocument.h:92
SkPDF::Metadata::fKeywords
SkString fKeywords
Definition:
SkPDFDocument.h:101
SkPDF::Metadata::fCreation
DateTime fCreation
Definition:
SkPDFDocument.h:116
SkPDF::Metadata::fModified
DateTime fModified
Definition:
SkPDFDocument.h:121
data
std::shared_ptr< const fml::Mapping > data
Definition:
texture_gles.cc:63
Generated on Sun Jun 23 2024 21:56:46 for Flutter Engine by
1.9.4