blob: 09a6296fbabf7f45b19300d24132f4a35fe21dea [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#include "SkAnnotation.h"
reedf70b5312016-03-04 16:36:20 -08009#include "SkAnnotationKeys.h"
10#include "SkCanvas.h"
bungemand3ebb482015-08-05 13:57:49 -070011#include "SkPoint.h"
reedf70b5312016-03-04 16:36:20 -080012#include "SkRect.h"
reed@google.comb0a34d82012-07-11 19:57:55 +000013
reed@google.comb0a34d82012-07-11 19:57:55 +000014const char* SkAnnotationKeys::URL_Key() {
15 return "SkAnnotationKey_URL";
16};
17
epoger@google.comb58772f2013-03-08 09:09:10 +000018const char* SkAnnotationKeys::Define_Named_Dest_Key() {
19 return "SkAnnotationKey_Define_Named_Dest";
20};
21
22const char* SkAnnotationKeys::Link_Named_Dest_Key() {
23 return "SkAnnotationKey_Link_Named_Dest";
24};
25
reedf70b5312016-03-04 16:36:20 -080026//////////////////////////////////////////////////////////////////////////////////////////////////
epoger@google.comb58772f2013-03-08 09:09:10 +000027
reed@google.comb0a34d82012-07-11 19:57:55 +000028void SkAnnotateRectWithURL(SkCanvas* canvas, const SkRect& rect, SkData* value) {
halcanary96fcdcc2015-08-27 07:41:13 -070029 if (nullptr == value) {
reed@google.comb0a34d82012-07-11 19:57:55 +000030 return;
31 }
reedf70b5312016-03-04 16:36:20 -080032 canvas->drawAnnotation(rect, SkAnnotationKeys::URL_Key(), value);
epoger@google.comb58772f2013-03-08 09:09:10 +000033}
epoger@google.com812b6f52013-03-06 00:47:22 +000034
epoger@google.comb58772f2013-03-08 09:09:10 +000035void SkAnnotateNamedDestination(SkCanvas* canvas, const SkPoint& point, SkData* name) {
halcanary96fcdcc2015-08-27 07:41:13 -070036 if (nullptr == name) {
epoger@google.comb58772f2013-03-08 09:09:10 +000037 return;
38 }
reedf70b5312016-03-04 16:36:20 -080039 const SkRect rect = SkRect::MakeXYWH(point.x(), point.y(), 0, 0);
40 canvas->drawAnnotation(rect, SkAnnotationKeys::Define_Named_Dest_Key(), name);
epoger@google.comb58772f2013-03-08 09:09:10 +000041}
42
43void SkAnnotateLinkToDestination(SkCanvas* canvas, const SkRect& rect, SkData* name) {
halcanary96fcdcc2015-08-27 07:41:13 -070044 if (nullptr == name) {
epoger@google.comb58772f2013-03-08 09:09:10 +000045 return;
46 }
reedf70b5312016-03-04 16:36:20 -080047 canvas->drawAnnotation(rect, SkAnnotationKeys::Link_Named_Dest_Key(), name);
reed@google.comb0a34d82012-07-11 19:57:55 +000048}