Drawing optimization

This commit is contained in:
daa84
2017-09-11 18:00:51 +03:00
parent ab6052705a
commit f7710ca912
9 changed files with 164 additions and 213 deletions

View File

@@ -0,0 +1,31 @@
use std::ptr;
use std::mem;
use pango_sys;
use pango;
use glib_ffi;
use glib::translate::*;
glib_wrapper! {
pub struct AttrIterator(Boxed<pango_sys::PangoAttrIterator>);
match fn {
copy => |ptr| pango_sys::pango_attr_iterator_copy(ptr as *mut _),
free => |ptr| pango_sys::pango_attr_iterator_destroy(ptr),
}
}
pub trait AttrIteratorFactory {
fn get_iterator(&self) -> AttrIterator;
}
impl AttrIteratorFactory for pango::AttrList {
fn get_iterator(&self) -> AttrIterator {
unsafe {
from_glib_none(pango_sys::pango_attr_list_get_iterator(
self.to_glib_none().0,
))
}
}
}

View File

@@ -1,8 +1,10 @@
mod item;
mod analysis;
mod attr_iterator;
pub use self::item::Item;
pub use self::analysis::Analysis;
pub use self::attr_iterator::{AttrIterator, AttrIteratorFactory};
use std::ptr;
@@ -14,16 +16,19 @@ use glib::translate::*;
pub fn pango_itemize(
context: &pango::Context,
text: &str,
attrs: &pango::AttrList
start_index: usize,
length: usize,
attrs: &pango::AttrList,
cached_iter: Option<&mut AttrIterator>,
) -> Vec<Item> {
unsafe {
FromGlibPtrContainer::from_glib_container(pango_sys::pango_itemize(
context.to_glib_none().0,
text.as_ptr() as *const i8,
0,
text.len() as i32,
start_index as i32,
length as i32,
attrs.to_glib_none().0,
ptr::null_mut(),
cached_iter.map(|iter| iter.to_glib_none_mut().0).unwrap_or(ptr::null_mut()),
))
}
}