Struct zng::font::ShapedText
source · pub struct ShapedText { /* private fields */ }
Expand description
Output of text layout.
Implementations§
source§impl ShapedText
impl ShapedText
sourcepub fn new(font: &Font) -> ShapedText
pub fn new(font: &Font) -> ShapedText
New empty text.
sourcepub fn glyphs(&self) -> impl Iterator<Item = (&Font, &[GlyphInstance])>
pub fn glyphs(&self) -> impl Iterator<Item = (&Font, &[GlyphInstance])>
Glyphs by font.
The glyphs are in text order by segments and in visual order (LTR) within segments, so the RTL text “لما “ will have the space glyph first, then “’álif”, “miim”, “láam”.
All glyph points are set as offsets to the top-left of the text full text.
Note that multiple glyphs can map to the same char and multiple chars can map to the same glyph.
sourcepub fn glyphs_slice(
&self,
range: impl RangeBounds<usize>,
) -> impl Iterator<Item = (&Font, &[GlyphInstance])>
pub fn glyphs_slice( &self, range: impl RangeBounds<usize>, ) -> impl Iterator<Item = (&Font, &[GlyphInstance])>
Glyphs in a range by font.
Similar output to glyphs
, but only glyphs in the range
.
sourcepub fn has_colored_glyphs(&self) -> bool
pub fn has_colored_glyphs(&self) -> bool
If the shaped text has any Emoji glyph associated with a font that has color palettes.
sourcepub fn has_images(&self) -> bool
pub fn has_images(&self) -> bool
If the shaped text has any Emoji glyph associated with a pixel image.
sourcepub fn colored_glyphs(
&self,
) -> impl Iterator<Item = (&Font, ShapedColoredGlyphs<'_>)>
pub fn colored_glyphs( &self, ) -> impl Iterator<Item = (&Font, ShapedColoredGlyphs<'_>)>
Glyphs by font and palette color.
sourcepub fn colored_glyphs_slice(
&self,
range: impl RangeBounds<usize>,
) -> impl Iterator<Item = (&Font, ShapedColoredGlyphs<'_>)>
pub fn colored_glyphs_slice( &self, range: impl RangeBounds<usize>, ) -> impl Iterator<Item = (&Font, ShapedColoredGlyphs<'_>)>
Glyphs in a range by font and palette color.
sourcepub fn image_glyphs(
&self,
) -> impl Iterator<Item = (&Font, ShapedImageGlyphs<'_>)>
pub fn image_glyphs( &self, ) -> impl Iterator<Item = (&Font, ShapedImageGlyphs<'_>)>
Glyphs by font and associated image.
sourcepub fn image_glyphs_slice(
&self,
range: impl RangeBounds<usize>,
) -> impl Iterator<Item = (&Font, ShapedImageGlyphs<'_>)>
pub fn image_glyphs_slice( &self, range: impl RangeBounds<usize>, ) -> impl Iterator<Item = (&Font, ShapedImageGlyphs<'_>)>
Glyphs in a range by font and associated image.
sourcepub fn size(&self) -> Size2D<Px, Px>
pub fn size(&self) -> Size2D<Px, Px>
Bounding box size, the width is the longest line or the first or last line width + absolute offset, the height is the bottom-most point of the last line.
sourcepub fn block_size(&self) -> Size2D<Px, Px>
pub fn block_size(&self) -> Size2D<Px, Px>
Size of the text, if it is not inlined.
sourcepub fn overflow_line(&self, max_height: Px) -> Option<ShapedLine<'_>>
pub fn overflow_line(&self, max_height: Px) -> Option<ShapedLine<'_>>
Gets the first line that overflows the max_height
. A line overflows when the line PxRect::max_y
is greater than max_height
.
sourcepub fn mid_size(&self) -> Size2D<Px, Px>
pub fn mid_size(&self) -> Size2D<Px, Px>
Bounding box of the mid-lines, that is the lines except the first and last.
sourcepub fn is_inlined(&self) -> bool
pub fn is_inlined(&self) -> bool
If the text first and last lines is defined externally by the inline layout.
When this is true
the shaped text only defines aligns horizontally and only the mid-lines. The vertical
offset is defined by the first line rectangle plus the mid_clear
.
sourcepub fn align(&self) -> Align
pub fn align(&self) -> Align
Last applied alignment.
If the text is inlined only the mid-lines are aligned, and only horizontally.
sourcepub fn overflow_align(&self) -> Align
pub fn overflow_align(&self) -> Align
Last applied overflow alignment.
Only used in dimensions of the text that overflow align_size
.
sourcepub fn align_size(&self) -> Size2D<Px, Px>
pub fn align_size(&self) -> Size2D<Px, Px>
Last applied alignment area.
The lines are aligned inside this size. If the text is inlined only the mid-lines are aligned and only horizontally.
sourcepub fn direction(&self) -> LayoutDirection
pub fn direction(&self) -> LayoutDirection
Last applied alignment direction.
Note that the glyph and word directions is defined by the TextShapingArgs::lang
and the computed
direction is in ShapedSegment::direction
.
sourcepub fn mid_clear(&self) -> Px
pub fn mid_clear(&self) -> Px
Last applied extra spacing between the first and second lines to clear the full width of the second line in the parent inline layout.
sourcepub fn reshape_lines(
&mut self,
constraints: PxConstraints2d,
inline_constraints: Option<InlineConstraintsLayout>,
align: Align,
overflow_align: Align,
line_height: Px,
line_spacing: Px,
direction: LayoutDirection,
)
pub fn reshape_lines( &mut self, constraints: PxConstraints2d, inline_constraints: Option<InlineConstraintsLayout>, align: Align, overflow_align: Align, line_height: Px, line_spacing: Px, direction: LayoutDirection, )
Reshape text lines.
Reshape text lines without re-wrapping, this is more efficient then fully reshaping every glyph, but may cause overflow if called with constraints incompatible with the ones used during the full text shaping.
The general process of shaping text is to generate a shaped-text without align during measure, and then reuse this shaped text every layout that does not invalidate any property that affects the text wrap.
sourcepub fn clear_reshape(&mut self)
pub fn clear_reshape(&mut self)
Restore text to initial shape.
sourcepub fn line_height(&self) -> Px
pub fn line_height(&self) -> Px
Height of a single line.
sourcepub fn line_spacing(&self) -> Px
pub fn line_spacing(&self) -> Px
Vertical spacing in between lines.
sourcepub fn baseline(&self) -> Px
pub fn baseline(&self) -> Px
Vertical offset from the line bottom up that is the text baseline.
The line bottom is the line_height
.
sourcepub fn overline(&self) -> Px
pub fn overline(&self) -> Px
Vertical offset from the line bottom up that is the overline placement.
sourcepub fn strikethrough(&self) -> Px
pub fn strikethrough(&self) -> Px
Vertical offset from the line bottom up that is the strikethrough placement.
sourcepub fn underline(&self) -> Px
pub fn underline(&self) -> Px
Vertical offset from the line bottom up that is the font defined underline placement.
sourcepub fn underline_descent(&self) -> Px
pub fn underline_descent(&self) -> Px
Vertical offset from the line bottom up that is the underline placement when the option for clearing all glyph descents is selected.
sourcepub fn lines(&self) -> impl Iterator<Item = ShapedLine<'_>>
pub fn lines(&self) -> impl Iterator<Item = ShapedLine<'_>>
Iterate over ShapedLine
selections split by LineBreak
or wrap.
sourcepub fn first_wrapped(&self) -> bool
pub fn first_wrapped(&self) -> bool
If the first line starts in a new inline row because it could not fit in the leftover inline space.
sourcepub fn line(&self, line_idx: usize) -> Option<ShapedLine<'_>>
pub fn line(&self, line_idx: usize) -> Option<ShapedLine<'_>>
Gets the line by index.
sourcepub fn empty(&self) -> ShapedText
pub fn empty(&self) -> ShapedText
Create an empty ShapedText
with the same metrics as self
.
sourcepub fn can_rewrap(&self, max_width: Px) -> bool
pub fn can_rewrap(&self, max_width: Px) -> bool
Check if any line can be better wrapped given the new wrap config.
Note that a new ShapedText
must be generated to rewrap.
sourcepub fn caret_origin(
&self,
caret: CaretIndex,
full_text: &str,
) -> Point2D<Px, Px>
pub fn caret_origin( &self, caret: CaretIndex, full_text: &str, ) -> Point2D<Px, Px>
Gets the top-middle origin for a caret visual that marks the insert index
in the string.
sourcepub fn nearest_line(&self, y: Px) -> Option<ShapedLine<'_>>
pub fn nearest_line(&self, y: Px) -> Option<ShapedLine<'_>>
Gets the line that contains the y
offset or is nearest to it.
sourcepub fn snap_caret_line(&self, caret: CaretIndex) -> CaretIndex
pub fn snap_caret_line(&self, caret: CaretIndex) -> CaretIndex
Changes the caret line if the current line cannot contain the current char byte index.
This retains the same line at ambiguous points at the end/start of wrapped lines.
sourcepub fn overflow_info(
&self,
max_size: Size2D<Px, Px>,
overflow_suffix_width: Px,
) -> Option<TextOverflowInfo>
pub fn overflow_info( &self, max_size: Size2D<Px, Px>, overflow_suffix_width: Px, ) -> Option<TextOverflowInfo>
Gets a full overflow analysis.
sourcepub fn highlight_rects(
&self,
range: Range<CaretIndex>,
full_txt: &str,
) -> impl Iterator<Item = Rect<Px, Px>>
pub fn highlight_rects( &self, range: Range<CaretIndex>, full_txt: &str, ) -> impl Iterator<Item = Rect<Px, Px>>
Rectangles of the text selected by range
.
Trait Implementations§
source§impl Clone for ShapedText
impl Clone for ShapedText
source§fn clone(&self) -> ShapedText
fn clone(&self) -> ShapedText
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for ShapedText
impl Debug for ShapedText
source§impl PartialEq for ShapedText
impl PartialEq for ShapedText
impl StructuralPartialEq for ShapedText
Auto Trait Implementations§
impl Freeze for ShapedText
impl !RefUnwindSafe for ShapedText
impl Send for ShapedText
impl Sync for ShapedText
impl Unpin for ShapedText
impl !UnwindSafe for ShapedText
Blanket Implementations§
§impl<T> AnyEq for T
impl<T> AnyEq for T
source§impl<T> AnyVarValue for Twhere
T: VarValue,
impl<T> AnyVarValue for Twhere
T: VarValue,
source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
dyn Any
methods.source§fn clone_boxed(&self) -> Box<dyn AnyVarValue>
fn clone_boxed(&self) -> Box<dyn AnyVarValue>
source§fn clone_boxed_var(&self) -> Box<dyn AnyVar>
fn clone_boxed_var(&self) -> Box<dyn AnyVar>
LocalVar<Self>
.source§fn eq_any(&self, other: &(dyn AnyVarValue + 'static)) -> bool
fn eq_any(&self, other: &(dyn AnyVarValue + 'static)) -> bool
self
equals other
.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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
source§impl<T> FsChangeNote for T
impl<T> FsChangeNote for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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