neovim-gtk/src/render/mod.rs

28 lines
870 B
Rust
Raw Normal View History

use sys::pango::*;
use pango;
2017-08-22 09:27:59 +00:00
use pango::prelude::*;
use cairo;
use pangocairo::CairoContextExt;
use std::ffi::CString;
2017-08-22 09:27:59 +00:00
pub fn render(ctx: &cairo::Context, font_desc: pango::FontDescription) {
let pango_context = ctx.create_pango_context();
2017-08-22 09:27:59 +00:00
pango_context.set_font_description(&font_desc);
let text = "TEST String".to_owned().into_bytes();
let len = text.len();
let text = CString::new(text).unwrap();
let attr_list = pango::AttrList::new();
2017-08-22 09:27:59 +00:00
ctx.move_to(0.0, 50.0);
let items = pango_itemize(&pango_context, &text, 0, len, &attr_list);
for item in items {
let mut glyphs = pango::GlyphString::new();
2017-08-20 18:09:57 +00:00
let analysis = item.analysis();
pango_shape(&text, len, &analysis, &mut glyphs);
2017-08-22 09:27:59 +00:00
let font = analysis.font();
let (ink, logical) = glyphs.extents(&font);
ctx.show_glyph_string(&font, &glyphs);
}
}