Skip to content

Commit d45610d

Browse files
committed
Add PDF/UA-2 FENote attribute owner
1 parent 9a4baaa commit d45610d

2 files changed

Lines changed: 59 additions & 5 deletions

File tree

src/attributes.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ impl<'a> Attributes<'a> {
6060
ArtifactAttributes::start_with_dict(self.dict)
6161
}
6262

63+
/// Set the `/O` attribute to `FENote` to start writing attributes for
64+
/// footnote elements. PDF/UA-2
65+
pub fn note(self) -> FENoteAttributes<'a> {
66+
FENoteAttributes::start_with_dict(self.dict)
67+
}
68+
6369
/// Set the `/O` attribute to `NSO` and set the `/NS` attribute to an
6470
/// indirect reference to a [`Namespace`] dictionary to start writing
6571
/// attributes for a namespace. PDF 2.0+
@@ -948,6 +954,51 @@ impl<'a> ArtifactAttributes<'a> {
948954

949955
deref!('a, ArtifactAttributes<'a> => Dict<'a>, dict);
950956

957+
/// Writer for a _foot- and endnote attributes dictionary_. PDF/UA-2
958+
///
959+
/// This struct is created by [`Attributes::note`].
960+
pub struct FENoteAttributes<'a> {
961+
dict: Dict<'a>,
962+
}
963+
964+
writer!(FENoteAttributes: |obj| Self::start_with_dict(obj.dict()));
965+
966+
impl<'a> FENoteAttributes<'a> {
967+
pub(crate) fn start_with_dict(mut dict: Dict<'a>) -> Self {
968+
dict.pair(Name(b"O"), AttributeOwner::FENote.to_name(true));
969+
Self { dict }
970+
}
971+
972+
/// Write the `/NoteType` attribute to set the type of note.
973+
pub fn note_type(&mut self, note_type: NoteType) -> &mut Self {
974+
self.dict.pair(Name(b"NoteType"), note_type.to_name());
975+
self
976+
}
977+
}
978+
979+
deref!('a, FENoteAttributes<'a> => Dict<'a>, dict);
980+
981+
/// The type of foot- or endnote.
982+
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
983+
pub enum NoteType {
984+
/// A footnote.
985+
Footnote,
986+
/// An endnote.
987+
Endnote,
988+
/// The type is not specified.
989+
None,
990+
}
991+
992+
impl NoteType {
993+
pub(crate) fn to_name(self) -> Name<'static> {
994+
match self {
995+
Self::Footnote => Name(b"Footnote"),
996+
Self::Endnote => Name(b"Endnote"),
997+
Self::None => Name(b"None"),
998+
}
999+
}
1000+
}
1001+
9511002
/// Owner of the attribute dictionary.
9521003
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
9531004
pub enum AttributeOwner {
@@ -983,6 +1034,8 @@ pub enum AttributeOwner {
9831034
Rdfa1_1,
9841035
/// ARIA 1.1 accessibility attributes for assistive technology. PDF 2.0+.
9851036
Aria1_1,
1037+
/// Attribute governing the interpretation of `FENote` elements. PDF/UA-2.
1038+
FENote,
9861039
/// The attribute owner is a namespace. PDF 2.0+.
9871040
NSO,
9881041
/// User-defined attributes. Requires to set the `/UserProperties` attribute
@@ -1016,6 +1069,7 @@ impl AttributeOwner {
10161069
Self::Css3 => Name(b"CSS-3"),
10171070
Self::Rdfa1_1 => Name(b"RDFa-1.10"),
10181071
Self::Aria1_1 => Name(b"ARIA-1.1"),
1072+
Self::FENote => Name(b"FENote"),
10191073
Self::NSO => Name(b"NSO"),
10201074
Self::User => Name(b"UserProperties"),
10211075
}

src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ pub mod writers {
113113
IconFit,
114114
};
115115
pub use attributes::{
116-
ArtifactAttributes, Attributes, FieldAttributes, LayoutAttributes,
117-
ListAttributes, TableAttributes, UserProperty,
116+
ArtifactAttributes, Attributes, FENoteAttributes, FieldAttributes,
117+
LayoutAttributes, ListAttributes, TableAttributes, UserProperty,
118118
};
119119
pub use color::{
120120
ColorSpace, DeviceN, DeviceNAttrs, DeviceNMixingHints, DeviceNProcess,
@@ -158,9 +158,9 @@ pub mod types {
158158
};
159159
pub use attributes::{
160160
AttributeOwner, BlockAlign, FieldRole, FieldState, InlineAlign,
161-
LayoutBorderStyle, LayoutTextPosition, LineHeight, ListNumbering, Placement,
162-
RubyAlign, RubyPosition, TableHeaderScope, TextAlign, TextDecorationType,
163-
WritingMode,
161+
LayoutBorderStyle, LayoutTextPosition, LineHeight, ListNumbering, NoteType,
162+
Placement, RubyAlign, RubyPosition, TableHeaderScope, TextAlign,
163+
TextDecorationType, WritingMode,
164164
};
165165
pub use color::{
166166
DeviceNSubtype, FunctionShadingType, OutputIntentSubtype, PaintType, TilingType,

0 commit comments

Comments
 (0)