use AttrList;
use Direction;
use Error;
use Rectangle;
use Stretch;
use Style;
use Variant;
use Weight;
use ffi;
use glib;
use glib::translate::*;
use std::mem;
use std::ptr;
pub fn config_key_get(key: &str) -> Option<String> {
unsafe {
from_glib_full(ffi::pango_config_key_get(key.to_glib_none().0))
}
}
pub fn config_key_get_system(key: &str) -> Option<String> {
unsafe {
from_glib_full(ffi::pango_config_key_get_system(key.to_glib_none().0))
}
}
pub fn extents_to_pixels<'a, 'b, P: Into<Option<&'a Rectangle>>, Q: Into<Option<&'b Rectangle>>>(inclusive: P, nearest: Q) {
let inclusive = inclusive.into();
let nearest = nearest.into();
unsafe {
ffi::pango_extents_to_pixels(mut_override(inclusive.to_glib_none().0), mut_override(nearest.to_glib_none().0));
}
}
pub fn find_base_dir(text: &str) -> Direction {
let length = text.len() as i32;
unsafe {
from_glib(ffi::pango_find_base_dir(text.to_glib_none().0, length))
}
}
pub fn find_paragraph_boundary(text: &str) -> (i32, i32) {
let length = text.len() as i32;
unsafe {
let mut paragraph_delimiter_index = mem::uninitialized();
let mut next_paragraph_start = mem::uninitialized();
ffi::pango_find_paragraph_boundary(text.to_glib_none().0, length, &mut paragraph_delimiter_index, &mut next_paragraph_start);
(paragraph_delimiter_index, next_paragraph_start)
}
}
pub fn get_lib_subdirectory() -> Option<String> {
unsafe {
from_glib_none(ffi::pango_get_lib_subdirectory())
}
}
pub fn get_sysconf_subdirectory() -> Option<String> {
unsafe {
from_glib_none(ffi::pango_get_sysconf_subdirectory())
}
}
pub fn is_zero_width(ch: char) -> bool {
unsafe {
from_glib(ffi::pango_is_zero_width(ch.to_glib()))
}
}
pub fn lookup_aliases(fontname: &str) -> Vec<String> {
unsafe {
let mut families = ptr::null_mut();
let mut n_families = mem::uninitialized();
ffi::pango_lookup_aliases(fontname.to_glib_none().0, &mut families, &mut n_families);
FromGlibContainer::from_glib_full_num(families, n_families as usize)
}
}
pub fn parse_enum<'a, P: Into<Option<&'a str>>>(type_: glib::types::Type, str: P, warn: bool) -> Option<(i32, String)> {
let str = str.into();
let str = str.to_glib_none();
unsafe {
let mut value = mem::uninitialized();
let mut possible_values = ptr::null_mut();
let ret = from_glib(ffi::pango_parse_enum(type_.to_glib(), str.0, &mut value, warn.to_glib(), &mut possible_values));
if ret { Some((value, from_glib_full(possible_values))) } else { None }
}
}
pub fn parse_markup(markup_text: &str, accel_marker: char) -> Result<(AttrList, String, char), Error> {
let length = markup_text.len() as i32;
unsafe {
let mut attr_list = ptr::null_mut();
let mut text = ptr::null_mut();
let mut accel_char = mem::uninitialized();
let mut error = ptr::null_mut();
let _ = ffi::pango_parse_markup(markup_text.to_glib_none().0, length, accel_marker.to_glib(), &mut attr_list, &mut text, &mut accel_char, &mut error);
if error.is_null() { Ok((from_glib_full(attr_list), from_glib_full(text), from_glib(accel_char))) } else { Err(from_glib_full(error)) }
}
}
pub fn parse_stretch(str: &str, warn: bool) -> Option<Stretch> {
unsafe {
let mut stretch = mem::uninitialized();
let ret = from_glib(ffi::pango_parse_stretch(str.to_glib_none().0, &mut stretch, warn.to_glib()));
if ret { Some(from_glib(stretch)) } else { None }
}
}
pub fn parse_style(str: &str, warn: bool) -> Option<Style> {
unsafe {
let mut style = mem::uninitialized();
let ret = from_glib(ffi::pango_parse_style(str.to_glib_none().0, &mut style, warn.to_glib()));
if ret { Some(from_glib(style)) } else { None }
}
}
pub fn parse_variant(str: &str, warn: bool) -> Option<Variant> {
unsafe {
let mut variant = mem::uninitialized();
let ret = from_glib(ffi::pango_parse_variant(str.to_glib_none().0, &mut variant, warn.to_glib()));
if ret { Some(from_glib(variant)) } else { None }
}
}
pub fn parse_weight(str: &str, warn: bool) -> Option<Weight> {
unsafe {
let mut weight = mem::uninitialized();
let ret = from_glib(ffi::pango_parse_weight(str.to_glib_none().0, &mut weight, warn.to_glib()));
if ret { Some(from_glib(weight)) } else { None }
}
}
pub fn quantize_line_geometry(thickness: &mut i32, position: &mut i32) {
unsafe {
ffi::pango_quantize_line_geometry(thickness, position);
}
}
pub fn split_file_list(str: &str) -> Vec<String> {
unsafe {
FromGlibPtrContainer::from_glib_full(ffi::pango_split_file_list(str.to_glib_none().0))
}
}
pub fn trim_string(str: &str) -> Option<String> {
unsafe {
from_glib_full(ffi::pango_trim_string(str.to_glib_none().0))
}
}
pub fn unichar_direction(ch: char) -> Direction {
unsafe {
from_glib(ffi::pango_unichar_direction(ch.to_glib()))
}
}
pub fn units_from_double(d: f64) -> i32 {
unsafe {
ffi::pango_units_from_double(d)
}
}
pub fn units_to_double(i: i32) -> f64 {
unsafe {
ffi::pango_units_to_double(i)
}
}
pub fn version() -> i32 {
unsafe {
ffi::pango_version()
}
}
pub fn version_check(required_major: i32, required_minor: i32, required_micro: i32) -> Option<String> {
unsafe {
from_glib_none(ffi::pango_version_check(required_major, required_minor, required_micro))
}
}
pub fn version_string() -> Option<String> {
unsafe {
from_glib_none(ffi::pango_version_string())
}
}