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: RectThe page’s own extent.
crop_box: RectThe visible region, already intersected with the media box.
rotate: RotationHow the page is displayed.
transparency: TransparencyThe 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
impl Page
Sourcepub fn objects(&self) -> &[PageObject]
pub fn objects(&self) -> &[PageObject]
The objects, for a caller who only reads them.
Sourcepub fn active_objects(&self) -> impl Iterator<Item = &PageObject>
pub fn active_objects(&self) -> impl Iterator<Item = &PageObject>
The objects that are painted, in painting order.
Sourcepub fn object_mut(&mut self, index: usize) -> Option<&mut PageObject>
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.
Sourcepub fn push_object(&mut self, object: PageObject)
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.
Sourcepub fn insert_object(
&mut self,
index: usize,
object: PageObject,
) -> Result<(), IndexOutOfRange>
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.
Sourcepub fn remove_object(&mut self, index: usize) -> Option<PageObject>
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.
Sourcepub fn is_dirty(&self) -> bool
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.
Sourcepub fn dirty_stream_set(&self) -> BTreeSet<Option<usize>>
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.
Sourcepub fn mark_clean(&mut self)
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.
Sourcepub fn ctm_at_start_of_stream(&self, stream: Option<usize>) -> Affine
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.
Sourcepub fn ctm_at_end_of_stream(&self, stream: usize) -> Affine
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.