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