Skip to main content

Link

Struct Link 

Source
pub struct Link {
    pub dict: Dict,
}
Expand description

A link annotation.

Fields§

§dict: Dict

The annotation dictionary.

Implementations§

Source

pub fn new(dict: Dict) -> Link

Wraps a dictionary as a link.

use pdfrum_doc::{Link, geom};
use pdfrum_object::{Array, Dict, Name, NoResolve, Object};

let link = Link::new(Dict::from_pairs([(
    Name::from("Rect"),
    Object::Array(Array::of([0, 700, 200, 780])),
)]));
assert_eq!(link.rect(&NoResolve), geom::rect(0.0, 700.0, 200.0, 780.0));
Source

pub fn rect<R: Resolve>(&self, r: &R) -> Rect

The link’s /Rect, not normalized.

use pdfrum_doc::nav::{Link, page_links};
use pdfrum_object::{Array, Dict, Name, NoResolve, Object};

let link = Dict::from_pairs([
    (Name::from("Subtype"), Object::Name(Name::from("Link"))),
    (
        Name::from("Rect"),
        Object::Array(Array::of([0, 700, 200, 780])),
    ),
]);
let page = Dict::from_pairs([(
    Name::from("Annots"),
    Object::Array(Array::of([Object::Dict(link)])),
)]);
use pdfrum_doc::geom;

let link = page_links(&page, &NoResolve)
    .next()
    .flatten()
    .expect("a link at index 0");
// Not normalized: the numbers are the ones the file wrote.
assert_eq!(link.rect(&NoResolve), geom::rect(0.0, 700.0, 200.0, 780.0));
Source

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

The link’s action, when it has one.

use pdfrum_doc::{ActionKind, Link};
use pdfrum_object::{Dict, Name, NoResolve, Object};

let action = Dict::from_pairs([(Name::from("S"), Object::Name(Name::from("URI")))]);
let link = Link::new(Dict::from_pairs([(Name::from("A"), Object::Dict(action))]));
assert_eq!(link.action(&NoResolve).map(|a| a.kind()), Some(ActionKind::Uri));
Source

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

Where the link goes.

/Dest is tried first and the action’s destination only when that yields no array — the same two-rung fallback a viewer applies.

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

let link = Link::new(Dict::from_pairs([(
    Name::from("Dest"),
    Object::Array(Array::of([Object::Int(1), Object::Name(Name::from("Fit"))])),
)]));

let mut diags = Diagnostics::default();
let dest = link.dest(&Dict::default(), &NoResolve, &Limits::default(), &mut diags);
// `/Dest` wins; the action is consulted only when it yields no array.
assert!(dest.array.is_some());

Trait Implementations§

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§

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

Formats the value using the given formatter. Read more
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

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.