- java.lang.Object
-
- be.yildizgames.common.util.BaseRegisterable
-
- be.yildizgames.common.util.Resource
-
- be.yildizgames.module.graphic.Font
-
- All Implemented Interfaces:
be.yildizgames.common.util.Registerable
- Direct Known Subclasses:
DummyFont
public abstract class Font extends be.yildizgames.common.util.ResourceObject containing data for a font. Immutable class.- Author:
- Grégory Van den Borre
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcomputeTextWidth(String text)Compute the width of a text with this font.Stringcrop(String originalText, int width)Crop a text if it is longer than a given width.booleanequals(Object obj)static Fontget(String name)Retrieve a Font from its name.floatgetCharSize(int key)Return the width of a particular char.inthashCode()protected voidsetCharWidth(float[] widthArray)Set the size for every char for this font.
-
-
-
Field Detail
-
CHARS
protected static final int CHARS
Number of char to use.- See Also:
- Constant Field Values
-
size
public final int size
Font height.
-
color
public final be.yildizgames.module.color.Color color
Font color.
-
-
Constructor Detail
-
Font
protected Font(String fontName, int fontSize, be.yildizgames.module.color.Color color)
Full constructor.- Parameters:
fontName- Font name, must be unique.fontSize- Font height.color- Font color.
-
-
Method Detail
-
get
public static Font get(String name)
Retrieve a Font from its name.- Parameters:
name- Font to retrieve.- Returns:
- The matching font.
-
crop
public final String crop(String originalText, int width)
Crop a text if it is longer than a given width. The outside part is replaced by "...", excepted if the width is not sufficient to contains it, then it returns an empty String.- Parameters:
originalText- Text to crop.width- Maximum text width allowed.- Returns:
- originalText if it is smaller than width, a cropped text with "..." if the text cannot fit in the given width, or "" if "..." cannot fit in the given width.
-
computeTextWidth
public final int computeTextWidth(String text)
Compute the width of a text with this font.- Parameters:
text- Text to use.- Returns:
- The text width.
-
getCharSize
public final float getCharSize(int key)
Return the width of a particular char.- Parameters:
key- Char to get the width.- Returns:
- The char width.
-
setCharWidth
protected final void setCharWidth(float[] widthArray)
Set the size for every char for this font.- Parameters:
widthArray- Array containing the size for every char.
-
hashCode
public final int hashCode()
- Overrides:
hashCodein classbe.yildizgames.common.util.Resource
-
equals
public final boolean equals(Object obj)
- Overrides:
equalsin classbe.yildizgames.common.util.Resource
-
-