Skip to content

Commit

Permalink
Allow merging of form fields and widget annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
tingerrr committed Nov 8, 2023
1 parent dfef8da commit ac818d2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/annotations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::*;
///
/// An array of this struct is created by [`Chunk::annotation`].
pub struct Annotation<'a> {
dict: Dict<'a>,
pub(crate) dict: Dict<'a>,
}

writer!(Annotation: |obj| {
Expand Down
15 changes: 15 additions & 0 deletions src/forms.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::types::AnnotationType;

use super::*;

/// Writer for an _interactive forms dictionary_. PDF 1.2+.
Expand Down Expand Up @@ -165,6 +167,19 @@ impl<'a> Field<'a> {
pub fn additional_actions(&mut self) -> AdditionalActions<'_> {
self.dict.insert(Name(b"AA")).start()
}

/// Finish writing this field as a widget annotation. This is encouraged
/// for fields which are non-root and terminal (i.e. they have a parent and
/// no children).
///
/// While the widget annotation could be a single child to a
/// terminal field, most readers will not correctly read the form
/// field, if it's not merged with its annotation.
pub fn to_annotation(self) -> Annotation<'a> {
let mut annot = Annotation { dict: self.dict };
annot.subtype(AnnotationType::Widget);
annot
}
}

deref!('a, Field<'a> => Dict<'a>, dict);
Expand Down

0 comments on commit ac818d2

Please sign in to comment.