Struct zng::font::ShapedText

source ·
pub struct ShapedText { /* private fields */ }
Expand description

Output of text layout.

Implementations§

source§

impl ShapedText

source

pub fn new(font: &Font) -> ShapedText

New empty text.

source

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.

source

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.

source

pub fn has_colored_glyphs(&self) -> bool

If the shaped text has any Emoji glyph associated with a font that has color palettes.

source

pub fn has_images(&self) -> bool

If the shaped text has any Emoji glyph associated with a pixel image.

source

pub fn colored_glyphs( &self, ) -> impl Iterator<Item = (&Font, ShapedColoredGlyphs<'_>)>

Glyphs by font and palette color.

source

pub fn colored_glyphs_slice( &self, range: impl RangeBounds<usize>, ) -> impl Iterator<Item = (&Font, ShapedColoredGlyphs<'_>)>

Glyphs in a range by font and palette color.

source

pub fn image_glyphs( &self, ) -> impl Iterator<Item = (&Font, ShapedImageGlyphs<'_>)>

Glyphs by font and associated image.

source

pub fn image_glyphs_slice( &self, range: impl RangeBounds<usize>, ) -> impl Iterator<Item = (&Font, ShapedImageGlyphs<'_>)>

Glyphs in a range by font and associated image.

source

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.

source

pub fn block_size(&self) -> Size2D<Px, Px>

Size of the text, if it is not inlined.

source

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.

source

pub fn mid_size(&self) -> Size2D<Px, Px>

Bounding box of the mid-lines, that is the lines except the first and last.

source

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.

source

pub fn align(&self) -> Align

Last applied alignment.

If the text is inlined only the mid-lines are aligned, and only horizontally.

source

pub fn overflow_align(&self) -> Align

Last applied overflow alignment.

Only used in dimensions of the text that overflow align_size.

source

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.

source

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.

source

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.

source

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.

source

pub fn clear_reshape(&mut self)

Restore text to initial shape.

source

pub fn line_height(&self) -> Px

Height of a single line.

source

pub fn line_spacing(&self) -> Px

Vertical spacing in between lines.

source

pub fn baseline(&self) -> Px

Vertical offset from the line bottom up that is the text baseline.

The line bottom is the line_height.

source

pub fn overline(&self) -> Px

Vertical offset from the line bottom up that is the overline placement.

source

pub fn strikethrough(&self) -> Px

Vertical offset from the line bottom up that is the strikethrough placement.

source

pub fn underline(&self) -> Px

Vertical offset from the line bottom up that is the font defined underline placement.

source

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.

source

pub fn is_empty(&self) -> bool

No segments.

source

pub fn lines(&self) -> impl Iterator<Item = ShapedLine<'_>>

Iterate over ShapedLine selections split by LineBreak or wrap.

source

pub fn lines_len(&self) -> usize

Returns the number of text lines.

source

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.

source

pub fn line(&self, line_idx: usize) -> Option<ShapedLine<'_>>

Gets the line by index.

source

pub fn empty(&self) -> ShapedText

Create an empty ShapedText with the same metrics as self.

source

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.

source

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.

source

pub fn nearest_line(&self, y: Px) -> Option<ShapedLine<'_>>

Gets the line that contains the y offset or is nearest to it.

source

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.

source

pub fn overflow_info( &self, max_size: Size2D<Px, Px>, overflow_suffix_width: Px, ) -> Option<TextOverflowInfo>

Gets a full overflow analysis.

source

pub fn highlight_rects( &self, range: Range<CaretIndex>, full_txt: &str, ) -> impl Iterator<Item = Rect<Px, Px>>

Rectangles of the text selected by range.

source

pub fn clip_lines( &self, clip_range: Range<CaretIndex>, clip_out: bool, txt: &str, lines: impl Iterator<Item = (Point2D<Px, Px>, Px)>, ) -> Vec<(Point2D<Px, Px>, Px)>

Clip under/overline to a text clip_range area, if clip_out only lines outside the range are visible.

Trait Implementations§

source§

impl Clone for ShapedText

source§

fn clone(&self) -> ShapedText

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 ShapedText

source§

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

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

impl PartialEq for ShapedText

source§

fn eq(&self, other: &ShapedText) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl StructuralPartialEq for ShapedText

Auto Trait Implementations§

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
§

impl<T> AnyEq for T
where T: Any + PartialEq,

§

fn equals(&self, other: &(dyn Any + 'static)) -> bool

§

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

source§

impl<T> AnyVarValue for T
where T: VarValue,

source§

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

Access to dyn Any methods.
source§

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

Access to mut dyn Any methods.
source§

fn clone_boxed(&self) -> Box<dyn AnyVarValue>

Clone the value.
source§

fn clone_boxed_var(&self) -> Box<dyn AnyVar>

Clone the value into a new boxed LocalVar<Self>.
source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Access to Box<dyn Any> methods.
source§

fn eq_any(&self, other: &(dyn AnyVarValue + 'static)) -> bool

Gets if self equals other.
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
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

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

Convert 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)

Convert &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)

Convert &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
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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> Instrument for T

source§

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

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

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

impl<T> IntoVar<T> for T
where T: VarValue,

source§

type Var = LocalVar<T>

Variable type that will wrap the T value. Read more
source§

fn into_var(self) -> <T as IntoVar<T>>::Var

Converts the source value into a var.
source§

fn into_boxed_var(self) -> Box<dyn VarBoxed<T>>
where Self: Sized,

Converts into BoxedVar<T>. 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<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

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

impl<T> WithSubscriber for T

source§

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

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,

source§

impl<T> IntoValue<T> for T
where T: VarValue,

§

impl<T> MaybeSendSync for T

source§

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

source§

impl<T> VarValue for T
where T: Debug + Clone + PartialEq + Any + Send + Sync,