Skip to main content

SoftwareTextMeasurer

Struct SoftwareTextMeasurer 

Source
pub struct SoftwareTextMeasurer { /* private fields */ }
Expand description

A TextMeasurer that measures text with a SoftwareTextFontSet and caches the results.

Implementations§

Source§

impl SoftwareTextMeasurer

Source

pub fn new(font: SoftwareTextFont, cache_capacity: usize) -> Self

Creates a measurer for the single face font with a metrics cache of cache_capacity entries.

Source

pub fn from_font_set(fonts: SoftwareTextFontSet, cache_capacity: usize) -> Self

Creates a measurer for fonts with a metrics cache of cache_capacity entries.

Source

pub fn from_fonts_or_default( fonts: &[&'static [u8]], cache_capacity: usize, ) -> Self

Creates a measurer for the font set that fonts yields, which falls back to the embedded default font. See SoftwareTextFontSet::from_fonts_or_default.

Source

pub fn register_hyphenation_dictionary_path( &self, locale: &str, path: impl AsRef<Path>, ) -> Result<(), HyphenationDictionaryError>

Registers the hyphenation dictionary for locale read from the file at path.

Source

pub fn register_hyphenation_dictionary_reader( &self, locale: &str, reader: &mut impl Read, ) -> Result<(), HyphenationDictionaryError>

Registers the hyphenation dictionary for locale read from reader.

Trait Implementations§

Source§

impl TextMeasurer for SoftwareTextMeasurer

Source§

fn measure(&self, text: &AnnotatedString, style: &TextStyle) -> TextMetrics

Measures text in style with line breaks only at \n.
Source§

fn begin_layout_pass(&self)

Called as each layout pass starts. A measurer that caches measurements can age them by passes and drop the ones recent passes did not use.
Source§

fn measure_subsequence( &self, text: &AnnotatedString, range: Range<usize>, style: &TextStyle, ) -> TextMetrics

Measures the bytes of text in range. The default measures a copy of that slice.
Source§

fn measure_line_prefix_widths( &self, text: &AnnotatedString, line_range: Range<usize>, style: &TextStyle, ) -> Option<TextLinePrefixWidths>

The widths of every prefix of one line.
Source§

fn measure_line_width( &self, text: &AnnotatedString, line_range: Range<usize>, style: &TextStyle, ) -> Option<f32>

Width of the bytes of text in line_range laid out as one line, or None when the measurer cannot tell. The default returns None.
Source§

fn line_height(&self, text: &AnnotatedString, style: &TextStyle) -> f32

Height of one line of text in style. The default reads it from measure.
Source§

fn glyph_line_box(&self, style: &TextStyle) -> Option<(f32, f32)>

The tight glyph box of a text line inside its line_height slot: (top_offset, height) in logical units, where height is the font’s natural ascent+descent extent and top_offset positions it within the slot (glyph rows are vertically centered). Selection chrome — the highlight, the caret and the finger handles — anchors to THIS box, not the full slot: with a paragraph line height above the natural one the reference shows gaps between highlighted lines and handles riding the glyphs. None means the box fills the slot.
Source§

fn first_baseline(&self, style: &TextStyle) -> Option<f32>

Distance from the top of a line slot down to that line’s baseline, in logical units — the number the rasterizer places glyph origins at. Read more
Source§

fn line_box(&self, style: &TextStyle) -> Option<LineBox>

One line’s whole box for a style: its advance, its baseline and what a paragraph of it gives back at its edges, with no string to measure. Read more
Source§

fn line_box_and_height( &self, _node_id: Option<NodeId>, text: &AnnotatedString, style: &TextStyle, ) -> (Option<LineBox>, f32)

TextMeasurer::line_box of style and TextMeasurer::line_height_for_node of text in it, together: a measurer that finds both in one font lookup answers them at once.
Source§

fn visit_line_boxes( &self, text: &AnnotatedString, style: &TextStyle, visit: &mut dyn FnMut(LineBox), ) -> Option<()>

Visits each displayed line’s resolved font box, including styled spans. The text must already contain its wrapping newlines. Returns None when the measurer does not provide these metrics; no callbacks run in that case. The default handles plain text and defers annotated spans to line_height.
Source§

fn get_offset_for_position( &self, text: &AnnotatedString, style: &TextStyle, x: f32, y: f32, ) -> usize

Returns the byte offset of the character boundary nearest to the point (x, y) of text drawn in style. Coordinates are in logical pixels from the top left of the text.
Source§

fn get_cursor_x_for_offset( &self, text: &AnnotatedString, style: &TextStyle, offset: usize, ) -> f32

Returns the x position, in logical pixels, of the cursor at byte offset of text drawn in style.
Source§

fn layout(&self, text: &AnnotatedString, style: &TextStyle) -> TextLayoutResult

Lays text out in style and returns the glyph and line positions.
Source§

fn choose_auto_hyphen_break( &self, line: &str, style: &TextStyle, segment_start_char: usize, measured_break_char: usize, ) -> Option<usize>

Returns an alternate break boundary for Hyphens::Auto when a greedy break split lands in the middle of a word. Read more
Source§

fn measure_for_node( &self, node_id: Option<usize>, text: &AnnotatedString, style: &TextStyle, ) -> TextMetrics

Like TextMeasurer::measure for the text of node node_id, so that an implementation can keep a cache for each node. The default ignores the node.
Source§

fn measure_subsequence_for_node( &self, node_id: Option<usize>, text: &AnnotatedString, range: Range<usize>, style: &TextStyle, ) -> TextMetrics

Like TextMeasurer::measure_subsequence for the text of node node_id. The default ignores the node.
Source§

fn line_height_for_node( &self, node_id: Option<usize>, text: &AnnotatedString, style: &TextStyle, ) -> f32

Like TextMeasurer::line_height for the text of node node_id. The default ignores the node.
Source§

fn measure_with_options( &self, text: &AnnotatedString, style: &TextStyle, options: TextLayoutOptions, max_width: Option<f32>, ) -> TextMetrics

Measures text wrapped to max_width under options. None means no width limit. The default reads the metrics from prepare_with_options.
Source§

fn measure_with_options_for_node( &self, node_id: Option<usize>, text: &AnnotatedString, style: &TextStyle, options: TextLayoutOptions, max_width: Option<f32>, ) -> TextMetrics

Like TextMeasurer::measure_with_options for the text of node node_id.
Source§

fn prepare_with_options( &self, text: &AnnotatedString, style: &TextStyle, options: TextLayoutOptions, max_width: Option<f32>, ) -> PreparedTextLayout

Lays text out wrapped to max_width under options and returns the display text with its metrics. None means no width limit.
Source§

fn prepare_with_options_for_node( &self, node_id: Option<usize>, text: &Rc<AnnotatedString>, style: &Arc<TextStyle>, options: TextLayoutOptions, max_width: Option<f32>, ) -> PreparedTextLayout

Lays text out in style for a node that holds both: a layout that leaves them as they are shares them instead of copying them.
Source§

fn prepare_with_options_fallback( &self, text: &AnnotatedString, style: &TextStyle, options: TextLayoutOptions, max_width: Option<f32>, ) -> PreparedTextLayout

The layout built from the measuring methods of this trait, which is also the default of prepare_with_options. An implementation that overrides prepare_with_options can call it for the cases it does not handle.

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> 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.