use sim_engine::{ShapedLine, TextShapingSession};
use super::{TextError, TextFont};
pub struct TextPreparationSession<'font> {
font: &'font TextFont,
engine: TextShapingSession<'font>,
}
impl<'font> TextPreparationSession<'font> {
pub(super) fn new(font: &'font TextFont) -> Result<Self, TextError> {
let settings = font.settings();
Ok(Self {
font,
engine: TextShapingSession::new(
font.face(),
settings.style(1.0)?,
settings.layout_budget(),
)?,
})
}
pub const fn font(&self) -> &TextFont {
self.font
}
pub fn allocation_bytes(&self) -> usize {
self.engine.allocation_bytes()
}
pub fn cached_plan_count(&self) -> usize {
self.engine.cached_plan_count()
}
pub fn clear_scratch(&mut self) {
self.engine.clear_scratch();
}
pub(super) fn shape_line(&mut self, text: &str) -> Result<ShapedLine, TextError> {
Ok(self.engine.shape_line(text)?)
}
}