1 /* 2 * Copyright 2012 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef SkAnnotation_DEFINED 9 #define SkAnnotation_DEFINED 10 11 #include "SkRefCnt.h" 12 #include "SkString.h" 13 #include "SkTypes.h" 14 15 class SkData; 16 class SkReadBuffer; 17 class SkWriteBuffer; 18 struct SkPoint; 19 20 /** 21 * Experimental class for annotating draws. Do not use directly yet. 22 * Use helper functions at the bottom of this file for now. 23 */ 24 class SkAnnotation : public SkRefCnt { 25 public: 26 virtual ~SkAnnotation(); 27 Create(const char key[],SkData * value)28 static SkAnnotation* Create(const char key[], SkData* value) { 29 return new SkAnnotation(key, value); 30 } 31 Create(SkReadBuffer & buffer)32 static SkAnnotation* Create(SkReadBuffer& buffer) { return new SkAnnotation(buffer); } 33 34 /** 35 * Return the data for the specified key, or NULL. 36 */ 37 SkData* find(const char key[]) const; 38 39 void writeToBuffer(SkWriteBuffer&) const; 40 41 private: 42 SkAnnotation(const char key[], SkData* value); 43 SkAnnotation(SkReadBuffer&); 44 45 SkString fKey; 46 SkData* fData; 47 48 typedef SkRefCnt INHERITED; 49 }; 50 51 /** 52 * Experimental collection of predefined Keys into the Annotation dictionary 53 */ 54 class SkAnnotationKeys { 55 public: 56 /** 57 * Returns the canonical key whose payload is a URL 58 */ 59 static const char* URL_Key(); 60 61 /** 62 * Returns the canonical key whose payload is the name of a destination to 63 * be defined. 64 */ 65 static const char* Define_Named_Dest_Key(); 66 67 /** 68 * Returns the canonical key whose payload is the name of a destination to 69 * be linked to. 70 */ 71 static const char* Link_Named_Dest_Key(); 72 }; 73 74 /////////////////////////////////////////////////////////////////////////////// 75 // 76 // Experimental helper functions to use Annotations 77 // 78 79 struct SkRect; 80 class SkCanvas; 81 82 /** 83 * Experimental! 84 * 85 * Annotate the canvas by associating the specified URL with the 86 * specified rectangle (in local coordinates, just like drawRect). If the 87 * backend of this canvas does not support annotations, this call is 88 * safely ignored. 89 * 90 * The caller is responsible for managing its ownership of the SkData. 91 */ 92 SK_API void SkAnnotateRectWithURL(SkCanvas*, const SkRect&, SkData*); 93 94 /** 95 * Experimental! 96 * 97 * Annotate the canvas by associating a name with the specified point. 98 * 99 * If the backend of this canvas does not support annotations, this call is 100 * safely ignored. 101 * 102 * The caller is responsible for managing its ownership of the SkData. 103 */ 104 SK_API void SkAnnotateNamedDestination(SkCanvas*, const SkPoint&, SkData*); 105 106 /** 107 * Experimental! 108 * 109 * Annotate the canvas by making the specified rectangle link to a named 110 * destination. 111 * 112 * If the backend of this canvas does not support annotations, this call is 113 * safely ignored. 114 * 115 * The caller is responsible for managing its ownership of the SkData. 116 */ 117 SK_API void SkAnnotateLinkToDestination(SkCanvas*, const SkRect&, SkData*); 118 119 120 #endif 121