java.lang.Object
dev.prozilla.pine.common.asset.text.Font
All Implemented Interfaces:
Asset, Destructible

public class Font extends Object implements Asset
Contains a font texture for drawing text.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Color
     
    static final int
     
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a default anti-aliased font with monospaced glyphs and default size 16.
    Font(boolean antiAlias)
    Creates a default font with monospaced glyphs and default size 16.
    Font(int size)
    Creates a default anti-aliased font with monospaced glyphs and specified size.
    Font(int size, boolean antiAlias)
    Creates a default font with monospaced glyphs and specified size.
    Font(Font font)
    Creates an anti-aliased font from an AWT Font.
    Font(Font font, boolean antiAlias)
    Creates a font from an AWT Font.
    Font(InputStream in, int size)
    Creates an anti-aliased Font from an input stream.
    Font(InputStream in, int size, boolean antiAlias)
    Creates a Font from an input stream.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Deletes the font.
    void
    drawText(Renderer renderer, CharSequence text, float x, float y, float z)
    Draw text at the specified position.
    void
    drawText(Renderer renderer, CharSequence text, float x, float y, float z, Color c)
    Draw text at the specified position and color.
    static String
    generateKey(String path, int size)
     
    int
    Gets the height of the specified text.
    Returns the path to the file this asset was loaded from.
    int
     
    int
    Gets the width of the specified text.
    setSize(int size)
    Creates a new font from the same font file, but with a different size.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • path

      public String path
    • DEFAULT_SIZE

      public static final int DEFAULT_SIZE
      See Also:
    • DEFAULT_COLOR

      public static final Color DEFAULT_COLOR
  • Constructor Details

    • Font

      public Font()
      Creates a default anti-aliased font with monospaced glyphs and default size 16.
    • Font

      public Font(boolean antiAlias)
      Creates a default font with monospaced glyphs and default size 16.
      Parameters:
      antiAlias - Whether the font should be anti-aliased or not
    • Font

      public Font(int size)
      Creates a default anti-aliased font with monospaced glyphs and specified size.
      Parameters:
      size - Font size
    • Font

      public Font(int size, boolean antiAlias)
      Creates a default font with monospaced glyphs and specified size.
      Parameters:
      size - Font size
      antiAlias - Whether the font should be anti-aliased or not
    • Font

      public Font(InputStream in, int size) throws FontFormatException, IOException
      Creates an anti-aliased Font from an input stream.
      Parameters:
      in - The input stream
      size - Font size
      Throws:
      FontFormatException - if fontFile does not contain the required font tables for the specified format
      IOException - If font can't be read
    • Font

      public Font(InputStream in, int size, boolean antiAlias) throws FontFormatException, IOException
      Creates a Font from an input stream.
      Parameters:
      in - The input stream
      size - Font size
      antiAlias - Whether the font should be anti-aliased or not
      Throws:
      FontFormatException - if fontFile does not contain the required font tables for the specified format
      IOException - If font can't be read
    • Font

      public Font(Font font)
      Creates an anti-aliased font from an AWT Font.
      Parameters:
      font - The AWT Font
    • Font

      public Font(Font font, boolean antiAlias)
      Creates a font from an AWT Font.
      Parameters:
      font - The AWT Font
      antiAlias - Whether the font should be anti-aliased or not
  • Method Details

    • getWidth

      public int getWidth(CharSequence text)
      Gets the width of the specified text.
      Parameters:
      text - The text
      Returns:
      Width of text
    • getHeight

      public int getHeight(CharSequence text)
      Gets the height of the specified text.
      Parameters:
      text - The text
      Returns:
      Height of text
    • getSize

      public int getSize()
    • drawText

      public void drawText(Renderer renderer, CharSequence text, float x, float y, float z, Color c)
      Draw text at the specified position and color.
      Parameters:
      renderer - The renderer to use
      text - TextRenderer to draw
      x - X coordinate of the text position
      y - Y coordinate of the text position
      c - Color to use
    • drawText

      public void drawText(Renderer renderer, CharSequence text, float x, float y, float z)
      Draw text at the specified position.
      Parameters:
      renderer - The renderer to use
      text - TextRenderer to draw
      x - X coordinate of the text position
      y - Y coordinate of the text position
    • setSize

      public Font setSize(int size)
      Creates a new font from the same font file, but with a different size.
    • getPath

      public String getPath()
      Description copied from interface: Asset
      Returns the path to the file this asset was loaded from.
      Specified by:
      getPath in interface Asset
      Returns:
      The path of this asset.
    • destroy

      public void destroy()
      Deletes the font.
      Specified by:
      destroy in interface Asset
      Specified by:
      destroy in interface Destructible
    • generateKey

      public static String generateKey(String path, int size)