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: ColorSpaceCacheColour spaces, keyed on the reference that named them.
functions: FunctionCacheFunctions, likewise.
images: ImageCacheDecoded images, keyed on (reference, requested size).
decode_target: RequestedSizeHow 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: SubstitutionOptionsHow 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
impl BuildContext
Sourcepub fn with_substitution(options: SubstitutionOptions) -> Self
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.
Sourcepub fn form_fonts<T: Any + Send + Sync>(
&mut self,
key: FormFontsKey,
load: impl FnOnce(&mut Self) -> T,
) -> Arc<T> ⓘ
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.
Sourcepub fn forms_in_flight(&self) -> usize
pub fn forms_in_flight(&self) -> usize
How many form parses are in flight.