1extern crate alloc;
10
11use crate::annotation::Annotation;
12use crate::types::*;
13use pdf_syntax::object::dict::keys::*;
14use pdf_syntax::object::{Name, Rect};
15
16#[derive(Debug)]
18pub struct TextAnnotation {
19 pub open: bool,
21 pub icon: alloc::string::String,
23}
24
25impl TextAnnotation {
26 pub fn from_annot(annot: &Annotation<'_>) -> Self {
28 let dict = annot.dict();
29 let open = dict.get::<bool>(Name::new(b"Open")).unwrap_or(false);
30 let icon = dict
31 .get::<Name>(NAME)
32 .map(|n| alloc::string::String::from(n.as_str()))
33 .unwrap_or_else(|| alloc::string::String::from("Note"));
34 Self { open, icon }
35 }
36}
37
38#[derive(Debug, Clone, Copy, PartialEq, Eq)]
40pub enum TextMarkupType {
41 Highlight,
43 Underline,
45 Squiggly,
47 StrikeOut,
49}
50
51#[derive(Debug)]
53pub struct TextMarkupAnnotation {
54 pub markup_type: TextMarkupType,
56 pub quad_points: Option<QuadPoints>,
58}
59
60impl TextMarkupAnnotation {
61 pub fn from_annot(annot: &Annotation<'_>) -> Option<Self> {
63 let markup_type = match annot.annotation_type() {
64 AnnotationType::Highlight => TextMarkupType::Highlight,
65 AnnotationType::Underline => TextMarkupType::Underline,
66 AnnotationType::Squiggly => TextMarkupType::Squiggly,
67 AnnotationType::StrikeOut => TextMarkupType::StrikeOut,
68 _ => return None,
69 };
70 let quad_points = annot.quad_points();
71 Some(Self {
72 markup_type,
73 quad_points,
74 })
75 }
76}
77
78#[derive(Debug)]
80pub struct CaretAnnotation {
81 pub symbol: alloc::string::String,
83 pub rd: Option<Rect>,
85}
86
87impl CaretAnnotation {
88 pub fn from_annot(annot: &Annotation<'_>) -> Self {
90 let dict = annot.dict();
91 let symbol = dict
92 .get::<Name>(SY)
93 .map(|n| alloc::string::String::from(n.as_str()))
94 .unwrap_or_else(|| alloc::string::String::from("None"));
95 let rd = dict.get::<Rect>(RD);
96 Self { symbol, rd }
97 }
98}
99
100#[derive(Debug)]
102pub struct PopupAnnotation {
103 pub open: bool,
105}
106
107impl PopupAnnotation {
108 pub fn from_annot(annot: &Annotation<'_>) -> Self {
110 let open = annot
111 .dict()
112 .get::<bool>(Name::new(b"Open"))
113 .unwrap_or(false);
114 Self { open }
115 }
116}