From 8231dd44ccbe64b99e9f84590c52374cbb1af557 Mon Sep 17 00:00:00 2001 From: Armin Wehrfritz Date: Mon, 12 Feb 2024 16:15:33 +0200 Subject: [PATCH] Implement the MediaPermissions dictonary --- examples/video.rs | 2 +- src/lib.rs | 2 +- src/renditions.rs | 37 +++++++++++++++++++++++++++---------- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/examples/video.rs b/examples/video.rs index 3a8cbf0..cd8400f 100644 --- a/examples/video.rs +++ b/examples/video.rs @@ -145,7 +145,7 @@ fn main() -> std::io::Result<()> { media_clip.data_url(Str(file_url)); } media_clip.data_type(Str(b"video/mp4")); - media_clip.temp_file(Str(b"TEMPACCESS")); + media_clip.permissions().temp_file(Str(b"TEMPACCESS")); media_clip.finish(); // Add controls for the media player. diff --git a/src/lib.rs b/src/lib.rs index 4ed38df..91415bc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -135,7 +135,7 @@ pub mod writers { ExponentialFunction, PostScriptFunction, SampledFunction, StitchingFunction, }; pub use object::{NameTree, NameTreeEntries, NumberTree, NumberTreeEntries}; - pub use renditions::{Rendition, MediaClip, MediaPlayParams}; + pub use renditions::{Rendition, MediaClip, MediaPlayParams, MediaPermissions}; pub use structure::{ Catalog, ClassMap, Destination, DeveloperExtension, DocumentInfo, MarkInfo, MarkedRef, Metadata, Names, ObjectRef, Outline, OutlineItem, Page, PageLabel, diff --git a/src/renditions.rs b/src/renditions.rs index 9b3c623..7f6d455 100644 --- a/src/renditions.rs +++ b/src/renditions.rs @@ -86,16 +86,9 @@ impl<'a> MediaClip<'a> { self } - /// Write the `/TF` attribute inside the `/P` dictionary controlling the - /// permissions to write a temporary file. - /// - /// The media permissions dictionary has a single entry. Thus, skip - /// implementing a full MediaPermissions dictionary object. - pub fn temp_file(&mut self, tf: Str) -> &mut Self { - self.insert(Name(b"P")).dict() - .pair(Name(b"Type"), Name(b"MediaPermissions")) - .pair(Name(b"TF"), tf); - self + /// Start writing the `/P`, i.e. media permissions, dictionary. + pub fn permissions(&mut self) -> MediaPermissions<'_> { + self.insert(Name(b"P")).start() } } @@ -131,6 +124,30 @@ impl<'a> MediaPlayParams<'a> { deref!('a, MediaPlayParams<'a> => Dict<'a>, dict); +/// Writer for an _media permissions dictionary_. +/// +/// This struct is created by [`Rendition::permissions`]. +pub struct MediaPermissions<'a> { + dict: Dict<'a>, +} + +writer!(MediaPermissions: |obj| { + let mut dict = obj.dict(); + dict.pair(Name(b"Type"), Name(b"MediaPermissions")); + Self { dict } +}); + +impl<'a> MediaPermissions<'a> { + /// Write the `/TF` attribute to control permissions to write a temporary file. + pub fn temp_file(&mut self, tf: Str) -> &mut Self { + self.pair(Name(b"TF"), tf); + self + } +} + +deref!('a, MediaPermissions<'a> => Dict<'a>, dict); + + /// Type of rendition objects. #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] pub enum RenditionType {