Skip to main content

LayoutState

Struct LayoutState 

Source
pub(crate) struct LayoutState {
Show 14 fields pub(crate) pages: Vec<Page>, pub(crate) current_page: Page, pub(crate) cursor_y: f32, pub(crate) page_has_content: bool, pub(crate) diagnostics: Vec<Diagnostic>, pub(crate) page: PageStyle, pub(crate) text: TextStyle, pub(crate) image_handles: Vec<ImageHandle>, pub(crate) current_left_pt: f32, pub(crate) pending_marker: Option<PendingMarker>, pub(crate) pending_labels: Vec<String>, pub(crate) label_pages: BTreeMap<String, u32>, pub(crate) pending_outline: Option<PendingOutline>, pub(crate) outline: Vec<OutlineEntry>,
}
Expand description

Mutable cursor + accumulator threaded through the layout.

Fields§

§pages: Vec<Page>§current_page: Page

In-progress page being filled.

§cursor_y: f32

Y position of the next baseline, measured from page top.

§page_has_content: bool

Whether current_page has had any block emitted yet (controls space_before skipping).

§diagnostics: Vec<Diagnostic>§page: PageStyle§text: TextStyle§image_handles: Vec<ImageHandle>

Image dedup table: resolved path → handle. Two #image(...) directives that reference the same on-disk file share one ImageHandle (and therefore one XObject in the emitted PDF).

§current_left_pt: f32

Left edge of the current text column. Equals page.margin at the top level; list layout pushes this rightward so item text hangs into the gutter under its marker.

§pending_marker: Option<PendingMarker>

Marker run to emit at the start of the next flushed line. Used by list items to draw / 1. in the gutter to the left of current_left_pt on the first line of each item. Cleared by flush_line once the marker is committed to a page.

§pending_labels: Vec<String>

Labels of blocks dispatched but not yet committed to a page. Bound to the page their first content lands on (issue #72): see LayoutState::bind_pending_labels.

§label_pages: BTreeMap<String, u32>

Built result of label → 1-based start page. Emitted into the PageGraph by LayoutState::finish.

§pending_outline: Option<PendingOutline>

Heading captured in layout_heading but not yet committed to a page. Bound to the page (and glyph-top y) of the heading’s first flushed line by LayoutState::bind_pending_outline, mirroring the pending-label flow.

§outline: Vec<OutlineEntry>

Bookmark/outline entries in document order. Emitted into the PageGraph by LayoutState::finish.

Implementations§

Source§

impl LayoutState

Source

pub(crate) fn layout_bibliography( &mut self, document: &Document, bib_node: &Node, )

Lay out a NodeKind::Bibliography node’s rendered entry children.

A declaration-only node (nothing cited, or a second #bibliography declaration) has no entry children and emits nothing, preserving the pre-rendering behavior of the directive being invisible in the PDF.

Source§

impl LayoutState

Source

pub(crate) fn layout_image(&mut self, node_id: NodeId, image: &Node)

Lay out a top-level Image node as a block. The image is horizontally centred within the column and capped at the column width; declared width/height override natural 72-DPI size.

Source

pub(crate) fn layout_figure(&mut self, document: &Document, figure: &Node)

Lay out a Figure block and keep image + caption together when the remaining space allows.

Source

fn measure_paragraph_height(&self, document: &Document, paragraph: &Node) -> f32

Source

fn intrinsic_image_size(image: &Node) -> Option<(f32, f32)>

Source

fn intern_image(&mut self, image: &Node) -> Option<ImageHandle>

Source§

impl LayoutState

Source

pub(crate) fn layout_list(&mut self, document: &Document, list_node: &Node)

Lay out a NodeKind::List and its NodeKind::ListItem children with hanging indent.

Source

fn layout_list_item_blocks( &mut self, document: &Document, item: &Node, regular: Font, size: f32, leading: f32, )

Source

fn flush_marker_only_line_if_pending(&mut self, leading: f32)

Source§

impl LayoutState

Source

pub(crate) const fn new(page: PageStyle, text: TextStyle) -> Self

Source

pub(crate) fn queue_label(&mut self, node: &Node)

Queue a block’s label attribute (if present) for binding to the page its first content commits to (issue #72).

Source

pub(crate) fn discard_unbound_labels(&mut self)

Drop labels still queued after a block finished laying out. The block (or its label) committed no content, so the label has no page; clearing it keeps a labelled no-content block out of label_pages instead of letting its label leak onto the next block that does emit content. Only the just-dispatched block’s label can be queued here, since queue_label runs once per top-level block.

Source

pub(crate) fn bind_pending_labels(&mut self)

Bind every queued label to the current page. Called at each first-content-commit site after its page-break check, so a label maps to where its target actually lands. First placement wins (or_insert), matching the resolver’s first-occurrence label rule.

Source

pub(crate) fn bind_pending_outline(&mut self, top_from_top_pt: f32)

Bind a pending heading to the current page as an outline entry. Called from flush_line after the page break check, so a heading whose first line spills to the next page records that page. Cleared on push so only the heading’s first flushed line binds; wrapped continuation lines of the same heading don’t restamp it.

Source

pub(crate) fn column_width_pt(&self) -> f32

Source

pub(crate) fn finish(self) -> LayoutResult

Source

pub(crate) fn layout_heading(&mut self, document: &Document, section: &Node)

Source

pub(crate) fn layout_paragraph(&mut self, document: &Document, paragraph: &Node)

Source

pub(crate) fn layout_raw_block(&mut self, raw: &Node)

Source

pub(crate) fn collect_words( &self, document: &Document, parent: &Node, default_font: Font, size: f32, ) -> Vec<WordItem>

Walk parent’s inline children and produce a flat list of [WordItem]s. Source ASCII whitespace becomes explicit collapsed glue on the following word; inline style/font boundaries alone produce no glue and no break opportunity. A source line wrap before closing punctuation is formatting only and attaches to the previous word. U+00A0 NBSP is intentionally preserved inside the word. Each visible fragment is shaped once here, and no-source-space fragments merge into one unbreakable layout word even when their fonts differ.

Source

pub(crate) fn collect_text_words( &self, raw: &str, font: Font, size: f32, current_word: &mut Option<Word>, pending_space: &mut Option<PendingSpace>, out: &mut Vec<WordItem>, )

Source

pub(crate) fn append_word_piece( &self, piece: &str, font: Font, size: f32, current_word: &mut Option<Word>, pending_space: &mut Option<PendingSpace>, out: &mut Vec<WordItem>, )

Source

pub(crate) fn append_to_current_word( current_word: &mut Option<Word>, text: String, font: Font, size: f32, width_pt: f32, subruns: Vec<WordSubRun>, shy_offsets: Vec<usize>, )

Source

pub(crate) fn flush_pending_word( current_word: &mut Option<Word>, out: &mut Vec<WordItem>, )

Source

pub(crate) fn flow_words(&mut self, items: &[WordItem], leading: f32)

Greedy line-break items and emit text runs onto the page, paginating as we go. leading is the line-height multiplier applied per line. WordItem::HardBreak forces a line flush at its position (and produces a blank line when two hard breaks are adjacent or one lands mid-paragraph with no words behind it).

Source

pub(crate) fn flush_line(&mut self, line: &[Word], leading: f32)

Emit one line worth of words at cursor_y, advancing past it. Computes the line’s typographic metrics from line itself so the caller doesn’t have to track them in parallel.

Source

pub(crate) fn flush_oversize_word(&mut self, word: &Word, leading: f32)

Emit a word that’s wider than the column by chopping it on already-shaped cluster boundaries. The word was shaped when it was collected, so this avoids re-running rustybuzz for every growing prefix of a degenerate long word.

Source

pub(crate) fn flush_oversize_chunk( &mut self, text: String, width_pt: f32, subruns: Vec<WordSubRun>, source: &Word, leading: f32, )

Source

pub(crate) fn start_new_page(&mut self)

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> 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.

§

impl<U, T> ToOwnedObj<U> for T
where U: FromObjRef<T>,

§

fn to_owned_obj(&self, data: FontData<'_>) -> U

Convert this type into T, using the provided data to resolve any offsets.
§

impl<U, T> ToOwnedTable<U> for T
where U: FromTableRef<T>,

§

fn to_owned_table(&self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.