Expand description
De-/Serializable runtime representation of bitmap font metadata.
§Usage
§RON
// Requires Cargo feature `serde-deserialize` and the `ron` crate:
const FONT_METADATA: &'static str = include_str!("../font-metadata.ron");
let font: raster_fonts::BitmapFont = ron::from_str(FONT_METADATA)?;
§JSON
// Requires Cargo feature `serde-deserialize` and the `serde_json` crate:
const FONT_METADATA: &'static str = include_str!("../font-metadata.json");
let font: raster_fonts::BitmapFont = serde_json::from_str(FONT_METADATA)?;
§RKYV
// `rkyv` requires the data to be aligned for zero-copy deserialization,
// which in turn requires some trickery to achieve in a `const` context:
const FONT_METADATA: &'static [u8] = {
#[repr(C)]
struct Aligned<T: ?Sized> {
_align: [usize; 0],
bytes: T,
}
const ALIGNED: &'static Aligned<[u8]> = &Aligned {
_align: [],
bytes: *include_bytes!("../font-metadata.rkyv"),
};
&ALIGNED.bytes
};
// Using the unsafe API for maximum performance:
use raster_fonts::BitmapFont;
let archived_font = unsafe { rkyv::archived_root::<BitmapFont>(FONT_METADATA) };
// Optionally, unpack the archived metadata before use:
use rkyv::Deserialize;
let deserialized_font: BitmapFont = archived_font.deserialize(&mut rkyv::Infallible).unwrap();
Structs§
- Archived
Bitmap Font - An archived
BitmapFont
- Archived
Bitmap Glyph - An archived
BitmapGlyph
- Archived
Source Rect - An archived
SourceRect
- Bitmap
Font - Runtime representation of all metadata for a single bitmap font.
- Bitmap
Font Resolver - The resolver for an archived
BitmapFont
- Bitmap
Glyph SourceRect
and horizontal metrics of a glyph required for text layout.- Bitmap
Glyph Resolver - The resolver for an archived
BitmapGlyph
- Source
Rect - Coordinates and size of a rendered glyph in a packed bitmap.
- Source
Rect Resolver - The resolver for an archived
SourceRect