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;
}
}
}