Skip to main content

BuildContext

Struct BuildContext 

Source
pub struct BuildContext {
    pub colorspaces: ColorSpaceCache,
    pub functions: FunctionCache,
    pub images: ImageCache,
    pub decode_target: RequestedSize,
    pub fonts: Arc<FontCache>,
    pub substitution: SubstitutionOptions,
    /* private fields */
}
Expand description

The caches and guards a build shares across the whole page.

Owned by the caller and passed down by &mut — no globals, no interior mutability.

Fields§

§colorspaces: ColorSpaceCache

Colour spaces, keyed on the reference that named them.

§functions: FunctionCache

Functions, likewise.

§images: ImageCache

Decoded images, keyed on (reference, requested size).

§decode_target: RequestedSize

How much resolution this build’s images are wanted at.

A hint: a codec that cannot reduce returns full resolution and the image reports the size it actually decoded at. Full — the default — asks for every sample, which is what a build with no render target behind it wants.

One value per build rather than one per image: the size that matters is the render target’s, so the question a decode hint answers is how much bigger an image is than the whole page bitmap, not how small a rectangle it lands in.

§fonts: Arc<FontCache>

Fonts: the loaded-font cache and the font-identity counter.

Shared by Arc rather than owned, so every session over one document — every worker of a parallel render, and a text run and a render run alike — loads each font once between them. A context built with BuildContext::new gets a fresh one, which is the right answer for a caller with no document to hang it on; the facade hands its own document-owned cache to every session it makes.

§substitution: SubstitutionOptions

How a non-embedded font finds a face to draw with.

Carried here rather than passed in per call because every font load under one document must make the same choice: a substitution that varied between two Tf operators naming the same resource would give one line of text different metrics from the next. Defaults to the built-in faces alone, which is what keeps tests hermetic; the tool fills it from --font-dir and --croscore-font-names.

Implementations§

Source§

impl BuildContext

Source

pub fn new() -> Self

An empty context.

Source

pub fn with_substitution(options: SubstitutionOptions) -> Self

An empty context whose non-embedded fonts resolve through options.

The caches start empty either way; this only fixes how substitution will answer, which must be settled before the first font loads.

Source

pub fn form_fonts<T: Any + Send + Sync>( &mut self, key: FormFontsKey, load: impl FnOnce(&mut Self) -> T, ) -> Arc<T>

The interactive form’s faces for key, built by load on the first ask and handed back from the cache on every later one.

load is a closure, not a value, so a hit costs nothing to build. FormFontsKey::Direct is never cached and always calls load: it is the one case with no reference anywhere to key on, and reusing one document’s faces for another’s would be wrong.

Source

pub fn forms_in_flight(&self) -> usize

How many form parses are in flight.

Trait Implementations§

Source§

impl Debug for BuildContext

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for BuildContext

Source§

fn default() -> BuildContext

Returns the “default value” for a type. 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> 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, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

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.