OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "SkAnnotation.h" | 8 #include "SkAnnotation.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkData.h" | 10 #include "SkData.h" |
| 11 #include "SkPDFCanon.h" |
11 #include "SkPDFDevice.h" | 12 #include "SkPDFDevice.h" |
12 #include "SkPDFDocument.h" | 13 #include "SkPDFDocument.h" |
13 #include "Test.h" | 14 #include "Test.h" |
14 | 15 |
15 /** Returns true if data (may contain null characters) contains needle (null | 16 /** Returns true if data (may contain null characters) contains needle (null |
16 * terminated). */ | 17 * terminated). */ |
17 static bool ContainsString(const char* data, size_t dataSize, const char* needle
) { | 18 static bool ContainsString(const char* data, size_t dataSize, const char* needle
) { |
18 size_t nSize = strlen(needle); | 19 size_t nSize = strlen(needle); |
19 for (size_t i = 0; i < dataSize - nSize; i++) { | 20 for (size_t i = 0; i < dataSize - nSize; i++) { |
20 if (strncmp(&data[i], needle, nSize) == 0) { | 21 if (strncmp(&data[i], needle, nSize) == 0) { |
(...skipping 13 matching lines...) Expand all Loading... |
34 | 35 |
35 SkAutoDataUnref data(SkData::NewWithCString("http://www.gooogle.com")); | 36 SkAutoDataUnref data(SkData::NewWithCString("http://www.gooogle.com")); |
36 | 37 |
37 REPORTER_ASSERT(reporter, 0 == *bm.getAddr32(0, 0)); | 38 REPORTER_ASSERT(reporter, 0 == *bm.getAddr32(0, 0)); |
38 SkAnnotateRectWithURL(&canvas, r, data.get()); | 39 SkAnnotateRectWithURL(&canvas, r, data.get()); |
39 REPORTER_ASSERT(reporter, 0 == *bm.getAddr32(0, 0)); | 40 REPORTER_ASSERT(reporter, 0 == *bm.getAddr32(0, 0)); |
40 } | 41 } |
41 | 42 |
42 DEF_TEST(Annotation_PdfLink, reporter) { | 43 DEF_TEST(Annotation_PdfLink, reporter) { |
43 SkISize size = SkISize::Make(612, 792); | 44 SkISize size = SkISize::Make(612, 792); |
44 SkMatrix initialTransform; | 45 SkPDFCanon canon; |
45 initialTransform.reset(); | 46 SkAutoTUnref<SkPDFDevice> device(SkPDFDevice::Create(size, 72.0f, &canon)); |
46 SkPDFDevice device(size, size, initialTransform); | 47 SkCanvas canvas(device.get()); |
47 SkCanvas canvas(&device); | |
48 | 48 |
49 SkRect r = SkRect::MakeXYWH(SkIntToScalar(72), SkIntToScalar(72), | 49 SkRect r = SkRect::MakeXYWH(SkIntToScalar(72), SkIntToScalar(72), |
50 SkIntToScalar(288), SkIntToScalar(72)); | 50 SkIntToScalar(288), SkIntToScalar(72)); |
51 SkAutoDataUnref data(SkData::NewWithCString("http://www.gooogle.com")); | 51 SkAutoDataUnref data(SkData::NewWithCString("http://www.gooogle.com")); |
52 SkAnnotateRectWithURL(&canvas, r, data.get()); | 52 SkAnnotateRectWithURL(&canvas, r, data.get()); |
53 | 53 |
54 SkPDFDocument doc; | 54 SkPDFDocument doc; |
55 doc.appendPage(&device); | 55 doc.appendPage(device.get()); |
56 SkDynamicMemoryWStream outStream; | 56 SkDynamicMemoryWStream outStream; |
57 doc.emitPDF(&outStream); | 57 doc.emitPDF(&outStream); |
58 SkAutoDataUnref out(outStream.copyToData()); | 58 SkAutoDataUnref out(outStream.copyToData()); |
59 const char* rawOutput = (const char*)out->data(); | 59 const char* rawOutput = (const char*)out->data(); |
60 | 60 |
61 REPORTER_ASSERT(reporter, ContainsString(rawOutput, out->size(), "/Annots ")
); | 61 REPORTER_ASSERT(reporter, ContainsString(rawOutput, out->size(), "/Annots ")
); |
62 } | 62 } |
63 | 63 |
64 DEF_TEST(Annotation_NamedDestination, reporter) { | 64 DEF_TEST(Annotation_NamedDestination, reporter) { |
65 SkISize size = SkISize::Make(612, 792); | 65 SkISize size = SkISize::Make(612, 792); |
66 SkMatrix initialTransform; | 66 SkPDFCanon canon; |
67 initialTransform.reset(); | 67 SkAutoTUnref<SkPDFDevice> device(SkPDFDevice::Create(size, 72.0f, &canon)); |
68 SkPDFDevice device(size, size, initialTransform); | 68 SkCanvas canvas(device.get()); |
69 SkCanvas canvas(&device); | |
70 | 69 |
71 SkPoint p = SkPoint::Make(SkIntToScalar(72), SkIntToScalar(72)); | 70 SkPoint p = SkPoint::Make(SkIntToScalar(72), SkIntToScalar(72)); |
72 SkAutoDataUnref data(SkData::NewWithCString("example")); | 71 SkAutoDataUnref data(SkData::NewWithCString("example")); |
73 SkAnnotateNamedDestination(&canvas, p, data.get()); | 72 SkAnnotateNamedDestination(&canvas, p, data.get()); |
74 | 73 |
75 SkPDFDocument doc; | 74 SkPDFDocument doc; |
76 doc.appendPage(&device); | 75 doc.appendPage(device.get()); |
77 SkDynamicMemoryWStream outStream; | 76 SkDynamicMemoryWStream outStream; |
78 doc.emitPDF(&outStream); | 77 doc.emitPDF(&outStream); |
79 SkAutoDataUnref out(outStream.copyToData()); | 78 SkAutoDataUnref out(outStream.copyToData()); |
80 const char* rawOutput = (const char*)out->data(); | 79 const char* rawOutput = (const char*)out->data(); |
81 | 80 |
82 REPORTER_ASSERT(reporter, | 81 REPORTER_ASSERT(reporter, |
83 ContainsString(rawOutput, out->size(), "/example ")); | 82 ContainsString(rawOutput, out->size(), "/example ")); |
84 } | 83 } |
OLD | NEW |