pub enum ContentsShape {
Absent,
Single(ObjRef),
Array(Vec<ObjRef>),
}Expand description
Where a regenerated element lands in the page’s /Contents.
The /Contents entry is a stream, an array of streams, or absent, and
adding or removing an element moves it between those shapes. The rules are
not symmetric, which is the point of naming them:
- absent gaining an element becomes a lone stream at index 0;
- a lone stream gaining a second becomes an array
[old new], and the new one is index 1; - an array gaining one appends, at
len - 1; - a lone stream losing index 0 loses the
/Contentskey entirely; - an array losing elements keeps being an array — even down to one element, and even down to none. Collapsing a one-element array back to a bare stream would be tidier and is deliberately not done: a second stream may well be added next, and every object’s recorded index would have to move again.
Variants§
Absent
No /Contents at all.
Single(ObjRef)
One stream, reached through /Contents directly.
Array(Vec<ObjRef>)
An array of stream references.
Implementations§
Source§impl ContentsShape
impl ContentsShape
Sourcepub fn read(page_dict: &Dict, r: &impl Resolve) -> Self
pub fn read(page_dict: &Dict, r: &impl Resolve) -> Self
Read the shape out of a page dictionary.
Anything that is neither a stream nor an array of streams — a dangling
reference, a number, a name — reads as ContentsShape::Absent, which
is how a page with unusable contents behaves everywhere else.
Sourcepub fn with_added(&self, added: ObjRef) -> (usize, Self)
pub fn with_added(&self, added: ObjRef) -> (usize, Self)
The index a newly added element takes, and the shape afterwards.
Sourcepub fn with_removed(
&self,
removed: &BTreeSet<usize>,
) -> (Self, BTreeMap<usize, usize>)
pub fn with_removed( &self, removed: &BTreeSet<usize>, ) -> (Self, BTreeMap<usize, usize>)
The shape after removed elements are dropped, and the map from each
surviving element’s old index to its new one.
Every object whose index is not in the map — one whose own element was removed, and one that was still streamless — collapses to index 0. That is the C++’s default-inserting map read literally, and it is deliberate: those objects were not written by this regeneration and their recorded index has to point somewhere.
Both halves of the map are usize: a /Contents index is a position
in an array, and there is no negative sentinel.
Trait Implementations§
Source§impl Clone for ContentsShape
impl Clone for ContentsShape
Source§fn clone(&self) -> ContentsShape
fn clone(&self) -> ContentsShape
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more