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
impl ContentStream
Sourcepub fn from_page(
view: &DocumentView<'_>,
page: &Page,
) -> Result<Self, ContentError>
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-shotpdfceroperation, 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.
Sourcepub fn from_form(
view: &DocumentView<'_>,
id: ObjId,
) -> Result<Self, ContentError>
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).
Sourcepub fn parse(buf: Vec<u8>) -> Result<Self, ContentError>
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.
Sourcepub fn parse_from(
buf: Vec<u8>,
tokens: Vec<ContentToken>,
from: usize,
) -> Result<Self, ContentError>
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.
Sourcepub fn operations(&self) -> impl Iterator<Item = Operation<'_>>
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.