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:
-
Nested Class Summary
-
Field Summary
Modifier 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
ConstructorDescriptionShapedText
(char[] text, int contextStart, int contextLimit, int start, int limit, int bidiFlags, FontPaint paint) Generate the shaped text layout. -
Method Summary
Modifier and TypeMethodDescriptionstatic float
doLayoutRun
(char[] text, int contextStart, int contextLimit, int start, int limit, boolean isRtl, FontPaint paint, int layoutStart, float[] advances, float curAdvance, it.unimi.dsi.fastutil.ints.IntArrayList glyphs, it.unimi.dsi.fastutil.floats.FloatArrayList positions, it.unimi.dsi.fastutil.bytes.ByteArrayList fontIndices, Function<Font, Byte> idGet, FontMetricsInt extent, ShapedText.RunConsumer consumer) static float
doLayoutRun
(char[] text, int contextStart, int contextLimit, int start, int limit, boolean isRtl, FontPaint paint, FontMetricsInt extent, ShapedText.RunConsumer consumer) float
Returns the total amount of advance consumed by this layout.float
getAdvance
(int i) Helper ofgetAdvances()
.float[]
The array of all chars advance, the length and order are relative to the text buffer.int
Effective ascent value of this layout.int
Returns the number of characters (i.e.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.int
@org.jetbrains.annotations.Unmodifiable float[]
This array holds the repeat of x offset, y offset of glyph positions.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
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
-
getGlyph
public int getGlyph(int i) Helper ofgetGlyphs()
. -
getPositions
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
-
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
-
getCharCount
@Internal public int getCharCount()Returns the number of characters (i.e. constructorlimit - start
in code units). -
getAdvances
@Internal public float[] getAdvances()The array of all chars advance, the length and order are relative to the text buffer. Only grapheme cluster bounds have advances, others are zeros. For example: [13.0, 0, 14.0, 0, 0] meaning c[0] and c[1] become a cluster; c[2], c[3] and c[4] become a cluster. The length is constructorlimit - start
in code units.- Returns:
- advances, or null
- See Also:
-
getAdvance
@Internal public float getAdvance(int i) Helper ofgetAdvances()
. -
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
-
getTextBlob
-
getMemoryUsage
@Internal public int getMemoryUsage() -
toString
-
doLayoutRun
@Internal public static float doLayoutRun(char[] text, int contextStart, int contextLimit, int start, int limit, boolean isRtl, FontPaint paint, FontMetricsInt extent, ShapedText.RunConsumer consumer) -
doLayoutRun
@Internal public static float doLayoutRun(char[] text, int contextStart, int contextLimit, int start, int limit, boolean isRtl, FontPaint paint, int layoutStart, float[] advances, float curAdvance, it.unimi.dsi.fastutil.ints.IntArrayList glyphs, it.unimi.dsi.fastutil.floats.FloatArrayList positions, it.unimi.dsi.fastutil.bytes.ByteArrayList fontIndices, Function<Font, Byte> idGet, FontMetricsInt extent, ShapedText.RunConsumer consumer)
-