MCPcopy Index your code
hub / github.com/endbasic/endbasic / draw_char

Function draw_char

std/src/console/drawing.rs:384–408  ·  view source on GitHub ↗

Writes a single character `ch` at `pos`.

(rasops: &mut R, font: &Font, pos: PixelsXY, ch: char)

Source from the content-addressed store, hash-verified

382
383/// Writes a single character `ch` at `pos`.
384fn draw_char<R>(rasops: &mut R, font: &Font, pos: PixelsXY, ch: char) -> io::Result<()>
385where
386 R: RasterOps,
387{
388 let glyph = font.glyph(ch);
389 for j in 0..font.glyph_size.height {
390 for k in 0..font.stride {
391 let row = glyph[j * font.stride + k];
392 let mut mask = 0x80;
393 for i in 0..font.glyph_size.width {
394 let bit = row & mask;
395 if bit != 0 {
396 // TODO(jmmv): The "as i16" conversions below are code smells. We should
397 // change the font glyph size representation to be u8s to allow widening
398 // the integers instead of having to truncate them.
399 let x = pos.x + i as i16 + k as i16 * 8;
400 let y = pos.y + j as i16;
401 rasops.draw_pixel(PixelsXY { x, y })?;
402 }
403 mask >>= 1;
404 }
405 }
406 }
407 Ok(())
408}
409
410/// Writes a single character `ch` at `pos`.
411pub fn draw_text<R>(rasops: &mut R, font: &Font, xy: PixelsXY, text: &str) -> io::Result<()>

Callers 1

draw_textFunction · 0.85

Calls 2

glyphMethod · 0.80
draw_pixelMethod · 0.45

Tested by

no test coverage detected