blob: 62c844a3cae900c4e5d18f6e55ccad6f58a3f28d [file] [log] [blame]
reed@google.comb0a34d82012-07-11 19:57:55 +00001/*
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.com0cd2ac62013-10-14 20:02:44 +000011#include "SkRefCnt.h"
reed@google.com4979f322013-10-14 16:49:15 +000012#include "SkString.h"
bungemand3ebb482015-08-05 13:57:49 -070013#include "SkTypes.h"
reed@google.comb0a34d82012-07-11 19:57:55 +000014
15class SkData;
commit-bot@chromium.org8b0e8ac2014-01-30 18:58:24 +000016class SkReadBuffer;
17class SkWriteBuffer;
epoger@google.comb58772f2013-03-08 09:09:10 +000018struct SkPoint;
reed@google.comb0a34d82012-07-11 19:57:55 +000019
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.com0cd2ac62013-10-14 20:02:44 +000024class SkAnnotation : public SkRefCnt {
reed@google.comb0a34d82012-07-11 19:57:55 +000025public:
reed@google.comb0a34d82012-07-11 19:57:55 +000026 virtual ~SkAnnotation();
27
commit-bot@chromium.orgd9579842014-02-27 11:47:36 +000028 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.comb0a34d82012-07-11 19:57:55 +000036 /**
reed@google.com4979f322013-10-14 16:49:15 +000037 * Return the data for the specified key, or NULL.
reed@google.comb0a34d82012-07-11 19:57:55 +000038 */
reed@google.com4979f322013-10-14 16:49:15 +000039 SkData* find(const char key[]) const;
reed@google.comb0a34d82012-07-11 19:57:55 +000040
commit-bot@chromium.org8b0e8ac2014-01-30 18:58:24 +000041 void writeToBuffer(SkWriteBuffer&) const;
reed@google.comb0a34d82012-07-11 19:57:55 +000042
43private:
commit-bot@chromium.orgd9579842014-02-27 11:47:36 +000044 SkAnnotation(const char key[], SkData* value);
45 SkAnnotation(SkReadBuffer&);
46
reed@google.com4979f322013-10-14 16:49:15 +000047 SkString fKey;
48 SkData* fData;
rmistry@google.comfbfcd562012-08-23 18:09:54 +000049
reed@google.com0cd2ac62013-10-14 20:02:44 +000050 typedef SkRefCnt INHERITED;
reed@google.comb0a34d82012-07-11 19:57:55 +000051};
52
53/**
54 * Experimental collection of predefined Keys into the Annotation dictionary
55 */
56class SkAnnotationKeys {
57public:
58 /**
59 * Returns the canonical key whose payload is a URL
60 */
61 static const char* URL_Key();
epoger@google.comb58772f2013-03-08 09:09:10 +000062
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.comb0a34d82012-07-11 19:57:55 +000074};
75
76///////////////////////////////////////////////////////////////////////////////
77//
78// Experimental helper functions to use Annotations
79//
80
81struct SkRect;
82class 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 */
94SK_API void SkAnnotateRectWithURL(SkCanvas*, const SkRect&, SkData*);
95
epoger@google.comb58772f2013-03-08 09:09:10 +000096/**
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 */
106SK_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 */
119SK_API void SkAnnotateLinkToDestination(SkCanvas*, const SkRect&, SkData*);
120
121
reed@google.comb0a34d82012-07-11 19:57:55 +0000122#endif