use crate::color::SeparationInfo;
use super::*;
pub struct Catalog<'a> {
dict: Dict<'a>,
}
writer!(Catalog: |obj| {
let mut dict = obj.dict();
dict.pair(Name(b"Type"), Name(b"Catalog"));
Self { dict }
});
impl<'a> Catalog<'a> {
pub fn pages(&mut self, id: Ref) -> &mut Self {
self.pair(Name(b"Pages"), id);
self
}
pub fn page_layout(&mut self, layout: PageLayout) -> &mut Self {
self.pair(Name(b"PageLayout"), layout.to_name());
self
}
pub fn page_labels(&mut self) -> NumberTree<'_, Ref> {
self.insert(Name(b"PageLabels")).start()
}
pub fn page_mode(&mut self, mode: PageMode) -> &mut Self {
self.pair(Name(b"PageMode"), mode.to_name());
self
}
pub fn viewer_preferences(&mut self) -> ViewerPreferences<'_> {
self.insert(Name(b"ViewerPreferences")).start()
}
pub fn names(&mut self) -> Names<'_> {
self.insert(Name(b"Names")).start()
}
pub fn destinations(&mut self, id: Ref) -> &mut Self {
self.pair(Name(b"Dests"), id);
self
}
pub fn outlines(&mut self, id: Ref) -> &mut Self {
self.pair(Name(b"Outlines"), id);
self
}
pub fn struct_tree_root(&mut self) -> StructTreeRoot<'_> {
self.insert(Name(b"StructTreeRoot")).start()
}
pub fn mark_info(&mut self) -> MarkInfo<'_> {
self.insert(Name(b"MarkInfo")).start()
}
pub fn lang(&mut self, lang: TextStr) -> &mut Self {
self.pair(Name(b"Lang"), lang);
self
}
pub fn version(&mut self, major: u8, minor: u8) -> &mut Self {
self.pair(Name(b"Version"), Name(format!("{}.{}", major, minor).as_bytes()));
self
}
pub fn metadata(&mut self, id: Ref) -> &mut Self {
self.pair(Name(b"Metadata"), id);
self
}
pub fn extensions(&mut self) -> TypedDict<'_, DeveloperExtension> {
self.insert(Name(b"Extensions")).dict().typed()
}
pub fn separation_info(&mut self) -> SeparationInfo<'_> {
self.insert(Name(b"SeparationInfo")).start()
}
pub fn output_intents(&mut self) -> TypedArray<'_, Dict> {
self.insert(Name(b"OutputIntents")).array().typed()
}
}
deref!('a, Catalog<'a> => Dict<'a>, dict);
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum PageLayout {
SinglePage,
OneColumn,
TwoColumnLeft,
TwoColumnRight,
TwoPageLeft,
TwoPageRight,
}
impl PageLayout {
pub(crate) fn to_name(self) -> Name<'static> {
match self {
Self::SinglePage => Name(b"SinglePage"),
Self::OneColumn => Name(b"OneColumn"),
Self::TwoColumnLeft => Name(b"TwoColumnLeft"),
Self::TwoColumnRight => Name(b"TwoColumnRight"),
Self::TwoPageLeft => Name(b"TwoPageLeft"),
Self::TwoPageRight => Name(b"TwoPageRight"),
}
}
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum PageMode {
UseNone,
UseOutlines,
UseThumbs,
FullScreen,
}
impl PageMode {
pub(crate) fn to_name(self) -> Name<'static> {
match self {
Self::UseNone => Name(b"UseNone"),
Self::UseOutlines => Name(b"UseOutlines"),
Self::UseThumbs => Name(b"UseThumbs"),
Self::FullScreen => Name(b"FullScreen"),
}
}
}
pub struct DeveloperExtension<'a> {
dict: Dict<'a>,
}
writer!(DeveloperExtension: |obj| {
let mut dict = obj.dict();
dict.pair(Name(b"Type"), Name(b"DeveloperExtension"));
Self { dict }
});
impl<'a> DeveloperExtension<'a> {
pub fn base_version(&mut self, major: u8, minor: u8) -> &mut Self {
self.pair(Name(b"BaseVersion"), Name(format!("{}.{}", major, minor).as_bytes()));
self
}
pub fn extension_level(&mut self, level: i32) -> &mut Self {
self.pair(Name(b"ExtensionLevel"), level);
self
}
}
deref!('a, DeveloperExtension<'a> => Dict<'a>, dict);
pub struct ViewerPreferences<'a> {
dict: Dict<'a>,
}
writer!(ViewerPreferences: |obj| Self { dict: obj.dict() });
impl<'a> ViewerPreferences<'a> {
pub fn hide_toolbar(&mut self, hide: bool) -> &mut Self {
self.pair(Name(b"HideToolbar"), hide);
self
}
pub fn hide_menubar(&mut self, hide: bool) -> &mut Self {
self.pair(Name(b"HideMenubar"), hide);
self
}
pub fn fit_window(&mut self, fit: bool) -> &mut Self {
self.pair(Name(b"FitWindow"), fit);
self
}
pub fn center_window(&mut self, center: bool) -> &mut Self {
self.pair(Name(b"CenterWindow"), center);
self
}
pub fn non_full_screen_page_mode(&mut self, mode: PageMode) -> &mut Self {
assert!(mode != PageMode::FullScreen, "mode must not full screen");
self.pair(Name(b"NonFullScreenPageMode"), mode.to_name());
self
}
pub fn direction(&mut self, dir: Direction) -> &mut Self {
self.pair(Name(b"Direction"), dir.to_name());
self
}
}
deref!('a, ViewerPreferences<'a> => Dict<'a>, dict);
pub struct StructTreeRoot<'a> {
dict: Dict<'a>,
}
writer!(StructTreeRoot: |obj| {
let mut dict = obj.dict();
dict.pair(Name(b"Type"), Name(b"StructTreeRoot"));
Self { dict }
});
impl<'a> StructTreeRoot<'a> {
pub fn child(&mut self, id: Ref) -> &mut Self {
self.dict.pair(Name(b"K"), id);
self
}
pub fn children(&mut self) -> TypedArray<'_, Ref> {
self.dict.insert(Name(b"K")).array().typed()
}
pub fn id_tree(&mut self) -> NameTree<'_, Ref> {
self.dict.insert(Name(b"IDTree")).start()
}
pub fn parent_tree(&mut self) -> NumberTree<'_, Ref> {
self.dict.insert(Name(b"ParentTree")).start()
}
pub fn parent_tree_next_key(&mut self, key: i32) -> &mut Self {
self.dict.pair(Name(b"ParentTreeNextKey"), key);
self
}
pub fn role_map(&mut self) -> RoleMap<'_> {
self.dict.insert(Name(b"RoleMap")).start()
}
pub fn class_map(&mut self) -> ClassMap<'_> {
self.dict.insert(Name(b"ClassMap")).start()
}
}
deref!('a, StructTreeRoot<'a> => Dict<'a>, dict);
pub struct StructElement<'a> {
dict: Dict<'a>,
}
writer!(StructElement: |obj| {
let mut dict = obj.dict();
dict.pair(Name(b"Type"), Name(b"StructElem"));
Self { dict }
});
impl<'a> StructElement<'a> {
pub fn kind(&mut self, role: StructRole) -> &mut Self {
self.dict.pair(Name(b"S"), role.to_name());
self
}
pub fn custom_kind(&mut self, name: Name) -> &mut Self {
self.dict.pair(Name(b"S"), name);
self
}
pub fn parent(&mut self, parent: Ref) -> &mut Self {
self.dict.pair(Name(b"P"), parent);
self
}
pub fn page(&mut self, page: Ref) -> &mut Self {
self.dict.pair(Name(b"Pg"), page);
self
}
pub fn child(&mut self, id: Ref) -> &mut Self {
self.dict.pair(Name(b"K"), id);
self
}
pub fn marked_content_child(&mut self) -> MarkedRef<'_> {
self.dict.insert(Name(b"K")).start()
}
pub fn object_child(&mut self) -> ObjectRef<'_> {
self.dict.insert(Name(b"K")).start()
}
pub fn children(&mut self) -> StructChildren<'_> {
self.dict.insert(Name(b"K")).start()
}
pub fn attributes(&mut self) -> TypedArray<'_, Attributes> {
self.dict.insert(Name(b"A")).array().typed()
}
pub fn attribute_class(&mut self) -> TypedArray<'_, Name> {
self.dict.insert(Name(b"C")).array().typed()
}
pub fn revision(&mut self, revision: i32) -> &mut Self {
self.dict.pair(Name(b"R"), revision);
self
}
pub fn title(&mut self, title: TextStr) -> &mut Self {
self.dict.pair(Name(b"T"), title);
self
}
pub fn lang(&mut self, lang: TextStr) -> &mut Self {
self.dict.pair(Name(b"Lang"), lang);
self
}
pub fn alt(&mut self, alt: TextStr) -> &mut Self {
self.dict.pair(Name(b"Alt"), alt);
self
}
pub fn expanded(&mut self, expanded: TextStr) -> &mut Self {
self.dict.pair(Name(b"E"), expanded);
self
}
pub fn actual_text(&mut self, actual_text: TextStr) -> &mut Self {
self.dict.pair(Name(b"ActualText"), actual_text);
self
}
}
deref!('a, StructElement<'a> => Dict<'a>, dict);
pub struct StructChildren<'a> {
arr: Array<'a>,
}
writer!(StructChildren: |obj| Self { arr: obj.array() });
impl<'a> StructChildren<'a> {
pub fn struct_element(&mut self, id: Ref) -> &mut Self {
self.arr.item(id);
self
}
pub fn marked_content_id(&mut self, id: i32) -> &mut Self {
self.arr.item(id);
self
}
pub fn marked_content_ref(&mut self) -> MarkedRef<'_> {
self.arr.push().start()
}
pub fn object_ref(&mut self) -> ObjectRef<'_> {
self.arr.push().start()
}
}
deref!('a, StructChildren<'a> => Array<'a>, arr);
pub struct MarkedRef<'a> {
dict: Dict<'a>,
}
writer!(MarkedRef: |obj| {
let mut dict = obj.dict();
dict.pair(Name(b"Type"), Name(b"MCR"));
Self { dict }
});
impl<'a> MarkedRef<'a> {
pub fn page(&mut self, page: Ref) -> &mut Self {
self.dict.pair(Name(b"Pg"), page);
self
}
pub fn stream(&mut self, stream: Ref) -> &mut Self {
self.dict.pair(Name(b"Stm"), stream);
self
}
pub fn stream_owner(&mut self, owner: Ref) -> &mut Self {
self.dict.pair(Name(b"StmOwn"), owner);
self
}
pub fn marked_content_id(&mut self, id: i32) -> &mut Self {
self.dict.pair(Name(b"MCID"), id);
self
}
}
deref!('a, MarkedRef<'a> => Dict<'a>, dict);
pub struct ObjectRef<'a> {
dict: Dict<'a>,
}
writer!(ObjectRef: |obj| {
let mut dict = obj.dict();
dict.pair(Name(b"Type"), Name(b"OBJR"));
Self { dict }
});
impl<'a> ObjectRef<'a> {
pub fn page(&mut self, page: Ref) -> &mut Self {
self.dict.pair(Name(b"Pg"), page);
self
}
pub fn object(&mut self, obj: Ref) -> &mut Self {
self.dict.pair(Name(b"Obj"), obj);
self
}
}
deref!('a, ObjectRef<'a> => Dict<'a>, dict);
pub struct RoleMap<'a> {
dict: TypedDict<'a, Name<'a>>,
}
writer!(RoleMap: |obj| Self { dict: obj.dict().typed() });
impl<'a> RoleMap<'a> {
pub fn insert(&mut self, name: Name, role: StructRole) -> &mut Self {
self.dict.pair(name, role.to_name());
self
}
}
deref!('a, RoleMap<'a> => TypedDict<'a, Name<'a>>, dict);
pub struct ClassMap<'a> {
dict: Dict<'a>,
}
writer!(ClassMap: |obj| Self { dict: obj.dict() });
impl<'a> ClassMap<'a> {
pub fn single(&mut self, name: Name) -> Attributes<'_> {
self.dict.insert(name).start()
}
pub fn multiple(&mut self, name: Name) -> TypedArray<'_, Attributes> {
self.dict.insert(name).array().typed()
}
}
deref!('a, ClassMap<'a> => Dict<'a>, dict);
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum StructRole {
Document,
Part,
Art,
Sect,
Div,
BlockQuote,
Caption,
TOC,
TOCI,
Index,
NonStruct,
Private,
P,
H1,
H2,
H3,
H4,
H5,
H6,
L,
LI,
Lbl,
LBody,
Table,
TR,
TH,
TD,
THead,
TBody,
TFoot,
Span,
Quote,
Note,
Reference,
BibEntry,
Code,
Link,
Annot,
Ruby,
Warichu,
RB,
RT,
RP,
WT,
WP,
Figure,
Formula,
Form,
}
impl StructRole {
pub(crate) fn to_name(self) -> Name<'static> {
match self {
Self::Document => Name(b"Document"),
Self::Part => Name(b"Part"),
Self::Art => Name(b"Art"),
Self::Sect => Name(b"Sect"),
Self::Div => Name(b"Div"),
Self::BlockQuote => Name(b"BlockQuote"),
Self::Caption => Name(b"Caption"),
Self::TOC => Name(b"TOC"),
Self::TOCI => Name(b"TOCI"),
Self::Index => Name(b"Index"),
Self::NonStruct => Name(b"NonStruct"),
Self::Private => Name(b"Private"),
Self::P => Name(b"P"),
Self::H1 => Name(b"H1"),
Self::H2 => Name(b"H2"),
Self::H3 => Name(b"H3"),
Self::H4 => Name(b"H4"),
Self::H5 => Name(b"H5"),
Self::H6 => Name(b"H6"),
Self::L => Name(b"L"),
Self::LI => Name(b"LI"),
Self::Lbl => Name(b"Lbl"),
Self::LBody => Name(b"LBody"),
Self::Table => Name(b"Table"),
Self::TR => Name(b"TR"),
Self::TH => Name(b"TH"),
Self::TD => Name(b"TD"),
Self::THead => Name(b"THead"),
Self::TBody => Name(b"TBody"),
Self::TFoot => Name(b"TFoot"),
Self::Span => Name(b"Span"),
Self::Quote => Name(b"Quote"),
Self::Note => Name(b"Note"),
Self::Reference => Name(b"Reference"),
Self::BibEntry => Name(b"BibEntry"),
Self::Code => Name(b"Code"),
Self::Link => Name(b"Link"),
Self::Annot => Name(b"Annot"),
Self::Ruby => Name(b"Ruby"),
Self::Warichu => Name(b"Warichu"),
Self::RB => Name(b"RB"),
Self::RT => Name(b"RT"),
Self::RP => Name(b"RP"),
Self::WT => Name(b"WT"),
Self::WP => Name(b"WP"),
Self::Figure => Name(b"Figure"),
Self::Formula => Name(b"Formula"),
Self::Form => Name(b"Form"),
}
}
}
pub struct MarkInfo<'a> {
dict: Dict<'a>,
}
writer!(MarkInfo: |obj| Self { dict: obj.dict() });
impl<'a> MarkInfo<'a> {
pub fn marked(&mut self, conformant: bool) -> &mut Self {
self.pair(Name(b"Marked"), conformant);
self
}
pub fn user_properties(&mut self, present: bool) -> &mut Self {
self.pair(Name(b"UserProperties"), present);
self
}
pub fn suspects(&mut self, present: bool) -> &mut Self {
self.pair(Name(b"Suspects"), present);
self
}
}
deref!('a, MarkInfo<'a> => Dict<'a>, dict);
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum Direction {
L2R,
R2L,
}
impl Direction {
pub(crate) fn to_name(self) -> Name<'static> {
match self {
Self::L2R => Name(b"L2R"),
Self::R2L => Name(b"R2L"),
}
}
}
pub struct PageLabel<'a> {
dict: Dict<'a>,
}
writer!(PageLabel: |obj| {
let mut dict = obj.dict();
dict.pair(Name(b"Type"), Name(b"PageLabel"));
Self { dict }
});
impl<'a> PageLabel<'a> {
pub fn style(&mut self, style: NumberingStyle) -> &mut Self {
self.pair(Name(b"S"), style.to_name());
self
}
pub fn prefix(&mut self, prefix: TextStr) -> &mut Self {
self.pair(Name(b"P"), prefix);
self
}
pub fn offset(&mut self, offset: i32) -> &mut Self {
self.pair(Name(b"St"), offset);
self
}
}
deref!('a, PageLabel<'a> => Dict<'a>, dict);
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum NumberingStyle {
Arabic,
LowerRoman,
UpperRoman,
LowerAlpha,
UpperAlpha,
}
impl NumberingStyle {
pub(crate) fn to_name(self) -> Name<'static> {
match self {
NumberingStyle::Arabic => Name(b"D"),
NumberingStyle::LowerRoman => Name(b"r"),
NumberingStyle::UpperRoman => Name(b"R"),
NumberingStyle::LowerAlpha => Name(b"a"),
NumberingStyle::UpperAlpha => Name(b"A"),
}
}
}
pub struct DocumentInfo<'a> {
dict: Dict<'a>,
}
writer!(DocumentInfo: |obj| Self { dict: obj.dict() });
impl<'a> DocumentInfo<'a> {
pub fn title(&mut self, title: TextStr) -> &mut Self {
self.pair(Name(b"Title"), title);
self
}
pub fn author(&mut self, author: TextStr) -> &mut Self {
self.pair(Name(b"Author"), author);
self
}
pub fn subject(&mut self, subject: TextStr) -> &mut Self {
self.pair(Name(b"Subject"), subject);
self
}
pub fn keywords(&mut self, keywords: TextStr) -> &mut Self {
self.pair(Name(b"Keywords"), keywords);
self
}
pub fn creator(&mut self, creator: TextStr) -> &mut Self {
self.pair(Name(b"Creator"), creator);
self
}
pub fn producer(&mut self, producer: TextStr) -> &mut Self {
self.pair(Name(b"Producer"), producer);
self
}
pub fn creation_date(&mut self, date: Date) -> &mut Self {
self.pair(Name(b"CreationDate"), date);
self
}
pub fn modified_date(&mut self, date: Date) -> &mut Self {
self.pair(Name(b"ModDate"), date);
self
}
pub fn trapped(&mut self, trapped: TrappingStatus) -> &mut Self {
self.pair(Name(b"Trapped"), trapped.to_name());
self
}
}
deref!('a, DocumentInfo<'a> => Dict<'a>, dict);
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum TrappingStatus {
Trapped,
NotTrapped,
Unknown,
}
impl TrappingStatus {
pub(crate) fn to_name(self) -> Name<'static> {
match self {
TrappingStatus::Trapped => Name(b"True"),
TrappingStatus::NotTrapped => Name(b"False"),
TrappingStatus::Unknown => Name(b"Unknown"),
}
}
}
pub struct Pages<'a> {
dict: Dict<'a>,
}
writer!(Pages: |obj| {
let mut dict = obj.dict();
dict.pair(Name(b"Type"), Name(b"Pages"));
Self { dict }
});
impl<'a> Pages<'a> {
pub fn parent(&mut self, parent: Ref) -> &mut Self {
self.pair(Name(b"Parent"), parent);
self
}
pub fn kids(&mut self, kids: impl IntoIterator<Item = Ref>) -> &mut Self {
self.insert(Name(b"Kids")).array().items(kids);
self
}
pub fn count(&mut self, count: i32) -> &mut Self {
self.pair(Name(b"Count"), count);
self
}
pub fn media_box(&mut self, rect: Rect) -> &mut Self {
self.pair(Name(b"MediaBox"), rect);
self
}
pub fn resources(&mut self) -> Resources<'_> {
self.insert(Name(b"Resources")).start()
}
}
deref!('a, Pages<'a> => Dict<'a>, dict);
pub struct Page<'a> {
dict: Dict<'a>,
}
writer!(Page: |obj| {
let mut dict = obj.dict();
dict.pair(Name(b"Type"), Name(b"Page"));
Self { dict }
});
impl<'a> Page<'a> {
pub fn parent(&mut self, parent: Ref) -> &mut Self {
self.pair(Name(b"Parent"), parent);
self
}
pub fn last_modified(&mut self, date: Date) -> &mut Self {
self.pair(Name(b"LastModified"), date);
self
}
pub fn media_box(&mut self, rect: Rect) -> &mut Self {
self.pair(Name(b"MediaBox"), rect);
self
}
pub fn crop_box(&mut self, rect: Rect) -> &mut Self {
self.pair(Name(b"CropBox"), rect);
self
}
pub fn bleed_box(&mut self, rect: Rect) -> &mut Self {
self.pair(Name(b"BleedBox"), rect);
self
}
pub fn trim_box(&mut self, rect: Rect) -> &mut Self {
self.pair(Name(b"TrimBox"), rect);
self
}
pub fn art_box(&mut self, rect: Rect) -> &mut Self {
self.pair(Name(b"ArtBox"), rect);
self
}
pub fn resources(&mut self) -> Resources<'_> {
self.insert(Name(b"Resources")).start()
}
pub fn contents(&mut self, id: Ref) -> &mut Self {
self.pair(Name(b"Contents"), id);
self
}
pub fn contents_array(&mut self, ids: impl IntoIterator<Item = Ref>) -> &mut Self {
self.insert(Name(b"Contents")).array().items(ids);
self
}
pub fn rotate(&mut self, degrees: i32) -> &mut Self {
self.pair(Name(b"Rotate"), degrees);
self
}
pub fn group(&mut self) -> Group<'_> {
self.insert(Name(b"Group")).start()
}
pub fn thumbnail(&mut self, id: Ref) -> &mut Self {
self.pair(Name(b"Thumb"), id);
self
}
pub fn duration(&mut self, seconds: f32) -> &mut Self {
self.pair(Name(b"Dur"), seconds);
self
}
pub fn transition(&mut self) -> Transition<'_> {
self.insert(Name(b"Trans")).start()
}
pub fn annotations(&mut self) -> TypedArray<'_, Annotation> {
self.insert(Name(b"Annots")).array().typed()
}
pub fn struct_parents(&mut self, key: i32) -> &mut Self {
self.pair(Name(b"StructParents"), key);
self
}
pub fn tab_order(&mut self, order: TabOrder) -> &mut Self {
self.pair(Name(b"Tabs"), order.to_name());
self
}
pub fn user_unit(&mut self, value: f32) -> &mut Self {
self.pair(Name(b"UserUnit"), value);
self
}
pub fn metadata(&mut self, id: Ref) -> &mut Self {
self.pair(Name(b"Metadata"), id);
self
}
}
deref!('a, Page<'a> => Dict<'a>, dict);
pub struct Outline<'a> {
dict: Dict<'a>,
}
writer!(Outline: |obj| {
let mut dict = obj.dict();
dict.pair(Name(b"Type"), Name(b"Outlines"));
Self { dict }
});
impl<'a> Outline<'a> {
pub fn first(&mut self, item: Ref) -> &mut Self {
self.pair(Name(b"First"), item);
self
}
pub fn last(&mut self, item: Ref) -> &mut Self {
self.pair(Name(b"Last"), item);
self
}
pub fn count(&mut self, count: i32) -> &mut Self {
assert!(count >= 0, "visible outline count must not be negative");
self.pair(Name(b"Count"), count);
self
}
}
deref!('a, Outline<'a> => Dict<'a>, dict);
pub struct OutlineItem<'a> {
dict: Dict<'a>,
}
writer!(OutlineItem: |obj| Self { dict: obj.dict() });
impl<'a> OutlineItem<'a> {
pub fn title(&mut self, title: TextStr) -> &mut Self {
self.pair(Name(b"Title"), title);
self
}
pub fn parent(&mut self, outline: Ref) -> &mut Self {
self.pair(Name(b"Parent"), outline);
self
}
pub fn prev(&mut self, outline: Ref) -> &mut Self {
self.pair(Name(b"Prev"), outline);
self
}
pub fn next(&mut self, outline: Ref) -> &mut Self {
self.pair(Name(b"Next"), outline);
self
}
pub fn first(&mut self, outline: Ref) -> &mut Self {
self.pair(Name(b"First"), outline);
self
}
pub fn last(&mut self, outline: Ref) -> &mut Self {
self.pair(Name(b"Last"), outline);
self
}
pub fn count(&mut self, items: i32) -> &mut Self {
self.pair(Name(b"Count"), items);
self
}
pub fn dest(&mut self) -> Destination<'_> {
self.insert(Name(b"Dest")).start()
}
pub fn dest_name(&mut self, name: Name) -> &mut Self {
self.pair(Name(b"Dest"), name);
self
}
pub fn color_rgb(&mut self, r: f32, g: f32, b: f32) -> &mut Self {
self.insert(Name(b"C")).array().items([r, g, b]);
self
}
pub fn flags(&mut self, flags: OutlineItemFlags) -> &mut Self {
self.pair(Name(b"F"), flags.bits() as i32);
self
}
}
deref!('a, OutlineItem<'a> => Dict<'a>, dict);
bitflags::bitflags! {
pub struct OutlineItemFlags: u32 {
const ITALIC = 1 << 0;
const BOLD = 1 << 1;
}
}
pub struct Names<'a> {
dict: Dict<'a>,
}
writer!(Names: |obj| Self { dict: obj.dict() });
impl Names<'_> {
pub fn destinations(&mut self) -> NameTree<'_, Ref> {
self.dict.insert(Name(b"Dests")).start()
}
pub fn appearances(&mut self) -> NameTree<'_, Ref> {
self.dict.insert(Name(b"AP")).start()
}
pub fn javascript(&mut self) -> NameTree<'_, Ref> {
self.dict.insert(Name(b"JavaScript")).start()
}
pub fn pages(&mut self) -> NameTree<'_, Ref> {
self.dict.insert(Name(b"Pages")).start()
}
pub fn templates(&mut self) -> NameTree<'_, Ref> {
self.dict.insert(Name(b"Templates")).start()
}
pub fn capture_ids(&mut self) -> NameTree<'_, Ref> {
self.dict.insert(Name(b"IDS")).start()
}
pub fn capture_urls(&mut self) -> NameTree<'_, Ref> {
self.dict.insert(Name(b"URLS")).start()
}
pub fn embedded_files(&mut self) -> NameTree<'_, Ref> {
self.dict.insert(Name(b"EmbeddedFiles")).start()
}
pub fn alternate_presentations(&mut self) -> NameTree<'_, Ref> {
self.dict.insert(Name(b"AlternatePresentations")).start()
}
pub fn renditions(&mut self) -> NameTree<'_, Ref> {
self.dict.insert(Name(b"Renditions")).start()
}
}
deref!('a, Names<'a> => Dict<'a>, dict);
pub struct Destination<'a> {
array: Array<'a>,
}
writer!(Destination: |obj| Self { array: obj.array() });
impl<'a> Destination<'a> {
pub fn page(mut self, page: Ref) -> Self {
self.item(page);
self
}
pub fn xyz(mut self, left: f32, top: f32, zoom: Option<f32>) {
self.item(Name(b"XYZ"));
self.item(left);
self.item(top);
self.item(zoom.unwrap_or_default());
}
pub fn fit(mut self) {
self.item(Name(b"Fit"));
}
pub fn fit_horizontal(mut self, top: f32) {
self.item(Name(b"FitH"));
self.item(top);
}
pub fn fit_vertical(mut self, left: f32) {
self.item(Name(b"FitV"));
self.item(left);
}
pub fn fit_rect(mut self, rect: Rect) {
self.item(Name(b"FitR"));
self.array.items([rect.x1, rect.y1, rect.x2, rect.y2]);
}
pub fn fit_bounding_box(mut self) {
self.item(Name(b"FitB"));
}
pub fn fit_bounding_box_horizontal(mut self, top: f32) {
self.item(Name(b"FitBH"));
self.item(top);
}
pub fn fit_bounding_box_vertical(mut self, left: f32) {
self.item(Name(b"FitBV"));
self.item(left);
}
}
deref!('a, Destination<'a> => Array<'a>, array);
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum TabOrder {
RowOrder,
ColumnOrder,
StructureOrder,
}
impl TabOrder {
pub(crate) fn to_name(self) -> Name<'static> {
match self {
Self::RowOrder => Name(b"R"),
Self::ColumnOrder => Name(b"C"),
Self::StructureOrder => Name(b"S"),
}
}
}
pub struct Metadata<'a> {
stream: Stream<'a>,
}
impl<'a> Metadata<'a> {
pub(crate) fn start(mut stream: Stream<'a>) -> Self {
stream.pair(Name(b"Type"), Name(b"Metadata"));
stream.pair(Name(b"Subtype"), Name(b"XML"));
Self { stream }
}
}
deref!('a, Metadata<'a> => Stream<'a>, stream);