pub struct TextEngine { /* private fields */ }Expand description
Fonts and metrics.
§Examples
use ferrochart_text::TextEngine;
let engine = TextEngine::new();
// The bundled font is monospaced: every digit has the same advance.
let adv = engine.ascii_advances(0);
assert!(adv[b'0' as usize] > 0.0);
assert_eq!(adv[b'1' as usize], adv[b'8' as usize]);
assert!(engine.line_metrics(0, 12.0).height() > 12.0);Implementations§
Source§impl TextEngine
impl TextEngine
Sourcepub fn add_font(&mut self, data: Vec<u8>) -> Result<u16, FontError>
pub fn add_font(&mut self, data: Vec<u8>) -> Result<u16, FontError>
Adds a font (TTF/OTF data) and returns its index.
§Errors
FontError::Invalid if the data cannot be parsed,
FontError::TooManyFonts beyond u16::MAX fonts.
Sourcepub fn font_count(&self) -> usize
pub fn font_count(&self) -> usize
Number of loaded fonts.
Sourcepub fn ascii_advances(&self, id: u16) -> &[f32; 128]
pub fn ascii_advances(&self, id: u16) -> &[f32; 128]
ASCII advances of font id at a font size of 1 px. Unknown ids use font 0.
Sourcepub fn subscript_advances(&self, id: u16) -> &[f32; 10]
pub fn subscript_advances(&self, id: u16) -> &[f32; 10]
Advances of the subscript digits ₀..=₉ (U+2080..=U+2089) of font
id at a font size of 1 px. Unknown ids use font 0.
Sourcepub fn line_metrics(&self, id: u16, size: f32) -> LineMetrics
pub fn line_metrics(&self, id: u16, size: f32) -> LineMetrics
Line metrics of font id at size px.
Sourcepub fn width(&self, id: u16, text: &str, size: f32) -> f32
pub fn width(&self, id: u16, text: &str, size: f32) -> f32
Width of text at size px: the sum of the advances, without kerning,
exactly as the core’s ASCII fast path measures it.
Trait Implementations§
Source§impl Debug for TextEngine
impl Debug for TextEngine
Auto Trait Implementations§
impl !RefUnwindSafe for TextEngine
impl !UnwindSafe for TextEngine
impl Forget for TextEngine
impl Freeze for TextEngine
impl Move for TextEngine
impl Send for TextEngine
impl Sync for TextEngine
impl Unpin for TextEngine
impl UnsafeUnpin for TextEngine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more