Skip to content

Commit

Permalink
Association kinds for embedded files
Browse files Browse the repository at this point in the history
Co-Authored-By: Martin Haug <[email protected]>
  • Loading branch information
laurmaedje and reknih committed Sep 27, 2024
1 parent cba8c6f commit b9ebb20
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ impl<'a> FileSpec<'a> {
self.insert(Name(b"EF")).dict().pair(Name(b"F"), id);
self
}

/// How this file relates to the PDF document it is embedded in.
/// PDF/A-3 and PDF/A-4f.
pub fn association_kind(&mut self, kind: AssociationKind) -> &mut Self {
self.pair(Name(b"AFRelationship"), kind.to_name());
self
}
}

deref!('a, FileSpec<'a> => Dict<'a>, dict);
Expand Down Expand Up @@ -137,3 +144,31 @@ impl<'a> EmbeddingParams<'a> {
}

deref!('a, EmbeddingParams<'a> => Dict<'a>, dict);

/// How an embedded file relates to the PDF document it is embedded in.
/// PDF/A-3 and PDF/A-4f.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum AssociationKind {
/// The PDF document was created from this source file.
Source,
/// This file was used to derive a visual presentation in the PDF.
Data,
/// An alternative representation of this document.
Alternative,
/// Additional resources for this document.
Supplement,
/// There is no clear relationship or it is not known.
Unspecified,
}

impl AssociationKind {
pub(crate) fn to_name(self) -> Name<'static> {
match self {
Self::Source => Name(b"Source"),
Self::Data => Name(b"Data"),
Self::Alternative => Name(b"Alternative"),
Self::Supplement => Name(b"Supplement"),
Self::Unspecified => Name(b"Unspecified"),
}
}
}

0 comments on commit b9ebb20

Please sign in to comment.