2 * Copyright 2012 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "SkAnnotation.h"
10 #include "SkReadBuffer.h"
11 #include "SkWriteBuffer.h"
15 SkAnnotation::SkAnnotation(const char key[], SkData* value) : fKey(key) {
17 value = SkData::NewEmpty();
24 SkAnnotation::~SkAnnotation() {
28 SkData* SkAnnotation::find(const char key[]) const {
29 return fKey.equals(key) ? fData : NULL;
32 SkAnnotation::SkAnnotation(SkReadBuffer& buffer) {
33 buffer.readString(&fKey);
34 fData = buffer.readByteArrayAsData();
37 void SkAnnotation::writeToBuffer(SkWriteBuffer& buffer) const {
38 buffer.writeString(fKey.c_str());
39 buffer.writeDataAsByteArray(fData);
42 const char* SkAnnotationKeys::URL_Key() {
43 return "SkAnnotationKey_URL";
46 const char* SkAnnotationKeys::Define_Named_Dest_Key() {
47 return "SkAnnotationKey_Define_Named_Dest";
50 const char* SkAnnotationKeys::Link_Named_Dest_Key() {
51 return "SkAnnotationKey_Link_Named_Dest";
54 ///////////////////////////////////////////////////////////////////////////////
58 static void annotate_paint(SkPaint& paint, const char* key, SkData* value) {
59 paint.setAnnotation(SkNEW_ARGS(SkAnnotation, (key, value)))->unref();
62 void SkAnnotateRectWithURL(SkCanvas* canvas, const SkRect& rect, SkData* value) {
67 annotate_paint(paint, SkAnnotationKeys::URL_Key(), value);
68 canvas->drawRect(rect, paint);
71 void SkAnnotateNamedDestination(SkCanvas* canvas, const SkPoint& point, SkData* name) {
76 annotate_paint(paint, SkAnnotationKeys::Define_Named_Dest_Key(), name);
77 canvas->drawPoint(point.x(), point.y(), paint);
80 void SkAnnotateLinkToDestination(SkCanvas* canvas, const SkRect& rect, SkData* name) {
85 annotate_paint(paint, SkAnnotationKeys::Link_Named_Dest_Key(), name);
86 canvas->drawRect(rect, paint);