pub struct FontData<'a> {
bytes: &'a [u8],
}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.
Fields§
§bytes: &'a [u8]Implementations§
Source§impl FontData<'static>
impl FontData<'static>
Sourceconst NULL_POOL_SIZE: usize = 262
const NULL_POOL_SIZE: usize = 262
The number of bytes required to represent the largest table we have.
This is checked by an assert at compile time, and can be increased as needed.
Sourcepub(crate) fn default_table_data() -> Self
pub(crate) fn default_table_data() -> Self
Return all zeroes suitable for the default impl of a table.
Sourcepub(crate) fn default_format_1_u16_table_data() -> Self
pub(crate) fn default_format_1_u16_table_data() -> Self
Return a [0x0, 0x01] byte pair (u16be) and then all zeros, to represent the default impl of a format 1 table with u16 format.
Sourcepub(crate) fn default_format_1_u8_table_data() -> Self
pub(crate) fn default_format_1_u8_table_data() -> Self
Return a single 0x01 and then all zeros, to represent the default impl of a format 1 table with u8 format.
Sourcepub(crate) const fn default_data_long_enough(n_bytes: usize) -> bool
pub(crate) const fn default_data_long_enough(n_bytes: usize) -> bool
Return true if our default data can represent a table n_bytes long
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.
Sourcepub fn take_up_to(&mut self, pos: usize) -> Option<FontData<'a>>
pub fn take_up_to(&mut self, pos: usize) -> Option<FontData<'a>>
returns self[..pos], and updates self to = self[pos..];
pub fn slice(&self, range: impl RangeBounds<usize>) -> Option<FontData<'a>>
Sourcepub fn read_at<T: Scalar>(&self, offset: usize) -> Result<T, ReadError>
pub fn read_at<T: Scalar>(&self, offset: usize) -> Result<T, ReadError>
Read a scalar at the provided location in the data.
Sourcepub fn read_be_at<T: Scalar>(
&self,
offset: usize,
) -> Result<BigEndian<T>, ReadError>
pub fn read_be_at<T: Scalar>( &self, offset: usize, ) -> Result<BigEndian<T>, ReadError>
Read a big-endian value at the provided location in the data.
pub fn read_with_args<T>(
&self,
range: Range<usize>,
args: &T::Args,
) -> Result<T, ReadError>where
T: FontReadWithArgs<'a>,
fn check_in_bounds(&self, offset: usize) -> Result<(), ReadError>
Sourcepub fn read_ref_at<T: AnyBitPattern + FixedSize>(
&self,
offset: usize,
) -> Result<&'a T, ReadError>
pub fn read_ref_at<T: AnyBitPattern + FixedSize>( &self, offset: usize, ) -> Result<&'a T, ReadError>
Interpret the bytes at the provided offset as a reference to T.
Returns an error if the slice offset.. is shorter than T::RAW_BYTE_LEN.
This is a wrapper around read_ref_unchecked, which panics if
the type does not uphold the required invariants.
§Panics
This function will panic if T is zero-sized, has an alignment
other than one, or has any internal padding.
Sourcepub fn read_array<T: AnyBitPattern + FixedSize>(
&self,
range: Range<usize>,
) -> Result<&'a [T], ReadError>
pub fn read_array<T: AnyBitPattern + FixedSize>( &self, range: Range<usize>, ) -> Result<&'a [T], ReadError>
Interpret the bytes at the provided offset as a slice of T.
Returns an error if range is out of bounds for the underlying data,
or if the length of the range is not a multiple of T::RAW_BYTE_LEN.
This is a wrapper around read_array_unchecked, which panics if
the type does not uphold the required invariants.
§Panics
This function will panic if T is zero-sized, has an alignment
other than one, or has any internal padding.