extern crate alloc;
use crate::annotation::Annotation;
use crate::types::*;
use pdf_syntax::object::dict::keys::*;
use pdf_syntax::object::{Name, Rect};
#[derive(Debug)]
pub struct TextAnnotation {
pub open: bool,
pub icon: alloc::string::String,
}
impl TextAnnotation {
pub fn from_annot(annot: &Annotation<'_>) -> Self {
let dict = annot.dict();
let open = dict.get::<bool>(Name::new(b"Open")).unwrap_or(false);
let icon = dict
.get::<Name>(NAME)
.map(|n| alloc::string::String::from(n.as_str()))
.unwrap_or_else(|| alloc::string::String::from("Note"));
Self { open, icon }
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TextMarkupType {
Highlight,
Underline,
Squiggly,
StrikeOut,
}
#[derive(Debug)]
pub struct TextMarkupAnnotation {
pub markup_type: TextMarkupType,
pub quad_points: Option<QuadPoints>,
}
impl TextMarkupAnnotation {
pub fn from_annot(annot: &Annotation<'_>) -> Option<Self> {
let markup_type = match annot.annotation_type() {
AnnotationType::Highlight => TextMarkupType::Highlight,
AnnotationType::Underline => TextMarkupType::Underline,
AnnotationType::Squiggly => TextMarkupType::Squiggly,
AnnotationType::StrikeOut => TextMarkupType::StrikeOut,
_ => return None,
};
let quad_points = annot.quad_points();
Some(Self {
markup_type,
quad_points,
})
}
}
#[derive(Debug)]
pub struct CaretAnnotation {
pub symbol: alloc::string::String,
pub rd: Option<Rect>,
}
impl CaretAnnotation {
pub fn from_annot(annot: &Annotation<'_>) -> Self {
let dict = annot.dict();
let symbol = dict
.get::<Name>(SY)
.map(|n| alloc::string::String::from(n.as_str()))
.unwrap_or_else(|| alloc::string::String::from("None"));
let rd = dict.get::<Rect>(RD);
Self { symbol, rd }
}
}
#[derive(Debug)]
pub struct PopupAnnotation {
pub open: bool,
}
impl PopupAnnotation {
pub fn from_annot(annot: &Annotation<'_>) -> Self {
let open = annot
.dict()
.get::<bool>(Name::new(b"Open"))
.unwrap_or(false);
Self { open }
}
}