use {CharacterCache, FontSize, Scalar};
use std::cell::RefCell;
use text;
pub struct GlyphCache<C> {
ref_cell: RefCell<C>,
}
impl<C> GlyphCache<C> {
pub fn new(cache: C) -> Self {
GlyphCache {
ref_cell: RefCell::new(cache),
}
}
pub fn char_width(&self, font_size: FontSize, ch: char) -> Scalar
where C: CharacterCache,
{
self.ref_cell.borrow_mut().character(font_size, ch).width()
}
pub fn char_widths<I>(&self,
font_size: FontSize,
chars: I) -> text::char::Widths<I::IntoIter, C>
where I: IntoIterator<Item=char>,
C: CharacterCache,
{
text::char::widths(chars, self, font_size)
}
pub fn width(&self, font_size: FontSize, text: &str) -> Scalar
where C: CharacterCache,
{
self.ref_cell.borrow_mut().width(font_size, text)
}
}
impl<C> ::std::ops::Deref for GlyphCache<C> {
type Target = RefCell<C>;
fn deref<'a>(&'a self) -> &'a RefCell<C> {
&self.ref_cell
}
}
impl<C> ::std::ops::DerefMut for GlyphCache<C> {
fn deref_mut<'a>(&'a mut self) -> &'a mut RefCell<C> {
&mut self.ref_cell
}
}