From 483e35e74ec020063a8f6eb6d1aa48fdd624fdf0 Mon Sep 17 00:00:00 2001
From: Jeremy Soller <jackpot51@gmail.com>
Date: Fri, 24 Feb 2017 18:51:50 -0700
Subject: [PATCH] Use TTF in terminal

---
 src/terminal/console.rs | 15 +++++++++++++--
 src/terminal/main.rs    |  3 ++-
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/src/terminal/console.rs b/src/terminal/console.rs
index 76420ed..a1cb89b 100644
--- a/src/terminal/console.rs
+++ b/src/terminal/console.rs
@@ -5,6 +5,7 @@ use std::collections::{BTreeSet, VecDeque};
 use std::io::Result;
 
 use orbclient::{Color, Event, EventOption, Renderer, Window};
+use orbfont::Font;
 
 #[cfg(target_arch = "x86_64")]
 #[inline(always)]
@@ -33,6 +34,8 @@ pub unsafe fn fast_set64(dst: *mut u64, src: u64, len: usize) {
 pub struct Console {
     pub console: ransid::Console,
     pub window: Window,
+    pub font: Font,
+    pub font_bold: Font,
     pub changed: BTreeSet<usize>,
     pub ctrl: bool,
     pub input: Vec<u8>,
@@ -48,6 +51,8 @@ impl Console {
         Console {
             console: ransid::Console::new(width as usize / 8, height as usize / 16),
             window: window,
+            font: Font::find(None, None, None).unwrap(),
+            font_bold: Font::find(None, None, Some("Bold")).unwrap(),
             changed: BTreeSet::new(),
             ctrl: false,
             input: Vec::new(),
@@ -197,12 +202,18 @@ impl Console {
         }
 
         {
+            let font = &self.font;
+            let font_bold = &self.font_bold;
             let window = &mut self.window;
             let changed = &mut self.changed;
             self.console.write(buf, |event| {
                 match event {
-                    ransid::Event::Char { x, y, c, color, .. } => {
-                        window.char(x as i32 * 8, y as i32 * 16, c, Color { data: color.data });/*, bold, false);*/
+                    ransid::Event::Char { x, y, c, color, bold, .. } => {
+                        if bold {
+                            font_bold.render(&c.to_string(), 16.0).draw(window, x as i32 * 8, y as i32 * 16, Color { data: color.data });
+                        } else {
+                            font.render(&c.to_string(), 16.0).draw(window, x as i32 * 8, y as i32 * 16, Color { data: color.data });
+                        }
                         changed.insert(y);
                     },
                     ransid::Event::Rect { x, y, w, h, color } => {
diff --git a/src/terminal/main.rs b/src/terminal/main.rs
index f4d81d4..8e5f2d3 100644
--- a/src/terminal/main.rs
+++ b/src/terminal/main.rs
@@ -4,6 +4,7 @@
 #![cfg_attr(not(target_os = "redox"), feature(process_try_wait))]
 
 extern crate orbclient;
+extern crate orbfont;
 
 #[cfg(not(target_os = "redox"))]
 extern crate libc;
@@ -203,7 +204,7 @@ fn main() {
     let slave_stderr = OpenOptions::new().read(false).write(true).open(&tty_path).unwrap();
 
     let width = 800;
-    let height = 600;
+    let height = 576;
 
     env::set_var("COLUMNS", format!("{}", width / 8));
     env::set_var("LINES", format!("{}", height / 16));
-- 
GitLab