rocketsplash-rt 0.2.2

Runtime library for loading and rendering Rocketsplash assets (.rst, .rsf)
Documentation
// <FILE>crates/rocketsplash-rt/src/font/cls_text_builder/test_cls_text_builder.rs</FILE>
// <DESC>Unit tests for TextBuilder behavior and shadow defaults.</DESC>
// <VERS>VERSION: 0.1.0</VERS>
// <WCTX>Public release refactor audit</WCTX>
// <CLOG>Move cls_text_builder inline tests into a dedicated test module.</CLOG>

use std::collections::BTreeMap;

use rocketsplash_formats::{
    FontAtlas, FontMeta, GlyphData, GlyphVariants, RenderMode, StyleFlags, FONT_ATLAS_VERSION,
};

use crate::font::Font;

#[test]
fn drop_shadow_defaults_expand_buffer() {
    let font = make_font();
    let builder = font.render("A").drop_shadow();
    let buffer = builder.build_buffer().expect("buffer builds");
    assert_eq!(buffer.width, 2);
    assert_eq!(buffer.height, 2);
    let base = buffer.cell(0, 0).expect("base cell");
    assert_eq!(base.ch, 'A');
    let shadow = buffer.cell(1, 1).expect("shadow cell");
    assert_eq!(shadow.ch, 'A');
    assert!(shadow.fg.is_some());
}

fn make_font() -> Font {
    let glyph = make_glyph('A');
    let variants = GlyphVariants {
        base: glyph,
        bold: None,
        italic: None,
        bold_italic: None,
        reverse: None,
    };
    let mut glyphs = BTreeMap::new();
    glyphs.insert('A', variants);
    let atlas = FontAtlas {
        version: FONT_ATLAS_VERSION,
        meta: FontMeta {
            font_name: "Test".to_string(),
            font_size: 12.0,
            created_at: 0,
            editor_version: "test".to_string(),
        },
        glyphs,
        line_height: 1,
        mode: RenderMode::Braille,
        available_styles: StyleFlags::empty(),
    };
    let bytes = rmp_serde::to_vec(&atlas).expect("serialize atlas");
    Font::from_bytes(&bytes).expect("load font")
}

fn make_glyph(ch: char) -> GlyphData {
    GlyphData {
        chars: ch.to_string(),
        width: 1,
        height: 1,
        opacity: Some(vec![255]),
    }
}

// <FILE>crates/rocketsplash-rt/src/font/cls_text_builder/test_cls_text_builder.rs</FILE>
// <VERS>END OF VERSION: 0.1.0</VERS>