use std::rc::Rc;
use super::geometry::{PaintClip, PaintRect, PaintTransform, PaintTranslation};
#[derive(Debug, Clone, PartialEq)]
pub(crate) struct LinkAnnotation {
pub(crate) rect: PaintRect,
pub(crate) target: Rc<str>,
}
impl LinkAnnotation {
pub(crate) fn from_paint_rect(rect: PaintRect, target: impl Into<Rc<str>>) -> Self {
Self {
rect,
target: target.into(),
}
}
pub(crate) fn x(&self) -> f32 {
self.rect.origin.x
}
pub(crate) fn y(&self) -> f32 {
self.rect.origin.y
}
pub(crate) fn width(&self) -> f32 {
self.rect.size.width
}
pub(crate) fn height(&self) -> f32 {
self.rect.size.height
}
pub(crate) fn paint_rect(&self) -> PaintRect {
self.rect
}
pub(crate) fn translated(mut self, offset: PaintTranslation) -> Self {
self.rect = offset.transform_rect(&self.rect);
self
}
pub(in crate::document) fn transformed(&self, transform: PaintTransform) -> Self {
let clip = transform.apply_clip_to_aabb(PaintClip::from_paint_rect(self.rect));
Self::from_paint_rect(clip.paint_rect(), Rc::clone(&self.target))
}
pub(in crate::document) fn clipped_to(self, clip: PaintClip) -> Option<Self> {
let clipped = PaintClip::from_paint_rect(self.rect).intersect(clip)?;
Some(Self::from_paint_rect(clipped.paint_rect(), self.target))
}
}
pub(crate) type RenderedLink = LinkAnnotation;