Skip to main content

Page

Struct Page 

Source
pub struct Page {
    pub objects: Vec<PageObject>,
    pub media_box: Rect,
    pub crop_box: Rect,
    pub rotate: Rotation,
    pub transparency: Transparency,
    pub resources: Option<Dict>,
    pub dirty_streams: BTreeSet<Option<usize>>,
    pub stream_ctms: BTreeMap<usize, Affine>,
}
Expand description

An interpreted page.

Fields§

§objects: Vec<PageObject>

The objects, in painting order.

§media_box: Rect

The page’s own extent.

§crop_box: Rect

The visible region, already intersected with the media box.

§rotate: Rotation

How the page is displayed.

§transparency: Transparency

The page’s transparency group. A page is always isolated, whatever its /Group says.

§resources: Option<Dict>

The page’s resource dictionary, for a caller that needs to re-resolve a name.

§dirty_streams: BTreeSet<Option<usize>>

/Contents elements that must be written again because objects were removed from them (see PageObject::set_active).

Only removals need recording here: a modified or hidden object still carries its own Content::dirty, but a removed one leaves nothing behind to say its stream lost something.

§stream_ctms: BTreeMap<usize, Affine>

The transform each /Contents element leaves in force at its end, keyed by element index.

A content stream can leave the transform changed for the ones after it — an unbalanced q/cm is legal and common — so a stream rewritten on its own must first undo what it inherited and then restate what it passes on. Only streams that actually changed the transform have an entry.

Implementations§

Source§

impl Page

Source

pub fn objects(&self) -> &[PageObject]

The objects, for a caller who only reads them.

Source

pub fn active_objects(&self) -> impl Iterator<Item = &PageObject>

The objects that are painted, in painting order.

Source

pub fn object_mut(&mut self, index: usize) -> Option<&mut PageObject>

The object at index, marked dirty for the caller’s edit.

Handing out a &mut is the edit, so the flag is set on the way out rather than being the caller’s to remember. A caller that only wants to read uses Page::objects.

Source

pub fn push_object(&mut self, object: PageObject)

Append an object to the end of the page’s painting order.

The object arrives dirty and streamless, so the next save gives it a content stream of its own — or the lowest free index, when the page had none.

Source

pub fn insert_object( &mut self, index: usize, object: PageObject, ) -> Result<(), IndexOutOfRange>

Insert an object at index, shifting the objects there and after.

A streamless object adopts its new neighbour’s stream so that the requested position survives the save: without that it would be appended to a fresh /Contents element, which is drawn last whatever its index in the list said. An index equal to the length appends.

§Errors

IndexOutOfRange when index is past the end.

Source

pub fn remove_object(&mut self, index: usize) -> Option<PageObject>

Remove the object at index and hand it back.

Its stream is recorded as dirty first — once the object is gone nothing is left to say the stream must lose it.

Source

pub fn is_dirty(&self) -> bool

Whether anything on the page needs its content stream rewritten.

The regenerator’s early-out: a page answering false keeps its /Contents and /Resources bytes exactly as they were.

Source

pub fn dirty_stream_set(&self) -> BTreeSet<Option<usize>>

Every content stream that has to be written again.

The union of the streams named by dirty objects — including inactive ones, whose streams must be regenerated precisely so that they lose them — and the streams recorded when objects were removed.

Source

pub fn mark_clean(&mut self)

Forget every pending change: the page is now as its bytes describe it.

Called once a save has written the regenerated streams.

Source

pub fn ctm_at_start_of_stream(&self, stream: Option<usize>) -> Affine

The transform in force where stream begins.

A content stream inherits whatever transform the streams before it left behind, so a stream rewritten on its own has to undo that inheritance before it states its own state — otherwise the regenerated bytes are interpreted under a matrix the original never saw. Stream 0, and a page that recorded no transforms at all, begin at the identity; the streamless object is appended after everything and so begins wherever the last stream ended.

Source

pub fn ctm_at_end_of_stream(&self, stream: usize) -> Affine

The transform in force where stream ends.

A stream that recorded nothing answers with the first later stream that did — the transform was never changed in between — and falls back to the last recorded one when there is no later stream at all.

Source§

impl Page

Source

pub fn empty() -> Self

An empty page of the default size.

A page with no /Contents parses successfully with zero objects; it is never an error.

Source

pub fn display_size(&self) -> (f64, f64)

The size the page displays at, with width and height swapped for a quarter or three-quarter turn.

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
Source§

impl Debug for Page

Source§

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

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

impl PartialEq for Page

Source§

fn eq(&self, other: &Page) -> 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 Page

Auto Trait Implementations§

§

impl !RefUnwindSafe for Page

§

impl !UnwindSafe for Page

§

impl Freeze for Page

§

impl Send for Page

§

impl Sync for Page

§

impl Unpin for Page

§

impl UnsafeUnpin 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, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

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.