[][src]Crate gfx_glyph

Fast GPU cached text rendering using gfx-rs & rusttype.

Makes use of three kinds of caching to optimise frame performance.

  • Caching of glyph positioning output to avoid repeated cost of identical text rendering on sequential frames.
  • Caches draw calculations to avoid repeated cost of identical text rendering on sequential frames.
  • GPU cache logic to dynamically maintain a GPU texture of rendered glyphs.

Example

use gfx_glyph::{GlyphBrushBuilder, Section};

let dejavu: &[u8] = include_bytes!("../../fonts/DejaVuSans.ttf");
let mut glyph_brush = GlyphBrushBuilder::using_font_bytes(dejavu).build(gfx_factory.clone());

let section = Section {
    text: "Hello gfx_glyph",
    ..Section::default()
};

glyph_brush.queue(section);
glyph_brush.queue(some_other_section);

glyph_brush.draw_queued(&mut gfx_encoder, &gfx_color, &gfx_depth)?;

Modules

rusttype

Re-exported rusttype types.

Structs

Font

A single font. This may or may not own the font data.

FontId

Id for a font

GlyphBrush

Object allowing glyph drawing, containing cache state. Manages glyph positioning cacheing, glyph draw caching & efficient GPU texture cache updating and re-sizing on demand.

GlyphBrushBuilder

Builder for a GlyphBrush.

OwnedSectionText
OwnedVariedSection
Point

A point in 2-dimensional space, with each dimension of type N.

PositionedGlyph

A glyph augmented with positioning and scaling information. You can query such a glyph for information that depends on the scale and position of the glyph.

Rect

A rectangle, with top-left corner at min, and bottom-right corner at max.

Scale

Defines the size of a rendered face of a font, in pixels, horizontally and vertically. A vertical scale of y pixels means that the distance betwen the ascent and descent lines (see VMetrics) of the face will be y pixels. If x and y are equal the scaling is uniform. Non-uniform scaling by a factor f in the horizontal direction is achieved by setting x equal to f times y.

Section

An object that contains all the info to render a section of text.

SectionGeometry
SectionText
VariedSection

An object that contains all the info to render a varied section of text. That is one including many parts with differing fonts/scales/colors bowing to a single layout.

Enums

BuiltInLineBreaker

Built-in linebreaking logic.

HorizontalAlign

Describes horizontal alignment preference for positioning & bounds.

Layout

Built-in GlyphPositioner implementations.

LineBreak

Indicator that a character is a line break, soft or hard. Includes the offset (byte-index) position.

SharedBytes

SharedBytes handles the lifetime of font data used in RustType. The data is either a shared reference to externally owned data, or managed by reference counting. SharedBytes can be conveniently used with From and Into, and dereferences to the contained bytes.

VerticalAlign

Describes vertical alignment preference for positioning & bounds. Currently a placeholder for future functionality.

Traits

FontMap

Mapper of FontId -> Font

GlyphCruncher

Common glyph layout logic.

GlyphPositioner

Logic to calculate glyph positioning using Font, SectionGeometry and SectionText.

LineBreaker

Producer of a LineBreak iterator. Used to allow to the Layout to be line break aware in a generic way.

Type Definitions

PositionedGlyphIter

PositionedGlyph iterator.