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 "SkFlattenable.h" 12 13class SkData; 14class SkDataSet; 15class SkStream; 16class SkWStream; 17 18/** 19 * Experimental class for annotating draws. Do not use directly yet. 20 * Use helper functions at the bottom of this file for now. 21 */ 22class SkAnnotation : public SkFlattenable { 23public: 24 enum Flags { 25 // If set, the associated drawing primitive should not be drawn 26 kNoDraw_Flag = 1 << 0, 27 }; 28 29 SkAnnotation(SkDataSet*, uint32_t flags); 30 virtual ~SkAnnotation(); 31 32 uint32_t getFlags() const { return fFlags; } 33 SkDataSet* getDataSet() const { return fDataSet; } 34 35 bool isNoDraw() const { return SkToBool(fFlags & kNoDraw_Flag); } 36 37 /** 38 * Helper for search the annotation's dataset. 39 */ 40 SkData* find(const char name[]) const; 41 42 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkAnnotation) 43 44protected: 45 SkAnnotation(SkFlattenableReadBuffer&); 46 virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE; 47 48private: 49 SkDataSet* fDataSet; 50 uint32_t fFlags; 51 52 void writeToStream(SkWStream*) const; 53 void readFromStream(SkStream*); 54 55 typedef SkFlattenable INHERITED; 56}; 57 58/** 59 * Experimental collection of predefined Keys into the Annotation dictionary 60 */ 61class SkAnnotationKeys { 62public: 63 /** 64 * Returns the canonical key whose payload is a URL 65 */ 66 static const char* URL_Key(); 67}; 68 69/////////////////////////////////////////////////////////////////////////////// 70// 71// Experimental helper functions to use Annotations 72// 73 74struct SkRect; 75class SkCanvas; 76 77/** 78 * Experimental! 79 * 80 * Annotate the canvas by associating the specified URL with the 81 * specified rectangle (in local coordinates, just like drawRect). If the 82 * backend of this canvas does not support annotations, this call is 83 * safely ignored. 84 * 85 * The caller is responsible for managing its ownership of the SkData. 86 */ 87SK_API void SkAnnotateRectWithURL(SkCanvas*, const SkRect&, SkData*); 88 89#endif 90