Struct Pcf

Source
pub struct Pcf<'a> {
    pub glyph_byte_length: usize,
    pub glyph_width: usize,
    pub glyph_height: usize,
    pub glyphs: &'a [u8],
    pub unicode_table: Option<&'a [u8]>,
}
Expand description

A PCF font

Use parse to create one, get_glyph_pixels to get a glyph by index, and iter_unicode_entries to get a glyph index by unicode character. PCF stores ASCII glyphs at the corresponding index, so you can retrieve ASCII characters without calling iter_unicode_entries by giving the ASCII number to get_glyph_pixels directly.

Fields§

§glyph_byte_length: usize§glyph_width: usize§glyph_height: usize§glyphs: &'a [u8]§unicode_table: Option<&'a [u8]>

Implementations§

Source§

impl<'a> Pcf<'a>

Source

pub fn parse(data: &[u8]) -> Result<Pcf<'_>, ParseError>

Parse a PCF font from some bytes

See ParseError for possible errors.

PCF fonts may optionally have a unicode table indicating which glyphs correspond to which unicode characters. This function does not validate the structure of the unicode table. Errors in the encoding of the unicode table, if they can be detected, are reported by the iterator returned from the iter_unicode_entries function.

Source

pub fn get_glyph_bits(&self, glyph_index: usize) -> Option<&[u8]>

Get the bits corresponding to the glyph’s bitmap

PCF stores the bitmap as packed bits. Each byte in the slice contains eight pixels, with the last byte of each row containing padding bits so that the next row starts on a byte boundary.

You might be looking for get_glyph_pixels instead, which unpacks the bits for you.

Source

pub fn get_glyph_pixels<'b>( &'b self, glyph_index: usize, ) -> Option<impl Iterator<Item = bool> + 'b>

Get the pixels that correspond to the given glyph’s bitmap

PCF stores bitmaps in the packed bits of each byte. This iterator unpacks the bits, returning a boolean for each pixel in the bitmap indicating whether that pixel is lit or not.

PCF stores ASCII glyphs in the corresponding index, so you can retrieve ASCII glyphs directly by calling get_glyph_pixels(b'a' as usize). Unicode characters must be looked up with (iter_unicode_entries)Pcf::iter_unicode_entries.

Source

pub fn iter_unicode_entries<'b>( &'b self, ) -> Option<impl Iterator<Item = (usize, Result<&'b str, Utf8Error>)> + 'b>

Iterate over the entries in the unicode table

PCF fonts may optionally include a unicode table indicating which unicode character each glyph corresponds to. If such a table exists, this function returns an iterator that will yield each unicode entry along with the index of the glyph that represents to it.

In the case of a malformed unicode table, the behavior of this iterator is unpredictable because errors can not always be unambiguously detected. The iterator may return a unicode entry with a string containing multiple graphemes that ought to each have their own glyph, it may return None, or it may return a core::str::Utf8Error.

If you are using the standard library, this iterator can be used to construct a HashMap lookup table of unicode character to glyph index pairs.

let glyph_lookup_table = pcf.iter_unicode_entries().unwrap()
	.filter_map(|(index, result)| result.ok().map(|character| (character, index)))
	.collect::<std::collections::HashMap<&str, usize>>();

Auto Trait Implementations§

§

impl<'a> Freeze for Pcf<'a>

§

impl<'a> RefUnwindSafe for Pcf<'a>

§

impl<'a> Send for Pcf<'a>

§

impl<'a> Sync for Pcf<'a>

§

impl<'a> Unpin for Pcf<'a>

§

impl<'a> UnwindSafe for Pcf<'a>

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> 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, 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.