Skip to main content

ContentStream

Struct ContentStream 

Source
pub struct ContentStream {
    pub buf: Vec<u8>,
    pub tokens: Vec<ContentToken>,
}
Expand description

A parsed content stream: the decoded bytes plus their lossless token stream.

Fields§

§buf: Vec<u8>

The decoded (defiltered, concatenated) content bytes — the buffer every token span indexes.

§tokens: Vec<ContentToken>

The tokens, in stream order.

Implementations§

Source§

impl ContentStream

Source

pub fn from_page( view: &DocumentView<'_>, page: &Page, ) -> Result<Self, ContentError>

Concatenate, decode, and tokenize a page’s Contents streams.

Multiple streams concatenate in order with a single LF between parts (§7.7.3.3: the split is guaranteed to fall on a token boundary, but the boundary itself may carry no whitespace — a separator can never merge tokens and its absence could fail to separate them).

§Which document does view mean? (decision 018)

This used to take &Document — always the file as loaded. It now takes a DocumentView, because the answer genuinely differs by caller and the type should make the caller say which they meant:

  • &doc.view() — the base revision. What a one-shot pdfcer operation, a text/redaction planner, or a save-time walk wants: the bytes on disk, no session overlay.
  • &session.view() — the edited state. What the rasterizer and the vector object model want, so the operator sees the page they are actually editing.

Getting this wrong is not a crash, it is the Pass 17.0 defect: the content parses fine and shows the wrong document. Every caller in the tree was audited when this signature changed, and the ones whose base-vs-session intent is not obvious from context carry a comment saying which they are and why.

§Errors

ContentError — decode failures or malformed content syntax.

Source

pub fn from_form( view: &DocumentView<'_>, id: ObjId, ) -> Result<Self, ContentError>

One form XObject’s own decoded content (Pass 119.0).

A form XObject is a content stream in its own right (§8.10.1) — a separate object with separate bytes, its own /Resources and its own coordinate space. It is emphatically not part of the page’s concatenated /Contents, which is why Self::from_page cannot reach the text inside one and why the edit surgery needed this door opened.

The view argument carries the same base-versus-session meaning as Self::from_page, and it is more load-bearing here: once a session can edit a form’s content, a second edit to the same form must compose on top of the first, and only a session view resolves the staged value.

§Errors

ContentError::NotAStream when the object is absent or is not a stream; a decode or syntax error otherwise. The /Subtype is not checked here: this decodes whatever stream it is pointed at, and deciding what counts as an editable form belongs to the caller that found it (crate::text_edit::forms).

Source

pub fn parse(buf: Vec<u8>) -> Result<Self, ContentError>

Tokenize decoded content bytes into the lossless token stream.

§Errors

ContentError — malformed syntax; offsets are into buf.

Source

pub fn parse_from( buf: Vec<u8>, tokens: Vec<ContentToken>, from: usize, ) -> Result<Self, ContentError>

Tokenize buf from byte from onward, appending to tokens – the tokens already read from buf[..from].

Equal to Self::parse of the same buf when from is a token boundary of it and tokens is exactly what parse produced before that boundary; that is how a caller re-tokenizes only the part of a concatenated /Contents that changed. A from past the end reads nothing more.

§Errors

ContentError – malformed syntax at or after from; offsets are into buf.

Source

pub fn operations(&self) -> impl Iterator<Item = Operation<'_>>

The semantic projection: iterate operations (operand run + operator, or a standalone inline image). Purely a VIEW over the token stream — never a second representation (001 §6.1.2).

Trailing operands with no operator (malformed per §7.8.2 “operands shall not be left over”) are simply not yielded — the tolerance every real viewer applies; the tokens remain in self.tokens for lossless re-emission.

Trait Implementations§

Source§

impl Clone for ContentStream

Source§

fn clone(&self) -> Self

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 ContentStream

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> Same for T

Source§

type Output = T

Should always be Self
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.