Struct webgl2_glyph::glyph_brush::GlyphCalculator[][src]

pub struct GlyphCalculator<F = FontArc, X = Extra, H = RandomXxHashBuilder64> { /* fields omitted */ }
Expand description

Cut down version of a GlyphBrush that can calculate pixel bounds, but is unable to actually render anything.

Build using a GlyphCalculatorBuilder.

Example

use glyph_brush::{ab_glyph::FontArc, GlyphCalculatorBuilder, GlyphCruncher, Section, Text};

let dejavu = FontArc::try_from_slice(include_bytes!("../../fonts/DejaVuSans.ttf")).unwrap();
let glyphs = GlyphCalculatorBuilder::using_font(dejavu).build();

let section = Section::default()
    .add_text(Text::new("Hello glyph_brush"));

// create the scope, equivalent to a lock on the cache when
// dropped will clean unused cached calculations like a draw call
let mut scope = glyphs.cache_scope();

let bounds = scope.glyph_bounds(section);

Caching behaviour

Calls to GlyphCalculatorGuard::glyph_bounds, GlyphCalculatorGuard::glyphs calculate the positioned glyphs for a section. This is cached so future calls to any of the methods for the same section are much cheaper.

Unlike a GlyphBrush there is no concept of actually drawing the section to imply when a section is used / no longer used. Instead a GlyphCalculatorGuard is created, that provides the calculation functionality. Dropping indicates the ‘cache frame’ is over, similar to when a GlyphBrush draws. Section calculations are cached for the next ‘cache frame’, if not used then they will be dropped.

Implementations

Returns the available fonts.

The FontId corresponds to the index of the font data.

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.