Package icyllis.modernui.graphics.text
Class LayoutCache
java.lang.Object
icyllis.modernui.graphics.text.LayoutCache
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:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Also computes per-cluster advances.static final int
Also computes total pixel bounds of all glyph images.static final int
The internal policy on the maximum length of a text run, shared globally. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
clear()
Clear the cache.static int
This only returns measurable memory usage, in other words, at leaststatic 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.
-
Field Details
-
MAX_PIECE_LENGTH
public static final int MAX_PIECE_LENGTHThe internal policy on the maximum length of a text run, shared globally.- See Also:
-
COMPUTE_CLUSTER_ADVANCES
public static final int COMPUTE_CLUSTER_ADVANCESAlso computes per-cluster advances.- See Also:
-
COMPUTE_GLYPHS_PIXEL_BOUNDS
public static final int COMPUTE_GLYPHS_PIXEL_BOUNDSAlso computes total pixel bounds of all glyph images.- See Also:
-
-
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 stackstart
- start char offsetlimit
- end char indexisRtl
- whether to layout in right-to-leftpaint
- the font paint affecting measurementcomputeFlags
- 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.
-