Package com.mta.tehreer.layout
Class Typesetter
java.lang.Object
com.mta.tehreer.layout.Typesetter
Represents a typesetter which performs text layout. It can be used to create lines, perform line
breaking, and do other contextual analysis based on the characters in the string.
-
Constructor Summary
ConstructorDescriptionTypesetter
(Spanned spanned) Constructs the typesetter object using a spanned text.Typesetter
(Spanned spanned, List<Object> defaultSpans) Typesetter
(String text, Typeface typeface, float typeSize) Constructs the typesetter object using given text, typeface and type size. -
Method Summary
Modifier and TypeMethodDescriptioncreateFrame
(int charStart, int charEnd, RectF frameRect, TextAlignment textAlignment) Creates a frame full of lines in the rectangle provided by theframeRect
parameter.createJustifiedLine
(int charStart, int charEnd, float justificationFactor, float justificationWidth) Creates a justified line of specified string range.createSimpleLine
(int charStart, int charEnd) Creates a simple line of specified string range.createTruncatedLine
(int charStart, int charEnd, float maxWidth, BreakMode breakMode, TruncationPlace truncationPlace) Creates a line of specified string range, truncating it with ellipsis character (U+2026) or three dots if it overflows the max width.createTruncatedLine
(int charStart, int charEnd, float maxWidth, BreakMode breakMode, TruncationPlace truncationPlace, ComposedLine truncationToken) Creates a line of specified string range, truncating it if it overflows the max width.createTruncatedLine
(int charStart, int charEnd, float maxWidth, BreakMode breakMode, TruncationPlace truncationPlace, String truncationToken) Creates a line of specified string range, truncating it if it overflows the max width.Returns the spanned source text for which this typesetter object was created.int
suggestBackwardBreak
(int charStart, int charEnd, float breakExtent, BreakMode breakMode) Suggests a backward break index based on the provided range and width.int
suggestForwardBreak
(int charStart, int charEnd, float breakExtent, BreakMode breakMode) Suggests a forward break index based on the provided range and width.
-
Constructor Details
-
Typesetter
Constructs the typesetter object using given text, typeface and type size.- Parameters:
text
- The text to typeset.typeface
- The typeface to use.typeSize
- The type size to apply.- Throws:
IllegalArgumentException
- iftext
is empty.
-
Typesetter
Constructs the typesetter object using a spanned text.- Parameters:
spanned
- The spanned text to typeset.- Throws:
IllegalArgumentException
- ifspanned
is empty.
-
Typesetter
-
-
Method Details
-
getSpanned
Returns the spanned source text for which this typesetter object was created.- Returns:
- The spanned source text for which this typesetter object was created.
-
suggestForwardBreak
public int suggestForwardBreak(int charStart, int charEnd, float breakExtent, @NonNull BreakMode breakMode) Suggests a forward break index based on the provided range and width. The measurement proceeds from first character to last character. If there is still room after measuring all characters, then last index is returned. Otherwise, break index is returned.- Parameters:
charStart
- The index to the first character (inclusive) for break calculations.charEnd
- The index to the last character (exclusive) for break calculations.breakExtent
- The requested break extent.breakMode
- The requested break mode.- Returns:
- The index (exclusive) that would cause the break.
- Throws:
IllegalArgumentException
- ifcharStart
is negative, orcharEnd
is greater than the length of source text, orcharStart
is greater than or equal tocharEnd
-
suggestBackwardBreak
public int suggestBackwardBreak(int charStart, int charEnd, float breakExtent, @NonNull BreakMode breakMode) Suggests a backward break index based on the provided range and width. The measurement proceeds from last character to first character. If there is still room after measuring all characters, then first index is returned. Otherwise, break index is returned.- Parameters:
charStart
- The index to the first character (inclusive) for break calculations.charEnd
- The index to the last character (exclusive) for break calculations.breakExtent
- The requested break extent.breakMode
- The requested break mode.- Returns:
- The index (inclusive) that would cause the break.
- Throws:
IllegalArgumentException
- ifcharStart
is negative, orcharEnd
is greater than the length of source text, orcharStart
is greater than or equal tocharEnd
-
createSimpleLine
Creates a simple line of specified string range.- Parameters:
charStart
- The index to first character of the line in source text.charEnd
- The index after the last character of the line in source text.- Returns:
- The new line object.
- Throws:
IllegalArgumentException
- ifcharStart
is negative, orcharEnd
is greater than the length of source text, orcharStart
is greater than or equal tocharEnd
-
createTruncatedLine
@NonNull public ComposedLine createTruncatedLine(int charStart, int charEnd, float maxWidth, @NonNull BreakMode breakMode, @NonNull TruncationPlace truncationPlace) Creates a line of specified string range, truncating it with ellipsis character (U+2026) or three dots if it overflows the max width.- Parameters:
charStart
- The index to first character of the line in source text.charEnd
- The index after the last character of the line in source text.maxWidth
- The width at which truncation will begin.breakMode
- The truncation mode to be used on the line.truncationPlace
- The place of truncation for the line.- Returns:
- The new line which is truncated if it overflows the
maxWidth
. - Throws:
IllegalArgumentException
- if any of the following is true:charStart
is negativecharEnd
is greater than the length of source textcharStart
is greater than or equal tocharEnd
-
createTruncatedLine
@NonNull public ComposedLine createTruncatedLine(int charStart, int charEnd, float maxWidth, @NonNull BreakMode breakMode, @NonNull TruncationPlace truncationPlace, @NonNull String truncationToken) Creates a line of specified string range, truncating it if it overflows the max width.- Parameters:
charStart
- The index to first character of the line in source text.charEnd
- The index after the last character of the line in source text.maxWidth
- The width at which truncation will begin.breakMode
- The truncation mode to be used on the line.truncationPlace
- The place of truncation for the line.truncationToken
- The token to indicate the line truncation.- Returns:
- The new line which is truncated if it overflows the
maxWidth
. - Throws:
IllegalArgumentException
- if any of the following is true:charStart
is negativecharEnd
is greater than the length of source textcharStart
is greater than or equal tocharEnd
-
createTruncatedLine
@NonNull public ComposedLine createTruncatedLine(int charStart, int charEnd, float maxWidth, @NonNull BreakMode breakMode, @NonNull TruncationPlace truncationPlace, @NonNull ComposedLine truncationToken) Creates a line of specified string range, truncating it if it overflows the max width.- Parameters:
charStart
- The index to first character of the line in source text.charEnd
- The index after the last character of the line in source text.maxWidth
- The width at which truncation will begin.breakMode
- The truncation mode to be used on the line.truncationPlace
- The place of truncation for the line.truncationToken
- The token to indicate the line truncation.- Returns:
- The new line which is truncated if it overflows the
maxWidth
. - Throws:
IllegalArgumentException
- if any of the following is true:charStart
is negativecharEnd
is greater than the length of source textcharStart
is greater than or equal tocharEnd
-
createJustifiedLine
@NonNull public ComposedLine createJustifiedLine(int charStart, int charEnd, float justificationFactor, float justificationWidth) Creates a justified line of specified string range.- Parameters:
charStart
- The index to first character of the line in source text.charEnd
- The index after the last character of the line in source text.justificationFactor
- The factor that specifies the full or partial justification. When set to 1.0 or greater, full justification is performed. If this parameter is set to less than 1.0, varying degrees of partial justification are performed. If it is set to 0 or less, no justification is performed.justificationWidth
- The width at which the line should be justified. If it is less than the actual width of the line, then negative justification is performed (that is, words are squeezed together).- Returns:
- The new justified line.
-
createFrame
@NonNull public ComposedFrame createFrame(int charStart, int charEnd, @NonNull RectF frameRect, @NonNull TextAlignment textAlignment) Creates a frame full of lines in the rectangle provided by theframeRect
parameter. The typesetter will continue to fill the frame until it either runs out of text or it finds that text no longer fits.- Parameters:
charStart
- The index to first character of the frame in source text.charEnd
- The index after the last character of the frame in source text.frameRect
- The rectangle specifying the frame to fill.textAlignment
- The horizontal text alignment of the lines in frame.- Returns:
- The new frame object.
-