aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkAnnotation.cpp
blob: 62f865d15fbf728fc8882c5cdfc2eb1490623662 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
 * Copyright 2012 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "SkAnnotation.h"
#include "SkDataSet.h"
#include "SkFlattenableBuffers.h"
#include "SkStream.h"

SkAnnotation::SkAnnotation(SkDataSet* data, uint32_t flags) {
    if (NULL == data) {
        data = SkDataSet::NewEmpty();
    } else {
        data->ref();
    }
    fDataSet = data;
    fFlags = flags;
}

SkAnnotation::~SkAnnotation() {
    fDataSet->unref();
}

SkData* SkAnnotation::find(const char name[]) const {
    return fDataSet->find(name);
}

SkAnnotation::SkAnnotation(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {
    fFlags = buffer.readUInt();
    fDataSet = buffer.readFlattenableT<SkDataSet>();
}

void SkAnnotation::flatten(SkFlattenableWriteBuffer& buffer) const {
    buffer.writeUInt(fFlags);
    buffer.writeFlattenable(fDataSet);
}

SK_DEFINE_FLATTENABLE_REGISTRAR(SkAnnotation)

const char* SkAnnotationKeys::URL_Key() {
    return "SkAnnotationKey_URL";
};

///////////////////////////////////////////////////////////////////////////////

#include "SkCanvas.h"

void SkAnnotateRectWithURL(SkCanvas* canvas, const SkRect& rect, SkData* value) {
    if (NULL == value) {
        return;
    }

    const char* key = SkAnnotationKeys::URL_Key();
    SkAutoTUnref<SkDataSet> dataset(SkNEW_ARGS(SkDataSet, (key, value)));
    SkAnnotation* ann = SkNEW_ARGS(SkAnnotation, (dataset,
                                                  SkAnnotation::kNoDraw_Flag));

    SkPaint paint;
    paint.setAnnotation(ann)->unref();
    SkASSERT(paint.isNoDrawAnnotation());

    canvas->drawRect(rect, paint);
}