Skip to main content

Bookmark

Struct Bookmark 

Source
pub struct Bookmark {
    pub dict: Dict,
    pub depth: usize,
}
Expand description

One outline item.

Fields§

§dict: Dict

The item’s dictionary.

§depth: usize

How deep in the outline it sits; the top level is zero.

Implementations§

Source§

impl Bookmark

Source

pub fn title<R: Resolve>(&self, r: &R) -> String

The item’s title.

Two details: /Title is type-filtered to a string, so a name-valued title reads as empty; and every code unit below 0x20 is raised to a space, so control characters become blanks without changing the length. The second matters because titles are compared case-insensitively when searching.

use pdfrum_common::{Diagnostics, Limits};
use pdfrum_doc::nav::outline_bookmarks;
use pdfrum_object::{Dict, Name, NoResolve, Object, PdfString};

let item = Dict::from_pairs([
    (Name::from("Title"), Object::Str(PdfString::literal(b"Introduction"))),
]);
let outlines = Dict::from_pairs([(Name::from("First"), Object::Dict(item))]);
let catalog = Dict::from_pairs([(Name::from("Outlines"), Object::Dict(outlines))]);

let (limits, mut diags) = (Limits::default(), Diagnostics::default());
let bookmarks = outline_bookmarks(&catalog, &NoResolve, &limits, &mut diags);

assert_eq!(bookmarks[0].title(&NoResolve), "Introduction");
Source

pub fn count<R: Resolve>(&self, r: &R) -> i64

/Count: positive for an open item with that many visible descendants, negative for a closed one, zero for a leaf.

The sign is preserved and the value is not masked.

use pdfrum_common::{Diagnostics, Limits};
use pdfrum_doc::nav::outline_bookmarks;
use pdfrum_object::{Dict, Name, NoResolve, Object, PdfString};

let item = Dict::from_pairs([
    (Name::from("Title"), Object::Str(PdfString::literal(b"Introduction"))),
]);
let outlines = Dict::from_pairs([(Name::from("First"), Object::Dict(item))]);
let catalog = Dict::from_pairs([(Name::from("Outlines"), Object::Dict(outlines))]);

let (limits, mut diags) = (Limits::default(), Diagnostics::default());
let bookmarks = outline_bookmarks(&catalog, &NoResolve, &limits, &mut diags);

// A leaf: zero, with no `/Count` in the file.
assert_eq!(bookmarks[0].count(&NoResolve), 0);
Source

pub fn style<R: Resolve>(&self, r: &R) -> i64

/F, the style flag word, unmasked — a file writing 15 reports 15, not the two defined bits.

use pdfrum_common::{Diagnostics, Limits};
use pdfrum_doc::nav::outline_bookmarks;
use pdfrum_object::{Dict, Name, NoResolve, Object, PdfString};

let item = Dict::from_pairs([
    (Name::from("Title"), Object::Str(PdfString::literal(b"Introduction"))),
]);
let outlines = Dict::from_pairs([(Name::from("First"), Object::Dict(item))]);
let catalog = Dict::from_pairs([(Name::from("Outlines"), Object::Dict(outlines))]);

let (limits, mut diags) = (Limits::default(), Diagnostics::default());
let bookmarks = outline_bookmarks(&catalog, &NoResolve, &limits, &mut diags);

assert_eq!(bookmarks[0].style(&NoResolve), 0);
Source

pub fn color<R: Resolve>(&self, r: &R) -> Option<(f32, f32, f32)>

/C, the item’s colour, as three components in [0, 1].

The array must hold exactly three entries and every one must be a number inside the unit interval; anything else is no colour. Upstream dereferences a non-number here without checking, which is a latent crash — we answer None.

use pdfrum_common::{Diagnostics, Limits};
use pdfrum_doc::nav::outline_bookmarks;
use pdfrum_object::{Dict, Name, NoResolve, Object, PdfString};

let item = Dict::from_pairs([
    (Name::from("Title"), Object::Str(PdfString::literal(b"Introduction"))),
]);
let outlines = Dict::from_pairs([(Name::from("First"), Object::Dict(item))]);
let catalog = Dict::from_pairs([(Name::from("Outlines"), Object::Dict(outlines))]);

let (limits, mut diags) = (Limits::default(), Diagnostics::default());
let bookmarks = outline_bookmarks(&catalog, &NoResolve, &limits, &mut diags);

// No `/C`: no colour. So is any array that is not exactly three
// numbers inside the unit interval.
assert_eq!(bookmarks[0].color(&NoResolve), None);
Source

pub fn action<R: Resolve>(&self, r: &R) -> Option<Action>

The item’s action.

use pdfrum_common::{Diagnostics, Limits};
use pdfrum_doc::nav::outline_bookmarks;
use pdfrum_object::{Dict, Name, NoResolve, Object, PdfString};

let item = Dict::from_pairs([
    (Name::from("Title"), Object::Str(PdfString::literal(b"Introduction"))),
]);
let outlines = Dict::from_pairs([(Name::from("First"), Object::Dict(item))]);
let catalog = Dict::from_pairs([(Name::from("Outlines"), Object::Dict(outlines))]);

let (limits, mut diags) = (Limits::default(), Diagnostics::default());
let bookmarks = outline_bookmarks(&catalog, &NoResolve, &limits, &mut diags);

assert!(bookmarks[0].action(&NoResolve).is_none());
Source

pub fn dest<R: Resolve>( &self, catalog: &Dict, r: &R, limits: &Limits, diags: &mut Diagnostics, ) -> Dest

Where the item goes: /Dest first, the action’s destination only when that yields no array.

use pdfrum_common::{Diagnostics, Limits};
use pdfrum_doc::nav::outline_bookmarks;
use pdfrum_object::{Dict, Name, NoResolve, Object, PdfString};

let item = Dict::from_pairs([
    (Name::from("Title"), Object::Str(PdfString::literal(b"Introduction"))),
]);
let outlines = Dict::from_pairs([(Name::from("First"), Object::Dict(item))]);
let catalog = Dict::from_pairs([(Name::from("Outlines"), Object::Dict(outlines))]);

let (limits, mut diags) = (Limits::default(), Diagnostics::default());
let bookmarks = outline_bookmarks(&catalog, &NoResolve, &limits, &mut diags);

let dest = bookmarks[0].dest(&catalog, &NoResolve, &limits, &mut diags);
assert!(dest.array.is_none());

Trait Implementations§

Source§

impl Clone for Bookmark

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Bookmark

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Bookmark

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Bookmark

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.