Class BMFont

java.lang.Object
com.ardor3d.ui.text.BMFont
All Implemented Interfaces:
Savable

public class BMFont extends Object implements Savable
Loads a font generated by BMFont ( @link http://www.angelcode.com/products/bmfont/ ).
  • Font info file *must* be in XML format.
  • The texture should be saved in 32 bit PNG format - TGA does not appear to work.
  • This class only supports a single page (see BMFont documentation for details on pages)
  • Constructor Details

    • BMFont

      public BMFont()
      This constructor should be used when loading as Savable
    • BMFont

      public BMFont(ResourceSource source, boolean useMipMaps) throws IOException
      Reads an XML BMFont description file and loads corresponding texture. Note that the TGA written by BMFont does not seem to be read properly by the Ardor3D loader. PNG works fine.
      Parameters:
      source - ResourceSource describing where this font comes from.
      useMipMaps - if true, use trilinear filtering with max anisotropy, else min filter is bilinear. MipMaps result in blurrier text, but less shimmering.
      Throws:
      IOException - if there are any problems reading the .fnt file.
  • Method Details

    • setBlendStateSetter

      public void setBlendStateSetter(BMFont.RenderStateSetter setter)
    • setAlphaStateSetter

      public void setAlphaStateSetter(BMFont.RenderStateSetter setter)
    • applyRenderStatesTo

      public void applyRenderStatesTo(Spatial spatial, boolean useBlend)
      apply default render states to spatial
      Parameters:
      spatial - the spatial
      useBlend - true if the blending is enabled
    • getStyleName

      public String getStyleName()
    • getSize

      public int getSize()
    • getLineHeight

      public int getLineHeight()
      The average of _common.base and _common.lineHeight seems to be the best general purpose value
      Returns:
      the line height
    • getTextureWidth

      public int getTextureWidth()
    • getTextureHeight

      public int getTextureHeight()
    • getChar

      public BMFont.Char getChar(int chr)
      Parameters:
      chr - ascii character code
      Returns:
      character descriptor for chr. If character is not in the char set, return '?' (if '?' is not in the char set, return will be null)
    • getKerning

      public int getKerning(int chr, int nextChr)
      Parameters:
      chr - ascii character code
      nextChr - ascii character code
      Returns:
      kerning information for this character pair
    • getMaxCharAdvance

      public int getMaxCharAdvance()
      Returns:
      the largest xadvance in this char set
    • getOutlineWidth

      public int getOutlineWidth()
    • getInfo

      public BMFont.Info getInfo()
    • writeXML

      public void writeXML(OutputStream outputStream) throws IOException
      Writes the XML for this font out to the OutputStream provided.
      Parameters:
      outputStream - the OutputStream to which the XML for this font will be written to
      Throws:
      IOException - thrown if there is any problem writing out to the OutputStream
    • initialize

      protected void initialize(ResourceSource source) throws MalformedURLException
      load the texture and create default render states. Only a single page is supported.
      Parameters:
      source - the source of the font file
      Throws:
      MalformedURLException - if the URL of the resource if malformed
    • getPageTexture

      public Texture getPageTexture()
    • getMappedChars

      public List<Integer> getMappedChars()
    • getKerningsForCharacter

      public Map<Integer,Integer> getKerningsForCharacter(int val)
    • getKerningMap

      public Map<Integer,Map<Integer,Integer>> getKerningMap()
    • parseFontFile

      protected void parseFontFile(ResourceSource source) throws IOException
      Parameters:
      source - the resource of the font file
      Throws:
      IOException - if something wrong occurs while reading the font from the file
    • write

      public void write(OutputCapsule capsule) throws IOException
      Specified by:
      write in interface Savable
      Throws:
      IOException
    • read

      public void read(InputCapsule capsule) throws IOException
      Specified by:
      read in interface Savable
      Throws:
      IOException
    • getClassTag

      public Class<?> getClassTag()
      Specified by:
      getClassTag in interface Savable