1use crate::types::{PdfLineStyle, PdfTextAnnotationIconType};
2
3macro_rules! pdf_string_enum {
4 ($(#[$meta:meta])* pub enum $name:ident { $($variant:ident => $raw:literal),+ $(,)? }) => {
5 $(#[$meta])*
6 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
7 pub enum $name {
8 $($variant),+
9 }
10
11 impl $name {
12 #[must_use]
13 pub const fn name(self) -> &'static str {
14 match self {
15 $(Self::$variant => $raw),+
16 }
17 }
18
19 #[must_use]
20 pub fn from_name(raw: &str) -> Option<Self> {
21 match raw {
22 $($raw => Some(Self::$variant),)+
23 _ => None,
24 }
25 }
26 }
27 };
28}
29
30pdf_string_enum! {
31 pub enum PdfAnnotationKey {
32 AdditionalActions => "/AA",
33 AppearanceDictionary => "/AP",
34 AppearanceState => "/AS",
35 DefaultAppearance => "/DA",
36 Destination => "/Dest",
37 Flags => "/F",
38 HighlightingMode => "/H",
39 IconName => "/Name",
40 InkList => "/InkList",
41 InteriorColor => "/IC",
42 LineEndingStyles => "/LE",
43 LinePoints => "/L",
44 Name => "/NM",
45 Open => "/Open",
46 Page => "/P",
47 Parent => "/Parent",
48 Popup => "/Popup",
49 QuadPoints => "/QuadPoints",
50 Quadding => "/Q",
51 TextLabel => "/T",
52 WidgetAppearanceDictionary => "/MK",
53 WidgetBackgroundColor => "/BG",
54 WidgetBorderColor => "/BC",
55 WidgetCaption => "/CA",
56 WidgetDefaultValue => "/DV",
57 WidgetDownCaption => "/AC",
58 WidgetFieldFlags => "/Ff",
59 WidgetFieldType => "/FT",
60 WidgetMaxLen => "/MaxLen",
61 WidgetOptions => "/Opt",
62 WidgetRolloverCaption => "/RC",
63 WidgetRotation => "/R",
64 WidgetTextLabelUi => "/TU",
65 WidgetValue => "/V"
66 }
67}
68
69pdf_string_enum! {
70 pub enum PdfAnnotationHighlightingMode {
71 None => "/N",
72 Invert => "/I",
73 Outline => "/O",
74 Push => "/P"
75 }
76}
77
78pdf_string_enum! {
79 pub enum PdfAnnotationLineEndingStyle {
80 None => "/None",
81 Square => "/Square",
82 Circle => "/Circle",
83 Diamond => "/Diamond",
84 OpenArrow => "/OpenArrow",
85 ClosedArrow => "/ClosedArrow"
86 }
87}
88
89impl PdfAnnotationLineEndingStyle {
90 #[must_use]
91 pub const fn from_line_style(style: PdfLineStyle) -> Self {
92 match style {
93 PdfLineStyle::None => Self::None,
94 PdfLineStyle::Square => Self::Square,
95 PdfLineStyle::Circle => Self::Circle,
96 PdfLineStyle::Diamond => Self::Diamond,
97 PdfLineStyle::OpenArrow => Self::OpenArrow,
98 PdfLineStyle::ClosedArrow => Self::ClosedArrow,
99 }
100 }
101
102 #[must_use]
103 pub const fn line_style(self) -> PdfLineStyle {
104 match self {
105 Self::None => PdfLineStyle::None,
106 Self::Square => PdfLineStyle::Square,
107 Self::Circle => PdfLineStyle::Circle,
108 Self::Diamond => PdfLineStyle::Diamond,
109 Self::OpenArrow => PdfLineStyle::OpenArrow,
110 Self::ClosedArrow => PdfLineStyle::ClosedArrow,
111 }
112 }
113}
114
115pdf_string_enum! {
116 pub enum PdfAnnotationSubtype {
117 Text => "/Text",
118 Link => "/Link",
119 FreeText => "/FreeText",
120 Line => "/Line",
121 Square => "/Square",
122 Circle => "/Circle",
123 Highlight => "/Highlight",
124 Underline => "/Underline",
125 StrikeOut => "/StrikeOut",
126 Ink => "/Ink",
127 Stamp => "/Stamp",
128 Popup => "/Popup",
129 Widget => "/Widget"
130 }
131}
132
133pdf_string_enum! {
134 pub enum PdfAnnotationTextIconName {
135 Comment => "/Comment",
136 Key => "/Key",
137 Note => "/Note",
138 Help => "/Help",
139 NewParagraph => "/NewParagraph",
140 Paragraph => "/Paragraph",
141 Insert => "/Insert"
142 }
143}
144
145impl PdfAnnotationTextIconName {
146 #[must_use]
147 pub const fn from_icon_type(icon_type: PdfTextAnnotationIconType) -> Self {
148 match icon_type {
149 PdfTextAnnotationIconType::Comment => Self::Comment,
150 PdfTextAnnotationIconType::Key => Self::Key,
151 PdfTextAnnotationIconType::Note => Self::Note,
152 PdfTextAnnotationIconType::Help => Self::Help,
153 PdfTextAnnotationIconType::NewParagraph => Self::NewParagraph,
154 PdfTextAnnotationIconType::Paragraph => Self::Paragraph,
155 PdfTextAnnotationIconType::Insert => Self::Insert,
156 }
157 }
158
159 #[must_use]
160 pub const fn icon_type(self) -> PdfTextAnnotationIconType {
161 match self {
162 Self::Comment => PdfTextAnnotationIconType::Comment,
163 Self::Key => PdfTextAnnotationIconType::Key,
164 Self::Note => PdfTextAnnotationIconType::Note,
165 Self::Help => PdfTextAnnotationIconType::Help,
166 Self::NewParagraph => PdfTextAnnotationIconType::NewParagraph,
167 Self::Paragraph => PdfTextAnnotationIconType::Paragraph,
168 Self::Insert => PdfTextAnnotationIconType::Insert,
169 }
170 }
171}
172
173pdf_string_enum! {
174 pub enum PdfAnnotationWidgetSubtype {
175 Button => "/Btn",
176 Choice => "/Ch",
177 Signature => "/Sig",
178 Text => "/Tx"
179 }
180}