OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 | 7 |
8 #include "SkAnnotation.h" | 8 #include "SkAnnotation.h" |
9 #include "SkDataSet.h" | 9 #include "SkDataSet.h" |
10 #include "SkFlattenableBuffers.h" | 10 #include "SkFlattenableBuffers.h" |
| 11 #include "SkPoint.h" |
11 #include "SkStream.h" | 12 #include "SkStream.h" |
12 | 13 |
13 SkAnnotation::SkAnnotation(SkDataSet* data, uint32_t flags) { | 14 SkAnnotation::SkAnnotation(SkDataSet* data, uint32_t flags) { |
14 if (NULL == data) { | 15 if (NULL == data) { |
15 data = SkDataSet::NewEmpty(); | 16 data = SkDataSet::NewEmpty(); |
16 } else { | 17 } else { |
17 data->ref(); | 18 data->ref(); |
18 } | 19 } |
19 fDataSet = data; | 20 fDataSet = data; |
20 fFlags = flags; | 21 fFlags = flags; |
(...skipping 14 matching lines...) Expand all Loading... |
35 | 36 |
36 void SkAnnotation::flatten(SkFlattenableWriteBuffer& buffer) const { | 37 void SkAnnotation::flatten(SkFlattenableWriteBuffer& buffer) const { |
37 buffer.writeUInt(fFlags); | 38 buffer.writeUInt(fFlags); |
38 buffer.writeFlattenable(fDataSet); | 39 buffer.writeFlattenable(fDataSet); |
39 } | 40 } |
40 | 41 |
41 const char* SkAnnotationKeys::URL_Key() { | 42 const char* SkAnnotationKeys::URL_Key() { |
42 return "SkAnnotationKey_URL"; | 43 return "SkAnnotationKey_URL"; |
43 }; | 44 }; |
44 | 45 |
| 46 const char* SkAnnotationKeys::Define_Named_Dest_Key() { |
| 47 return "SkAnnotationKey_Define_Named_Dest"; |
| 48 }; |
| 49 |
| 50 const char* SkAnnotationKeys::Link_Named_Dest_Key() { |
| 51 return "SkAnnotationKey_Link_Named_Dest"; |
| 52 }; |
| 53 |
45 /////////////////////////////////////////////////////////////////////////////// | 54 /////////////////////////////////////////////////////////////////////////////// |
46 | 55 |
47 #include "SkCanvas.h" | 56 #include "SkCanvas.h" |
48 | 57 |
| 58 static void annotate_paint(SkPaint& paint, const char* key, SkData* value) { |
| 59 SkAutoTUnref<SkDataSet> dataset(SkNEW_ARGS(SkDataSet, (key, value))); |
| 60 SkAnnotation* ann = SkNEW_ARGS(SkAnnotation, (dataset, |
| 61 SkAnnotation::kNoDraw_Flag)); |
| 62 |
| 63 paint.setAnnotation(ann)->unref(); |
| 64 SkASSERT(paint.isNoDrawAnnotation()); |
| 65 } |
| 66 |
49 void SkAnnotateRectWithURL(SkCanvas* canvas, const SkRect& rect, SkData* value)
{ | 67 void SkAnnotateRectWithURL(SkCanvas* canvas, const SkRect& rect, SkData* value)
{ |
50 if (NULL == value) { | 68 if (NULL == value) { |
51 return; | 69 return; |
52 } | 70 } |
53 | |
54 const char* key = SkAnnotationKeys::URL_Key(); | |
55 SkAutoTUnref<SkDataSet> dataset(SkNEW_ARGS(SkDataSet, (key, value))); | |
56 SkAnnotation* ann = SkNEW_ARGS(SkAnnotation, (dataset, | |
57 SkAnnotation::kNoDraw_Flag)); | |
58 | |
59 SkPaint paint; | 71 SkPaint paint; |
60 paint.setAnnotation(ann)->unref(); | 72 annotate_paint(paint, SkAnnotationKeys::URL_Key(), value); |
61 SkASSERT(paint.isNoDrawAnnotation()); | |
62 | |
63 canvas->drawRect(rect, paint); | 73 canvas->drawRect(rect, paint); |
64 } | 74 } |
| 75 |
| 76 void SkAnnotateNamedDestination(SkCanvas* canvas, const SkPoint& point, SkData*
name) { |
| 77 if (NULL == name) { |
| 78 return; |
| 79 } |
| 80 SkPaint paint; |
| 81 annotate_paint(paint, SkAnnotationKeys::Define_Named_Dest_Key(), name); |
| 82 canvas->drawPoint(point.x(), point.y(), paint); |
| 83 } |
| 84 |
| 85 void SkAnnotateLinkToDestination(SkCanvas* canvas, const SkRect& rect, SkData* n
ame) { |
| 86 if (NULL == name) { |
| 87 return; |
| 88 } |
| 89 SkPaint paint; |
| 90 annotate_paint(paint, SkAnnotationKeys::Link_Named_Dest_Key(), name); |
| 91 canvas->drawRect(rect, paint); |
| 92 } |
OLD | NEW |