[][src]Crate glyph_brush_layout

Text layout for ab_glyph.

Example

use glyph_brush_layout::{ab_glyph::*, *};

let dejavu = FontRef::try_from_slice(include_bytes!("../../fonts/DejaVuSans.ttf"))?;
let garamond = FontRef::try_from_slice(include_bytes!("../../fonts/GaramondNo8-Reg.ttf"))?;

// Simple font mapping: FontId(0) -> deja vu sans, FontId(1) -> garamond
let fonts = &[dejavu, garamond];

// Layout "hello glyph_brush_layout" on an unbounded line with the second
// word suitably bigger, greener and serif-ier.
let glyphs = Layout::default().calculate_glyphs(
    fonts,
    &SectionGeometry {
        screen_position: (150.0, 50.0),
        ..SectionGeometry::default()
    },
    &[
        SectionText {
            text: "hello ",
            scale: PxScale::from(20.0),
            font_id: FontId(0),
        },
        SectionText {
            text: "glyph_brush_layout",
            scale: PxScale::from(25.0),
            font_id: FontId(1),
        },
    ],
);

assert_eq!(glyphs.len(), 24);

let SectionGlyph { glyph, font_id, section_index, byte_index } = &glyphs[4];
assert_eq!(glyph.id, fonts[0].glyph_id('o'));
assert_eq!(*font_id, FontId(0));
assert_eq!(*section_index, 0);
assert_eq!(*byte_index, 4);

let SectionGlyph { glyph, font_id, section_index, byte_index } = &glyphs[14];
assert_eq!(glyph.id, fonts[1].glyph_id('u'));
assert_eq!(*font_id, FontId(1));
assert_eq!(*section_index, 1);
assert_eq!(*byte_index, 8);

Modules

ab_glyph

Re-exported ab_glyph types.

Structs

FontId

Id for a font.

SectionGeometry
SectionGlyph

A positioned glyph with info relating to the SectionText from which it was derived.

SectionText

Text to layout together using a font & scale.

Enums

BuiltInLineBreaker

Built-in linebreaking logic.

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

VerticalAlign

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

Traits

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.

ToSectionText