wip
| -rw-r--r-- | src/lib.rs | 33 | ||||
| -rw-r--r-- | tests/test.rs | 3 |
2 files changed, 21 insertions, 15 deletions
@@ -55,21 +55,24 @@ pub unsafe fn render( line_spacing: f32, ) -> Image<Box<[u8]>, 3> { assert_eq!(c * r, cells.len(), "cells too short."); + let met = fonts.regular.metrics(&[]); + let fac = ppem / met.units_per_em as f32; - let (fw, h) = dims(&fonts.regular, ppem, line_spacing); - let fh = h - line_spacing; - let (w, h) = ((fw * c as f32).ceil() as u32, (h * r as f32).ceil() as u32); + let (fw, fh_) = dims(&fonts.regular, ppem, line_spacing); + let fh = fh_; + let (w, h) = ( + (fw * c as f32).ceil() as u32, + (fh_ * r as f32).ceil() as u32, + ); let mut i = Image::build(w as _, h as _).fill(bgcolor); if w < 60 || h < 60 { return i; } - for (col, k) in cells.chunks_exact(c as _).zip(0..) { for (&cell, j) in zip(col, 0..) { if cell.style.bg != bgcolor { - let cell = - Image::<_, 4>::build(fw.ceil() as u32, (fh + line_spacing).round() as u32) - .fill(cell.style.bg.join(255)); + let cell = Image::<_, 4>::build(fw.ceil() as u32, (fh_).round() as u32) + .fill(cell.style.bg.join(255)); unsafe { i.as_mut().overlay_at( @@ -178,15 +181,18 @@ pub unsafe fn render( } let item = Image::<_, 1>::build(x.placement.width, x.placement.height) .buf_unchecked(x.data); + // item.as_ref().show(); + dbg!(x.placement); + i.as_mut().blend_alpha_and_color_at( &item.as_ref(), color, ((j as f32 * fw + glyph.x) + x.placement.left as f32).round() as u32, - ( - dbg!(((k + 1) as f32 * fh) - (x.placement.top as f32)) - // + ((k as f32) * line_spacing as f32) - ) - .round() as u32, + // fh as u32 - x.placement.top as u32, + ((((k + 1) as f32 * (fh)) - (x.placement.top as f32)) + + ((k as f32) * line_spacing as f32)) + .round() as u32 + - (met.descent * fac).round() as u32, ); } } @@ -214,8 +220,7 @@ pub fn dims(font: &FontRef, ppem: f32, line_spacing: f32) -> (f32, f32) { let f = ppem / m.units_per_em as f32; ( m.max_width * f, - m.ascent * f + line_spacing, - // ((ppem + line_spacing) * (m.ascent / m.units_per_em as f32)), + (m.ascent + m.descent) * f, // + line_spacing * f, ) } pub use crate::cell::Cell; diff --git a/tests/test.rs b/tests/test.rs index f8d6aa2..1186472 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -14,7 +14,8 @@ fn main() { dbg!(cols, rows); - let cells = include_str!("../src/lib.rs") + let cells = //include_str!("../src/lib.rs") + "||||ppppppre|rlly rea(ly regl(y fugck thgis i plight is hard plifhgt plongkokignpookfiokogk" .chars() .filter(|x| !x.is_whitespace()) .take(cols * rows) |