pango_itemize/pango_shape implementation

This commit is contained in:
daa84 2017-08-18 18:35:33 +03:00
parent b2ae40982f
commit 063bd86fd7
6 changed files with 95 additions and 0 deletions

View File

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

19
src/render/mod.rs Normal file
View File

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

View File

@ -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<UiMutex<State>>, ctx: &cairo::Context) {
}
fn gtk_draw(state_arc: &Arc<UiMutex<State>>, ctx: &cairo::Context) -> Inhibit {
render::render(ctx);
update_line_metrics(state_arc, ctx);
if state_arc.borrow_mut().request_nvim_resize {

2
src/sys/mod.rs Normal file
View File

@ -0,0 +1,2 @@
pub mod pango;

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

@ -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<pango_sys::PangoItem>);
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
}
}

44
src/sys/pango/mod.rs Normal file
View File

@ -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<item::Item> {
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,
);
}
}