Class ShapedText

java.lang.Object
icyllis.modernui.graphics.text.ShapedText

@Immutable public class ShapedText extends Object
Text shaping result object for single style text, a sequence of positioned glyphs. You can get text shaping result by 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

    Fields
    Modifier and Type
    Field
    Description
    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 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

    Constructors
    Constructor
    Description
    ShapedText(char[] text, int contextStart, int contextLimit, int start, int limit, int bidiFlags, FontPaint paint)
    Generate the shaped text layout.
  • Method Summary

    Modifier and Type
    Method
    Description
    float
    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 of getGlyphs().
    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 of getPositions().
    float
    getY(int i)
    Helper of getPositions().
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • BIDI_LTR

      public static final int BIDI_LTR
      BiDi flags that indicating base direction is left-to-right.
      See Also:
    • BIDI_RTL

      public static final int BIDI_RTL
      BiDi flags that indicating base direction is right-to-left.
      See Also:
    • BIDI_DEFAULT_LTR

      public static final int BIDI_DEFAULT_LTR
      BiDi 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_RTL
      BiDi 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_LTR
      BiDi 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_RTL
      BiDi 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 null
      contextStart - the context start index of text array
      contextLimit - the context end index of text array
      start - the start index of the layout
      limit - the end index of the layout
      bidiFlags - one of BiDi flags listed above
      paint - 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 is getGlyphCount().
      Returns:
      glyphs
    • getGlyphs

      public void getGlyphs(int glyphIndex, int glyphCount, @NonNull int[] dstGlyphs, int dstOffset)
      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 of getGlyphs().
    • 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 of getPositions().
    • getY

      public float getY(int i)
      Helper of getPositions().
    • getFont

      public Font getFont(int i)
      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

      public String toString()
      Overrides:
      toString in class Object