Class Font

java.lang.Object
com.github.darksoulq.abyssallib.server.resource.asset.Font
All Implemented Interfaces:
Asset

public class Font extends Object implements Asset
Represents a Minecraft font resource supporting bitmap, space, TTF, and Unihex providers, with full Unicode occupation tracking.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    Represents a font glyph.
    static final record 
    A spacing glyph that adjusts character advance.
    static final record 
    A glyph from a bitmap texture.
    static final record 
    TTF font provider.
    static final record 
    Unihex font provider with size overrides.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Font(@NotNull String namespace, @NotNull String id)
    Constructs a new empty Font.
    Font(@NotNull String namespace, @NotNull String id, byte[] data)
    Constructs a new Font from pre-compiled byte data.
    Font(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull String namespace, @NotNull String id)
    Loads a font definition from plugin resources, supports only single-char bitmap providers.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    emit(@NotNull Map<String,byte[]> files)
    Emits this font to a JSON file format.
    static @Nullable net.kyori.adventure.text.Component
    getGlyph(@NotNull String namespace, @NotNull String name)
    Retrieves a mapped glyph component globally by its registered namespace and name.
    glyph(@NotNull Texture texture, int height, int ascent)
    Creates a texture glyph (bitmap glyph) without registering a global tag resolver.
    glyph(@NotNull String name, @NotNull Texture texture, int height, int ascent)
    Creates a named texture glyph (bitmap glyph) and registers it globally for tag resolution.
    glyphs(@NotNull Texture texture, int spriteW, int spriteH, int height, int ascent)
    Converts a texture atlas into glyphs split into rows.
    offset(int pixelOffset, char unicode)
    Creates an offset glyph that affects spacing only.
    void
    ttf(@NotNull File ttfFile, int shiftX, int shiftY, int size, int oversample)
    Registers a TrueType font provider.
    void
    unihex(@NotNull File zipFile, @NotNull List<Font.UnihexFont.Override> overrides)
    Registers a Unihex ZIP provider.

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Font

      public Font(@NotNull @NotNull String namespace, @NotNull @NotNull String id)
      Constructs a new empty Font.
      Parameters:
      namespace - The font's namespace.
      id - The font's identifier (usually filename without extension).
    • Font

      public Font(@NotNull @NotNull String namespace, @NotNull @NotNull String id, byte[] data)
      Constructs a new Font from pre-compiled byte data.
      Parameters:
      namespace - The font's namespace.
      id - The font's identifier (usually filename without extension).
      data - The raw byte data representing the font JSON.
    • Font

      public Font(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull String namespace, @NotNull @NotNull String id)
      Loads a font definition from plugin resources, supports only single-char bitmap providers.
      Parameters:
      plugin - The plugin providing the resource.
      namespace - Namespace for this font.
      id - Font identifier (without .json).
      Throws:
      IllegalStateException - If the requested resource path cannot be located.
      RuntimeException - If an I/O error occurs during file reading or parsing.
  • Method Details

    • getGlyph

      @Nullable public static @Nullable net.kyori.adventure.text.Component getGlyph(@NotNull @NotNull String namespace, @NotNull @NotNull String name)
      Retrieves a mapped glyph component globally by its registered namespace and name.
      Parameters:
      namespace - The namespace the glyph was registered under.
      name - The unique identifier name of the glyph.
      Returns:
      The text component representation of the glyph, or null if absent.
    • offset

      @NotNull public @NotNull Font.OffsetGlyph offset(int pixelOffset, char unicode)
      Creates an offset glyph that affects spacing only.
      Parameters:
      pixelOffset - The horizontal offset in pixels.
      unicode - The specific unicode character to map the offset to.
      Returns:
      The created Font.OffsetGlyph.
    • ttf

      public void ttf(@NotNull @NotNull File ttfFile, int shiftX, int shiftY, int size, int oversample) throws IOException
      Registers a TrueType font provider.
      Parameters:
      ttfFile - The TTF file.
      shiftX - X offset for rendering.
      shiftY - Y offset for rendering.
      size - Size of font in pixels.
      oversample - Oversample factor.
      Throws:
      IOException - If the file fails to load or parse.
      IllegalStateException - If a detected unicode character is already occupied.
    • unihex

      public void unihex(@NotNull @NotNull File zipFile, @NotNull @NotNull List<Font.UnihexFont.Override> overrides) throws IOException
      Registers a Unihex ZIP provider.
      Parameters:
      zipFile - ZIP file containing .hex glyphs.
      overrides - List of overrides for character sizing.
      Throws:
      IOException - If loading the ZIP fails.
      IllegalStateException - If a detected unicode character is already occupied.
    • glyph

      @NotNull public @NotNull Font.TextureGlyph glyph(@NotNull @NotNull String name, @NotNull @NotNull Texture texture, int height, int ascent)
      Creates a named texture glyph (bitmap glyph) and registers it globally for tag resolution.
      Parameters:
      name - The name of the glyph used for the tag resolver.
      texture - The texture used by the glyph.
      height - The height of the image.
      ascent - The ascent of the glyph.
      Returns:
      The glyph that has been created.
    • glyph

      @NotNull public @NotNull Font.TextureGlyph glyph(@NotNull @NotNull Texture texture, int height, int ascent)
      Creates a texture glyph (bitmap glyph) without registering a global tag resolver.
      Parameters:
      texture - The texture used by the glyph.
      height - The height of the image.
      ascent - The ascent of the glyph.
      Returns:
      The glyph that has been created.
    • glyphs

      @NotNull public @NotNull List<LinkedList<Font.Glyph>> glyphs(@NotNull @NotNull Texture texture, int spriteW, int spriteH, int height, int ascent)
      Converts a texture atlas into glyphs split into rows.
      Parameters:
      texture - Texture data.
      spriteW - Width of a single glyph.
      spriteH - Height of a single glyph.
      height - Glyph visual height.
      ascent - Glyph ascent.
      Returns:
      Glyphs grouped by texture rows.
    • emit

      public void emit(@NotNull @NotNull Map<String,byte[]> files)
      Emits this font to a JSON file format.
      Specified by:
      emit in interface Asset
      Parameters:
      files - Output file map for resource pack building.