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§impl Debug for ContentsShape
impl Debug for ContentsShape
impl Eq for ContentsShape
Source§impl PartialEq for ContentsShape
impl PartialEq for ContentsShape
impl StructuralPartialEq for ContentsShape
Auto Trait Implementations§
impl Freeze for ContentsShape
impl RefUnwindSafe for ContentsShape
impl Send for ContentsShape
impl Sync for ContentsShape
impl Unpin for ContentsShape
impl UnsafeUnpin for ContentsShape
impl UnwindSafe for ContentsShape
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
Source§fn to_owned_obj(&self, data: FontData<'_>) -> U
fn to_owned_obj(&self, data: FontData<'_>) -> U
T, using the provided data to resolve any offsets.