| 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 "SkFlattenableBuffers.h" | 10 #include "SkFlattenableBuffers.h" |
| 11 #include "SkPoint.h" | 11 #include "SkPoint.h" |
| 12 #include "SkStream.h" | 12 #include "SkStream.h" |
| 13 | 13 |
| 14 SkAnnotation::SkAnnotation(const char key[], SkData* value, uint32_t flags) | 14 SkAnnotation::SkAnnotation(const char key[], SkData* value) : fKey(key) { |
| 15 : fKey(key) { | |
| 16 if (NULL == value) { | 15 if (NULL == value) { |
| 17 value = SkData::NewEmpty(); | 16 value = SkData::NewEmpty(); |
| 18 } else { | 17 } else { |
| 19 value->ref(); | 18 value->ref(); |
| 20 } | 19 } |
| 21 fData = value; | 20 fData = value; |
| 22 fFlags = flags; | |
| 23 } | 21 } |
| 24 | 22 |
| 25 SkAnnotation::~SkAnnotation() { | 23 SkAnnotation::~SkAnnotation() { |
| 26 fData->unref(); | 24 fData->unref(); |
| 27 } | 25 } |
| 28 | 26 |
| 29 SkData* SkAnnotation::find(const char key[]) const { | 27 SkData* SkAnnotation::find(const char key[]) const { |
| 30 return fKey.equals(key) ? fData : NULL; | 28 return fKey.equals(key) ? fData : NULL; |
| 31 } | 29 } |
| 32 | 30 |
| 33 SkAnnotation::SkAnnotation(SkFlattenableReadBuffer& buffer) { | 31 SkAnnotation::SkAnnotation(SkFlattenableReadBuffer& buffer) { |
| 34 fFlags = buffer.readUInt(); | |
| 35 buffer.readString(&fKey); | 32 buffer.readString(&fKey); |
| 36 fData = buffer.readByteArrayAsData(); | 33 fData = buffer.readByteArrayAsData(); |
| 37 } | 34 } |
| 38 | 35 |
| 39 void SkAnnotation::writeToBuffer(SkFlattenableWriteBuffer& buffer) const { | 36 void SkAnnotation::writeToBuffer(SkFlattenableWriteBuffer& buffer) const { |
| 40 buffer.writeUInt(fFlags); | |
| 41 buffer.writeString(fKey.c_str()); | 37 buffer.writeString(fKey.c_str()); |
| 42 buffer.writeDataAsByteArray(fData); | 38 buffer.writeDataAsByteArray(fData); |
| 43 } | 39 } |
| 44 | 40 |
| 45 const char* SkAnnotationKeys::URL_Key() { | 41 const char* SkAnnotationKeys::URL_Key() { |
| 46 return "SkAnnotationKey_URL"; | 42 return "SkAnnotationKey_URL"; |
| 47 }; | 43 }; |
| 48 | 44 |
| 49 const char* SkAnnotationKeys::Define_Named_Dest_Key() { | 45 const char* SkAnnotationKeys::Define_Named_Dest_Key() { |
| 50 return "SkAnnotationKey_Define_Named_Dest"; | 46 return "SkAnnotationKey_Define_Named_Dest"; |
| 51 }; | 47 }; |
| 52 | 48 |
| 53 const char* SkAnnotationKeys::Link_Named_Dest_Key() { | 49 const char* SkAnnotationKeys::Link_Named_Dest_Key() { |
| 54 return "SkAnnotationKey_Link_Named_Dest"; | 50 return "SkAnnotationKey_Link_Named_Dest"; |
| 55 }; | 51 }; |
| 56 | 52 |
| 57 /////////////////////////////////////////////////////////////////////////////// | 53 /////////////////////////////////////////////////////////////////////////////// |
| 58 | 54 |
| 59 #include "SkCanvas.h" | 55 #include "SkCanvas.h" |
| 60 | 56 |
| 61 static void annotate_paint(SkPaint& paint, const char* key, SkData* value) { | 57 static void annotate_paint(SkPaint& paint, const char* key, SkData* value) { |
| 62 SkAnnotation* ann = SkNEW_ARGS(SkAnnotation, (key, value, | 58 paint.setAnnotation(SkNEW_ARGS(SkAnnotation, (key, value)))->unref(); |
| 63 SkAnnotation::kNoDraw_Flag)); | |
| 64 | |
| 65 paint.setAnnotation(ann)->unref(); | |
| 66 SkASSERT(paint.isNoDrawAnnotation()); | |
| 67 } | 59 } |
| 68 | 60 |
| 69 void SkAnnotateRectWithURL(SkCanvas* canvas, const SkRect& rect, SkData* value)
{ | 61 void SkAnnotateRectWithURL(SkCanvas* canvas, const SkRect& rect, SkData* value)
{ |
| 70 if (NULL == value) { | 62 if (NULL == value) { |
| 71 return; | 63 return; |
| 72 } | 64 } |
| 73 SkPaint paint; | 65 SkPaint paint; |
| 74 annotate_paint(paint, SkAnnotationKeys::URL_Key(), value); | 66 annotate_paint(paint, SkAnnotationKeys::URL_Key(), value); |
| 75 canvas->drawRect(rect, paint); | 67 canvas->drawRect(rect, paint); |
| 76 } | 68 } |
| 77 | 69 |
| 78 void SkAnnotateNamedDestination(SkCanvas* canvas, const SkPoint& point, SkData*
name) { | 70 void SkAnnotateNamedDestination(SkCanvas* canvas, const SkPoint& point, SkData*
name) { |
| 79 if (NULL == name) { | 71 if (NULL == name) { |
| 80 return; | 72 return; |
| 81 } | 73 } |
| 82 SkPaint paint; | 74 SkPaint paint; |
| 83 annotate_paint(paint, SkAnnotationKeys::Define_Named_Dest_Key(), name); | 75 annotate_paint(paint, SkAnnotationKeys::Define_Named_Dest_Key(), name); |
| 84 canvas->drawPoint(point.x(), point.y(), paint); | 76 canvas->drawPoint(point.x(), point.y(), paint); |
| 85 } | 77 } |
| 86 | 78 |
| 87 void SkAnnotateLinkToDestination(SkCanvas* canvas, const SkRect& rect, SkData* n
ame) { | 79 void SkAnnotateLinkToDestination(SkCanvas* canvas, const SkRect& rect, SkData* n
ame) { |
| 88 if (NULL == name) { | 80 if (NULL == name) { |
| 89 return; | 81 return; |
| 90 } | 82 } |
| 91 SkPaint paint; | 83 SkPaint paint; |
| 92 annotate_paint(paint, SkAnnotationKeys::Link_Named_Dest_Key(), name); | 84 annotate_paint(paint, SkAnnotationKeys::Link_Named_Dest_Key(), name); |
| 93 canvas->drawRect(rect, paint); | 85 canvas->drawRect(rect, paint); |
| 94 } | 86 } |
| OLD | NEW |