Home | History | Annotate | Download | only in core
      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 
     13 class SkData;
     14 class SkDataSet;
     15 class SkStream;
     16 class SkWStream;
     17 struct SkPoint;
     18 
     19 /**
     20  *  Experimental class for annotating draws. Do not use directly yet.
     21  *  Use helper functions at the bottom of this file for now.
     22  */
     23 class SkAnnotation : public SkFlattenable {
     24 public:
     25     enum Flags {
     26         // If set, the associated drawing primitive should not be drawn
     27         kNoDraw_Flag  = 1 << 0,
     28     };
     29 
     30     SkAnnotation(SkDataSet*, uint32_t flags);
     31     virtual ~SkAnnotation();
     32 
     33     uint32_t getFlags() const { return fFlags; }
     34     SkDataSet* getDataSet() const { return fDataSet; }
     35 
     36     bool isNoDraw() const { return SkToBool(fFlags & kNoDraw_Flag); }
     37 
     38     /**
     39      *  Helper for search the annotation's dataset.
     40      */
     41     SkData* find(const char name[]) const;
     42 
     43     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkAnnotation)
     44 
     45 protected:
     46     SkAnnotation(SkFlattenableReadBuffer&);
     47     virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
     48 
     49 private:
     50     SkDataSet*  fDataSet;
     51     uint32_t    fFlags;
     52 
     53     void writeToStream(SkWStream*) const;
     54     void readFromStream(SkStream*);
     55 
     56     typedef SkFlattenable INHERITED;
     57 };
     58 
     59 /**
     60  *  Experimental collection of predefined Keys into the Annotation dictionary
     61  */
     62 class SkAnnotationKeys {
     63 public:
     64     /**
     65      *  Returns the canonical key whose payload is a URL
     66      */
     67     static const char* URL_Key();
     68 
     69     /**
     70      *  Returns the canonical key whose payload is the name of a destination to
     71      *  be defined.
     72      */
     73     static const char* Define_Named_Dest_Key();
     74 
     75     /**
     76      *  Returns the canonical key whose payload is the name of a destination to
     77      *  be linked to.
     78      */
     79     static const char* Link_Named_Dest_Key();
     80 };
     81 
     82 ///////////////////////////////////////////////////////////////////////////////
     83 //
     84 // Experimental helper functions to use Annotations
     85 //
     86 
     87 struct SkRect;
     88 class SkCanvas;
     89 
     90 /**
     91  *  Experimental!
     92  *
     93  *  Annotate the canvas by associating the specified URL with the
     94  *  specified rectangle (in local coordinates, just like drawRect). If the
     95  *  backend of this canvas does not support annotations, this call is
     96  *  safely ignored.
     97  *
     98  *  The caller is responsible for managing its ownership of the SkData.
     99  */
    100 SK_API void SkAnnotateRectWithURL(SkCanvas*, const SkRect&, SkData*);
    101 
    102 /**
    103  *  Experimental!
    104  *
    105  *  Annotate the canvas by associating a name with the specified point.
    106  *
    107  *  If the backend of this canvas does not support annotations, this call is
    108  *  safely ignored.
    109  *
    110  *  The caller is responsible for managing its ownership of the SkData.
    111  */
    112 SK_API void SkAnnotateNamedDestination(SkCanvas*, const SkPoint&, SkData*);
    113 
    114 /**
    115  *  Experimental!
    116  *
    117  *  Annotate the canvas by making the specified rectangle link to a named
    118  *  destination.
    119  *
    120  *  If the backend of this canvas does not support annotations, this call is
    121  *  safely ignored.
    122  *
    123  *  The caller is responsible for managing its ownership of the SkData.
    124  */
    125 SK_API void SkAnnotateLinkToDestination(SkCanvas*, const SkRect&, SkData*);
    126 
    127 
    128 #endif
    129