ibm437 0.5.0

IBM437 bitmap font — works with embedded-graphics and raw framebuffers (minifb, softbuffer, SDL2…)
Documentation
//! Minimal example: render IBM437 text into a raw `&mut [u32]` framebuffer.
//!
//! The buffer this fills is windowing-agnostic — hand it to minifb,
//! softbuffer, SDL2, or any crate that takes a packed ARGB pixel buffer.
//!
//! Run with:
//! ```sh
//! cargo run --example framebuffer_hello --features framebuffer
//! ```

use ibm437::framebuffer::FbFont;

fn main() {
    const WIDTH: usize = 640;
    const HEIGHT: usize = 200;

    let mut buffer = vec![0x00_10_10_30u32; WIDTH * HEIGHT];

    let regular = FbFont::regular_8x8();
    let bold = FbFont::bold_8x8();
    let large = FbFont::regular_9x14();

    let white = 0x00FF_FFFF;
    let yellow = 0x00FF_FF00;
    let cyan = 0x0000_FFFF;
    let bg_blue = Some(0x0000_0080);

    regular.draw_str(
        &mut buffer,
        WIDTH,
        10,
        10,
        "IBM437 8\u{00D7}8 regular",
        white,
        None,
    );
    bold.draw_str(
        &mut buffer,
        WIDTH,
        10,
        22,
        "IBM437 8\u{00D7}8 bold",
        yellow,
        None,
    );
    large.draw_str(
        &mut buffer,
        WIDTH,
        10,
        34,
        "IBM437 9\u{00D7}14 regular",
        cyan,
        None,
    );

    large.draw_str(
        &mut buffer,
        WIDTH,
        10,
        60,
        "\u{250C}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2510}",
        white,
        bg_blue,
    );
    large.draw_str(
        &mut buffer,
        WIDTH,
        10,
        74,
        "\u{2502} Hello, framebuffer \u{2502}",
        white,
        bg_blue,
    );
    large.draw_str(
        &mut buffer,
        WIDTH,
        10,
        88,
        "\u{2514}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2518}",
        white,
        bg_blue,
    );

    regular.draw_str(
        &mut buffer,
        WIDTH,
        10,
        120,
        "The buffer is a plain &mut [u32] \u{2014} use it with minifb, softbuffer, SDL2\u{2026}",
        0x00AA_AAAA,
        None,
    );

    // Integer scaling: each source pixel becomes a scale\u{00D7}scale block.
    let big = FbFont::regular_8x8().with_scale(3);
    big.draw_str(
        &mut buffer,
        WIDTH,
        10,
        145,
        "SCALED 3\u{00D7}",
        yellow,
        None,
    );

    // At this point `buffer` is ready:
    //   window.update_with_buffer(&buffer, WIDTH, HEIGHT).unwrap();
    println!(
        "Buffer filled ({}\u{00D7}{}, {} pixels). Plug it into your windowing library!",
        WIDTH,
        HEIGHT,
        buffer.len()
    );
}