Class MeasuredText.Builder
- Enclosing class:
MeasuredText
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addReplacementRun
(Locale locale, int length, float width) void
addStyleRun
(FontPaint paint, LineBreakConfig lineBreakConfig, int length, boolean isRtl) appendReplacementRun
(TextPaint paint, int length, float width) Used to inform the text layout that the given length is replaced with the object of given width.appendStyleRun
(TextPaint paint, int length, boolean isRtl) Apply styles to the given length.appendStyleRun
(TextPaint paint, LineBreakConfig lineBreakConfig, int length, boolean isRtl) Apply styles to the given length.build()
Starts laying-out the text and creates a MeasuredText for the result.setComputeLayout
(boolean computeLayout) By passing true to this method, the build method will compute all full layout information.
-
Constructor Details
-
Builder
Construct a builder.The MeasuredText returned by build method will hold a reference of the text, then the char array must be immutable.
- Parameters:
text
- a text, with full range, can be empty
-
-
Method Details
-
appendStyleRun
@NonNull public MeasuredText.Builder appendStyleRun(@NonNull TextPaint paint, @IntRange(from=0L) int length, boolean isRtl) Apply styles to the given length.Keeps an internal offset which increases at every append. The initial value for this offset is zero. After the style is applied the internal offset is moved to
offset + length
, and next call will start from this new position.- Parameters:
paint
- a paintlength
- a length to be applied with a given paint, can not exceed the length of the textisRtl
- true if the text is in RTL context, otherwise false.
-
appendStyleRun
@NonNull public MeasuredText.Builder appendStyleRun(@NonNull TextPaint paint, @Nullable LineBreakConfig lineBreakConfig, @IntRange(from=0L) int length, boolean isRtl) Apply styles to the given length.Keeps an internal offset which increases at every append. The initial value for this offset is zero. After the style is applied the internal offset is moved to
offset + length
, and next call will start from this new position.- Parameters:
paint
- a paintlineBreakConfig
- a line break configuration.length
- a length to be applied with a given paint, can not exceed the length of the textisRtl
- true if the text is in RTL context, otherwise false.
-
addStyleRun
-
appendReplacementRun
@NonNull public MeasuredText.Builder appendReplacementRun(@NonNull TextPaint paint, @IntRange(from=0L) int length, @FloatRange(from=0.0) float width) Used to inform the text layout that the given length is replaced with the object of given width.Keeps an internal offset which increases at every append. The initial value for this offset is zero. After the style is applied the internal offset is moved to
offset + length
, and next call will start from this new position.Informs the layout engine that the given length should not be processed, instead the provided width should be used for calculating the width of that range.
- Parameters:
paint
- a paintlength
- a length to be replaced with the object, can not exceed the length of the textwidth
- a replacement width of the range in pixels
-
addReplacementRun
-
setComputeLayout
By passing true to this method, the build method will compute all full layout information.- Parameters:
computeLayout
- true if you want to retrieve full layout info, e.g. glyphs bounds
-
build
Starts laying-out the text and creates a MeasuredText for the result.Once you called this method, you can't touch this Builder again.
- Returns:
- text measurement result
-