pub struct DefaultTextSystem { /* private fields */ }Expand description
The GPUI text rendering sub system.
Implementations§
Source§impl DefaultTextSystem
impl DefaultTextSystem
Sourcepub fn new(
platform_text_system: Arc<dyn PlatformTextSystem>,
) -> DefaultTextSystem
pub fn new( platform_text_system: Arc<dyn PlatformTextSystem>, ) -> DefaultTextSystem
Create a new DefaultTextSystem with the given platform text system.
Sourcepub fn platform_text_system(&self) -> &Arc<dyn PlatformTextSystem> ⓘ
pub fn platform_text_system(&self) -> &Arc<dyn PlatformTextSystem> ⓘ
The platform text system this engine wraps.
Sourcepub fn font_generation(&self) -> &Arc<Atomic<usize>> ⓘ
pub fn font_generation(&self) -> &Arc<Atomic<usize>> ⓘ
The generation that advances whenever Self::add_fonts installs fonts.
Sourcepub fn take_font_runs(&self) -> Vec<FontRun>
pub fn take_font_runs(&self) -> Vec<FontRun>
Takes a pooled font-run buffer, or an empty one when the pool is dry.
Sourcepub fn recycle_font_runs(&self, font_runs: Vec<FontRun>)
pub fn recycle_font_runs(&self, font_runs: Vec<FontRun>)
Returns a font-run buffer to the pool for reuse.
Sourcepub fn all_font_names(&self) -> Vec<String>
pub fn all_font_names(&self) -> Vec<String>
Get sorted, unique font family names available to the platform text system.
Includes fonts registered with Self::add_fonts.
Sourcepub fn add_fonts(&self, fonts: Vec<Cow<'static, [u8]>>) -> Result<(), Error>
pub fn add_fonts(&self, fonts: Vec<Cow<'static, [u8]>>) -> Result<(), Error>
Add a font’s data to the text system.
Cached font resolution and line layouts are invalidated after installation. Layouts already in progress may complete against the previous font set.
Sourcepub fn get_font_for_id(&self, id: FontId) -> Option<Font>
pub fn get_font_for_id(&self, id: FontId) -> Option<Font>
Get the Font for the Font Id.
Sourcepub fn resolve_font(&self, font: &Font) -> FontId
pub fn resolve_font(&self, font: &Font) -> FontId
Resolves the specified font, falling back to the default font stack if the font fails to load.
§Panics
Panics if the font and none of the fallbacks can be resolved.
Sourcepub fn prewarm_fonts(&self, fonts: &[Font])
pub fn prewarm_fonts(&self, fonts: &[Font])
Prewarm any system font caches needed to shape text.
This may be expensive, so callers should generally invoke it on a background executor. Missing entries are still populated on demand by the normal shaping path.
Sourcepub fn bounding_box(&self, font_id: FontId, font_size: Pixels) -> Bounds<Pixels>
pub fn bounding_box(&self, font_id: FontId, font_size: Pixels) -> Bounds<Pixels>
Get the bounding box for the given font and font size. A font’s bounding box is the smallest rectangle that could enclose all glyphs in the font. superimposed over one another.
Sourcepub fn typographic_bounds(
&self,
font_id: FontId,
font_size: Pixels,
character: char,
) -> Result<Bounds<Pixels>, Error>
pub fn typographic_bounds( &self, font_id: FontId, font_size: Pixels, character: char, ) -> Result<Bounds<Pixels>, Error>
Get the typographic bounds for the given character, in the given font and size.
Sourcepub fn advance(
&self,
font_id: FontId,
font_size: Pixels,
ch: char,
) -> Result<Size<Pixels>, Error>
pub fn advance( &self, font_id: FontId, font_size: Pixels, ch: char, ) -> Result<Size<Pixels>, Error>
Get the advance width for the given character, in the given font and size.
Sourcepub fn layout_width(
&self,
font_id: FontId,
font_size: Pixels,
ch: char,
) -> Pixels
pub fn layout_width( &self, font_id: FontId, font_size: Pixels, ch: char, ) -> Pixels
Returns the shaped layout width of for the given character, in the given font and size.
Sourcepub fn em_width(
&self,
font_id: FontId,
font_size: Pixels,
) -> Result<Pixels, Error>
pub fn em_width( &self, font_id: FontId, font_size: Pixels, ) -> Result<Pixels, Error>
Returns the width of an em.
Uses the width of the m character in the given font and size.
Sourcepub fn em_advance(
&self,
font_id: FontId,
font_size: Pixels,
) -> Result<Pixels, Error>
pub fn em_advance( &self, font_id: FontId, font_size: Pixels, ) -> Result<Pixels, Error>
Returns the advance width of an em.
Uses the advance width of the m character in the given font and size.
Sourcepub fn ch_width(
&self,
font_id: FontId,
font_size: Pixels,
) -> Result<Pixels, Error>
pub fn ch_width( &self, font_id: FontId, font_size: Pixels, ) -> Result<Pixels, Error>
Returns the width of an ch.
Uses the width of the 0 character in the given font and size.
Sourcepub fn ch_advance(
&self,
font_id: FontId,
font_size: Pixels,
) -> Result<Pixels, Error>
pub fn ch_advance( &self, font_id: FontId, font_size: Pixels, ) -> Result<Pixels, Error>
Returns the advance width of an ch.
Uses the advance width of the 0 character in the given font and size.
Sourcepub fn units_per_em(&self, font_id: FontId) -> u32
pub fn units_per_em(&self, font_id: FontId) -> u32
Get the number of font size units per ‘em square’, Per MDN: “an abstract square whose height is the intended distance between lines of type in the same type size”
Sourcepub fn cap_height(&self, font_id: FontId, font_size: Pixels) -> Pixels
pub fn cap_height(&self, font_id: FontId, font_size: Pixels) -> Pixels
Get the height of a capital letter in the given font and size.
Sourcepub fn x_height(&self, font_id: FontId, font_size: Pixels) -> Pixels
pub fn x_height(&self, font_id: FontId, font_size: Pixels) -> Pixels
Get the height of the x character in the given font and size.
Sourcepub fn ascent(&self, font_id: FontId, font_size: Pixels) -> Pixels
pub fn ascent(&self, font_id: FontId, font_size: Pixels) -> Pixels
Get the recommended distance from the baseline for the given font
Sourcepub fn descent(&self, font_id: FontId, font_size: Pixels) -> Pixels
pub fn descent(&self, font_id: FontId, font_size: Pixels) -> Pixels
Get the recommended distance below the baseline for the given font, in single spaced text.
Sourcepub fn baseline_offset(
&self,
font_id: FontId,
font_size: Pixels,
line_height: Pixels,
) -> Pixels
pub fn baseline_offset( &self, font_id: FontId, font_size: Pixels, line_height: Pixels, ) -> Pixels
Get the recommended baseline offset for the given font and line height.
Sourcepub fn line_wrapper(
self: Arc<DefaultTextSystem>,
font: Font,
font_size: Pixels,
) -> LineWrapperHandle
pub fn line_wrapper( self: Arc<DefaultTextSystem>, font: Font, font_size: Pixels, ) -> LineWrapperHandle
Returns a handle to a line wrapper, for the given font and font size.
Sourcepub fn raster_bounds(
&self,
params: &RenderGlyphParams,
) -> Result<Bounds<DevicePixels>, Error>
pub fn raster_bounds( &self, params: &RenderGlyphParams, ) -> Result<Bounds<DevicePixels>, Error>
Get the rasterized size and location of a specific, rendered glyph.
Sourcepub fn rasterize_glyph(
&self,
params: &RenderGlyphParams,
) -> Result<(Size<DevicePixels>, Vec<u8>), Error>
pub fn rasterize_glyph( &self, params: &RenderGlyphParams, ) -> Result<(Size<DevicePixels>, Vec<u8>), Error>
Rasterizes a glyph, returning its size and coverage bitmap.
Sourcepub fn glyph_dilation_for_color(&self, color: Hsla) -> u8
pub fn glyph_dilation_for_color(&self, color: Hsla) -> u8
Returns the dilation level to use for a glyph painted in the given color.
Sourcepub fn recommended_rendering_mode(
&self,
font_id: FontId,
font_size: Pixels,
) -> TextRenderingMode
pub fn recommended_rendering_mode( &self, font_id: FontId, font_size: Pixels, ) -> TextRenderingMode
Returns the text rendering mode recommended by the platform for the given font and size.
The return value will never be TextRenderingMode::PlatformDefault.
Trait Implementations§
Source§impl TextSystem for DefaultTextSystem
impl TextSystem for DefaultTextSystem
Source§fn take_missing_glyph_receiver(&self) -> Option<Box<dyn MissingGlyphReports>>
fn take_missing_glyph_receiver(&self) -> Option<Box<dyn MissingGlyphReports>>
Source§fn enable_missing_glyph_reporting(&self)
fn enable_missing_glyph_reporting(&self)
Source§fn disable_missing_glyph_reporting(&self)
fn disable_missing_glyph_reporting(&self)
Source§fn platform_text_system(&self) -> &Arc<dyn PlatformTextSystem> ⓘ
fn platform_text_system(&self) -> &Arc<dyn PlatformTextSystem> ⓘ
Source§fn all_font_names(&self) -> Vec<String>
fn all_font_names(&self) -> Vec<String>
Source§fn add_fonts(&self, fonts: Vec<Cow<'static, [u8]>>) -> Result<(), Error>
fn add_fonts(&self, fonts: Vec<Cow<'static, [u8]>>) -> Result<(), Error>
Source§fn get_font_for_id(&self, id: FontId) -> Option<Font>
fn get_font_for_id(&self, id: FontId) -> Option<Font>
Source§fn resolve_font(&self, font: &Font) -> FontId
fn resolve_font(&self, font: &Font) -> FontId
Source§fn prewarm_fonts(&self, fonts: &[Font])
fn prewarm_fonts(&self, fonts: &[Font])
Source§fn bounding_box(&self, font_id: FontId, font_size: Pixels) -> Bounds<Pixels>
fn bounding_box(&self, font_id: FontId, font_size: Pixels) -> Bounds<Pixels>
Source§fn typographic_bounds(
&self,
font_id: FontId,
font_size: Pixels,
character: char,
) -> Result<Bounds<Pixels>, Error>
fn typographic_bounds( &self, font_id: FontId, font_size: Pixels, character: char, ) -> Result<Bounds<Pixels>, Error>
Source§fn advance(
&self,
font_id: FontId,
font_size: Pixels,
ch: char,
) -> Result<Size<Pixels>, Error>
fn advance( &self, font_id: FontId, font_size: Pixels, ch: char, ) -> Result<Size<Pixels>, Error>
Source§fn layout_width(&self, font_id: FontId, font_size: Pixels, ch: char) -> Pixels
fn layout_width(&self, font_id: FontId, font_size: Pixels, ch: char) -> Pixels
Source§fn em_width(&self, font_id: FontId, font_size: Pixels) -> Result<Pixels, Error>
fn em_width(&self, font_id: FontId, font_size: Pixels) -> Result<Pixels, Error>
Source§fn em_advance(
&self,
font_id: FontId,
font_size: Pixels,
) -> Result<Pixels, Error>
fn em_advance( &self, font_id: FontId, font_size: Pixels, ) -> Result<Pixels, Error>
Source§fn ch_width(&self, font_id: FontId, font_size: Pixels) -> Result<Pixels, Error>
fn ch_width(&self, font_id: FontId, font_size: Pixels) -> Result<Pixels, Error>
0 character, in a font and size.Source§fn ch_advance(
&self,
font_id: FontId,
font_size: Pixels,
) -> Result<Pixels, Error>
fn ch_advance( &self, font_id: FontId, font_size: Pixels, ) -> Result<Pixels, Error>
0 character, in a font and size.Source§fn units_per_em(&self, font_id: FontId) -> u32
fn units_per_em(&self, font_id: FontId) -> u32
Source§fn cap_height(&self, font_id: FontId, font_size: Pixels) -> Pixels
fn cap_height(&self, font_id: FontId, font_size: Pixels) -> Pixels
Source§fn x_height(&self, font_id: FontId, font_size: Pixels) -> Pixels
fn x_height(&self, font_id: FontId, font_size: Pixels) -> Pixels
Source§fn ascent(&self, font_id: FontId, font_size: Pixels) -> Pixels
fn ascent(&self, font_id: FontId, font_size: Pixels) -> Pixels
Source§fn descent(&self, font_id: FontId, font_size: Pixels) -> Pixels
fn descent(&self, font_id: FontId, font_size: Pixels) -> Pixels
Source§fn baseline_offset(
&self,
font_id: FontId,
font_size: Pixels,
line_height: Pixels,
) -> Pixels
fn baseline_offset( &self, font_id: FontId, font_size: Pixels, line_height: Pixels, ) -> Pixels
Source§fn take_font_runs(&self) -> Vec<FontRun>
fn take_font_runs(&self) -> Vec<FontRun>
Source§fn recycle_font_runs(&self, font_runs: Vec<FontRun>)
fn recycle_font_runs(&self, font_runs: Vec<FontRun>)
Source§fn line_wrapper(
self: Arc<DefaultTextSystem>,
font: Font,
font_size: Pixels,
) -> LineWrapperHandle
fn line_wrapper( self: Arc<DefaultTextSystem>, font: Font, font_size: Pixels, ) -> LineWrapperHandle
Source§fn raster_bounds(
&self,
params: &RenderGlyphParams,
) -> Result<Bounds<DevicePixels>, Error>
fn raster_bounds( &self, params: &RenderGlyphParams, ) -> Result<Bounds<DevicePixels>, Error>
Source§fn rasterize_glyph(
&self,
params: &RenderGlyphParams,
) -> Result<(Size<DevicePixels>, Vec<u8>), Error>
fn rasterize_glyph( &self, params: &RenderGlyphParams, ) -> Result<(Size<DevicePixels>, Vec<u8>), Error>
Source§fn glyph_dilation_for_color(&self, color: Hsla) -> u8
fn glyph_dilation_for_color(&self, color: Hsla) -> u8
Source§fn recommended_rendering_mode(
&self,
font_id: FontId,
font_size: Pixels,
) -> TextRenderingMode
fn recommended_rendering_mode( &self, font_id: FontId, font_size: Pixels, ) -> TextRenderingMode
Source§fn layout_index(&self) -> LineLayoutIndex
fn layout_index(&self) -> LineLayoutIndex
Source§fn reuse_layouts(&self, range: Range<LineLayoutIndex>)
fn reuse_layouts(&self, range: Range<LineLayoutIndex>)
range.Source§fn truncate_layouts(&self, index: LineLayoutIndex)
fn truncate_layouts(&self, index: LineLayoutIndex)
index.Source§fn finish_frame(&self)
fn finish_frame(&self)
Source§fn layout_wrapped_line(
&self,
text: &str,
font_size: Pixels,
runs: &[FontRun],
wrap_width: Option<Pixels>,
max_lines: Option<usize>,
) -> Arc<WrappedLineLayout> ⓘ
fn layout_wrapped_line( &self, text: &str, font_size: Pixels, runs: &[FontRun], wrap_width: Option<Pixels>, max_lines: Option<usize>, ) -> Arc<WrappedLineLayout> ⓘ
text, reusing a cached layout when the inputs match.Source§fn layout_line(
&self,
text: &str,
font_size: Pixels,
runs: &[FontRun],
force_width: Option<Pixels>,
) -> Arc<LineLayout> ⓘ
fn layout_line( &self, text: &str, font_size: Pixels, runs: &[FontRun], force_width: Option<Pixels>, ) -> Arc<LineLayout> ⓘ
text, reusing a cached layout when the inputs match.Source§fn try_layout_line_by_hash(
&self,
text_hash: u64,
text_len: usize,
font_size: Pixels,
runs: &[FontRun],
force_width: Option<Pixels>,
) -> Option<Arc<LineLayout>>
fn try_layout_line_by_hash( &self, text_hash: u64, text_len: usize, font_size: Pixels, runs: &[FontRun], force_width: Option<Pixels>, ) -> Option<Arc<LineLayout>>
Source§fn layout_line_by_hash(
&self,
text_hash: u64,
text_len: usize,
font_size: Pixels,
runs: &[FontRun],
force_width: Option<Pixels>,
materialize_text: Box<dyn FnOnce() -> SharedString>,
) -> Arc<LineLayout> ⓘ
fn layout_line_by_hash( &self, text_hash: u64, text_len: usize, font_size: Pixels, runs: &[FontRun], force_width: Option<Pixels>, materialize_text: Box<dyn FnOnce() -> SharedString>, ) -> Arc<LineLayout> ⓘ
Auto Trait Implementations§
impl !Freeze for DefaultTextSystem
impl !RefUnwindSafe for DefaultTextSystem
impl !Unpin for DefaultTextSystem
impl !UnsafeUnpin for DefaultTextSystem
impl !UnwindSafe for DefaultTextSystem
impl Send for DefaultTextSystem
impl Sync for DefaultTextSystem
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more