Skip to main content

Page

Struct Page 

Source
pub struct Page {
    pub index: usize,
    pub media_box: Rect,
    pub crop_box: Rect,
    pub rotate: i32,
    pub resources: Dict,
    /* private fields */
}
Expand description

A single page with inherited attributes already applied.

Defaults: media_box falls back to US Letter (612x792) when absent or invalid, crop_box falls back to (and is intersected with) media_box, and rotate is normalized to one of {0, 90, 180, 270}. Every construction path normalizes rotateDocument::page and Page::from_parts alike — so the invariant holds however a Page was built. rotate is a public field, so a caller may still overwrite it afterwards; Page::size reads it modulo a full turn and so stays correct if they do.

Fields§

§index: usize

0-based page index.

§media_box: Rect§crop_box: Rect§rotate: i32§resources: Dict

The page’s (inherited) /Resources dictionary.

Implementations§

Source§

impl Page

Source

pub const US_LETTER: Rect

The default media box for a page that declares none: US Letter (612 by 792 points). Public because the default is part of the observable contract — a caller comparing two APIs’ pages needs to know which rectangle “the file said nothing” maps to.

Source

pub fn from_parts( index: usize, media_box: Rect, crop_box: Rect, rotate: i32, resources: Dict, dict: Dict, obj_ref: Option<ObjRef>, ) -> Page

Builds a page from already-resolved attributes.

Document::page resolves page-tree inheritance itself; this is for a caller that has done that resolution some other way — notably the asynchronous API, which flattens the page tree while reading it — and needs the same Page type back.

rotate is normalized here to one of {0, 90, 180, 270} exactly as Document::page normalizes it, so a caller may pass a raw /Rotate straight through: a negative or over-a-full-turn multiple of 90 is reduced, and a value that is not a multiple of 90 falls back to 0 (lenient). The caller does not have to pre-normalize, and the Page invariant holds whichever constructor built it.

Source

pub fn from_tree_attrs( index: usize, resources: Option<Dict>, media_box: Option<Rect>, crop_box: Option<Rect>, rotate: Option<i32>, dict: Dict, obj_ref: Option<ObjRef>, ) -> Page

Builds a page from raw, possibly missing page-tree attributes, applying the same defaults Document::page applies (ISO 32000 §7.7.3.3): a missing or degenerate /MediaBox reads as Page::US_LETTER, /CropBox clips to the media box and falls back to it, a missing /Rotate reads as 0 and is normalized, and missing /Resources read as empty.

This is the one implementation of page defaulting. The synchronous tree walk routes through it, and a caller that resolved inheritance some other way — notably the asynchronous API, which flattens the page tree while reading it — gets the identical Page back, so the two APIs cannot disagree about what an attribute-less page looks like.

Source

pub fn object_ref(&self) -> Option<ObjRef>

The page’s indirect object reference, when the page came from an indirect kid in the page tree (pages inlined directly into a /Kids array have none).

Source

pub fn content(&self, doc: &Document) -> Result<Vec<u8>>

The page’s decoded content: the /Contents stream, or all streams of a /Contents array decoded and joined with b"\n". A missing /Contents yields empty content (lenient).

This drives page_content_with to completion on the calling thread. There is one implementation of the algorithm, so this and the asynchronous API cannot drift apart in what they consider a page’s content to be.

Source

pub fn size(&self) -> (f32, f32)

Crop-box width and height, swapped when /Rotate is a quarter turn.

Both constructors normalize rotate, but the field is public and so can be overwritten with a raw /Rotate; the rotation is therefore read modulo a full turn rather than compared against 90 and 270 exactly, so that -90 and 450 swap the dimensions just as 270 and 90 do. For an already-normalized value this is the same test as before: 0, 90, 180 and 270 are unchanged by rem_euclid(360).

Source

pub fn dict(&self) -> &Dict

The raw page dictionary.

Trait Implementations§

Source§

impl Clone for Page

Source§

fn clone(&self) -> Page

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

Auto Trait Implementations§

§

impl Freeze for Page

§

impl RefUnwindSafe for Page

§

impl Send for Page

§

impl Sync for Page

§

impl Unpin for Page

§

impl UnsafeUnpin for Page

§

impl UnwindSafe for Page

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.