MCPcopy
hub / github.com/libgdx/libgdx / GlyphLayout

Class GlyphLayout

gdx/src/com/badlogic/gdx/graphics/g2d/GlyphLayout.java:48–630  ·  view source on GitHub ↗

Stores GlyphRun runs of glyphs for a piece of text. The text may contain newlines and color markup tags. Where wrapping occurs is determined by BitmapFontData#getWrapIndex(Array, int). Additionally, when BitmapFontData#markupEnabled is true wrapping can occur at color sta

Source from the content-addressed store, hash-verified

46 * @author Alexander Dorokhov
47 * @author Thomas Creutzenberg */
48public class GlyphLayout implements Poolable {
49 static private final Pool<GlyphRun> glyphRunPool = new DefaultPool<>(GlyphRun::new);
50 static private final IntArray colorStack = new IntArray(4);
51 static private final float epsilon = 0.0001f;
52
53 /** Each run has the glyphs for a line of text.
54 * <p>
55 * Runs are pooled, so references should not be kept past the next call to
56 * {@link #setText(BitmapFont, CharSequence, int, int, Color, float, int, boolean, String)} or {@link #reset()}. */
57 public final Array<GlyphRun> runs = new Array(1);
58
59 /** Determines the colors of the glpyhs in the {@link #runs}. Entries are pairs where the first is the glyph index (across all
60 * runs) where the color starts and the second is the color encoded as ABGR8888.
61 * <p>
62 * For example: <code>[0, WHITE, 4, GREEN, 5, WHITE]</code><br>
63 * Glpyhs 0 to 3 are WHITE, 4 is GREEN and 5 to the end are WHITE.
64 * <p>
65 * The array is empty if there are no runs, otherwise it has at least two entries: <code>[0, startColor]</code> */
66 public final IntArray colors = new IntArray(2);
67
68 /** Number of glyphs across all {@link #runs}. */
69 public int glyphCount;
70
71 public float width, height;
72
73 /** Creates an empty GlyphLayout. */
74 public GlyphLayout () {
75 }
76
77 /** @see #setText(BitmapFont, CharSequence) */
78 public GlyphLayout (BitmapFont font, CharSequence str) {
79 setText(font, str);
80 }
81
82 /** @see #setText(BitmapFont, CharSequence) */
83 public GlyphLayout (BitmapFont font, CharSequence str, Color color, float targetWidth, int halign, boolean wrap) {
84 setText(font, str, color, targetWidth, halign, wrap);
85 }
86
87 /** @see #setText(BitmapFont, CharSequence) */
88 public GlyphLayout (BitmapFont font, CharSequence str, int start, int end, Color color, float targetWidth, int halign,
89 boolean wrap, String truncate) {
90 setText(font, str, start, end, color, targetWidth, halign, wrap, truncate);
91 }
92
93 /** Calls {@link #setText(BitmapFont, CharSequence, int, int, Color, float, int, boolean, String) setText} with the whole
94 * string, the font's current color, and no alignment or wrapping. */
95 public void setText (BitmapFont font, CharSequence str) {
96 setText(font, str, 0, str.length(), font.getColor(), 0, Align.left, false, null);
97 }
98
99 /** Calls {@link #setText(BitmapFont, CharSequence, int, int, Color, float, int, boolean, String) setText} with the whole
100 * string and no truncation. */
101 public void setText (BitmapFont font, CharSequence str, Color color, float targetWidth, int halign, boolean wrap) {
102 setText(font, str, 0, str.length(), color, targetWidth, halign, wrap, null);
103 }
104
105 /** @param color The default color to use for the text (the BitmapFont {@link BitmapFont#getColor() color} is not used). If

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected