zng_ext_font

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

source

pub fn kind(&self) -> TextSegmentKind

Segment kind.

source

pub fn level(&self) -> BidiLevel

Segment bidi level.

source

pub fn direction(&self) -> LayoutDirection

Layout direction of glyphs in the segment.

source

pub fn has_last_glyph(&self) -> bool

If the segment contains the last glyph of the line.

source

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.

source

pub fn glyph(&self, index: usize) -> Option<(&'a Font, GlyphInstance)>

Gets the specific glyph and font.

source

pub fn clusters(&self) -> &[u32]

Map glyph -> char.

Each glyphs glyph pairs with an entry in this slice that is the char byte index in text. If a font ligature bridges multiple segments only the first segment will have a non-empty map.

source

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.

source

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

source

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

source

pub fn x_width(&self) -> (Px, Px)

Gets the segment x offset and advance.

source

pub fn advance(&self) -> f32

Segment exact width in pixels.

source

pub fn rect(&self) -> PxRect

Bounds of the word or spaces.

source

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.

source

pub fn inline_info(&self) -> InlineSegmentInfo

Segment info for widget inline segments.

source

pub fn overline(&self) -> (PxPoint, Px)

Overline spanning the word or spaces, start point + width.

source

pub fn strikethrough(&self) -> (PxPoint, Px)

Strikethrough spanning the word or spaces, start point + width.

source

pub fn underline(&self) -> (PxPoint, Px)

Underline spanning the word or spaces, not skipping.

The y is defined by the font metrics.

Returns start point + width.

source

pub fn underline_skip_glyphs( &self, thickness: Px, ) -> impl Iterator<Item = (PxPoint, 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.

source

pub fn underline_descent(&self) -> (PxPoint, Px)

Underline spanning the word or spaces, not skipping.

The y is the baseline + descent + 1px.

Returns start point + width.

source

pub fn text_range(&self) -> Range<usize>

Get the text bytes range of this segment in the original text.

source

pub fn text_start(&self) -> usize

Get the text byte range start of this segment in the original text.

source

pub fn text_end(&self) -> usize

Get the text byte range end of this segment in the original text.

source

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.

source

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.

source

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.

source

pub fn index(&self) -> usize

Gets the segment index in the line.

Trait Implementations§

source§

impl<'a> Clone for ShapedSegment<'a>

source§

fn clone(&self) -> ShapedSegment<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ShapedSegment<'_>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

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> 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> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> FsChangeNote for T
where T: Debug + Any + Send + Sync,

source§

fn as_any(&self) -> &(dyn Any + 'static)

Access any.
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

source§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T

source§

impl<T> StateValue for T
where T: Any + Send + Sync,