Skip to main content

Dest

Struct Dest 

Source
pub struct Dest {
    pub array: Option<Array>,
}
Expand description

A destination.

Fields§

§array: Option<Array>

The underlying array, empty when the destination did not resolve.

Implementations§

Source§

impl Dest

Source

pub fn create<R: Resolve>( catalog: &Dict, object: Option<&Object>, r: &R, limits: &Limits, diags: &mut Diagnostics, ) -> Dest

Reads a /Dest or /D value of any type.

A string or a name is looked up through the named-destination ladder against the current document — including for a remote /GoToR destination, whose named target is never resolved in the file it actually names. That is the behavior, not an oversight to fix.

use pdfrum_common::{Diagnostics, Limits};
use pdfrum_doc::Dest;
use pdfrum_object::{Array, Dict, Name, NoResolve, Object};

let array = Object::Array(Array::of([
    Object::Int(2),
    Object::Name(Name::from("XYZ")),
    Object::from(0.0_f32),
    Object::from(792.0_f32),
    Object::Int(0),
]));
let (catalog, limits) = (Dict::default(), Limits::default());
let mut diags = Diagnostics::default();
let dest = Dest::create(&catalog, Some(&array), &NoResolve, &limits, &mut diags);

assert!(dest.array.is_some());
Source

pub fn zoom_mode<R: Resolve>(&self, r: &R) -> ZoomMode

The view mode.

The name at index 1 is read coercively, so a string (XYZ) matches here even though Dest::xyz would reject it.

use pdfrum_common::{Diagnostics, Limits};
use pdfrum_doc::Dest;
use pdfrum_object::{Array, Dict, Name, NoResolve, Object};

let array = Object::Array(Array::of([
    Object::Int(2),
    Object::Name(Name::from("XYZ")),
    Object::from(0.0_f32),
    Object::from(792.0_f32),
    Object::Int(0),
]));
let (catalog, limits) = (Dict::default(), Limits::default());
let mut diags = Diagnostics::default();
let dest = Dest::create(&catalog, Some(&array), &NoResolve, &limits, &mut diags);
use pdfrum_doc::ZoomMode;

assert_eq!(dest.zoom_mode(&NoResolve), ZoomMode::Xyz);
Source

pub fn num_params<R: Resolve>(&self, r: &R) -> usize

How many parameters this destination actually carries: the mode’s maximum, capped by what the array holds.

use pdfrum_common::{Diagnostics, Limits};
use pdfrum_doc::Dest;
use pdfrum_object::{Array, Dict, Name, NoResolve, Object};

let array = Object::Array(Array::of([
    Object::Int(2),
    Object::Name(Name::from("XYZ")),
    Object::from(0.0_f32),
    Object::from(792.0_f32),
    Object::Int(0),
]));
let (catalog, limits) = (Dict::default(), Limits::default());
let mut diags = Diagnostics::default();
let dest = Dest::create(&catalog, Some(&array), &NoResolve, &limits, &mut diags);

// `XYZ` names three parameters, and the array carries all three.
assert_eq!(dest.num_params(&NoResolve), 3);
Source

pub fn param(&self, index: usize) -> f32

Parameter index, counting from the first one after the mode name.

Unbounded: an index past the end reads as zero.

use pdfrum_common::{Diagnostics, Limits};
use pdfrum_doc::Dest;
use pdfrum_object::{Array, Dict, Name, NoResolve, Object};

let array = Object::Array(Array::of([
    Object::Int(2),
    Object::Name(Name::from("XYZ")),
    Object::from(0.0_f32),
    Object::from(792.0_f32),
    Object::Int(0),
]));
let (catalog, limits) = (Dict::default(), Limits::default());
let mut diags = Diagnostics::default();
let dest = Dest::create(&catalog, Some(&array), &NoResolve, &limits, &mut diags);

assert_eq!(dest.param(1), 792.0);
// Past the end reads as zero rather than panicking.
assert_eq!(dest.param(99), 0.0);
Source

pub fn params_all(&self) -> Vec<f32>

Every parameter, ignoring the mode entirely.

use pdfrum_common::{Diagnostics, Limits};
use pdfrum_doc::Dest;
use pdfrum_object::{Array, Dict, Name, NoResolve, Object};

let array = Object::Array(Array::of([
    Object::Int(2),
    Object::Name(Name::from("XYZ")),
    Object::from(0.0_f32),
    Object::from(792.0_f32),
    Object::Int(0),
]));
let (catalog, limits) = (Dict::default(), Limits::default());
let mut diags = Diagnostics::default();
let dest = Dest::create(&catalog, Some(&array), &NoResolve, &limits, &mut diags);

assert_eq!(dest.params_all(), [0.0, 792.0, 0.0]);
Source

pub fn xyz<R: Resolve>(&self, r: &R) -> Option<Xyz>

The three XYZ coordinates, when this is a well-formed XYZ destination.

Four gates, in order: at least five elements; index 1 is a name (not a string) spelling XYZ; each of indices 2–4 is a number or it is absent; and a zoom of exactly zero counts as absent while an x or y of zero does not.

use pdfrum_common::{Diagnostics, Limits};
use pdfrum_doc::Dest;
use pdfrum_object::{Array, Dict, Name, NoResolve, Object};

let array = Object::Array(Array::of([
    Object::Int(2),
    Object::Name(Name::from("XYZ")),
    Object::from(0.0_f32),
    Object::from(792.0_f32),
    Object::Int(0),
]));
let (catalog, limits) = (Dict::default(), Limits::default());
let mut diags = Diagnostics::default();
let dest = Dest::create(&catalog, Some(&array), &NoResolve, &limits, &mut diags);

let xyz = dest.xyz(&NoResolve).expect("a well-formed XYZ destination");
assert_eq!((xyz.x, xyz.y), (Some(0.0), Some(792.0)));
// A written zoom of zero means "unchanged", and reads as absent.
assert_eq!(xyz.zoom, None);
Source

pub fn page_index<R: Resolve>( &self, r: &R, page_index_of: impl Fn(u32) -> Option<PageIndex>, diags: &mut Diagnostics, ) -> Option<PageIndex>

The page index this destination names, or None when it names none.

A number at index 0 is returned verbatim, with no bounds check against the document’s page count — a file naming page 11 of a three-page document reports 11. A dictionary needs its object number looked up in the page tree, so an inline page dictionary, which has no number, cannot be found.

An out-of-range page index is a Some; only a genuine failure — four of them, all answering alike — is None.

page_index_of maps an object number — the indirect reference a dictionary entry carries — to the page it is, so its u32 argument is an object number and not an index. Only the answer is a PageIndex.

use pdfrum_common::{Diagnostics, Limits};
use pdfrum_doc::Dest;
use pdfrum_object::{Array, Dict, Name, NoResolve, Object};

let array = Object::Array(Array::of([
    Object::Int(2),
    Object::Name(Name::from("XYZ")),
    Object::from(0.0_f32),
    Object::from(792.0_f32),
    Object::Int(0),
]));
let (catalog, limits) = (Dict::default(), Limits::default());
let mut diags = Diagnostics::default();
let dest = Dest::create(&catalog, Some(&array), &NoResolve, &limits, &mut diags);
use pdfrum_common::PageIndex;

// A number at index 0 is returned verbatim, with no bounds check.
let page = dest.page_index(&NoResolve, |_| None, &mut diags);
assert_eq!(page, Some(PageIndex::from(2)));

Trait Implementations§

Source§

impl Clone for Dest

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 Dest

Source§

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

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

impl Default for Dest

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Dest

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 Dest

Auto Trait Implementations§

§

impl Freeze for Dest

§

impl RefUnwindSafe for Dest

§

impl Send for Dest

§

impl Sync for Dest

§

impl Unpin for Dest

§

impl UnsafeUnpin for Dest

§

impl UnwindSafe for Dest

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.