Progress..

This commit is contained in:
daa 2017-08-20 21:09:57 +03:00
parent 063bd86fd7
commit 6964d2e756
6 changed files with 41 additions and 5 deletions

View File

@ -23,6 +23,7 @@ pango = { git = 'https://github.com/gtk-rs/pango' }
pango-sys = { git = 'https://github.com/gtk-rs/sys' } pango-sys = { git = 'https://github.com/gtk-rs/sys' }
gio = { git = 'https://github.com/gtk-rs/gio' } gio = { git = 'https://github.com/gtk-rs/gio' }
pangocairo = { git = 'https://github.com/RazrFalcon/pangocairo-rs' } pangocairo = { git = 'https://github.com/RazrFalcon/pangocairo-rs' }
pangocairo-sys = "0.3.4"
neovim-lib = "0.4" neovim-lib = "0.4"
phf = "0.7" phf = "0.7"
log = "0.3" log = "0.3"

View File

@ -10,6 +10,7 @@ extern crate cairo;
extern crate pango; extern crate pango;
extern crate pango_sys; extern crate pango_sys;
extern crate pangocairo; extern crate pangocairo;
extern crate pangocairo_sys;
extern crate neovim_lib; extern crate neovim_lib;
extern crate phf; extern crate phf;
#[macro_use] #[macro_use]

View File

@ -14,6 +14,8 @@ pub fn render(ctx: &cairo::Context) {
let items = pango_itemize(&pango_context, &text, 0, len, &attr_list); let items = pango_itemize(&pango_context, &text, 0, len, &attr_list);
for item in items { for item in items {
let mut glyphs = pango::GlyphString::new(); 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());
} }
} }

22
src/sys/pango/analysis.rs Normal file
View File

@ -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
}
}

View File

@ -6,6 +6,8 @@ use pango_sys;
use glib_ffi; use glib_ffi;
use glib::translate::*; use glib::translate::*;
use super::analysis;
glib_wrapper! { glib_wrapper! {
pub struct Item(Boxed<pango_sys::PangoItem>); pub struct Item(Boxed<pango_sys::PangoItem>);
@ -16,7 +18,7 @@ glib_wrapper! {
} }
impl Item { impl Item {
pub fn analysis(&self) -> &pango_sys::PangoAnalysis { pub fn analysis(&self) -> analysis::Analysis {
&self.0.analysis analysis::Analysis::from(&self.0.analysis)
} }
} }

View File

@ -1,10 +1,13 @@
mod item; mod item;
mod analysis;
use std::ptr; use std::ptr;
use std::ffi::CStr; use std::ffi::CStr;
use pango; use pango;
use pango_sys; use pango_sys;
use cairo;
use pangocairo_sys;
use glib::translate::*; use glib::translate::*;
@ -30,15 +33,20 @@ pub fn pango_itemize(
pub fn pango_shape( pub fn pango_shape(
text: &CStr, text: &CStr,
length: usize, length: usize,
analysis: &pango_sys::PangoAnalysis, analysis: &analysis::Analysis,
glyphs: &mut pango::GlyphString, glyphs: &mut pango::GlyphString,
) { ) {
unsafe { unsafe {
pango_sys::pango_shape( pango_sys::pango_shape(
text.as_ptr(), text.as_ptr(),
length as i32, length as i32,
analysis as *const pango_sys::PangoAnalysis, analysis.to_glib_ptr(),
glyphs.to_glib_none_mut().0, 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();
}