small software-rendered rust tty
italics
bendn 9 months ago
parent 3c9272a · commit dd7607b
-rw-r--r--CascadiaCode.ttfbin648732 -> 0 bytes
-rw-r--r--CascadiaCodeNFItalic.ttfbin0 -> 2352780 bytes
-rw-r--r--src/render.rs51
3 files changed, 30 insertions, 21 deletions
diff --git a/CascadiaCode.ttf b/CascadiaCode.ttf
deleted file mode 100644
index b47bf63..0000000
--- a/CascadiaCode.ttf
+++ /dev/null
Binary files differ
diff --git a/CascadiaCodeNFItalic.ttf b/CascadiaCodeNFItalic.ttf
new file mode 100644
index 0000000..66894ea
--- /dev/null
+++ b/CascadiaCodeNFItalic.ttf
Binary files differ
diff --git a/src/render.rs b/src/render.rs
index 1788547..f6f7232 100644
--- a/src/render.rs
+++ b/src/render.rs
@@ -38,16 +38,25 @@ pub fn render(
};
}
if let Some(l) = cell.letter {
- let id = FONT.charmap().map(l);
+ let f = if (cell.style.flags & crate::term::ITALIC) != 0 {
+ *IFONT
+ } else {
+ *FONT
+ };
+ let id = f.charmap().map(l);
let mut scbd = ScaleContext::new();
- let mut scbd = scbd.builder(*FONT);
+ let mut scbd = scbd.builder(f);
scbd = scbd.size(ppem);
if (cell.style.flags & crate::term::BOLD) != 0 {
scbd = scbd.variations(
- BFONT
- .values()
- .zip(FONT.variations())
- .map(|x| (x.1.tag(), x.0)),
+ if (cell.style.flags & crate::term::ITALIC) != 0 {
+ *BIFONT
+ } else {
+ *BFONT
+ }
+ .values()
+ .zip(f.variations())
+ .map(|x| (x.1.tag(), x.0)),
);
}
let x = Render::new(&[Source::Outline])
@@ -71,14 +80,6 @@ pub fn render(
i.as_mut().overlay_blended_at(
&item.as_ref(),
- // &Image::<Box<[u8]>, 4>::from(
- // Image::<_, 1>::build(
- // x.placement.width,
- // x.placement.height,
- // )
- // .buf(&*x.data),
- // )
- // .as_ref(),
4 + ((j as f32 * sz) + x.placement.left as f32)
as u32,
((k as f32 * (ppem * 1.25)) as u32)
@@ -101,21 +102,29 @@ pub static FONT: LazyLock<FontRef<'static>> = LazyLock::new(|| {
.unwrap()
});
+pub static IFONT: LazyLock<FontRef<'static>> = LazyLock::new(|| {
+ FontRef::from_index(
+ &include_bytes!("../CascadiaCodeNFItalic.ttf")[..],
+ 0,
+ )
+ .unwrap()
+});
+
+pub static BIFONT: LazyLock<Instance<'static>> = LazyLock::new(|| {
+ IFONT.instances().find_by_name("Bold Italic").unwrap()
+});
+
pub static BFONT: LazyLock<Instance<'static>> =
LazyLock::new(|| FONT.instances().find_by_name("Bold").unwrap());
-// pub static IFONT: LazyLock<FontRef<'static>> = LazyLock::new(|| {
-// FONT.fonts()
-// .find(|f| f.attributes().style() == Style::Italic)
-// .unwrap()
-// });
-use fimg::{BlendingOverlay, Image, OverlayAt};
+use fimg::{Image, OverlayAt};
// let x = b"echo -e \"\x1b(0lqqqk\nx \x1b(Bx\nmqqqj";
// let x = String::from_utf8_lossy(&x);
// println!("{}", x);
#[test]
fn t() {
- FONT.instances()
+ IFONT
+ .instances()
.for_each(|f| drop(dbg!(f.name(None).unwrap().to_string())));
let f =
FontRef::from_index(&include_bytes!("../cjk.ttc")[..], 0).unwrap();