pub struct CacheBuilder { /* private fields */ }
Expand description

Builder & rebuilder for Cache.

Example

use rusttype::gpu_cache::Cache;

// Create a cache with all default values set explicitly
// equivalent to `Cache::builder().build()`
let default_cache = Cache::builder()
    .dimensions(256, 256)
    .scale_tolerance(0.1)
    .position_tolerance(0.1)
    .pad_glyphs(true)
    .align_4x4(false)
    .multithread(true)
    .build();

// Create a cache with all default values, except with a dimension of 1024x1024
let bigger_cache = Cache::builder().dimensions(1024, 1024).build();

Implementations§

source§

impl CacheBuilder

source

pub fn dimensions(self, width: u32, height: u32) -> CacheBuilder

width & height dimensions of the 2D texture that will hold the cache contents on the GPU.

This must match the dimensions of the actual texture used, otherwise cache_queued will try to cache into coordinates outside the bounds of the texture.

Example (set to default value)
let cache = Cache::builder().dimensions(256, 256).build();
source

pub fn scale_tolerance<V>(self, scale_tolerance: V) -> CacheBuilder
where V: Into<f32>,

Specifies the tolerances (maximum allowed difference) for judging whether an existing glyph in the cache is close enough to the requested glyph in scale to be used in its place. Due to floating point inaccuracies a min value of 0.001 is enforced.

Both scale_tolerance and position_tolerance are measured in pixels.

Tolerances produce even steps for scale and subpixel position. Only a single glyph texture will be used within a single step. For example, scale_tolerance = 0.1 will have a step 9.95-10.05 so similar glyphs with scale 9.98 & 10.04 will match.

A typical application will produce results with no perceptible inaccuracies with scale_tolerance and position_tolerance set to 0.1. Depending on the target DPI higher tolerance may be acceptable.

Example (set to default value)
let cache = Cache::builder().scale_tolerance(0.1).build();
source

pub fn position_tolerance<V>(self, position_tolerance: V) -> CacheBuilder
where V: Into<f32>,

Specifies the tolerances (maximum allowed difference) for judging whether an existing glyph in the cache is close enough to the requested glyph in subpixel offset to be used in its place. Due to floating point inaccuracies a min value of 0.001 is enforced.

Both scale_tolerance and position_tolerance are measured in pixels.

Tolerances produce even steps for scale and subpixel position. Only a single glyph texture will be used within a single step. For example, scale_tolerance = 0.1 will have a step 9.95-10.05 so similar glyphs with scale 9.98 & 10.04 will match.

Note that since position_tolerance is a tolerance of subpixel offsets, setting it to 1.0 or higher is effectively a “don’t care” option.

A typical application will produce results with no perceptible inaccuracies with scale_tolerance and position_tolerance set to 0.1. Depending on the target DPI higher tolerance may be acceptable.

Example (set to default value)
let cache = Cache::builder().position_tolerance(0.1).build();
source

pub fn pad_glyphs(self, pad_glyphs: bool) -> CacheBuilder

Pack glyphs in texture with a padding of a single zero alpha pixel to avoid bleeding from interpolated shader texture lookups near edges.

If glyphs are never transformed this may be set to false to slightly improve the glyph packing.

Example (set to default value)
let cache = Cache::builder().pad_glyphs(true).build();
source

pub fn align_4x4(self, align_4x4: bool) -> CacheBuilder

Align glyphs in texture to 4x4 texel boundaries.

If your backend requires texture updates to be aligned to 4x4 texel boundaries (e.g. WebGL), this should be set to true.

Example (set to default value)
let cache = Cache::builder().align_4x4(false).build();
source

pub fn multithread(self, multithread: bool) -> CacheBuilder

When multiple CPU cores are available spread rasterization work across all cores.

Significantly reduces worst case latency in multicore environments.

Platform-specific behaviour

This option has no effect on wasm32.

Example (set to default value)
let cache = Cache::builder().multithread(true).build();
source

pub fn build<'a>(self) -> Cache<'a>

Constructs a new cache. Note that this is just the CPU side of the cache. The GPU texture is managed by the user.

Panics

scale_tolerance or position_tolerance are less than or equal to zero.

Example
let cache = Cache::builder().build();
source

pub fn rebuild(self, cache: &mut Cache<'_>)

Rebuilds a Cache with new attributes. All cached glyphs are cleared, however the glyph queue is retained unmodified.

Panics

scale_tolerance or position_tolerance are less than or equal to zero.

Example
// Rebuild the cache with different dimensions
cache.to_builder().dimensions(768, 768).rebuild(&mut cache);

Trait Implementations§

source§

impl Clone for CacheBuilder

source§

fn clone(&self) -> CacheBuilder

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for CacheBuilder

source§

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

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

impl Default for CacheBuilder

source§

fn default() -> CacheBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
where T: Component + Float, Swp: WhitePoint, Dwp: WhitePoint, D: AdaptFrom<S, Swp, Dwp, T>,

source§

fn adapt_into_using<M>(self, method: M) -> D
where M: TransformMatrix<Swp, Dwp, T>,

Convert the source color to the destination color using the specified method
source§

fn adapt_into(self) -> D

Convert the source color to the destination color using the bradford method by default
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, U> ConvertInto<U> for T
where U: ConvertFrom<T>,

source§

fn convert_into(self) -> U

Convert into T with values clamped to the color defined bounds Read more
source§

fn convert_unclamped_into(self) -> U

Convert into T. The resulting color might be invalid in its color space Read more
source§

fn try_convert_into(self) -> Result<U, OutOfBounds<U>>

Convert into T, returning ok if the color is inside of its defined range, otherwise an OutOfBounds error is returned which contains the unclamped color. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

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<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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

§

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

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSync for T
where T: Sync,