pub struct MockFont {
pub font_metrics: LayoutFontMetrics,
pub space_width: Option<usize>,
pub glyph_advances: BTreeMap<u16, u16>,
pub glyph_sizes: BTreeMap<u16, (i32, i32)>,
pub glyph_indices: BTreeMap<u32, u16>,
}Expand description
A mock font implementation for testing text layout without real fonts.
This allows testing text shaping, layout, and rendering code paths without needing to load actual TrueType/OpenType font files.
Fields§
§font_metrics: LayoutFontMetricsFont metrics (ascent, descent, etc.).
space_width: Option<usize>Width of the space character in font units.
glyph_advances: BTreeMap<u16, u16>Horizontal advance widths keyed by glyph ID.
glyph_sizes: BTreeMap<u16, (i32, i32)>Glyph bounding box sizes (width, height) keyed by glyph ID.
glyph_indices: BTreeMap<u32, u16>Unicode codepoint to glyph ID mapping.
Implementations§
Source§impl MockFont
impl MockFont
Sourcepub fn new(font_metrics: LayoutFontMetrics) -> Self
pub fn new(font_metrics: LayoutFontMetrics) -> Self
Creates a new MockFont with the given font metrics.
Sourcepub fn with_space_width(self, width: usize) -> Self
pub fn with_space_width(self, width: usize) -> Self
Sets the space character width.
Sourcepub fn with_glyph_advance(self, glyph_index: u16, advance: u16) -> Self
pub fn with_glyph_advance(self, glyph_index: u16, advance: u16) -> Self
Adds a horizontal advance value for a glyph.
Sourcepub fn with_glyph_size(self, glyph_index: u16, size: (i32, i32)) -> Self
pub fn with_glyph_size(self, glyph_index: u16, size: (i32, i32)) -> Self
Adds a bounding box size for a glyph.
Sourcepub fn with_glyph_index(self, unicode: u32, index: u16) -> Self
pub fn with_glyph_index(self, unicode: u32, index: u16) -> Self
Adds a Unicode codepoint to glyph ID mapping.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for MockFont
impl RefUnwindSafe for MockFont
impl Send for MockFont
impl Sync for MockFont
impl Unpin for MockFont
impl UnsafeUnpin for MockFont
impl UnwindSafe for MockFont
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more