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 "SkData.h" | 9 #include "SkData.h" |
10 #include "SkPaint.h" | 10 #include "SkPaint.h" |
11 #include "SkPoint.h" | 11 #include "SkPoint.h" |
12 #include "SkReadBuffer.h" | 12 #include "SkReadBuffer.h" |
13 #include "SkWriteBuffer.h" | 13 #include "SkWriteBuffer.h" |
14 | 14 |
15 SkAnnotation::SkAnnotation(const char key[], SkData* value) : fKey(key) { | 15 SkAnnotation::SkAnnotation(const char key[], SkData* value) : fKey(key) { |
16 if (NULL == value) { | 16 if (nullptr == value) { |
17 value = SkData::NewEmpty(); | 17 value = SkData::NewEmpty(); |
18 } else { | 18 } else { |
19 value->ref(); | 19 value->ref(); |
20 } | 20 } |
21 fData = value; | 21 fData = value; |
22 } | 22 } |
23 | 23 |
24 SkAnnotation::~SkAnnotation() { | 24 SkAnnotation::~SkAnnotation() { |
25 fData->unref(); | 25 fData->unref(); |
26 } | 26 } |
27 | 27 |
28 SkData* SkAnnotation::find(const char key[]) const { | 28 SkData* SkAnnotation::find(const char key[]) const { |
29 return fKey.equals(key) ? fData : NULL; | 29 return fKey.equals(key) ? fData : nullptr; |
30 } | 30 } |
31 | 31 |
32 SkAnnotation::SkAnnotation(SkReadBuffer& buffer) { | 32 SkAnnotation::SkAnnotation(SkReadBuffer& buffer) { |
33 buffer.readString(&fKey); | 33 buffer.readString(&fKey); |
34 fData = buffer.readByteArrayAsData(); | 34 fData = buffer.readByteArrayAsData(); |
35 } | 35 } |
36 | 36 |
37 void SkAnnotation::writeToBuffer(SkWriteBuffer& buffer) const { | 37 void SkAnnotation::writeToBuffer(SkWriteBuffer& buffer) const { |
38 buffer.writeString(fKey.c_str()); | 38 buffer.writeString(fKey.c_str()); |
39 buffer.writeDataAsByteArray(fData); | 39 buffer.writeDataAsByteArray(fData); |
(...skipping 13 matching lines...) Expand all Loading... |
53 | 53 |
54 /////////////////////////////////////////////////////////////////////////////// | 54 /////////////////////////////////////////////////////////////////////////////// |
55 | 55 |
56 #include "SkCanvas.h" | 56 #include "SkCanvas.h" |
57 | 57 |
58 static void annotate_paint(SkPaint& paint, const char* key, SkData* value) { | 58 static void annotate_paint(SkPaint& paint, const char* key, SkData* value) { |
59 paint.setAnnotation(SkAnnotation::Create(key, value))->unref(); | 59 paint.setAnnotation(SkAnnotation::Create(key, value))->unref(); |
60 } | 60 } |
61 | 61 |
62 void SkAnnotateRectWithURL(SkCanvas* canvas, const SkRect& rect, SkData* value)
{ | 62 void SkAnnotateRectWithURL(SkCanvas* canvas, const SkRect& rect, SkData* value)
{ |
63 if (NULL == value) { | 63 if (nullptr == value) { |
64 return; | 64 return; |
65 } | 65 } |
66 SkPaint paint; | 66 SkPaint paint; |
67 annotate_paint(paint, SkAnnotationKeys::URL_Key(), value); | 67 annotate_paint(paint, SkAnnotationKeys::URL_Key(), value); |
68 canvas->drawRect(rect, paint); | 68 canvas->drawRect(rect, paint); |
69 } | 69 } |
70 | 70 |
71 void SkAnnotateNamedDestination(SkCanvas* canvas, const SkPoint& point, SkData*
name) { | 71 void SkAnnotateNamedDestination(SkCanvas* canvas, const SkPoint& point, SkData*
name) { |
72 if (NULL == name) { | 72 if (nullptr == name) { |
73 return; | 73 return; |
74 } | 74 } |
75 SkPaint paint; | 75 SkPaint paint; |
76 annotate_paint(paint, SkAnnotationKeys::Define_Named_Dest_Key(), name); | 76 annotate_paint(paint, SkAnnotationKeys::Define_Named_Dest_Key(), name); |
77 canvas->drawPoint(point.x(), point.y(), paint); | 77 canvas->drawPoint(point.x(), point.y(), paint); |
78 } | 78 } |
79 | 79 |
80 void SkAnnotateLinkToDestination(SkCanvas* canvas, const SkRect& rect, SkData* n
ame) { | 80 void SkAnnotateLinkToDestination(SkCanvas* canvas, const SkRect& rect, SkData* n
ame) { |
81 if (NULL == name) { | 81 if (nullptr == name) { |
82 return; | 82 return; |
83 } | 83 } |
84 SkPaint paint; | 84 SkPaint paint; |
85 annotate_paint(paint, SkAnnotationKeys::Link_Named_Dest_Key(), name); | 85 annotate_paint(paint, SkAnnotationKeys::Link_Named_Dest_Key(), name); |
86 canvas->drawRect(rect, paint); | 86 canvas->drawRect(rect, paint); |
87 } | 87 } |
OLD | NEW |