pub struct TextSystem { /* private fields */ }Expand description
Fonts plus layout scratch space: builds Paragraphs.
Create one per application (or per UI thread) and keep it: it caches font data and reuses
layout buffers. Every face a paragraph uses becomes one densa_text::Font, so all
paragraphs (and the bundled font’s other users, such as the grid) share cached glyphs.
Faces stay loaded for the system’s lifetime (system CJK fonts can be tens of MB each).
Implementations§
Source§impl TextSystem
impl TextSystem
Sourcepub fn new() -> Result<Self, FontError>
pub fn new() -> Result<Self, FontError>
The text system applications want: the bundled JetBrains Mono for monospace (the
default family), and the operating system’s fonts for other families and for every
character the bundled font lacks (Korean, Japanese, Chinese, symbols, …).
Without the system-fonts feature (on by default) this is bundled.
§Errors
Only if the bundled font were corrupt.
Sourcepub fn bundled() -> Result<Self, FontError>
pub fn bundled() -> Result<Self, FontError>
A text system with only the bundled JetBrains Mono, which also stands in for every
generic family (monospace, sans-serif, …): the same text lays out the same on
every machine, for tests and screenshots. Characters it lacks are drawn as its
missing-glyph box; add fonts with register_font.
§Errors
Only if the bundled font were corrupt.
Sourcepub fn register_font(
&mut self,
data: FontBytes,
) -> Result<Vec<String>, FontError>
pub fn register_font( &mut self, data: FontBytes, ) -> Result<Vec<String>, FontError>
Adds the fonts in data (a font file or collection); returns their family names.
§Errors
FontError::Parse if data holds no readable font.
Sourcepub fn paragraph(
&mut self,
text: &str,
style: &ParagraphStyle,
spans: &[Span],
) -> Result<Paragraph, ParagraphError>
pub fn paragraph( &mut self, text: &str, style: &ParagraphStyle, spans: &[Span], ) -> Result<Paragraph, ParagraphError>
Shapes text with style, spans overriding parts of it, then breaks and aligns it.
Allocates (shaping is not a per-frame operation); drawing the result does not.
§Errors
ParagraphError for a size, line height or width out of range, a span that does not
lie on character boundaries within text, or a font that cannot be read.