Class ShapedText
TextShaper.shapeText(java.lang.CharSequence, int, int, icyllis.modernui.text.TextDirectionHeuristic, icyllis.modernui.text.TextPaint, icyllis.modernui.text.TextShaper.GlyphsConsumer)
, or directly
calling the constructor if no text direction heuristic algorithm is needed.
Text shaping is the process of translating a string of character codes (such as Unicode codepoints) into a properly arranged sequence of glyphs that can be rendered onto a screen or into final output form for inclusion in a document. See HarfBuzz for more.
This object is immutable, internal buffers may be shared between threads.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
BiDi flags that indicating that the base direction depends on the first strong directional character in the text according to the Unicode Bidirectional Algorithm.static final int
BiDi flags that indicating that the base direction depends on the first strong directional character in the text according to the Unicode Bidirectional Algorithm.static final int
BiDi flags that indicating base direction is left-to-right.static final int
BiDi flags that indicating the whole text direction is determined to be left-to-right, no BiDi analysis will be performed.static final int
BiDi flags that indicating the whole text direction is determined to be right-to-left, no BiDi analysis will be performed.static final int
BiDi flags that indicating base direction is right-to-left. -
Constructor Summary
ConstructorsConstructorDescriptionShapedText
(char[] text, int contextStart, int contextLimit, int start, int limit, int bidiFlags, FontPaint paint) Generate the shaped text layout. -
Method Summary
Modifier and TypeMethodDescriptionfloat
Returns the total amount of advance consumed by this layout.int
Effective ascent value of this layout.int
Effective descent value of this layout.getFont
(int i) Returns which font should be used for the i-th glyph.int
getGlyph
(int i) Helper ofgetGlyphs()
.int
Returns the number of glyphs.@org.jetbrains.annotations.Unmodifiable int[]
The array is about all laid-out glyph codes for in order visually from left to right.void
getGlyphs
(int glyphIndex, int glyphCount, int[] dstGlyphs, int dstOffset) Copy an array of glyphs for the given range.int
@org.jetbrains.annotations.Unmodifiable float[]
This array holds the repeat of x offset, y offset of glyph positions.void
getPositions
(int glyphIndex, int glyphCount, float[] dstPositions, int dstOffset) Copy an array of glyph positions for the given range.float
getX
(int i) Helper ofgetPositions()
.float
getY
(int i) Helper ofgetPositions()
.toString()
-
Field Details
-
BIDI_LTR
public static final int BIDI_LTRBiDi flags that indicating base direction is left-to-right.- See Also:
-
BIDI_RTL
public static final int BIDI_RTLBiDi flags that indicating base direction is right-to-left.- See Also:
-
BIDI_DEFAULT_LTR
public static final int BIDI_DEFAULT_LTRBiDi flags that indicating that the base direction depends on the first strong directional character in the text according to the Unicode Bidirectional Algorithm. If no strong directional character is present, the base direction is left-to-right.- See Also:
-
BIDI_DEFAULT_RTL
public static final int BIDI_DEFAULT_RTLBiDi flags that indicating that the base direction depends on the first strong directional character in the text according to the Unicode Bidirectional Algorithm. If no strong directional character is present, the base direction is right-to-left.- See Also:
-
BIDI_OVERRIDE_LTR
public static final int BIDI_OVERRIDE_LTRBiDi flags that indicating the whole text direction is determined to be left-to-right, no BiDi analysis will be performed.- See Also:
-
BIDI_OVERRIDE_RTL
public static final int BIDI_OVERRIDE_RTLBiDi flags that indicating the whole text direction is determined to be right-to-left, no BiDi analysis will be performed.- See Also:
-
-
Constructor Details
-
ShapedText
public ShapedText(@NonNull char[] text, int contextStart, int contextLimit, int start, int limit, int bidiFlags, @NonNull FontPaint paint) Generate the shaped text layout. The layout object will not be associated with the text array and the paint after construction.If bidiFlags are not OVERRIDE, the text array is the entire context, the caller is responsible for creating a copy of the context. Otherwise, the text array can be larger than context range, which is specified by contextStart and contextLimit.
The context range will affect BiDi analysis and shaping results, it can be slightly larger than the layout range.
- Parameters:
text
- text buffer, cannot be nullcontextStart
- the context start index of text arraycontextLimit
- the context end index of text arraystart
- the start index of the layoutlimit
- the end index of the layoutbidiFlags
- one of BiDi flags listed abovepaint
- layout params
-
-
Method Details
-
getGlyphCount
public int getGlyphCount()Returns the number of glyphs. -
getGlyphs
@Experimental public @org.jetbrains.annotations.Unmodifiable int[] getGlyphs()The array is about all laid-out glyph codes for in order visually from left to right. The length isgetGlyphCount()
.- Returns:
- glyphs
-
getGlyphs
Copy an array of glyphs for the given range. The array is about all laid-out glyph codes for in order visually from left to right. -
getGlyph
public int getGlyph(int i) Helper ofgetGlyphs()
. -
getPositions
@Experimental public @org.jetbrains.annotations.Unmodifiable float[] getPositions()This array holds the repeat of x offset, y offset of glyph positions. The length is twice as long as the glyph array.- Returns:
- glyph positions
-
getPositions
public void getPositions(int glyphIndex, int glyphCount, @NonNull float[] dstPositions, int dstOffset) Copy an array of glyph positions for the given range. This array holds the repeat of x offset, y offset of glyph positions. -
getX
public float getX(int i) Helper ofgetPositions()
. -
getY
public float getY(int i) Helper ofgetPositions()
. -
getFont
Returns which font should be used for the i-th glyph.- Parameters:
i
- the index- Returns:
- the font
-
getAscent
public int getAscent()Effective ascent value of this layout.If two or more fonts are used in this series of glyphs, the effective ascent will be the minimum ascent value across the all fonts.
- Returns:
- effective ascent value
-
getDescent
public int getDescent()Effective descent value of this layout.If two or more fonts are used in this series of glyphs, the effective descent will be the maximum descent value across the all fonts.
- Returns:
- effective descent value
-
getAdvance
public float getAdvance()Returns the total amount of advance consumed by this layout.The advance is an amount of width consumed by the glyph. The total amount of advance is a total amount of advance consumed by this series of glyphs. In other words, if another glyph is placed next to this series of glyphs, it's X offset should be shifted this amount of width.
- Returns:
- total amount of advance
-
getMemoryUsage
@Internal public int getMemoryUsage() -
toString
-