skia_safe/core/
annotation.rs

1use crate::{Canvas, Data, Point, Rect};
2
3pub mod annotate {
4    use crate::prelude::*;
5    use crate::{Canvas, Data, Point, Rect};
6    use skia_bindings::{
7        SkAnnotateLinkToDestination, SkAnnotateNamedDestination, SkAnnotateRectWithURL,
8    };
9
10    pub fn rect_with_url(canvas: &Canvas, rect: impl AsRef<Rect>, data: &Data) {
11        unsafe {
12            SkAnnotateRectWithURL(
13                canvas.native_mut(),
14                rect.as_ref().native(),
15                data.native_mut_force(),
16            )
17        }
18    }
19
20    pub fn named_destination(canvas: &Canvas, point: impl Into<Point>, data: &Data) {
21        unsafe {
22            SkAnnotateNamedDestination(
23                canvas.native_mut(),
24                point.into().native(),
25                data.native_mut_force(),
26            )
27        }
28    }
29
30    pub fn link_to_destination(canvas: &Canvas, rect: impl AsRef<Rect>, data: &Data) {
31        unsafe {
32            SkAnnotateLinkToDestination(
33                canvas.native_mut(),
34                rect.as_ref().native(),
35                data.native_mut_force(),
36            )
37        }
38    }
39}
40
41impl Canvas {
42    // TODO: accept str or the Url type from the url crate?
43    pub fn annotate_rect_with_url(&self, rect: impl AsRef<Rect>, data: &Data) -> &Self {
44        annotate::rect_with_url(self, rect, data);
45        self
46    }
47
48    // TODO: is data a string here, and if so, of what encoding?
49    pub fn annotate_named_destination(&self, point: impl Into<Point>, data: &Data) -> &Self {
50        annotate::named_destination(self, point, data);
51        self
52    }
53
54    // TODO: use str?
55    pub fn annotate_link_to_destination(&self, rect: impl AsRef<Rect>, data: &Data) -> &Self {
56        annotate::link_to_destination(self, rect, data);
57        self
58    }
59}