pub struct Glyph { /* private fields */ }Expand description
Represents a single glyph (character) in a font.
Contains the character’s bitmap data and rendering metrics. Glyphs store both allocated dimensions (for layout) and actual bitmap dimensions (for rendering).
§Bitmap Data
The data field contains 8-bit grayscale pixel data in row-major order:
- Each byte represents one pixel’s intensity/alpha (0-255)
- Total size is
width × heightbytes - Empty glyphs (spaces, etc.) may have zero-sized data
§Dimensions
Two sets of dimensions are stored:
- Allocated (
alloc_width,alloc_height): Space reserved for layout - Actual (
width,height): Size of the bitmap data
Allocated height can be negative for characters with descenders (e.g., ‘g’, ‘y’).
Implementations§
Source§impl Glyph
impl Glyph
Sourcepub fn code(&self) -> &u16
pub fn code(&self) -> &u16
Glyph code/index in the font.
This is the internal glyph identifier used by the font file format.
Sourcepub fn character(&self) -> &u16
pub fn character(&self) -> &u16
Unicode character code this glyph represents.
Maps to the Unicode character value (0-65535 range for BMP). This is the character that will be displayed when this glyph is rendered.
Sourcepub fn alloc_height(&self) -> &i8
pub fn alloc_height(&self) -> &i8
Allocated height in the font layout (can be negative).
This is the vertical space reserved for the glyph in text layout. Negative values indicate descenders (parts of characters below the baseline). For example, lowercase ‘g’ or ‘y’ typically have negative allocated heights.
Sourcepub fn alloc_width(&self) -> &u8
pub fn alloc_width(&self) -> &u8
Allocated width in the font layout.
This is the horizontal advance width - how far to move the cursor after rendering this glyph. May differ from the actual bitmap width.
Sourcepub fn width(&self) -> &u8
pub fn width(&self) -> &u8
Actual bitmap width in pixels.
The width of the glyph’s pixel data. The data field contains
width × height bytes of bitmap information.
Sourcepub fn height(&self) -> &u8
pub fn height(&self) -> &u8
Actual bitmap height in pixels.
The height of the glyph’s pixel data. The data field contains
width × height bytes of bitmap information.
Sourcepub fn kerning(&self) -> &u32
pub fn kerning(&self) -> &u32
Kerning adjustment value.
Used for pair-wise spacing adjustments between specific character combinations. The exact interpretation depends on the kerning data in the font.
Sourcepub fn data(&self) -> &Vec<u8> ⓘ
pub fn data(&self) -> &Vec<u8> ⓘ
8-bit grayscale bitmap data.
Contains the glyph’s pixel data in row-major order:
- Size:
width × heightbytes - Format: One byte per pixel (0 = transparent, 255 = opaque)
- Empty for characters with no visual representation (e.g., spaces)
§Example Layout
For a 3×2 glyph, data is stored as:
[row0_col0, row0_col1, row0_col2, row1_col0, row1_col1, row1_col2]Source§impl Glyph
impl Glyph
Sourcepub fn code_mut(&mut self) -> &mut u16
pub fn code_mut(&mut self) -> &mut u16
Glyph code/index in the font.
This is the internal glyph identifier used by the font file format.
Sourcepub fn character_mut(&mut self) -> &mut u16
pub fn character_mut(&mut self) -> &mut u16
Unicode character code this glyph represents.
Maps to the Unicode character value (0-65535 range for BMP). This is the character that will be displayed when this glyph is rendered.
Sourcepub fn alloc_height_mut(&mut self) -> &mut i8
pub fn alloc_height_mut(&mut self) -> &mut i8
Allocated height in the font layout (can be negative).
This is the vertical space reserved for the glyph in text layout. Negative values indicate descenders (parts of characters below the baseline). For example, lowercase ‘g’ or ‘y’ typically have negative allocated heights.
Sourcepub fn alloc_width_mut(&mut self) -> &mut u8
pub fn alloc_width_mut(&mut self) -> &mut u8
Allocated width in the font layout.
This is the horizontal advance width - how far to move the cursor after rendering this glyph. May differ from the actual bitmap width.
Sourcepub fn width_mut(&mut self) -> &mut u8
pub fn width_mut(&mut self) -> &mut u8
Actual bitmap width in pixels.
The width of the glyph’s pixel data. The data field contains
width × height bytes of bitmap information.
Sourcepub fn height_mut(&mut self) -> &mut u8
pub fn height_mut(&mut self) -> &mut u8
Actual bitmap height in pixels.
The height of the glyph’s pixel data. The data field contains
width × height bytes of bitmap information.
Sourcepub fn kerning_mut(&mut self) -> &mut u32
pub fn kerning_mut(&mut self) -> &mut u32
Kerning adjustment value.
Used for pair-wise spacing adjustments between specific character combinations. The exact interpretation depends on the kerning data in the font.
Sourcepub fn data_mut(&mut self) -> &mut Vec<u8> ⓘ
pub fn data_mut(&mut self) -> &mut Vec<u8> ⓘ
8-bit grayscale bitmap data.
Contains the glyph’s pixel data in row-major order:
- Size:
width × heightbytes - Format: One byte per pixel (0 = transparent, 255 = opaque)
- Empty for characters with no visual representation (e.g., spaces)
§Example Layout
For a 3×2 glyph, data is stored as:
[row0_col0, row0_col1, row0_col2, row1_col0, row1_col1, row1_col2]Source§impl Glyph
impl Glyph
Sourcepub fn set_code(&mut self, val: u16) -> &mut Self
pub fn set_code(&mut self, val: u16) -> &mut Self
Glyph code/index in the font.
This is the internal glyph identifier used by the font file format.
Sourcepub fn set_character(&mut self, val: u16) -> &mut Self
pub fn set_character(&mut self, val: u16) -> &mut Self
Unicode character code this glyph represents.
Maps to the Unicode character value (0-65535 range for BMP). This is the character that will be displayed when this glyph is rendered.
Sourcepub fn set_alloc_height(&mut self, val: i8) -> &mut Self
pub fn set_alloc_height(&mut self, val: i8) -> &mut Self
Allocated height in the font layout (can be negative).
This is the vertical space reserved for the glyph in text layout. Negative values indicate descenders (parts of characters below the baseline). For example, lowercase ‘g’ or ‘y’ typically have negative allocated heights.
Sourcepub fn set_alloc_width(&mut self, val: u8) -> &mut Self
pub fn set_alloc_width(&mut self, val: u8) -> &mut Self
Allocated width in the font layout.
This is the horizontal advance width - how far to move the cursor after rendering this glyph. May differ from the actual bitmap width.
Sourcepub fn set_width(&mut self, val: u8) -> &mut Self
pub fn set_width(&mut self, val: u8) -> &mut Self
Actual bitmap width in pixels.
The width of the glyph’s pixel data. The data field contains
width × height bytes of bitmap information.
Sourcepub fn set_height(&mut self, val: u8) -> &mut Self
pub fn set_height(&mut self, val: u8) -> &mut Self
Actual bitmap height in pixels.
The height of the glyph’s pixel data. The data field contains
width × height bytes of bitmap information.
Sourcepub fn set_kerning(&mut self, val: u32) -> &mut Self
pub fn set_kerning(&mut self, val: u32) -> &mut Self
Kerning adjustment value.
Used for pair-wise spacing adjustments between specific character combinations. The exact interpretation depends on the kerning data in the font.
Sourcepub fn set_data(&mut self, val: Vec<u8>) -> &mut Self
pub fn set_data(&mut self, val: Vec<u8>) -> &mut Self
8-bit grayscale bitmap data.
Contains the glyph’s pixel data in row-major order:
- Size:
width × heightbytes - Format: One byte per pixel (0 = transparent, 255 = opaque)
- Empty for characters with no visual representation (e.g., spaces)
§Example Layout
For a 3×2 glyph, data is stored as:
[row0_col0, row0_col1, row0_col2, row1_col0, row1_col1, row1_col2]Trait Implementations§
Source§impl<'de> Deserialize<'de> for Glyph
impl<'de> Deserialize<'de> for Glyph
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl StructuralPartialEq for Glyph
Auto Trait Implementations§
impl Freeze for Glyph
impl RefUnwindSafe for Glyph
impl Send for Glyph
impl Sync for Glyph
impl Unpin for Glyph
impl UnsafeUnpin for Glyph
impl UnwindSafe for Glyph
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
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>
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>
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§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.