Package icyllis.modernui.graphics.text

# 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:
  - `MeasuredText`
  - `LayoutCache`

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static interface`
  `ShapedText.RunConsumer`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `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.
  `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.
  `static final int`
  `BIDI_LTR`
  BiDi flags that indicating base direction is left-to-right.
  `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.
  `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.
  `static final int`
  `BIDI_RTL`
  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
  `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)`
  `static float`
  `doLayoutRun(char[] text, int contextStart, int contextLimit, int start, int limit, boolean isRtl, FontPaint paint, FontMetricsInt extent, ShapedText.RunConsumer consumer)`
  `float`
  `getAdvance()`
  Returns the total amount of advance consumed by this layout.
  `float`
  `getAdvance(int i)`
  Helper of `getAdvances()`.
  `float[]`
  `getAdvances()`
  The array of all chars advance, the length and order are relative to the text buffer.
  `int`
  `getAscent()`
  Effective ascent value of this layout.
  `int`
  `getCharCount()`
  Returns the number of characters (i.e.
  `int`
  `getDescent()`
  Effective descent value of this layout.
  `Font`
  `getFont(int i)`
  Returns which font should be used for the i-th glyph.
  `int`
  `getGlyph(int i)`
  Helper of `getGlyphs()`.
  `int`
  `getGlyphCount()`
  Returns the number of glyphs.
  `@org.jetbrains.annotations.Unmodifiable int[]`
  `getGlyphs()`
  The array is about all laid-out glyph codes for in order visually from left to right.
  `int`
  `getMemoryUsage()`
  `@org.jetbrains.annotations.Unmodifiable float[]`
  `getPositions()`
  This array holds the repeat of x offset, y offset of glyph positions.
  `TextBlob`
  `getTextBlob()`
  `float`
  `getX(int i)`
  Helper of `getPositions()`.
  `float`
  `getY(int i)`
  Helper of `getPositions()`.
  `String`
  `toString()`

  ### 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:
      - Constant Field Values

  - ### BIDI_RTL

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

  - ### 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:
      - Constant Field Values

  - ### 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:
      - Constant Field Values

  - ### 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:
      - Constant Field Values

  - ### 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:
      - Constant Field Values

- ## 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

    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

  - ### getGlyph

    public int getGlyph(int i)
    Helper of `getGlyphs()`.

  - ### 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 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

  - ### getCharCount

    @Internal public int getCharCount()
    Returns the number of characters (i.e. constructor `limit - 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 constructor `limit - start` in code units.
    Returns:
      advances, or null
    See Also:
      - `GraphemeBreak`

  - ### getAdvance

    @Internal public float getAdvance(int i)
    Helper of `getAdvances()`.

  - ### 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

    @Experimental public TextBlob getTextBlob()

  - ### getMemoryUsage

    @Internal public int getMemoryUsage()

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`

  - ### 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)