| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 #include "SkDocument.h" | 7 #include "SkDocument.h" |
| 8 #include "SkStream.h" | 8 #include "SkStream.h" |
| 9 #include "SkData.h" | 9 #include "SkData.h" |
| 10 #include "Test.h" | 10 #include "Test.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 metadata.fCreation.fEnabled = true; | 22 metadata.fCreation.fEnabled = true; |
| 23 metadata.fCreation.fDateTime = now; | 23 metadata.fCreation.fDateTime = now; |
| 24 metadata.fModified.fEnabled = true; | 24 metadata.fModified.fEnabled = true; |
| 25 metadata.fModified.fDateTime = now; | 25 metadata.fModified.fDateTime = now; |
| 26 | 26 |
| 27 SkDynamicMemoryWStream pdf; | 27 SkDynamicMemoryWStream pdf; |
| 28 sk_sp<SkDocument> doc = SkDocument::MakePDF(&pdf, SK_ScalarDefaultRasterDPI, | 28 sk_sp<SkDocument> doc = SkDocument::MakePDF(&pdf, SK_ScalarDefaultRasterDPI, |
| 29 metadata, nullptr, false); | 29 metadata, nullptr, false); |
| 30 doc->beginPage(612.0f, 792.0f); | 30 doc->beginPage(612.0f, 792.0f); |
| 31 doc->close(); | 31 doc->close(); |
| 32 SkAutoTUnref<SkData> data(pdf.copyToData()); | 32 sk_sp<SkData> data(pdf.copyToData()); |
| 33 static const char* expectations[] = { | 33 static const char* expectations[] = { |
| 34 "/Title (A1)", | 34 "/Title (A1)", |
| 35 "/Author (A2)", | 35 "/Author (A2)", |
| 36 "/Subject (A3)", | 36 "/Subject (A3)", |
| 37 "/Keywords (A4)", | 37 "/Keywords (A4)", |
| 38 "/Creator (A5)", | 38 "/Creator (A5)", |
| 39 "/Producer (Skia/PDF ", | 39 "/Producer (Skia/PDF ", |
| 40 "/CreationDate (D:", | 40 "/CreationDate (D:", |
| 41 "/ModDate (D:" | 41 "/ModDate (D:" |
| 42 }; | 42 }; |
| 43 const uint8_t* bytes = data->bytes(); | 43 const uint8_t* bytes = data->bytes(); |
| 44 for (const char* expectation : expectations) { | 44 for (const char* expectation : expectations) { |
| 45 size_t len = strlen(expectation); | 45 size_t len = strlen(expectation); |
| 46 bool found = false; | 46 bool found = false; |
| 47 size_t N = 1 + data->size() - len; | 47 size_t N = 1 + data->size() - len; |
| 48 for (size_t i = 0; i < N; ++i) { | 48 for (size_t i = 0; i < N; ++i) { |
| 49 if (0 == memcmp(bytes + i, expectation, len)) { | 49 if (0 == memcmp(bytes + i, expectation, len)) { |
| 50 found = true; | 50 found = true; |
| 51 break; | 51 break; |
| 52 } | 52 } |
| 53 } | 53 } |
| 54 if (!found) { | 54 if (!found) { |
| 55 ERRORF(r, "expectation missing: '%s'.", expectation); | 55 ERRORF(r, "expectation missing: '%s'.", expectation); |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 } | 58 } |
| OLD | NEW |