Struct zng::font::ShapedSegment
source · pub struct ShapedSegment<'a> { /* private fields */ }
Expand description
Represents a word or space selection of a ShapedText
.
Implementations§
source§impl<'a> ShapedSegment<'a>
impl<'a> ShapedSegment<'a>
sourcepub fn kind(&self) -> TextSegmentKind
pub fn kind(&self) -> TextSegmentKind
Segment kind.
sourcepub fn direction(&self) -> LayoutDirection
pub fn direction(&self) -> LayoutDirection
Layout direction of glyphs in the segment.
sourcepub fn has_last_glyph(&self) -> bool
pub fn has_last_glyph(&self) -> bool
If the segment contains the last glyph of the line.
sourcepub fn glyphs(&self) -> impl Iterator<Item = (&'a Font, &'a [GlyphInstance])>
pub fn glyphs(&self) -> impl Iterator<Item = (&'a Font, &'a [GlyphInstance])>
Glyphs in the word or space.
The glyphs are in visual order (LTR) within segments, so the RTL text “لما” will yield “’á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, you can use the clusters
map to find the char for each glyph. Some font ligatures also bridge multiple segments, in this case only the first shaped
segment has glyphs the subsequent ones are empty.
sourcepub fn glyph(&self, index: usize) -> Option<(&'a Font, GlyphInstance)>
pub fn glyph(&self, index: usize) -> Option<(&'a Font, GlyphInstance)>
Gets the specific glyph and font.
sourcepub fn ligature_segs_count(&self) -> usize
pub fn ligature_segs_count(&self) -> usize
Number of next segments that are empty because their text is included in a ligature glyph or glyphs started in this segment.
sourcepub fn glyphs_with_x_advance(
&self,
) -> impl Iterator<Item = (&'a Font, impl Iterator<Item = (GlyphInstance, f32)> + 'a)> + 'a
pub fn glyphs_with_x_advance( &self, ) -> impl Iterator<Item = (&'a Font, impl Iterator<Item = (GlyphInstance, f32)> + 'a)> + 'a
Glyphs in the segment, paired with the x-advance.
Yields (Font, [(glyph, advance)])
.
sourcepub fn cluster_glyphs_with_x_advance(
&self,
) -> impl Iterator<Item = (&Font, impl Iterator<Item = (u32, &[GlyphInstance], f32)>)>
pub fn cluster_glyphs_with_x_advance( &self, ) -> impl Iterator<Item = (&Font, impl Iterator<Item = (u32, &[GlyphInstance], f32)>)>
Glyphs per cluster in the segment, paired with the x-advance of the cluster.
Yields (Font, [(cluster, [glyph], advance)])
.
sourcepub fn overflow_char_glyph(&self, max_width_px: f32) -> Option<(usize, usize)>
pub fn overflow_char_glyph(&self, max_width_px: f32) -> Option<(usize, usize)>
Gets the first char and glyph with advance that overflows max_width
.
sourcepub fn inline_info(&self) -> InlineSegmentInfo
pub fn inline_info(&self) -> InlineSegmentInfo
Segment info for widget inline segments.
sourcepub fn overline(&self) -> (Point2D<Px, Px>, Px)
pub fn overline(&self) -> (Point2D<Px, Px>, Px)
Overline spanning the word or spaces, start point + width.
sourcepub fn strikethrough(&self) -> (Point2D<Px, Px>, Px)
pub fn strikethrough(&self) -> (Point2D<Px, Px>, Px)
Strikethrough spanning the word or spaces, start point + width.
sourcepub fn underline(&self) -> (Point2D<Px, Px>, Px)
pub fn underline(&self) -> (Point2D<Px, Px>, Px)
Underline spanning the word or spaces, not skipping.
The y is defined by the font metrics.
Returns start point + width.
sourcepub fn underline_skip_glyphs(
&self,
thickness: Px,
) -> impl Iterator<Item = (Point2D<Px, Px>, Px)> + 'a
pub fn underline_skip_glyphs( &self, thickness: Px, ) -> impl Iterator<Item = (Point2D<Px, Px>, Px)> + 'a
Underline spanning the word or spaces, skipping glyph descends that intercept the line.
Returns an iterator of start point + width for underline segments.
sourcepub fn underline_descent(&self) -> (Point2D<Px, Px>, Px)
pub fn underline_descent(&self) -> (Point2D<Px, Px>, Px)
Underline spanning the word or spaces, not skipping.
The y is the baseline + descent + 1px.
Returns start point + width.
sourcepub fn text_range(&self) -> Range<usize>
pub fn text_range(&self) -> Range<usize>
Get the text bytes range of this segment in the original text.
sourcepub fn text_start(&self) -> usize
pub fn text_start(&self) -> usize
Get the text byte range start of this segment in the original text.
sourcepub fn text_end(&self) -> usize
pub fn text_end(&self) -> usize
Get the text byte range end of this segment in the original text.
sourcepub fn text_glyph_range(
&self,
glyph_range: impl RangeBounds<usize>,
) -> Range<usize>
pub fn text_glyph_range( &self, glyph_range: impl RangeBounds<usize>, ) -> Range<usize>
Get the text bytes range of the glyph_range
in this segment’s text
.
sourcepub fn text<'s>(&self, full_text: &'s str) -> &'s str
pub fn text<'s>(&self, full_text: &'s str) -> &'s str
Select the string represented by this segment.
The full_text
must be equal to the original text that was used to generate the parent ShapedText
.
sourcepub fn nearest_char_index(&self, x: Px, full_text: &str) -> usize
pub fn nearest_char_index(&self, x: Px, full_text: &str) -> usize
Gets the insert index in the segment text that is nearest to x
.
Trait Implementations§
source§impl<'a> Clone for ShapedSegment<'a>
impl<'a> Clone for ShapedSegment<'a>
source§fn clone(&self) -> ShapedSegment<'a>
fn clone(&self) -> ShapedSegment<'a>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<'a> Debug for ShapedSegment<'a>
impl<'a> Debug for ShapedSegment<'a>
impl<'a> Copy for ShapedSegment<'a>
Auto Trait Implementations§
impl<'a> Freeze for ShapedSegment<'a>
impl<'a> !RefUnwindSafe for ShapedSegment<'a>
impl<'a> Send for ShapedSegment<'a>
impl<'a> Sync for ShapedSegment<'a>
impl<'a> Unpin for ShapedSegment<'a>
impl<'a> !UnwindSafe for ShapedSegment<'a>
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> 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