pub struct TextLayoutEngine { /* private fields */ }Expand description
Breaks TextRun sequences into LineBoxes that fit within a given width.
Uses real glyph-advance metrics from FontRegistry (rustybuzz + ttf-parser).
Implementations§
Source§impl TextLayoutEngine
impl TextLayoutEngine
pub fn new(fonts: &FontRegistry, style: &DocumentStyle) -> Self
Sourcepub fn measure_text_mm(
&self,
fonts: &FontRegistry,
text: &str,
font_size: f64,
bold: bool,
italic: bool,
) -> f64
pub fn measure_text_mm( &self, fonts: &FontRegistry, text: &str, font_size: f64, bold: bool, italic: bool, ) -> f64
Measures the rendered width of text in mm using real glyph metrics.
Sourcepub fn default_family_name(&self) -> &str
pub fn default_family_name(&self) -> &str
Returns the default font family name used for measurement.
Sourcepub fn set_default_family(&mut self, name: impl Into<String>)
pub fn set_default_family(&mut self, name: impl Into<String>)
Overrides the default font family used for measurement.
Used by Paragraph to apply a per-paragraph font family.
Always restore with the previous value after the layout call.
Sourcepub fn line_height_mm(&self, fonts: &FontRegistry, font_size: f64) -> f64
pub fn line_height_mm(&self, fonts: &FontRegistry, font_size: f64) -> f64
Returns the line height in mm for font_size (pt).
Sourcepub fn layout_runs(
&self,
fonts: &FontRegistry,
runs: &[TextRun],
max_width_mm: f64,
alignment: TextAlign,
font_size: f64,
tab_stops: &[TabStop],
) -> LayoutResult
pub fn layout_runs( &self, fonts: &FontRegistry, runs: &[TextRun], max_width_mm: f64, alignment: TextAlign, font_size: f64, tab_stops: &[TabStop], ) -> LayoutResult
Lays out runs into LineBoxes fitting max_width_mm.
tab_stops controls how \t characters inside runs are handled.
Pass an empty slice when no tab stops are defined.
Sourcepub fn layout_plain(
&self,
fonts: &FontRegistry,
text: &str,
max_width_mm: f64,
alignment: TextAlign,
font_size: f64,
style: AppliedStyle,
) -> LayoutResult
pub fn layout_plain( &self, fonts: &FontRegistry, text: &str, max_width_mm: f64, alignment: TextAlign, font_size: f64, style: AppliedStyle, ) -> LayoutResult
Convenience wrapper: lay out a plain string with a uniform style.
Sourcepub fn layout_runs_with_mode(
&self,
fonts: &FontRegistry,
runs: &[TextRun],
max_width_mm: f64,
alignment: TextAlign,
font_size: f64,
tab_stops: &[TabStop],
mode: LineBreakingMode,
) -> LayoutResult
pub fn layout_runs_with_mode( &self, fonts: &FontRegistry, runs: &[TextRun], max_width_mm: f64, alignment: TextAlign, font_size: f64, tab_stops: &[TabStop], mode: LineBreakingMode, ) -> LayoutResult
Layout with explicit line-breaking mode.
When mode is LineBreakingMode::KnuthPlass and the optimal_wrap
feature is compiled, uses the Knuth-Plass algorithm for better paragraph
colour (inter-word spacing consistency). Falls back to greedy otherwise.
Sourcepub fn hyphenate_word(&self, word: &str) -> Vec<usize>
pub fn hyphenate_word(&self, word: &str) -> Vec<usize>
Returns hyphenation break points (byte indices) for a word.
Requires the hyphenation feature. Returns an empty Vec when the
feature is disabled or the word has fewer than 5 characters.
Auto Trait Implementations§
impl Freeze for TextLayoutEngine
impl RefUnwindSafe for TextLayoutEngine
impl Send for TextLayoutEngine
impl Sync for TextLayoutEngine
impl Unpin for TextLayoutEngine
impl UnsafeUnpin for TextLayoutEngine
impl UnwindSafe for TextLayoutEngine
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> 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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
Source§fn to_owned_obj(&self, data: FontData<'_>) -> U
fn to_owned_obj(&self, data: FontData<'_>) -> U
T, using the provided data to resolve any offsets.