pub struct TextShaper {
pub measurer: TextMeasurer,
pub atlas: GlyphAtlas,
}Expand description
Combines the measurer and the atlas into a text shaper.
The shaper is the single place where text is turned into positioned glyphs, so the Canvas2D backend and the GPU backends lay text out identically — the same label lands on the same pixel no matter which backend is in use.
Fields§
§measurer: TextMeasurerThe measurer used to size the text.
atlas: GlyphAtlasThe atlas the glyphs are rasterised into.
Implementations§
Source§impl TextShaper
Inherent implementation of TextShaper.
impl TextShaper
Inherent implementation of TextShaper.
Sourcepub fn new(measurer: TextMeasurer, atlas: GlyphAtlas) -> Self
pub fn new(measurer: TextMeasurer, atlas: GlyphAtlas) -> Self
Creates a shaper with the given measurer and atlas.
§Arguments
TextMeasurer- ATextMeasurerparameter.GlyphAtlas- AGlyphAtlasparameter.
Sourcepub fn measurer(&self) -> &TextMeasurer
pub fn measurer(&self) -> &TextMeasurer
Sourcepub fn atlas(&self) -> &GlyphAtlas
pub fn atlas(&self) -> &GlyphAtlas
Sourcepub fn atlas_mut(&mut self) -> &mut GlyphAtlas
pub fn atlas_mut(&mut self) -> &mut GlyphAtlas
Returns the atlas as mutable, so a backend can upload it.
§Returns
&mut GlyphAtlas- Amut GlyphAtlasvalue.
Sourcepub fn shape(
&mut self,
text: &str,
style: &TextStyle,
x: f64,
y: f64,
) -> TextRun
pub fn shape( &mut self, text: &str, style: &TextStyle, x: f64, y: f64, ) -> TextRun
Shapes a run of text.
x and y are the anchor of the text; the alignment and the
vertical alignment of the style decide which part of the text
lands on the anchor.
A text that carries rich-text markup — {name|content} — is
split into its runs, and each run is shaped with the style that
the name refers to.
§Arguments
&str- Shared reference to astr.&TextStyle- Shared reference to aTextStyle.f64- A 64-bit float (f64).
§Returns
TextRun- ATextRunvalue.