rocketsplash-rt 0.2.2

Runtime library for loading and rendering Rocketsplash assets (.rst, .rsf)
Documentation
// <FILE>crates/rocketsplash-rt/src/font/fnc_stamp_glyph.rs</FILE>
// <DESC>Stamp a runtime glyph into a render buffer.</DESC>
// <VERS>VERSION: 1.0.0</VERS>
// <WCTX>Public release refactor audit</WCTX>
// <CLOG>Extract glyph stamping from fnc_render_text and streamline writes</CLOG>

use crate::font::RuntimeGlyph;
use crate::{RenderBuffer, TextStyle};

pub(super) fn stamp_glyph(
    buffer: &mut RenderBuffer,
    glyph: &RuntimeGlyph,
    x_offset: i64,
    y_offset: i64,
    style: TextStyle,
) {
    let width = buffer.width as i64;
    let height = buffer.height as i64;
    let opacity_values = glyph.opacity.as_ref();

    for y in 0..glyph.height {
        let row_base = y * glyph.width;
        for x in 0..glyph.width {
            let target_x = x_offset + x as i64;
            let target_y = y_offset + y as i64;
            if target_x < 0 || target_y < 0 || target_x >= width || target_y >= height {
                continue;
            }

            let Some(ch) = glyph.char_at(x, y) else {
                continue;
            };
            let opacity = opacity_values
                .and_then(|values| values.get(row_base + x))
                .copied()
                .unwrap_or_else(|| if ch == ' ' { 0 } else { 255 });
            if ch == ' ' && opacity == 0 {
                continue;
            }

            let idx = target_y as usize * buffer.width + target_x as usize;
            let cell = &mut buffer.cells[idx];
            cell.ch = ch;
            cell.opacity = opacity;
            cell.style = style;
        }
    }
}

// <FILE>crates/rocketsplash-rt/src/font/fnc_stamp_glyph.rs</FILE>
// <VERS>END OF VERSION: 1.0.0</VERS>