Skip to main content

Session

Struct Session 

Source
pub struct Session<'a> { /* private fields */ }
Expand description

A retained pipeline: content, styling, and every stage between them and the page.

let mut session = Session::new(&registry);
session.set_content(Book::default());
session.set_style(Stylesheets::parse(&[]));
let pages = &session.preview().pages;

A computed style can only resolve to a face already in the registry. A session over a borrowed registry leaves it as the host made it, so a sheet that brings its own @font-face needs the host to load that face before the sheet is set. A session that owns its registry registers the faces the sheet declares from the files add_font_file hands over.

Implementations§

Source§

impl Session<'_>

Source

pub fn set_content(&mut self, book: Book)

Sets the book, and with it every stage below box construction.

Node identity is the engine’s: the tree is renumbered on the way in, so a host may hand over sections it built by hand.

Source

pub fn replace_source(&mut self, name: &str, sections: Vec<Section>)

Replaces every section that came from one source file.

The source is the replaceable unit because a host names files and one file may split into several sections. A name the book does not already have appends instead, which is how a file it has not seen before arrives.

Source

pub fn set_source_attributes(&mut self, name: &str, attributes: &Attributes)

Names every section that came from one source by these classes and this id, and styles the book again.

The names sit beside the source rather than in it, so every node keeps the bytes it was read from. A name the book does not carry changes nothing.

Source

pub fn set_source_warnings(&mut self, warnings: Vec<Warning>)

Adds a frontend’s complaints to the run’s diagnostics.

A construct the content vocabulary cannot express is reported where the source was read, which is upstream of every stage a session runs. The output’s warnings are the whole run’s, so they belong in the same channel rather than in a second one the host has to remember to read. Which of them still apply after an edit is the caller’s to decide; this replaces the lot.

Source

pub fn set_style(&mut self, sheets: Stylesheets)

Sets the styling, and with it whichever stage the change reaches, which is usually far short of everything.

Source

pub fn set_metadata(&mut self, metadata: Metadata)

Names the book: title, author, and whatever else a frontend read.

The declared language is the one field a stage below reads, and a book that changes it is hyphenated again. The pages already laid out are otherwise the pages the export writes under the new name.

Source

pub fn add_font(&mut self, source: FontSource) -> Result<Vec<u16>, AddFontError>

Registers a face, and re-runs everything a face can change.

A family the registry did not have is a family the cascade resolved to something else, so the styling is compiled again and the lines are broken again. The output’s font table is rebuilt with them.

Only a session that owns its registry has one to add to; one that borrowed it says so instead.

Source

pub fn add_image( &mut self, url: &str, bytes: Vec<u8>, ) -> Result<Option<u32>, AddImageError>

Registers one image, and the index DrawItem::Image.asset gets for it. None for bytes no probe recognises, which is a diagnostic on the next display structure and no asset.

A url registered again with the bytes it already answers for costs nothing. Registered again with different bytes, it replaces them in place: the box the image takes is re-broken only if the header now reports a different size, since the PDF writer reads the asset table fresh on every export and needs no invalidation to see new pixels at an unchanged size. An image whose contour was traced is the exception, because the pixels are what the contour came from. Only a session that owns its asset table has one to add to; one that borrowed it says so instead.

Source§

impl Session<'_>

Source

pub fn add_font_file( &mut self, url: &str, bytes: Vec<u8>, ) -> Result<(), AddFontError>

Keeps a font file under the url a @font-face names it by, and registers whatever the sheet declares from it.

A url no rule names is kept until one does, so the file and the sheet can arrive in either order. The same bytes at the same url again cost nothing.

Source§

impl Session<'_>

Source

pub fn inspect(&mut self, node: NodeId) -> Option<Inspection>

The element one node stands for, the rules that matched it and what it computed to, and its border box on each page it reaches. A text node answers for the element that holds it. A pseudo-element answers for itself, with its own boxes: the box ::before or ::after generates on a block, or else the area its text covers on each page.

Nothing for a node the book does not hold, or for the id the engine writes its own text under. An id names a node only until the next edit, so the answer is about the book as it stands.

Source

pub fn inspect_margin_box( &mut self, index: usize, which: MarginBox, ) -> Option<Inspection>

The same for one margin box of the page at index, counting from 0: the page selector it answers to, the @page rules that set it, and the box its text takes.

Nothing for a page the book does not have, for a blank page, and for a box no rule for that page names.

Source

pub fn hit(&mut self, index: usize, x: f32, y: f32) -> Option<NodeId>

The innermost element at a point on the page at index, in points from its top-left corner: the element that holds the text there, or else the innermost block whose border box holds the point, padding and empty space included. Where two such things overlap, the one painted later answers. A pseudo-element answers with its own id: a drop cap, the line a paragraph opens on, and the box or the text of ::before and ::after. An inline element on the opening line answers for itself.

Nothing outside every box, and nothing for a page the book does not have.

Source§

impl Session<'_>

Source

pub fn preview(&mut self) -> &LayoutOutput

The display structure, brought up to date.

Source

pub fn export(&mut self) -> Result<Vec<u8>, PdfError>

The same, as PDF bytes. The stages above the painter are the ones the preview used, so an export cannot contradict it.

Source

pub fn folios(&mut self, nodes: &[NodeId]) -> Vec<Option<Folios>>

Where each of these nodes’ content is set, answered in the order they were asked about: the folios it runs between, and the pages of the book those folios are.

A node covers itself and everything under it, so a heading answers with the page its own text is on, and a chapter with the pages it runs across. Nothing for a node the book does not hold, and nothing for one whose content reaches no page: a node the engine synthesized, or a scene break, whose ornament the engine wrote itself.

The answer is a walk over the pages the session already holds. It runs a stage only when an edit has left one to run.

Source

pub fn into_output(self) -> LayoutOutput

The display structure by value, consuming the session.

Source§

impl<'a> Session<'a>

Source

pub fn new(registry: &'a FontRegistry) -> Session<'a>

A session over the faces in registry, with no content and the built-in sheet alone.

Source

pub fn with_assets( registry: &'a FontRegistry, assets: &'a Assets, ) -> Session<'a>

The same, over images the host has already probed.

Source

pub fn owning(registry: FontRegistry) -> Session<'static>

A session that owns the faces it lays out against, and takes more through add_font.

This is the shape a worker needs: font bytes cross the boundary once, the module keeps them, and no caller on the other side of the wall has a registry to lend.

Source§

impl Session<'_>

Source

pub fn book(&self) -> &Book

The session’s own copy of the book, node ids assigned.

Source

pub fn names(&self, source: Option<&str>) -> Names

The classes and the ids the blocks and inlines of one source carry, or of the whole book when source is None, as the book holds them now. A section’s own names are not in the answer.

Source

pub fn styles(&self) -> &StyleTree

The compiled styling behind the last update.

Source

pub fn sheets(&self) -> Option<&Stylesheets>

The sheets the styling was compiled from, as the host last set them.

Source

pub fn images(&self) -> &Assets

The images this session holds, by the url each was registered under.

Source

pub fn font_files(&self) -> &dyn FontLoader

The files add_font_file handed over, by the url a @font-face names them by.

Source

pub fn fonts(&self) -> &FontRegistry

The faces this session lays out against.

A painter that has to draw with the same file the shaper used reaches the bytes through here; the display structure names ids, and the registry is what they index.

Source

pub fn stages(&self) -> Stages

How many times each stage has run.

Source

pub fn reuses_sections(&self) -> bool

Whether a section’s lines survive an edit elsewhere in the book. This goes false when the styling breaks a precondition, either masters of different measures or inline content that depends on pagination, and everything is re-broken instead.

Auto Trait Implementations§

§

impl<'a> Freeze for Session<'a>

§

impl<'a> RefUnwindSafe for Session<'a>

§

impl<'a> Send for Session<'a>

§

impl<'a> Sync for Session<'a>

§

impl<'a> Unpin for Session<'a>

§

impl<'a> UnsafeUnpin for Session<'a>

§

impl<'a> UnwindSafe for Session<'a>

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
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> Finish for T

§

fn finish(self)

Does nothing but move self, equivalent to drop.
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.