Writes a single character `ch` at `pos`.
(rasops: &mut R, font: &Font, pos: PixelsXY, ch: char)
| 382 | |
| 383 | /// Writes a single character `ch` at `pos`. |
| 384 | fn draw_char<R>(rasops: &mut R, font: &Font, pos: PixelsXY, ch: char) -> io::Result<()> |
| 385 | where |
| 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`. |
| 411 | pub fn draw_text<R>(rasops: &mut R, font: &Font, xy: PixelsXY, text: &str) -> io::Result<()> |
no test coverage detected