Package icyllis.modernui.graphics.text

# Class MeasuredText

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

public class MeasuredText extends Object
Text shaping result object for multi-style text, so there are multiple style runs of positioned glyphs.

See Also:
  - `ShapedText`
  - `LayoutCache`

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `MeasuredText.Builder`
  For creating a MeasuredText.
  `static class`
  `MeasuredText.ReplacementRun`
  `static class`
  `MeasuredText.Run`
  A logical run, subrange of bidi run.
  `static class`
  `MeasuredText.StyleRun`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `float`
  `getAdvance(int pos)`
  Returns the advance of the char at the given index of the text buffer.
  `float`
  `getAdvance(int start, int end)`
  Returns the advance of the chars in the given range of the text buffer.
  `void`
  `getExtent(int start, int end, FontMetricsInt extent)`
  Expands the font metrics with those of the chars in the given range of the text buffer.
  `int`
  `getMemoryUsage()`
  Note: The text buffer is not within the calculation range.
  `MeasuredText.Run[]`
  `getRuns()`
  Returns runs of text.
  `char[]`
  `getTextBuf()`
  Returns the text buffer.
  `MeasuredText.Run`
  `searchRun(int pos)`
  Binary search with ranges.
  `String`
  `toString()`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Method Details

  - ### getTextBuf

    @NonNull public char[] getTextBuf()
    Returns the text buffer. Elements may change if recycled at higher level, keep it synchronized with MeasuredText.
    Returns:
      the backend buffer of the text

  - ### getRuns

    @NonNull public MeasuredText.Run[] getRuns()
    Returns runs of text. Successive style runs may remain the same font paint under optimization consideration.
    Returns:
      all text runs, may empty if text buf is empty

  - ### getExtent

    public void getExtent(int start, int end, @NonNull FontMetricsInt extent)
    Expands the font metrics with those of the chars in the given range of the text buffer.
    Parameters:
      `start` - the start index
      `end` - the end index
      `extent` - receives the metrics

  - ### getAdvance

    public float getAdvance(int pos)
    Returns the advance of the char at the given index of the text buffer.

    This follows grapheme cluster break. For example: there are 6 chars (uint_16), the first two are the first grapheme, the last four are the second one. Then mAdvances[0] is for the first grapheme, mAdvances[2] for the second one, other elements are zero. It's in the same order of `getTextBuf()`

    Parameters:
      `pos` - the char index
    Returns:
      advance

  - ### getAdvance

    public float getAdvance(int start, int end)
    Returns the advance of the chars in the given range of the text buffer.
    Parameters:
      `start` - the start index
      `end` - the end index
    Returns:
      advance
    See Also:
      - `getAdvance(int)`

  - ### searchRun

    @Nullable public MeasuredText.Run searchRun(int pos)
    Binary search with ranges.
    Parameters:
      `pos` - char index
    Returns:
      the run

  - ### getMemoryUsage

    public int getMemoryUsage()
    Note: The text buffer is not within the calculation range.
    Returns:
      memory usage in bytes

  - ### toString

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