Skip to main content

TextSystem

Struct TextSystem 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for TextSystem

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> ErasedDestructor for T
where T: 'static,

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.