public class TextWidthUtils
extends java.lang.Object
| Constructor and Description |
|---|
TextWidthUtils() |
| Modifier and Type | Method and Description |
|---|---|
static float |
getCharWidth(char c,
float boldOffset,
boolean bold)
Get the width of a char using the default widths.
Minecraft takes the ceil of the width. This method reads the default char widths from the charwidths.bin resource.The widths array will be cached after the first call. |
static float[] |
getCharWidths()
Get the default char widths array.
The widths array will be cached after the first call. This method reads the default char widths from the charwidths.bin resource.The widths array will be cached after the first call. |
static float |
getComponentWidth(TextComponent component)
Calculate the width of a component using the default widths.
Minecraft takes the ceil of the width. This method reads the default char widths from the charwidths.bin resource.The widths array will be cached after the first call. |
static float |
getComponentWidth(TextComponent component,
float[] widths)
Calculate the width of a component using the given widths array.
Minecraft takes the ceil of the width. |
static float |
getComponentWidth(TextComponent component,
float[] widths,
float boldOffset)
Calculate the width of a component using the given widths array.
The bold offset is 1 for the vanilla font and 0.5 for unihex fonts. Minecraft takes the ceil of the width. |
public static float[] getCharWidths()
charwidths.bin resource.java.lang.IllegalStateException - If the charwidths.bin resource could not be foundjava.lang.RuntimeException - If the charwidths.bin resource could not be readpublic static float getCharWidth(char c,
float boldOffset,
boolean bold)
charwidths.bin resource.c - The char to calculate the width ofboldOffset - The bold offsetbold - If the char is boldjava.lang.IllegalStateException - If the charwidths.bin resource could not be foundjava.lang.RuntimeException - If the charwidths.bin resource could not be readpublic static float getComponentWidth(TextComponent component)
charwidths.bin resource.component - The component to calculate the width ofjava.lang.IllegalStateException - If the charwidths.bin resource could not be foundjava.lang.RuntimeException - If the charwidths.bin resource could not be readpublic static float getComponentWidth(TextComponent component, float[] widths)
component - The component to calculate the width ofwidths - The char widths arraypublic static float getComponentWidth(TextComponent component, float[] widths, float boldOffset)
component - The component to calculate the width ofwidths - The char widths arrayboldOffset - The bold offset