Struct read_fonts::FontData
source · pub struct FontData<'a> { /* private fields */ }Expand description
A reference to raw binary font data.
This is a wrapper around a byte slice, that provides convenience methods for parsing and validating that data.
Implementations§
source§impl<'a> FontData<'a>
impl<'a> FontData<'a>
sourcepub const fn new(bytes: &'a [u8]) -> Self
pub const fn new(bytes: &'a [u8]) -> Self
Create a new FontData with these bytes.
You generally don’t need to do this? It is handled for you when loading data from disk, but may be useful in tests.
pub fn split_off(&self, pos: usize) -> Option<FontData<'a>>
pub fn slice(&self, range: impl RangeBounds<usize>) -> Option<FontData<'a>>
pub fn read_at<T: ReadScalar>(&self, offset: usize) -> Result<T, ReadError>
pub fn read_with_args<T>(
&self,
range: Range<usize>,
args: &T::Args
) -> Result<T, ReadError>where
T: FontReadWithArgs<'a>,
sourcepub unsafe fn read_at_unchecked<T: ReadScalar>(&self, offset: usize) -> T
pub unsafe fn read_at_unchecked<T: ReadScalar>(&self, offset: usize) -> T
Read a scalar value out of the buffer at offset, elliding bounds checks
Safety
The range offset..offset + T::RAW_BYTE_LEN must be in bounds.
pub fn read_ref_at<T: FixedSize>(
&self,
offset: usize
) -> Result<&'a T, ReadError>
pub fn read_array<T: FixedSize>(
&self,
range: Range<usize>
) -> Result<&'a [T], ReadError>
sourcepub unsafe fn read_array_unchecked<T: FixedSize>(
&self,
range: Range<usize>
) -> &'a [T] ⓘ
pub unsafe fn read_array_unchecked<T: FixedSize>(
&self,
range: Range<usize>
) -> &'a [T] ⓘ
Interpret the bytes at offset as a reference to some type T.
Safety
T must be a struct or scalar that has alignment of 1, a non-zero size,
and no internal padding, and range must have a length that is non-zero
and is a multiple of size_of::<T>().