PulpCore

pulpcore.image
Class CoreFont

java.lang.Object
  extended by pulpcore.image.CoreFont

public class CoreFont
extends Object

The CoreFont class is a image-based font used for drawing text.


Method Summary
 CoreFont background(int argbColor)
          Deprecated. Background colors do not appear correctly
 boolean canDisplay(char ch)
           
 CoreFont fade(int alpha)
          Deprecated. Fade dynamically using a Label instead
 int getCharPosition(String s, int beginIndex, int charIndex)
           
 int getCharWidth(char ch)
          Gets the width of the specified character.
 int getHeight()
           
 CoreImage getImage()
           
 int getKerning(char left, char right)
           
 int getStringWidth(String s)
          Gets the total width of all the characters in a string.
 int getStringWidth(String s, int beginIndex, int endIndex)
          Gets the total width of a range of characters in a string.
static CoreFont getSystemFont()
           
static CoreFont load(String fontAsset)
          Loads a PNG-based image font from the asset catalog.
 CoreFont scale(double scale)
          Deprecated. Scale dynamically using a Label instead
 CoreFont tint(int rgbColor)
          Returns a new CoreFont with every pixel set to the specified color, without changing the alpha of each pixel.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getSystemFont

public static CoreFont getSystemFont()

load

public static CoreFont load(String fontAsset)
Loads a PNG-based image font from the asset catalog.

This method never returns null. If the image is not found, or the PNG image does not have font information, an error is printed to the log and the system font is returned. If the system font cannot be found, an Error is thrown.

PNG-based image fonts are created from a font.properties file. See the Text example in the distribution archive.

Fonts are internally cached (using a WeakReference), and if the font was previously loaded, this method may return the same reference.

Parameters:
fontAsset - The name of a PNG image file with font information.
Returns:
The font, or a broken image if the font cannot be found.

canDisplay

public boolean canDisplay(char ch)

getStringWidth

public int getStringWidth(String s)
Gets the total width of all the characters in a string. Tracking between characters is included. If a character isn't valid for this font, the last character in the set is used.

Equivalent to calling getStringWidth(s, 0, s.length())


getStringWidth

public int getStringWidth(String s,
                          int beginIndex,
                          int endIndex)
Gets the total width of a range of characters in a string. Tracking and kerning between characters is included. If a character isn't valid for this font, the last character in the set is used.

Parameters:
beginIndex - the beginning index, inclusive.
endIndex - the ending index, exclusive.

getCharPosition

public int getCharPosition(String s,
                           int beginIndex,
                           int charIndex)

getCharWidth

public int getCharWidth(char ch)
Gets the width of the specified character. Tracking and kerning is not included. If a character isn't valid for this font, the last character in the set is used.


getKerning

public int getKerning(char left,
                      char right)

getHeight

public int getHeight()

getImage

public CoreImage getImage()

tint

public CoreFont tint(int rgbColor)
Returns a new CoreFont with every pixel set to the specified color, without changing the alpha of each pixel.

Tinted fonts are internally cached using SoftReferences.


background

public CoreFont background(int argbColor)
Deprecated. Background colors do not appear correctly


fade

public CoreFont fade(int alpha)
Deprecated. Fade dynamically using a Label instead


scale

public CoreFont scale(double scale)
Deprecated. Scale dynamically using a Label instead

Creates a scaled instance of this font.


PulpCore

Copyright © 2007-2009 Interactive Pulp, LLC.