reed@google.com | b0a34d8 | 2012-07-11 19:57:55 +0000 | [diff] [blame] | 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 | #include "SkAnnotation.h" |
reed | f70b531 | 2016-03-04 16:36:20 -0800 | [diff] [blame] | 9 | #include "SkAnnotationKeys.h" |
| 10 | #include "SkCanvas.h" |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 11 | #include "SkPoint.h" |
reed | f70b531 | 2016-03-04 16:36:20 -0800 | [diff] [blame] | 12 | #include "SkRect.h" |
reed@google.com | b0a34d8 | 2012-07-11 19:57:55 +0000 | [diff] [blame] | 13 | |
reed@google.com | b0a34d8 | 2012-07-11 19:57:55 +0000 | [diff] [blame] | 14 | const char* SkAnnotationKeys::URL_Key() { |
| 15 | return "SkAnnotationKey_URL"; |
| 16 | }; |
| 17 | |
epoger@google.com | b58772f | 2013-03-08 09:09:10 +0000 | [diff] [blame] | 18 | const char* SkAnnotationKeys::Define_Named_Dest_Key() { |
| 19 | return "SkAnnotationKey_Define_Named_Dest"; |
| 20 | }; |
| 21 | |
| 22 | const char* SkAnnotationKeys::Link_Named_Dest_Key() { |
| 23 | return "SkAnnotationKey_Link_Named_Dest"; |
| 24 | }; |
| 25 | |
reed | f70b531 | 2016-03-04 16:36:20 -0800 | [diff] [blame] | 26 | ////////////////////////////////////////////////////////////////////////////////////////////////// |
epoger@google.com | b58772f | 2013-03-08 09:09:10 +0000 | [diff] [blame] | 27 | |
reed@google.com | b0a34d8 | 2012-07-11 19:57:55 +0000 | [diff] [blame] | 28 | void SkAnnotateRectWithURL(SkCanvas* canvas, const SkRect& rect, SkData* value) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 29 | if (nullptr == value) { |
reed@google.com | b0a34d8 | 2012-07-11 19:57:55 +0000 | [diff] [blame] | 30 | return; |
| 31 | } |
reed | f70b531 | 2016-03-04 16:36:20 -0800 | [diff] [blame] | 32 | canvas->drawAnnotation(rect, SkAnnotationKeys::URL_Key(), value); |
epoger@google.com | b58772f | 2013-03-08 09:09:10 +0000 | [diff] [blame] | 33 | } |
epoger@google.com | 812b6f5 | 2013-03-06 00:47:22 +0000 | [diff] [blame] | 34 | |
epoger@google.com | b58772f | 2013-03-08 09:09:10 +0000 | [diff] [blame] | 35 | void SkAnnotateNamedDestination(SkCanvas* canvas, const SkPoint& point, SkData* name) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 36 | if (nullptr == name) { |
epoger@google.com | b58772f | 2013-03-08 09:09:10 +0000 | [diff] [blame] | 37 | return; |
| 38 | } |
reed | f70b531 | 2016-03-04 16:36:20 -0800 | [diff] [blame] | 39 | const SkRect rect = SkRect::MakeXYWH(point.x(), point.y(), 0, 0); |
| 40 | canvas->drawAnnotation(rect, SkAnnotationKeys::Define_Named_Dest_Key(), name); |
epoger@google.com | b58772f | 2013-03-08 09:09:10 +0000 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | void SkAnnotateLinkToDestination(SkCanvas* canvas, const SkRect& rect, SkData* name) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 44 | if (nullptr == name) { |
epoger@google.com | b58772f | 2013-03-08 09:09:10 +0000 | [diff] [blame] | 45 | return; |
| 46 | } |
reed | f70b531 | 2016-03-04 16:36:20 -0800 | [diff] [blame] | 47 | canvas->drawAnnotation(rect, SkAnnotationKeys::Link_Named_Dest_Key(), name); |
reed@google.com | b0a34d8 | 2012-07-11 19:57:55 +0000 | [diff] [blame] | 48 | } |