pub struct Link {
pub dict: Dict,
}Expand description
A link annotation.
Fields§
§dict: DictThe annotation dictionary.
Implementations§
Source§impl Link
impl Link
Sourcepub fn new(dict: Dict) -> Link
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));Sourcepub fn rect<R: Resolve>(&self, r: &R) -> Rect
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));Sourcepub fn action<R: Resolve>(&self, r: &R) -> Option<Action>
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));Sourcepub fn dest<R: Resolve>(
&self,
catalog: &Dict,
r: &R,
limits: &Limits,
diags: &mut Diagnostics,
) -> Dest
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§
impl StructuralPartialEq for Link
Auto Trait Implementations§
impl Freeze for Link
impl RefUnwindSafe for Link
impl Send for Link
impl Sync for Link
impl Unpin for Link
impl UnsafeUnpin for Link
impl UnwindSafe for Link
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more