use glib::translate::*;
use std::clone::Clone;
use std::cmp::PartialEq;
use std::ops::Drop;
use ffi;
use ffi::enums::{
Antialias,
SubpixelOrder,
HintStyle,
HintMetrics,
FontType,
FontWeight,
FontSlant,
};
use ::matrices::Matrix;
use ffi::{
cairo_font_options_t,
cairo_font_face_t,
cairo_scaled_font_t
};
pub use ffi::{
FontExtents,
Glyph,
TextCluster,
TextExtents
};
pub struct FontOptions(*mut cairo_font_options_t);
impl FontOptions {
pub fn new() -> FontOptions {
let font_options = unsafe {
FontOptions(ffi::cairo_font_options_create())
};
font_options.ensure_status();
font_options
}
#[doc(hidden)]
pub fn get_ptr(&self) -> *mut cairo_font_options_t {
let FontOptions(ptr) = *self;
ptr
}
pub fn ensure_status(&self) {
let status = unsafe {
ffi::cairo_font_options_status(self.get_ptr())
};
status.ensure_valid()
}
pub fn merge(&mut self, other: &mut FontOptions) {
unsafe {
ffi::cairo_font_options_merge(self.get_ptr(), other.get_ptr())
}
}
pub fn hash(&self) -> u64{
unsafe {
ffi::cairo_font_options_hash(self.get_ptr()) as u64
}
}
pub fn set_antialias(&self, antialias: Antialias) {
unsafe {
ffi::cairo_font_options_set_antialias(self.get_ptr(), antialias)
}
}
pub fn get_antialias(&self) -> Antialias {
unsafe {
ffi::cairo_font_options_get_antialias(self.get_ptr())
}
}
pub fn set_subpixel_order(&self, order: SubpixelOrder) {
unsafe {
ffi::cairo_font_options_set_subpixel_order(self.get_ptr(), order)
}
}
pub fn get_subpixel_order(&self) -> SubpixelOrder {
unsafe {
ffi::cairo_font_options_get_subpixel_order(self.get_ptr())
}
}
pub fn set_hint_style(&self, hint_style: HintStyle) {
unsafe {
ffi::cairo_font_options_set_hint_style(self.get_ptr(), hint_style)
}
}
pub fn get_hint_style(&self) -> HintStyle {
unsafe {
ffi::cairo_font_options_get_hint_style(self.get_ptr())
}
}
pub fn set_hint_metrics(&self, hint_metrics: HintMetrics) {
unsafe {
ffi::cairo_font_options_set_hint_metrics(self.get_ptr(), hint_metrics)
}
}
pub fn get_hint_metrics(&self) -> HintMetrics {
unsafe {
ffi::cairo_font_options_get_hint_metrics(self.get_ptr())
}
}
}
impl PartialEq for FontOptions {
fn eq(&self, other: &FontOptions) -> bool {
unsafe {
ffi::cairo_font_options_equal(self.get_ptr(), other.get_ptr()).as_bool()
}
}
}
impl Clone for FontOptions {
fn clone(&self) -> FontOptions {
unsafe {
FontOptions(ffi::cairo_font_options_copy(self.get_ptr()))
}
}
}
impl Drop for FontOptions {
fn drop(&mut self) {
unsafe {
ffi::cairo_font_options_destroy(self.get_ptr())
}
}
}
pub struct FontFace(pub *mut cairo_font_face_t);
impl FontFace {
#[doc(hidden)]
pub fn get_ptr(&self) -> *mut cairo_font_face_t {
let FontFace(ptr) = *self;
ptr
}
pub fn toy_create(family: &str, slant: FontSlant, weight: FontWeight) -> FontFace {
let font_face = FontFace(
unsafe {
ffi::cairo_toy_font_face_create(family.to_glib_none().0, slant, weight)
}
);
font_face.ensure_status();
font_face
}
pub fn toy_get_family(&self) -> Option<String> {
unsafe {
from_glib_none(ffi::cairo_toy_font_face_get_family(self.get_ptr()))
}
}
pub fn toy_get_slant(&self) -> FontSlant {
unsafe {
ffi::cairo_toy_font_face_get_slant(self.get_ptr())
}
}
pub fn toy_get_weight(&self) -> FontWeight {
unsafe {
ffi::cairo_toy_font_face_get_weight(self.get_ptr())
}
}
pub fn ensure_status(&self) {
let status = unsafe {
ffi::cairo_font_face_status(self.get_ptr())
};
status.ensure_valid()
}
pub fn get_type(&self) -> FontType {
unsafe {
ffi::cairo_font_face_get_type(self.get_ptr())
}
}
pub fn get_reference_count(&self) -> usize {
unsafe {
ffi::cairo_font_face_get_reference_count(self.get_ptr()) as usize
}
}
pub fn reference(&self) -> FontFace {
unsafe {
FontFace(ffi::cairo_font_face_reference(self.get_ptr()))
}
}
}
impl Drop for FontFace {
fn drop(&mut self) {
unsafe {
ffi::cairo_font_face_destroy(self.get_ptr())
}
}
}
pub struct ScaledFont(pub *mut cairo_scaled_font_t);
impl ScaledFont {
#[doc(hidden)]
pub fn get_ptr(&self) -> *mut cairo_scaled_font_t {
let ScaledFont(ptr) = *self;
ptr
}
pub fn new(font_face: FontFace, font_matrix: &mut Matrix, ctm: &mut Matrix, options: FontOptions) -> ScaledFont {
let scaled_font = unsafe {
ScaledFont(ffi::cairo_scaled_font_create(font_face.get_ptr(), font_matrix, ctm, options.get_ptr()))
};
scaled_font.ensure_status();
scaled_font
}
pub fn ensure_status(&self) {
let status = unsafe {
ffi::cairo_scaled_font_status(self.get_ptr())
};
status.ensure_valid()
}
pub fn get_type(&self) -> FontType {
unsafe {
ffi::cairo_scaled_font_get_type(self.get_ptr())
}
}
pub fn get_reference_count(&self) -> usize {
unsafe {
ffi::cairo_scaled_font_get_reference_count(self.get_ptr()) as usize
}
}
pub fn reference(&self) -> ScaledFont {
unsafe {
ScaledFont(ffi::cairo_scaled_font_reference(self.get_ptr()))
}
}
}
impl Drop for ScaledFont {
fn drop(&mut self) {
unsafe {
ffi::cairo_scaled_font_destroy(self.get_ptr())
}
}
}