Package icyllis.modernui.graphics.text

# Class LayoutCache

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

@ThreadSafe public final class LayoutCache extends Object
Globally shared layout cache. Useful when recycling layouts, or raw data source and layout information are separated. Max memory usage: 7~10 MB.

Since:
  2.6
See Also:
  - `LayoutPiece`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `COMPUTE_CLUSTER_ADVANCES`
  Also computes per-cluster advances.
  `static final int`
  `COMPUTE_GLYPHS_PIXEL_BOUNDS`
  Also computes total pixel bounds of all glyph images.
  `static final int`
  `MAX_PIECE_LENGTH`
  The internal policy on the maximum length of a text run, shared globally.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `LayoutCache()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static void`
  `clear()`
  Clear the cache.
  `static int`
  `getMemoryUsage()`
  This only returns measurable memory usage, in other words, at least
  `static LayoutPiece`
  `getOrCreate(char[] buf, int contextStart, int contextLimit, int start, int limit, boolean isRtl, FontPaint paint, int computeFlags)`
  Get or create the layout piece from the global cache with given requirements.
  `static int`
  `getSize()`
  Returns the approximate number of entries in this cache.

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

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

- ## Field Details

  - ### MAX_PIECE_LENGTH

    public static final int MAX_PIECE_LENGTH
    The internal policy on the maximum length of a text run, shared globally.
    See Also:
      - Constant Field Values

  - ### COMPUTE_CLUSTER_ADVANCES

    public static final int COMPUTE_CLUSTER_ADVANCES
    Also computes per-cluster advances.
    See Also:
      - `LayoutPiece.getAdvances()`
      - Constant Field Values

  - ### COMPUTE_GLYPHS_PIXEL_BOUNDS

    public static final int COMPUTE_GLYPHS_PIXEL_BOUNDS
    Also computes total pixel bounds of all glyph images.
    See Also:
      - `LayoutPiece.getBoundsX()`
      - `LayoutPiece.getBoundsY()`
      - Constant Field Values

- ## Constructor Details

  - ### LayoutCache

    public LayoutCache()

- ## Method Details

  - ### getOrCreate

    @NonNull public static LayoutPiece getOrCreate(@NonNull char[] buf, int contextStart, int contextLimit, int start, int limit, boolean isRtl, @NonNull FontPaint paint, int computeFlags)
    Get or create the layout piece from the global cache with given requirements.

    In particular, the given range cannot exceed `MAX_PIECE_LENGTH` to increase the reuse rate of pieced text. The given text must be in the same paragraph and should not break the grapheme cluster.

    Use computeFlags to compute optional info lazily.

    Parameters:
      `buf` - text buffer, cannot be null or empty, only referred in stack
      `start` - start char offset
      `limit` - end char index
      `isRtl` - whether to layout in right-to-left
      `paint` - the font paint affecting measurement
      `computeFlags` - additional desired info to compute, or 0
    Returns:
      the layout piece

  - ### getSize

    public static int getSize()
    Returns the approximate number of entries in this cache.

  - ### getMemoryUsage

    public static int getMemoryUsage()
    This only returns measurable memory usage, in other words, at least
    Returns:
      memory usage in bytes

  - ### clear

    public static void clear()
    Clear the cache.