Skip to main content

Glyph

Struct Glyph 

Source
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 × height bytes
  • 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

Source

pub fn code(&self) -> &u16

Glyph code/index in the font.

This is the internal glyph identifier used by the font file format.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn data(&self) -> &Vec<u8>

8-bit grayscale bitmap data.

Contains the glyph’s pixel data in row-major order:

  • Size: width × height bytes
  • 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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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 × height bytes
  • 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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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 × height bytes
  • 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 Clone for Glyph

Source§

fn clone(&self) -> Glyph

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Glyph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Glyph

Source§

fn default() -> Glyph

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Glyph

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Glyph

Source§

fn eq(&self, other: &Glyph) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Glyph

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,