diff --git a/pdf/src/object/types.rs b/pdf/src/object/types.rs index 4ee43b1..c76afe0 100644 --- a/pdf/src/object/types.rs +++ b/pdf/src/object/types.rs @@ -959,10 +959,58 @@ pub struct FieldDictionary { #[pdf(key="AA")] pub actions: Option, + #[pdf(key="AP")] + pub appearance_streams: Option>, + #[pdf(other)] pub other: Dictionary } +#[derive(Object, ObjectWrite, Debug, DataSize, Clone)] +pub struct AppearanceStreams { + #[pdf(key="N")] + pub normal: AppearanceStreamEntry, + + #[pdf(key="R")] + pub rollover: Option, + + #[pdf(key="D")] + pub down: Option, +} + +#[derive(Clone, Debug)] +pub enum AppearanceStreamEntry { + Single(Stream), + Dict(HashMap) +} +impl Object for AppearanceStreamEntry { + fn from_primitive(p: Primitive, resolve: &impl Resolve) -> Result { + match dbg!(p.resolve(resolve)?) { + p @ Primitive::Dictionary(_) => Object::from_primitive(p, resolve).map(AppearanceStreamEntry::Dict), + p @ Primitive::Stream(_) => Object::from_primitive(p, resolve).map(AppearanceStreamEntry::Single), + p => Err(PdfError::UnexpectedPrimitive {expected: "Dict or Stream", found: p.get_debug_name()}) + } + } +} +impl ObjectWrite for AppearanceStreamEntry { + fn to_primitive(&self, update: &mut impl Updater) -> Result { + match self { + AppearanceStreamEntry::Dict(d) => d.to_primitive(update), + AppearanceStreamEntry::Single(s) => s.to_primitive(update), + } + } +} +impl DataSize for AppearanceStreamEntry { + const IS_DYNAMIC: bool = true; + const STATIC_HEAP_SIZE: usize = std::mem::size_of::(); + fn estimate_heap_size(&self) -> usize { + match self { + AppearanceStreamEntry::Dict(d) => d.estimate_heap_size(), + AppearanceStreamEntry::Single(s) => s.estimate_heap_size() + } + } +} + #[derive(Debug, DataSize)] pub enum Counter { Arabic,