TextLayout
struct · ferroui-base · v0.5.0
struct TextLayout
Represents a multi line text layout.
Members
newnew_with_paragraph_stylesfrom_utf16from_utf16_with_paragraph_stylesfrom_text_sourcefrom_text_source_with_paragraph_stylesshared_plainis_sharedline_heightmax_widthmax_heightmax_linesletter_spacingtext_linesline_originline_flow_directionheightextentbaselineoverhang_afteroverhang_leadingoverhang_trailingwidthwidth_including_trailing_whitespacewidth_holdis_truncated_by_heightis_truncated_by_max_lineshas_collapsed_linesholds_widthdrawbuild_geometrytry_build_geometryhit_test_text_positionhit_test_text_rangehit_test_pointget_line_index_from_character_indexdispose
new
fn new(text: &str, typeface: Typeface, options: TextLayoutOptions) -> Self
Initializes a new instance of the TextLayout class.
text— the text.typeface— the typeface.options— the remaining (optional) parameters.
new_with_paragraph_styles
fn new_with_paragraph_styles(text: &str, typeface: Typeface, options: TextLayoutOptions, styles: Option<TextParagraphStyles>) -> Self
Formats independent paragraphs without changing the existing options or constructor contract. Style ranges use UTF-16 positions, including a paragraph's terminator. Caret, range geometry and drawing share the same line origins, including first-line indentation and paragraph spacing.
from_utf16
fn from_utf16(text: ReadOnlyMemory<u16>, typeface: Typeface, options: TextLayoutOptions) -> Self
Initializes a new instance of the TextLayout class from UTF-16 text
(no transcoding).
from_utf16_with_paragraph_styles
fn from_utf16_with_paragraph_styles(text: ReadOnlyMemory<u16>, typeface: Typeface, options: TextLayoutOptions, styles: Option<TextParagraphStyles>) -> Self
UTF-16 variant of Self::new_with_paragraph_styles.
from_text_source
fn from_text_source(text_source: Rc<dyn ITextSource>, paragraph_properties: Rc<dyn TextParagraphProperties>, text_trimming: Option<Rc<dyn TextTrimming>>, max_width: f64, max_height: f64, max_lines: i32, text_run_cache: Option<Rc<TextRunCache>>) -> Self
Initializes a new instance of the TextLayout class.
text_source— the text source.paragraph_properties— the default text paragraph properties.text_trimming— the text trimming (upstream default:None).max_width— the maximum width (upstream default: positive infinity).max_height— the maximum height (upstream default: positive infinity).max_lines— the maximum number of text lines (upstream default: 0).text_run_cache— an optional cache for shaped text runs to avoid redundant shaping.
from_text_source_with_paragraph_styles
fn from_text_source_with_paragraph_styles(text_source: Rc<dyn ITextSource>, paragraph_properties: Rc<dyn TextParagraphProperties>, text_trimming: Option<Rc<dyn TextTrimming>>, max_width: f64, max_height: f64, max_lines: i32, text_run_cache: Option<Rc<TextRunCache>>, paragraph_styles: Option<TextParagraphStyles>) -> Self
Formats a custom text source with paragraph overrides. A style is chosen at each required line break, never at a soft wrap.
shared_plain
fn shared_plain(text: &str, text_source: impl FnOnce() -> Rc<dyn ITextSource>, paragraph_properties: &Rc<dyn TextParagraphProperties>, text_trimming: &Rc<dyn TextTrimming>, max_width: f64, max_height: f64, max_lines: i32, text_run_cache: Option<Rc<TextRunCache>>) -> Rc<Self>
The layout of the plain text text: one run of the default run properties of
paragraph_properties. A text that was laid out before with the same properties,
trimming and constraint gets the layout that was made then, which every asker holds
(a FerroUI addition, docs/porting/desktop-performance.md, section 9.29).
text_source is asked for the source when the layout has to be made; it gives exactly
text in runs of the default run properties. text_run_cache is used while the layout
is made.
The font manager of the thread keeps the layout, so dispose leaves
it alone (is_shared). A long text, a text with decorations or font
features and a paragraph with tab stops get a layout of their own, as
from_text_source makes it.
is_shared
fn is_shared(self: &Self) -> bool
Whether the font manager keeps this layout for the next use of its text
(shared_plain).
line_height
fn line_height(self: &Self) -> f64
Gets the height of each line of text.
A value of NaN (equivalent to an attribute value of "Auto") indicates that the line height is determined automatically from the current font characteristics. The default is NaN.
max_width
fn max_width(self: &Self) -> f64
Gets the maximum width.
max_height
fn max_height(self: &Self) -> f64
Gets the maximum height.
max_lines
fn max_lines(self: &Self) -> i32
Gets the maximum number of text lines.
letter_spacing
fn letter_spacing(self: &Self) -> f64
Gets the text spacing.
text_lines
fn text_lines(self: &Self) -> &[Rc<dyn TextLine>]
Gets the text lines.
line_origin
fn line_origin(self: &Self, index: usize) -> Point
The actual line origin used for drawing, hit testing and native carets.
line_flow_direction
fn line_flow_direction(self: &Self, index: usize) -> FlowDirection
The base flow direction of the paragraph containing this line.
height
fn height(self: &Self) -> f64
The distance from the top of the first line to the bottom of the last line.
extent
fn extent(self: &Self) -> f64
The distance from the topmost black pixel of the first line to the bottommost black pixel of the last line.
baseline
fn baseline(self: &Self) -> f64
The distance from the top of the first line to the baseline of the first line.
overhang_after
fn overhang_after(self: &Self) -> f64
The distance from the bottom of the last line to the extent bottom.
overhang_leading
fn overhang_leading(self: &Self) -> f64
The maximum distance from the leading black pixel to the leading alignment point of a line.
overhang_trailing
fn overhang_trailing(self: &Self) -> f64
The maximum distance from the trailing black pixel to the trailing alignment point of a line.
width
fn width(self: &Self) -> f64
The maximum advance width between the leading and trailing alignment points of a line, excluding the width of whitespace characters at the end of the line.
width_including_trailing_whitespace
fn width_including_trailing_whitespace(self: &Self) -> f64
The maximum advance width between the leading and trailing alignment points of a line, including the width of whitespace characters at the end of the line.
width_hold
fn width_hold(self: &Self) -> Option<(f64, f64)>
The range of maximum widths [low, high) over which a layout of the same text with the
same properties makes the same lines as this one, or None when it is not known (the
layout is then only known to hold at its own maximum width). An addition (FerroUI
deviation, desktop-performance.md section 9.12): a text block keeps its layout for any
width inside the range.
Wrapping is greedy: a line ends at the last break opportunity whose text (without the white space after it) fits the width. The lines stay the same while every line still fits, from the width of the widest line without its trailing white space (with it for the last line and a line that ends at a required break, which have no break after it), and while no line can take the first word of the next one, up to the width of a line with its trailing white space and that word. The range is known for left-to-right text that wraps without letter spacing, tabs or paragraph styles, and that left no line out for the maximum height (the same lines have the same height) or the line limit, whose lines are one shaped run each and end at break opportunities (no line was broken inside a word). Trimming and a line limit that changed nothing do not narrow it (section 9.27): a line is trimmed only when it does not fit the width or when lines after it are left out, and inside the range every line fits and the lines, so their count, are the same.
is_truncated_by_height
fn is_truncated_by_height(self: &Self) -> bool
Whether lines of the text were left out because they did not fit the maximum height. An addition: a layout that left nothing out has the lines a layout with a larger maximum height has (desktop-performance.md section 9.12).
is_truncated_by_max_lines
fn is_truncated_by_max_lines(self: &Self) -> bool
Whether lines with text were left out because of the line limit. An addition: a layout that left nothing out is the layout without a line limit (desktop-performance.md section 9.27).
has_collapsed_lines
fn has_collapsed_lines(self: &Self) -> bool
Whether a line was collapsed: trimmed because it did not fit the width, or because lines after it were left out. An addition: a layout without one is the layout without trimming (desktop-performance.md section 9.27).
holds_width
fn holds_width(self: &Self, width: f64) -> bool
Whether width is inside TextLayout::width_hold. Stops at the first line that shows
it is not, without computing the whole hold.
draw
fn draw(self: &Self, context: &mut dyn ITextDrawingSink, origin: Point)
Draws the text layout.
context— the drawing context.origin— the origin.
build_geometry
fn build_geometry(self: &Self, origin: Point) -> crate::Ref<crate::media::Geometry>
Obtains the scalable contours of this already shaped layout at origin.
The geometry follows the same line positions, bidi ordering, style runs,
letter spacing and decoration strokes as Self::draw, without shaping
or measuring the text again. An empty layout produces an empty geometry.
Glyph paints are not retained; callers can fill or stroke the returned
geometry. Bitmap-only glyphs contribute no contours, and colour glyphs
contribute only outlines exposed by the platform glyph-run contract.
try_build_geometry
fn try_build_geometry(self: &Self, origin: Point) -> Option<crate::Ref<crate::media::Geometry>>
Obtains all contours at origin without accepting a partial glyph
outline. Positions and decorations are the same as build_geometry.
Returns None when the platform cannot verify completeness or any run
contains bitmap or colour-font glyphs. Glyph paints are not represented
by geometry; callers must preserve or validate those separately before
replacing text with a path. An empty layout succeeds with empty geometry.
hit_test_text_position
fn hit_test_text_position(self: &Self, text_position: i32) -> Rect
Get the pixel location relative to the top-left of the layout box given the text position.
text_position— the text position.
hit_test_text_range
fn hit_test_text_range(self: &Self, start: i32, length: i32) -> Vec<Rect>
Gets the bounding rectangles of a range of text, relative to the top-left of the layout box.
hit_test_point
fn hit_test_point(self: &Self, point: Point) -> TextHitTestResult
Gets the character hit of a point relative to the top-left of the layout box.
get_line_index_from_character_index
fn get_line_index_from_character_index(self: &Self, char_index: i32, trailing_edge: bool) -> i32
Gets the index of the line that contains a character index.
dispose
fn dispose(self: &Self)
Releases the text lines. A layout its font manager keeps
(is_shared) is released by the font manager, when nothing holds it
any more.
Trait implementations
SendSyncFreezeUnsafeUnpinUnpinUnwindSafeRefUnwindSafeClassDefaultsBorrow<T>BorrowMut<T>Into<U>From<T>TryInto<U>TryFrom<U>AnyErasedDestructorIntoEither
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.