1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/core/SkAnnotation.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,87 @@ 1.4 +/* 1.5 + * Copyright 2012 Google Inc. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license that can be 1.8 + * found in the LICENSE file. 1.9 + */ 1.10 + 1.11 +#include "SkAnnotation.h" 1.12 +#include "SkData.h" 1.13 +#include "SkReadBuffer.h" 1.14 +#include "SkWriteBuffer.h" 1.15 +#include "SkPoint.h" 1.16 +#include "SkStream.h" 1.17 + 1.18 +SkAnnotation::SkAnnotation(const char key[], SkData* value) : fKey(key) { 1.19 + if (NULL == value) { 1.20 + value = SkData::NewEmpty(); 1.21 + } else { 1.22 + value->ref(); 1.23 + } 1.24 + fData = value; 1.25 +} 1.26 + 1.27 +SkAnnotation::~SkAnnotation() { 1.28 + fData->unref(); 1.29 +} 1.30 + 1.31 +SkData* SkAnnotation::find(const char key[]) const { 1.32 + return fKey.equals(key) ? fData : NULL; 1.33 +} 1.34 + 1.35 +SkAnnotation::SkAnnotation(SkReadBuffer& buffer) { 1.36 + buffer.readString(&fKey); 1.37 + fData = buffer.readByteArrayAsData(); 1.38 +} 1.39 + 1.40 +void SkAnnotation::writeToBuffer(SkWriteBuffer& buffer) const { 1.41 + buffer.writeString(fKey.c_str()); 1.42 + buffer.writeDataAsByteArray(fData); 1.43 +} 1.44 + 1.45 +const char* SkAnnotationKeys::URL_Key() { 1.46 + return "SkAnnotationKey_URL"; 1.47 +}; 1.48 + 1.49 +const char* SkAnnotationKeys::Define_Named_Dest_Key() { 1.50 + return "SkAnnotationKey_Define_Named_Dest"; 1.51 +}; 1.52 + 1.53 +const char* SkAnnotationKeys::Link_Named_Dest_Key() { 1.54 + return "SkAnnotationKey_Link_Named_Dest"; 1.55 +}; 1.56 + 1.57 +/////////////////////////////////////////////////////////////////////////////// 1.58 + 1.59 +#include "SkCanvas.h" 1.60 + 1.61 +static void annotate_paint(SkPaint& paint, const char* key, SkData* value) { 1.62 + paint.setAnnotation(SkAnnotation::Create(key, value))->unref(); 1.63 +} 1.64 + 1.65 +void SkAnnotateRectWithURL(SkCanvas* canvas, const SkRect& rect, SkData* value) { 1.66 + if (NULL == value) { 1.67 + return; 1.68 + } 1.69 + SkPaint paint; 1.70 + annotate_paint(paint, SkAnnotationKeys::URL_Key(), value); 1.71 + canvas->drawRect(rect, paint); 1.72 +} 1.73 + 1.74 +void SkAnnotateNamedDestination(SkCanvas* canvas, const SkPoint& point, SkData* name) { 1.75 + if (NULL == name) { 1.76 + return; 1.77 + } 1.78 + SkPaint paint; 1.79 + annotate_paint(paint, SkAnnotationKeys::Define_Named_Dest_Key(), name); 1.80 + canvas->drawPoint(point.x(), point.y(), paint); 1.81 +} 1.82 + 1.83 +void SkAnnotateLinkToDestination(SkCanvas* canvas, const SkRect& rect, SkData* name) { 1.84 + if (NULL == name) { 1.85 + return; 1.86 + } 1.87 + SkPaint paint; 1.88 + annotate_paint(paint, SkAnnotationKeys::Link_Named_Dest_Key(), name); 1.89 + canvas->drawRect(rect, paint); 1.90 +}