fn layout_padded_glyphs<F, SF>(
    font: &SF,
    padding: f32,
) -> (Vec<Glyph>, Rect<f32>)
where
    F: Font,
    SF: ScaleFont<F>,
{
    let target_width = font.scale().y * 32.0;

    let mut bounds = Rect::<f32> {
        left: 0.0,
        right: 0.0,
        top: 0.0,
        bottom: 0.0,
    };

    let v_advance = font.height() + padding;

    let mut glyphs = vec![];
    glyphs.reserve(font.glyph_count());

    let mut caret = ab_glyph::point(padding, padding);
    for (_glyph_id, c) in font.codepoint_ids() {
        if c.is_control() {
            continue;
        }

        // assign the glyph's position, ensure that it is always exactly
        // pixel-aligned.
        let mut glyph = font.scaled_glyph(c);
        caret.x = caret.x.ceil();
        caret.y = caret.y.ceil();
        glyph.position = caret;

        let outline_option = font.outline_glyph(glyph.clone());
        if outline_option.is_none() {
            continue;
        }
        let outline = outline_option.unwrap();

        let glyph_bounds = outline.px_bounds();

        caret.x += glyph_bounds.width() + padding;
        bounds.right = bounds.right.max(caret.x);

        if caret.x >= target_width {
            caret.y += v_advance;
            caret.x = padding;
        }

        bounds.bottom =
            bounds.bottom.max(caret.y + glyph_bounds.height() + padding);

        glyphs.push(glyph);
    }

    (glyphs, bounds)
}
/// Position every glyph in the font such that each can be rendered without
/// any overlap and with a bit of padding between each glyph.
Position every glyph in the font such that each can be rendered without
any overlap and with a bit of padding between each glyph.
Position every glyph in the font such that each can be rendered without any overlap and with a bit of padding between each glyph .
fn layout_padded_glyphs<F, SF>(
    font: &SF,
    padding: f32,
) -> (Vec<Glyph>, Rect<f32>)
where
    F: Font,
    SF: ScaleFont<F>,
{
    let target_width = font.scale().y * 32.0;
    let mut bounds = Rect::<f32> {
        left: 0.0,
        right: 0.0,
        top: 0.0,
        bottom: 0.0,
    };
    let v_advance = font.height() + padding;
    let mut glyphs = vec![];
    glyphs.reserve(font.glyph_count());
    let mut caret = ab_glyph::point(padding, padding);
    for (_glyph_id, c) in font.codepoint_ids() {
        if c.is_control() {
            continue;
        }
        // assign the glyph's position, ensure that it is always exactly
        // pixel-aligned.
        let mut glyph = font.scaled_glyph(c);
        caret.x = caret.x.ceil();
        caret.y = caret.y.ceil();
        glyph.position = caret;
        let outline_option = font.outline_glyph(glyph.clone());
        if outline_option.is_none() {
            continue;
        }
        let outline = outline_option.unwrap();
        let glyph_bounds = outline.px_bounds();
        caret.x += glyph_bounds.width() + padding;
        bounds.right = bounds.right.max(caret.x);
        if caret.x >= target_width {
            caret.y += v_advance;
            caret.x = padding;
        }
        bounds.bottom =
            bounds.bottom.max(caret.y + glyph_bounds.height() + padding);
        glyphs.push(glyph);
    }
    (glyphs, bounds)
}
fn layout_padded_glyphs < F , SF > ( font : & SF , padding : f32 , ) -> ( Vec < Glyph > , Rect < f32 > ) where F : Font , SF : ScaleFont < F > , { let target_width = font . scale ( ) . y * 32.0 ; let mut bounds = Rect :: < f32 > { left : 0.0 , right : 0.0 , top : 0.0 , bottom : 0.0 , } ; let v_advance = font . height ( ) + padding ; let mut glyphs = vec ! [ ] ; glyphs . reserve ( font . glyph_count ( ) ) ; let mut caret = ab_glyph :: point ( padding , padding ) ; for ( _glyph_id , c ) in font . codepoint_ids ( ) { if c . is_control ( ) { continue ; } // assign the glyph's position, ensure that it is always exactly // pixel-aligned. let mut glyph = font . scaled_glyph ( c ) ; caret . x = caret . x . ceil ( ) ; caret . y = caret . y . ceil ( ) ; glyph . position = caret ; let outline_option = font . outline_glyph ( glyph . clone ( ) ) ; if outline_option . is_none ( ) { continue ; } let outline = outline_option . unwrap ( ) ; let glyph_bounds = outline . px_bounds ( ) ; caret . x += glyph_bounds . width ( ) + padding ; bounds . right = bounds . right . max ( caret . x ) ; if caret . x >= target_width { caret . y += v_advance ; caret . x = padding ; } bounds . bottom = bounds . bottom . max ( caret . y + glyph_bounds . height ( ) + padding ) ; glyphs . push ( glyph ) ; } ( glyphs , bounds ) }
Position every glyph in the font such that each can be rendered without
any overlap and with a bit of padding between each glyph.
Position every glyph in the font such that each can be rendered without any overlap and with a bit of padding between each glyph .
font
&SF
padding
f32