Class Font

  • All Implemented Interfaces:
    be.yildizgames.common.util.Registerable
    Direct Known Subclasses:
    DummyFont

    public abstract class Font
    extends be.yildizgames.common.util.Resource
    Object containing data for a font. Immutable class.
    Author:
    Grégory Van den Borre
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static int CHARS
      Number of char to use.
      be.yildizgames.module.color.Color color
      Font color.
      int size
      Font height.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected Font​(String fontName, int fontSize, be.yildizgames.module.color.Color color)
      Full constructor.
    • Field Detail

      • 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:
        hashCode in class be.yildizgames.common.util.Resource
      • equals

        public final boolean equals​(Object obj)
        Overrides:
        equals in class be.yildizgames.common.util.Resource