pub struct FontStack { /* private fields */ }Expand description
Fonts the application shipped, tried a glyph at a time in the order given.
A family is the faces of one typeface, a file for each weight or style. Text in a stack
is set in the first family, and each letter that family has no glyph for comes from the
next family that has one, the way CSS reads font-family: Inter, Pretendard. Letters no
family has come from the machine’s own fonts. Within a family the face is picked by the
weight and style the text asks for, which each face’s file says for itself.
A stack is registered once and named by id, so a theme can make it the font of every
role and stay Copy:
static INTER_REGULAR: &[u8] = include_bytes!("../assets/fonts/Inter-Regular.otf");
static INTER_BOLD: &[u8] = include_bytes!("../assets/fonts/Inter-Bold.otf");
static PRETENDARD_REGULAR: &[u8] = include_bytes!("../assets/fonts/Pretendard-Regular.otf");
let latin = [asset(AssetKind::Font, INTER_REGULAR), asset(AssetKind::Font, INTER_BOLD)];
let korean = [asset(AssetKind::Font, PRETENDARD_REGULAR)];
let stack = FontStack::new().family(latin).family(korean).register();
let theme = Theme::adaptive(DesignSystem::Material3).with_default_font(stack);The faces have to be registered before the stack that names them, which the order above gives for free. A stack naming an id that is not a registered face is reported by the Renderer, and that face is left out.
Implementations§
Source§impl FontStack
impl FontStack
pub fn new() -> Self
Sourcepub fn family(self, faces: impl IntoIterator<Item = u32>) -> Self
pub fn family(self, faces: impl IntoIterator<Item = u32>) -> Self
Adds one family, tried after every family added before it. An empty family is left
out, and so is anything past MAX_FONT_STACK_FAMILIES families or
MAX_FONT_STACK_FACES faces.
Sourcepub fn to_bytes(&self) -> Vec<u8> ⓘ
pub fn to_bytes(&self) -> Vec<u8> ⓘ
The asset bytes: the magic, the version, then the families.
Sourcepub fn from_bytes(bytes: &[u8]) -> Option<Self>
pub fn from_bytes(bytes: &[u8]) -> Option<Self>
Reads bytes FontStack::to_bytes wrote, or None for anything else.