diff --git a/src/main.rs b/src/main.rs index ac76661..d8303e8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,9 +3,12 @@ extern crate gtk_sys; extern crate gio; extern crate gdk; extern crate gdk_sys; +#[macro_use] extern crate glib; +extern crate glib_sys as glib_ffi; extern crate cairo; extern crate pango; +extern crate pango_sys; extern crate pangocairo; extern crate neovim_lib; extern crate phf; @@ -19,12 +22,15 @@ extern crate serde_derive; extern crate serde; extern crate toml; +mod sys; + mod value; mod mode; mod ui_model; #[macro_use] mod ui; mod nvim; +mod render; mod shell; mod input; mod settings; diff --git a/src/render/mod.rs b/src/render/mod.rs new file mode 100644 index 0000000..2ed4ea8 --- /dev/null +++ b/src/render/mod.rs @@ -0,0 +1,19 @@ +use sys::pango::*; +use pango; +use cairo; +use pangocairo::CairoContextExt; +use std::ffi::CString; + +pub fn render(ctx: &cairo::Context) { + let pango_context = ctx.create_pango_context(); + let text = "TEST String".to_owned().into_bytes(); + let len = text.len(); + let text = CString::new(text).unwrap(); + let attr_list = pango::AttrList::new(); + + let items = pango_itemize(&pango_context, &text, 0, len, &attr_list); + for item in items { + let mut glyphs = pango::GlyphString::new(); + pango_shape(&text, len, item.analysis(), &mut glyphs); + } +} diff --git a/src/shell.rs b/src/shell.rs index 1f87a20..97e443a 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -30,6 +30,7 @@ use popup_menu::PopupMenu; use tabline::Tabline; use error; use mode; +use render; const DEFAULT_FONT_NAME: &str = "DejaVu Sans Mono 12"; pub const MINIMUM_SUPPORTED_NVIM_VERSION: &str = "0.2"; @@ -592,6 +593,7 @@ fn update_line_metrics(state_arc: &Arc>, ctx: &cairo::Context) { } fn gtk_draw(state_arc: &Arc>, ctx: &cairo::Context) -> Inhibit { + render::render(ctx); update_line_metrics(state_arc, ctx); if state_arc.borrow_mut().request_nvim_resize { diff --git a/src/sys/mod.rs b/src/sys/mod.rs new file mode 100644 index 0000000..aefcb94 --- /dev/null +++ b/src/sys/mod.rs @@ -0,0 +1,2 @@ + +pub mod pango; diff --git a/src/sys/pango/item.rs b/src/sys/pango/item.rs new file mode 100644 index 0000000..497e787 --- /dev/null +++ b/src/sys/pango/item.rs @@ -0,0 +1,22 @@ +use std::ptr; +use std::mem; + +use pango_sys; + +use glib_ffi; +use glib::translate::*; + +glib_wrapper! { + pub struct Item(Boxed); + + match fn { + copy => |ptr| pango_sys::pango_item_copy(ptr as *mut pango_sys::PangoItem), + free => |ptr| pango_sys::pango_item_free(ptr), + } +} + +impl Item { + pub fn analysis(&self) -> &pango_sys::PangoAnalysis { + &self.0.analysis + } +} diff --git a/src/sys/pango/mod.rs b/src/sys/pango/mod.rs new file mode 100644 index 0000000..c12b170 --- /dev/null +++ b/src/sys/pango/mod.rs @@ -0,0 +1,44 @@ +mod item; + +use std::ptr; +use std::ffi::CStr; + +use pango; +use pango_sys; + +use glib::translate::*; + +pub fn pango_itemize( + context: &pango::Context, + text: &CStr, + start_index: usize, + length: usize, + attrs: &pango::AttrList, +) -> Vec { + unsafe { + FromGlibPtrContainer::from_glib_container(pango_sys::pango_itemize( + context.to_glib_none().0, + text.as_ptr(), + start_index as i32, + length as i32, + attrs.to_glib_none().0, + ptr::null_mut(), + )) + } +} + +pub fn pango_shape( + text: &CStr, + length: usize, + analysis: &pango_sys::PangoAnalysis, + glyphs: &mut pango::GlyphString, +) { + unsafe { + pango_sys::pango_shape( + text.as_ptr(), + length as i32, + analysis as *const pango_sys::PangoAnalysis, + glyphs.to_glib_none_mut().0, + ); + } +}