reed@google.com | b0a34d8 | 2012-07-11 19:57:55 +0000 | [diff] [blame] | 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 | |
reed@google.com | 0cd2ac6 | 2013-10-14 20:02:44 +0000 | [diff] [blame] | 11 | #include "SkRefCnt.h" |
reed@google.com | 4979f32 | 2013-10-14 16:49:15 +0000 | [diff] [blame] | 12 | #include "SkString.h" |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame^] | 13 | #include "SkTypes.h" |
reed@google.com | b0a34d8 | 2012-07-11 19:57:55 +0000 | [diff] [blame] | 14 | |
| 15 | class SkData; |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 16 | class SkReadBuffer; |
| 17 | class SkWriteBuffer; |
epoger@google.com | b58772f | 2013-03-08 09:09:10 +0000 | [diff] [blame] | 18 | struct SkPoint; |
reed@google.com | b0a34d8 | 2012-07-11 19:57:55 +0000 | [diff] [blame] | 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 | */ |
reed@google.com | 0cd2ac6 | 2013-10-14 20:02:44 +0000 | [diff] [blame] | 24 | class SkAnnotation : public SkRefCnt { |
reed@google.com | b0a34d8 | 2012-07-11 19:57:55 +0000 | [diff] [blame] | 25 | public: |
reed@google.com | b0a34d8 | 2012-07-11 19:57:55 +0000 | [diff] [blame] | 26 | virtual ~SkAnnotation(); |
| 27 | |
commit-bot@chromium.org | d957984 | 2014-02-27 11:47:36 +0000 | [diff] [blame] | 28 | static SkAnnotation* Create(const char key[], SkData* value) { |
| 29 | return SkNEW_ARGS(SkAnnotation, (key, value)); |
| 30 | } |
| 31 | |
| 32 | static SkAnnotation* Create(SkReadBuffer& buffer) { |
| 33 | return SkNEW_ARGS(SkAnnotation, (buffer)); |
| 34 | } |
| 35 | |
reed@google.com | b0a34d8 | 2012-07-11 19:57:55 +0000 | [diff] [blame] | 36 | /** |
reed@google.com | 4979f32 | 2013-10-14 16:49:15 +0000 | [diff] [blame] | 37 | * Return the data for the specified key, or NULL. |
reed@google.com | b0a34d8 | 2012-07-11 19:57:55 +0000 | [diff] [blame] | 38 | */ |
reed@google.com | 4979f32 | 2013-10-14 16:49:15 +0000 | [diff] [blame] | 39 | SkData* find(const char key[]) const; |
reed@google.com | b0a34d8 | 2012-07-11 19:57:55 +0000 | [diff] [blame] | 40 | |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 41 | void writeToBuffer(SkWriteBuffer&) const; |
reed@google.com | b0a34d8 | 2012-07-11 19:57:55 +0000 | [diff] [blame] | 42 | |
| 43 | private: |
commit-bot@chromium.org | d957984 | 2014-02-27 11:47:36 +0000 | [diff] [blame] | 44 | SkAnnotation(const char key[], SkData* value); |
| 45 | SkAnnotation(SkReadBuffer&); |
| 46 | |
reed@google.com | 4979f32 | 2013-10-14 16:49:15 +0000 | [diff] [blame] | 47 | SkString fKey; |
| 48 | SkData* fData; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 49 | |
reed@google.com | 0cd2ac6 | 2013-10-14 20:02:44 +0000 | [diff] [blame] | 50 | typedef SkRefCnt INHERITED; |
reed@google.com | b0a34d8 | 2012-07-11 19:57:55 +0000 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | /** |
| 54 | * Experimental collection of predefined Keys into the Annotation dictionary |
| 55 | */ |
| 56 | class SkAnnotationKeys { |
| 57 | public: |
| 58 | /** |
| 59 | * Returns the canonical key whose payload is a URL |
| 60 | */ |
| 61 | static const char* URL_Key(); |
epoger@google.com | b58772f | 2013-03-08 09:09:10 +0000 | [diff] [blame] | 62 | |
| 63 | /** |
| 64 | * Returns the canonical key whose payload is the name of a destination to |
| 65 | * be defined. |
| 66 | */ |
| 67 | static const char* Define_Named_Dest_Key(); |
| 68 | |
| 69 | /** |
| 70 | * Returns the canonical key whose payload is the name of a destination to |
| 71 | * be linked to. |
| 72 | */ |
| 73 | static const char* Link_Named_Dest_Key(); |
reed@google.com | b0a34d8 | 2012-07-11 19:57:55 +0000 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | /////////////////////////////////////////////////////////////////////////////// |
| 77 | // |
| 78 | // Experimental helper functions to use Annotations |
| 79 | // |
| 80 | |
| 81 | struct SkRect; |
| 82 | class SkCanvas; |
| 83 | |
| 84 | /** |
| 85 | * Experimental! |
| 86 | * |
| 87 | * Annotate the canvas by associating the specified URL with the |
| 88 | * specified rectangle (in local coordinates, just like drawRect). If the |
| 89 | * backend of this canvas does not support annotations, this call is |
| 90 | * safely ignored. |
| 91 | * |
| 92 | * The caller is responsible for managing its ownership of the SkData. |
| 93 | */ |
| 94 | SK_API void SkAnnotateRectWithURL(SkCanvas*, const SkRect&, SkData*); |
| 95 | |
epoger@google.com | b58772f | 2013-03-08 09:09:10 +0000 | [diff] [blame] | 96 | /** |
| 97 | * Experimental! |
| 98 | * |
| 99 | * Annotate the canvas by associating a name with the specified point. |
| 100 | * |
| 101 | * If the backend of this canvas does not support annotations, this call is |
| 102 | * safely ignored. |
| 103 | * |
| 104 | * The caller is responsible for managing its ownership of the SkData. |
| 105 | */ |
| 106 | SK_API void SkAnnotateNamedDestination(SkCanvas*, const SkPoint&, SkData*); |
| 107 | |
| 108 | /** |
| 109 | * Experimental! |
| 110 | * |
| 111 | * Annotate the canvas by making the specified rectangle link to a named |
| 112 | * destination. |
| 113 | * |
| 114 | * If the backend of this canvas does not support annotations, this call is |
| 115 | * safely ignored. |
| 116 | * |
| 117 | * The caller is responsible for managing its ownership of the SkData. |
| 118 | */ |
| 119 | SK_API void SkAnnotateLinkToDestination(SkCanvas*, const SkRect&, SkData*); |
| 120 | |
| 121 | |
reed@google.com | b0a34d8 | 2012-07-11 19:57:55 +0000 | [diff] [blame] | 122 | #endif |