Skip to content

Commit

Permalink
Implement the MediaPermissions dictonary
Browse files Browse the repository at this point in the history
  • Loading branch information
awehrfritz committed Feb 12, 2024
1 parent 8cb4be1 commit 8231dd4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
2 changes: 1 addition & 1 deletion examples/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
37 changes: 27 additions & 10 deletions src/renditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 8231dd4

Please sign in to comment.