Package icyllis.modernui.text

# Class TextShaper

java.lang.Object
icyllis.modernui.text.TextShaper

public class TextShaper extends Object
Provides conversion from a text into glyph array.

Text shaping is a preprocess for drawing text into canvas with glyphs. The glyph is a most primitive unit of the text drawing, consist of glyph identifier in the font file and its position and style. You can draw the shape result to Canvas by calling `Canvas.drawShapedText(icyllis.modernui.graphics.text.ShapedText, float, float, icyllis.modernui.graphics.Paint)`.

For most of the use cases, `shapeText(java.lang.CharSequence, int, int, icyllis.modernui.text.TextDirectionHeuristic, icyllis.modernui.text.TextPaint, icyllis.modernui.text.TextShaper.GlyphsConsumer)` will provide text shaping functionalities needed.

Since:
  3.8

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static interface`
  `TextShaper.GlyphsConsumer`
  A consumer interface for accepting text shape result.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static ShapedText`
  `shapeText(char[] text, int start, int count, TextDirectionHeuristic dir, TextPaint paint)`
  Shape non-styled text.
  `static ShapedText`
  `shapeText(CharSequence text, int start, int count, TextDirectionHeuristic dir, TextPaint paint)`
  Shape non-styled text.
  `static void`
  `shapeText(CharSequence text, int start, int count, TextDirectionHeuristic dir, TextPaint paint, TextShaper.GlyphsConsumer consumer)`
  Shape multi-styled text.
  `static ShapedText`
  `shapeTextRun(char[] text, int start, int count, int contextStart, int contextCount, boolean isRtl, TextPaint paint)`
  Shape non-styled text.
  `static ShapedText`
  `shapeTextRun(CharSequence text, int start, int count, int contextStart, int contextCount, boolean isRtl, TextPaint paint)`
  Shape non-styled text.

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

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

- ## Method Details

  - ### shapeText

    public static void shapeText(@NonNull CharSequence text, @IntRange(from=0L) int start, @IntRange(from=0L) int count, @NonNull TextDirectionHeuristic dir, @NonNull TextPaint paint, @NonNull TextShaper.GlyphsConsumer consumer)
    Shape multi-styled text.

    In the LTR context, the shape result will go from left to right, thus you may want to draw glyphs from left most position of the canvas. In the RTL context, the shape result will go from right to left, thus you may want to draw glyphs from right most position of the canvas.

    Parameters:
      `text` - a styled text.
      `start` - a start index of shaping target in the text.
      `count` - a length of shaping target in the text.
      `dir` - a text direction.
      `paint` - a paint
      `consumer` - a consumer of the shape result.

  - ### shapeText

    @NonNull public static ShapedText shapeText(@NonNull char[] text, @IntRange(from=0L) int start, @IntRange(from=0L) int count, @NonNull TextDirectionHeuristic dir, @NonNull TextPaint paint)
    Shape non-styled text.

    This function shapes the text of the given range under the context of given context range. Some script, e.g. Arabic or Devanagari, changes letter shape based on its location or surrounding characters.

    Parameters:
      `text` - a text buffer to be shaped
      `start` - a start index of shaping target in the buffer.
      `count` - a length of shaping target in the buffer.
      `dir` - a text direction.
      `paint` - a paint used for shaping text.
    Returns:
      a shape result.

  - ### shapeText

    @NonNull public static ShapedText shapeText(@NonNull CharSequence text, @IntRange(from=0L) int start, @IntRange(from=0L) int count, @NonNull TextDirectionHeuristic dir, @NonNull TextPaint paint)
    Shape non-styled text.

    This function shapes the text of the given range under the context of given context range. Some script, e.g. Arabic or Devanagari, changes letter shape based on its location or surrounding characters.

    Parameters:
      `text` - a text buffer to be shaped. Any styled spans stored in this text are ignored.
      `start` - a start index of shaping target in the buffer.
      `count` - a length of shaping target in the buffer.
      `dir` - a text direction.
      `paint` - a paint used for shaping text.
    Returns:
      a shape result

  - ### shapeTextRun

    @NonNull public static ShapedText shapeTextRun(@NonNull char[] text, @IntRange(from=0L) int start, @IntRange(from=0L) int count, int contextStart, int contextCount, boolean isRtl, @NonNull TextPaint paint)
    Shape non-styled text.

    This function shapes the text of the given range under the context of given context range. Some script, e.g. Arabic or Devanagari, changes letter shape based on its location or surrounding characters.

    Parameters:
      `text` - a text buffer to be shaped
      `start` - a start index of shaping target in the buffer.
      `count` - a length of shaping target in the buffer.
      `contextStart` - a start index of context used for shaping in the buffer.
      `contextCount` - a length of context used for shaping in the buffer.
      `isRtl` - true if this text is shaped for RTL direction, false otherwise.
      `paint` - a paint used for shaping text.
    Returns:
      a shape result.

  - ### shapeTextRun

    @NonNull public static ShapedText shapeTextRun(@NonNull CharSequence text, @IntRange(from=0L) int start, @IntRange(from=0L) int count, int contextStart, int contextCount, boolean isRtl, @NonNull TextPaint paint)
    Shape non-styled text.

    This function shapes the text of the given range under the context of given context range. Some script, e.g. Arabic or Devanagari, changes letter shape based on its location or surrounding characters.

    Parameters:
      `text` - a text buffer to be shaped. Any styled spans stored in this text are ignored.
      `start` - a start index of shaping target in the buffer.
      `count` - a length of shaping target in the buffer.
      `contextStart` - a start index of context used for shaping in the buffer.
      `contextCount` - a length of context used for shaping in the buffer.
      `isRtl` - true if this text is shaped for RTL direction, false otherwise.
      `paint` - a paint used for shaping text.
    Returns:
      a shape result