From 6964d2e756817130d79a352edd7e4be45e98ef7a Mon Sep 17 00:00:00 2001 From: daa Date: Sun, 20 Aug 2017 21:09:57 +0300 Subject: [PATCH] Progress.. --- Cargo.toml | 1 + src/main.rs | 1 + src/render/mod.rs | 4 +++- src/sys/pango/analysis.rs | 22 ++++++++++++++++++++++ src/sys/pango/item.rs | 6 ++++-- src/sys/pango/mod.rs | 12 ++++++++++-- 6 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 src/sys/pango/analysis.rs diff --git a/Cargo.toml b/Cargo.toml index 6631a0d..544c20d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,6 +23,7 @@ pango = { git = 'https://github.com/gtk-rs/pango' } pango-sys = { git = 'https://github.com/gtk-rs/sys' } gio = { git = 'https://github.com/gtk-rs/gio' } pangocairo = { git = 'https://github.com/RazrFalcon/pangocairo-rs' } +pangocairo-sys = "0.3.4" neovim-lib = "0.4" phf = "0.7" log = "0.3" diff --git a/src/main.rs b/src/main.rs index d8303e8..54e3769 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,7 @@ extern crate cairo; extern crate pango; extern crate pango_sys; extern crate pangocairo; +extern crate pangocairo_sys; extern crate neovim_lib; extern crate phf; #[macro_use] diff --git a/src/render/mod.rs b/src/render/mod.rs index 2ed4ea8..d0bf0c8 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -14,6 +14,8 @@ pub fn render(ctx: &cairo::Context) { 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); + let analysis = item.analysis(); + pango_shape(&text, len, &analysis, &mut glyphs); + let (ink, logical) = glyphs.extents(&analysis.font()); } } diff --git a/src/sys/pango/analysis.rs b/src/sys/pango/analysis.rs new file mode 100644 index 0000000..7c7c85f --- /dev/null +++ b/src/sys/pango/analysis.rs @@ -0,0 +1,22 @@ +use pango_sys; +use pango; + +use glib::translate::*; + +pub struct Analysis<'a>(&'a pango_sys::PangoAnalysis); + +impl <'a> Analysis <'a> { + pub fn from(analysis: &'a pango_sys::PangoAnalysis) -> Self { + Analysis(analysis) + } + + pub fn font(&self) -> pango::Font { + unsafe { + from_glib_none(self.0.font) + } + } + + pub fn to_glib_ptr(&self) -> *const pango_sys::PangoAnalysis { + self.0 + } +} diff --git a/src/sys/pango/item.rs b/src/sys/pango/item.rs index 497e787..45e3ca6 100644 --- a/src/sys/pango/item.rs +++ b/src/sys/pango/item.rs @@ -6,6 +6,8 @@ use pango_sys; use glib_ffi; use glib::translate::*; +use super::analysis; + glib_wrapper! { pub struct Item(Boxed); @@ -16,7 +18,7 @@ glib_wrapper! { } impl Item { - pub fn analysis(&self) -> &pango_sys::PangoAnalysis { - &self.0.analysis + pub fn analysis(&self) -> analysis::Analysis { + analysis::Analysis::from(&self.0.analysis) } } diff --git a/src/sys/pango/mod.rs b/src/sys/pango/mod.rs index c12b170..8e009de 100644 --- a/src/sys/pango/mod.rs +++ b/src/sys/pango/mod.rs @@ -1,10 +1,13 @@ mod item; +mod analysis; use std::ptr; use std::ffi::CStr; use pango; use pango_sys; +use cairo; +use pangocairo_sys; use glib::translate::*; @@ -30,15 +33,20 @@ pub fn pango_itemize( pub fn pango_shape( text: &CStr, length: usize, - analysis: &pango_sys::PangoAnalysis, + analysis: &analysis::Analysis, glyphs: &mut pango::GlyphString, ) { unsafe { pango_sys::pango_shape( text.as_ptr(), length as i32, - analysis as *const pango_sys::PangoAnalysis, + analysis.to_glib_ptr(), glyphs.to_glib_none_mut().0, ); } } + +pub fn pango_cairo_show_glyph_string(ctx: &cairo::Context, font: &pango::Font, glyphs: &pango::GlyphString) { + pangocairo_sys::pango_cairo_show_glyph_string(); +} +