APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.badlogic.gdx.tools.hiero.unicodefont

public Class UnicodeFont

extends Object
Class Inheritance
Imports
java.awt.Font, .FontFormatException, .FontMetrics, .Rectangle, java.awt.font.GlyphVector, .TextAttribute, java.io.IOException, java.lang.reflect.Field, java.util.ArrayList, .Collections, .Comparator, .Iterator, .List, .Map, org.lwjgl.opengl.GL11, com.badlogic.gdx.Gdx, com.badlogic.gdx.graphics.Color, .Texture, com.badlogic.gdx.graphics.g2d.BitmapFont, .BitmapFont.BitmapFontData, .BitmapFontCache, .GlyphLayout, .GlyphLayout.GlyphRun, .TextureRegion, com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator, .FreeTypeFontGenerator.FreeTypeFontParameter, com.badlogic.gdx.tools.hiero.HieroSettings, com.badlogic.gdx.tools.hiero.unicodefont.effects.Effect, com.badlogic.gdx.utils.Array, .GdxRuntimeException

A bitmap font that can display unicode glyphs from a TrueTypeFont. For efficiency, glyphs are packed on to textures. Glyphs can be loaded to the textures on the fly, when they are first needed for display. However, it is best to load the glyphs that are known to be needed at startup.
Author
Nathan Sweet

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum

Field Summary

Modifier and TypeField and Description
private int
pack-priv BitmapFont
private BitmapFontCache
private int
private final List<Effect>
private Font
private float
private FreeTypeFontGenerator
private int
private final List<GlyphPage>
private int
private final Glyph[][]
private static final Comparator<T>
heightComparator

Sorts glyphs by height, tallest first.

private GlyphLayout
private int
private static final int
private FontMetrics
private Glyph
private boolean
private int
private int
private int
private int
private int
private int
private static final int
private static final int
private final List<Glyph>
pack-priv UnicodeFont.RenderType
private int
private String
private static final int
U

private static final int
private static final int
V

private static final int
private static final int
X

private static final int
private static final int
Y

private static final int

Constructor Summary

AccessConstructor and Description
public
UnicodeFont(String
The file system or classpath location of the TrueTypeFont file.
ttfFileRef
,
String
The file system or classpath location of the Hiero settings file.
hieroFileRef
)

public
UnicodeFont(String
The file system or classpath location of the TrueTypeFont file.
ttfFileRef
,
HieroSettings settings)

public
UnicodeFont(String
The file system or classpath location of the TrueTypeFont file.
ttfFileRef
,
int size, boolean bold, boolean italic)

public
UnicodeFont(Font font, String
The file system or classpath location of the Hiero settings file.
hieroFileRef
)

Creates a new UnicodeFont.

public
UnicodeFont(Font font, HieroSettings settings)

Creates a new UnicodeFont.

public
UnicodeFont(Font font)

Creates a new UnicodeFont.

public
UnicodeFont(Font font, int size, boolean bold, boolean italic)

Creates a new UnicodeFont.

Method Summary

Modifier and TypeMethod and Description
public void
addAsciiGlyphs()

Queues the glyphs in the ASCII character set (codepoints 32 through 255) to be loaded.

public void
addGlyphs(int startCodePoint, int endCodePoint)

Queues the glyphs in the specified codepoint range (inclusive) to be loaded.

public void
addGlyphs(String text)

Queues the glyphs in the specified text to be loaded.

public void
addNeheGlyphs()

Queues the glyphs in the NEHE character set (codepoints 32 through 128) to be loaded.

private static Font
createFont(String
The file system or classpath location of the TrueTypeFont file.
ttfFileRef
)

public void
dispose()

Releases all resources used by this UnicodeFont.

private void
drawBitmap(String text, int startIndex, int endIndex)

public void
drawString(float x, float y, String text, Color color, int startIndex, int endIndex)

public void
drawString(float x, float y, String text)

public void
drawString(float x, float y, String text, Color col)

private void
drawUnicode(String text, int startIndex, int endIndex)

public int
getAscent()

Gets the distance from the baseline to the y drawing location.

public int
getDescent()

Gets the distance from the baseline to the bottom of most alphanumeric characters with descenders.

public List<E>
getEffects()

Returns a list of Effects that will be applied to the glyphs.

public Font
getFont()

Returns the TrueTypeFont for this UnicodeFont.

public String
getFontFile()

Returns the path to the TTF file for this UnicodeFont, or null.

public float
public Glyph
getGlyph(int glyphCode, int codePoint, Rectangle bounds, GlyphVector vector, int index)

Returns the glyph for the specified codePoint.

private Rectangle
getGlyphBounds(GlyphVector vector, int index, int codePoint)

public int
getGlyphPageHeight()

Returns the height of the backing textures.

public List<E>
getGlyphPages()

Returns the GlyphPages for this UnicodeFont.

public int
getGlyphPageWidth()

Returns the width of the backing textures.

public int
public int
getLeading()

Gets the extra distance between the descent of one line of text to the ascent of the next.

public int
getLineHeight()

Returns the distance from one line of text to the next.

public boolean
public int
getPaddingAdvanceX()

Gets the additional amount to offset glyphs on the x axis.

public int
getPaddingAdvanceY()

Gets the additional amount to offset a line of text on the y axis.

public int
getPaddingBottom()

Returns the padding below a glyph on the GlyphPage to allow for effects to be drawn.

public int
getPaddingLeft()

Returns the padding to the left of a glyph on the GlyphPage to allow for effects to be drawn.

public int
getPaddingRight()

Returns the padding to the right of a glyph on the GlyphPage to allow for effects to be drawn.

public int
getPaddingTop()

Returns the padding above a glyph on the GlyphPage to allow for effects to be drawn.

public UnicodeFont.RenderType
public int
public int
public int
getYOffset(String text)

Returns the distance from the y drawing location to the top most pixel of the specified text.

private void
initializeFont(Font baseFont, int size, boolean bold, boolean italic)

public boolean
loadGlyphs()

Loads all queued glyphs to the backing textures.

public boolean
loadGlyphs(int maxGlyphsToLoad)

Loads up to the specified number of queued glyphs to the backing textures.

private void
public void
setGamma(float gamma)

public void
setGlyphPageHeight(int glyphPageHeight)

Sets the height of the backing textures.

public void
setGlyphPageWidth(int glyphPageWidth)

Sets the width of the backing textures.

public void
setMono(boolean mono)

public void
setPaddingAdvanceX(int paddingAdvanceX)

Sets the additional amount to offset glyphs on the x axis.

public void
setPaddingAdvanceY(int paddingAdvanceY)

Sets the additional amount to offset a line of text on the y axis.

public void
setPaddingBottom(int paddingBottom)

Sets the padding below a glyph on the GlyphPage to allow for effects to be drawn.

public void
setPaddingLeft(int paddingLeft)

Sets the padding to the left of a glyph on the GlyphPage to allow for effects to be drawn.

public void
setPaddingRight(int paddingRight)

Sets the padding to the right of a glyph on the GlyphPage to allow for effects to be drawn.

public void
setPaddingTop(int paddingTop)

Sets the padding above a glyph on the GlyphPage to allow for effects to be drawn.

public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ascentback to summary
private int ascent
bitmapFontback to summary
pack-priv BitmapFont bitmapFont
cacheback to summary
private BitmapFontCache cache
descentback to summary
private int descent
effectsback to summary
private final List<Effect> effects
fontback to summary
private Font font
gammaback to summary
private float gamma
generatorback to summary
private FreeTypeFontGenerator generator
glyphPageHeightback to summary
private int glyphPageHeight
glyphPagesback to summary
private final List<GlyphPage> glyphPages
glyphPageWidthback to summary
private int glyphPageWidth
glyphsback to summary
private final Glyph[][] glyphs
heightComparatorback to summary
private static final Comparator<T> heightComparator

Sorts glyphs by height, tallest first.

layoutback to summary
private GlyphLayout layout
leadingback to summary
private int leading
MAX_GLYPH_CODEback to summary
private static final int MAX_GLYPH_CODE
metricsback to summary
private FontMetrics metrics
missingGlyphback to summary
private Glyph missingGlyph
monoback to summary
private boolean mono
paddingAdvanceXback to summary
private int paddingAdvanceX
paddingAdvanceYback to summary
private int paddingAdvanceY
paddingBottomback to summary
private int paddingBottom
paddingLeftback to summary
private int paddingLeft
paddingRightback to summary
private int paddingRight
paddingTopback to summary
private int paddingTop
PAGE_SIZEback to summary
private static final int PAGE_SIZE
PAGESback to summary
private static final int PAGES
queuedGlyphsback to summary
private final List<Glyph> queuedGlyphs
renderTypeback to summary
pack-priv UnicodeFont.RenderType renderType
spaceWidthback to summary
private int spaceWidth
ttfFileRefback to summary
private String ttfFileRef
Uback to summary
private static final int U
U2back to summary
private static final int U2
Vback to summary
private static final int V
V2back to summary
private static final int V2
Xback to summary
private static final int X
X2back to summary
private static final int X2
Yback to summary
private static final int Y
Y2back to summary
private static final int Y2

Constructor Detail

UnicodeFontback to summary
public UnicodeFont(String ttfFileRef, String hieroFileRef)
Parameters
ttfFileRef:String

The file system or classpath location of the TrueTypeFont file.

hieroFileRef:String

The file system or classpath location of the Hiero settings file.

UnicodeFontback to summary
public UnicodeFont(String ttfFileRef, HieroSettings settings)
Parameters
ttfFileRef:String

The file system or classpath location of the TrueTypeFont file.

UnicodeFontback to summary
public UnicodeFont(String ttfFileRef, int size, boolean bold, boolean italic)
Parameters
ttfFileRef:String

The file system or classpath location of the TrueTypeFont file.

UnicodeFontback to summary
public UnicodeFont(Font font, String hieroFileRef)

Creates a new UnicodeFont.

Parameters
hieroFileRef:String

The file system or classpath location of the Hiero settings file.

UnicodeFontback to summary
public UnicodeFont(Font font, HieroSettings settings)

Creates a new UnicodeFont.

UnicodeFontback to summary
public UnicodeFont(Font font)

Creates a new UnicodeFont.

UnicodeFontback to summary
public UnicodeFont(Font font, int size, boolean bold, boolean italic)

Creates a new UnicodeFont.

Method Detail

addAsciiGlyphsback to summary
public void addAsciiGlyphs()

Queues the glyphs in the ASCII character set (codepoints 32 through 255) to be loaded. Note that the glyphs are not actually loaded until loadGlyphs() is called.

addGlyphsback to summary
public void addGlyphs(int startCodePoint, int endCodePoint)

Queues the glyphs in the specified codepoint range (inclusive) to be loaded. Note that the glyphs are not actually loaded until loadGlyphs() is called. Some characters like combining marks and non-spacing marks can only be rendered with the context of other glyphs. In this case, use addGlyphs(String).

addGlyphsback to summary
public void addGlyphs(String text)

Queues the glyphs in the specified text to be loaded. Note that the glyphs are not actually loaded until loadGlyphs() is called.

addNeheGlyphsback to summary
public void addNeheGlyphs()

Queues the glyphs in the NEHE character set (codepoints 32 through 128) to be loaded. Note that the glyphs are not actually loaded until loadGlyphs() is called.

createFontback to summary
private static Font createFont(String ttfFileRef)
Parameters
ttfFileRef:String

The file system or classpath location of the TrueTypeFont file.

disposeback to summary
public void dispose()

Releases all resources used by this UnicodeFont. This method should be called when this UnicodeFont instance is no longer needed.

drawBitmapback to summary
private void drawBitmap(String text, int startIndex, int endIndex)
drawStringback to summary
public void drawString(float x, float y, String text, Color color, int startIndex, int endIndex)
drawStringback to summary
public void drawString(float x, float y, String text)
drawStringback to summary
public void drawString(float x, float y, String text, Color col)
drawUnicodeback to summary
private void drawUnicode(String text, int startIndex, int endIndex)
getAscentback to summary
public int getAscent()

Gets the distance from the baseline to the y drawing location.

getDescentback to summary
public int getDescent()

Gets the distance from the baseline to the bottom of most alphanumeric characters with descenders.

getEffectsback to summary
public List<E> getEffects()

Returns a list of Effects that will be applied to the glyphs.

getFontback to summary
public Font getFont()

Returns the TrueTypeFont for this UnicodeFont.

getFontFileback to summary
public String getFontFile()

Returns the path to the TTF file for this UnicodeFont, or null. If this UnicodeFont was created without specifying the TTF file, it will try to determine the path using Sun classes. If this fails, null is returned.

getGammaback to summary
public float getGamma()
getGlyphback to summary
public Glyph getGlyph(int glyphCode, int codePoint, Rectangle bounds, GlyphVector vector, int index)

Returns the glyph for the specified codePoint. If the glyph does not exist yet, it is created and queued to be loaded.

getGlyphBoundsback to summary
private Rectangle getGlyphBounds(GlyphVector vector, int index, int codePoint)
getGlyphPageHeightback to summary
public int getGlyphPageHeight()

Returns the height of the backing textures.

getGlyphPagesback to summary
public List<E> getGlyphPages()

Returns the GlyphPages for this UnicodeFont.

getGlyphPageWidthback to summary
public int getGlyphPageWidth()

Returns the width of the backing textures.

getHeightback to summary
public int getHeight(String text)
getLeadingback to summary
public int getLeading()

Gets the extra distance between the descent of one line of text to the ascent of the next.

getLineHeightback to summary
public int getLineHeight()

Returns the distance from one line of text to the next. This is the sum of the descent, ascent, leading, padding top, padding bottom, and padding advance y. To change the line height, use setPaddingAdvanceY(int).

getMonoback to summary
public boolean getMono()
getPaddingAdvanceXback to summary
public int getPaddingAdvanceX()

Gets the additional amount to offset glyphs on the x axis.

getPaddingAdvanceYback to summary
public int getPaddingAdvanceY()

Gets the additional amount to offset a line of text on the y axis.

getPaddingBottomback to summary
public int getPaddingBottom()

Returns the padding below a glyph on the GlyphPage to allow for effects to be drawn.

getPaddingLeftback to summary
public int getPaddingLeft()

Returns the padding to the left of a glyph on the GlyphPage to allow for effects to be drawn.

getPaddingRightback to summary
public int getPaddingRight()

Returns the padding to the right of a glyph on the GlyphPage to allow for effects to be drawn.

getPaddingTopback to summary
public int getPaddingTop()

Returns the padding above a glyph on the GlyphPage to allow for effects to be drawn.

getRenderTypeback to summary
public UnicodeFont.RenderType getRenderType()
getSpaceWidthback to summary
public int getSpaceWidth()
getWidthback to summary
public int getWidth(String text)
getYOffsetback to summary
public int getYOffset(String text)

Returns the distance from the y drawing location to the top most pixel of the specified text.

initializeFontback to summary
private void initializeFont(Font baseFont, int size, boolean bold, boolean italic)
loadGlyphsback to summary
public boolean loadGlyphs()

Loads all queued glyphs to the backing textures. Glyphs that are typically displayed together should be added and loaded at the same time so that they are stored on the same backing texture. This reduces the number of backing texture binds required to draw glyphs.

loadGlyphsback to summary
public boolean loadGlyphs(int maxGlyphsToLoad)

Loads up to the specified number of queued glyphs to the backing textures. This is typically called from the game loop to load glyphs on the fly that were requested for display but have not yet been loaded.

loadSettingsback to summary
private void loadSettings(HieroSettings settings)
setGammaback to summary
public void setGamma(float gamma)
setGlyphPageHeightback to summary
public void setGlyphPageHeight(int glyphPageHeight)

Sets the height of the backing textures. Default is 512.

setGlyphPageWidthback to summary
public void setGlyphPageWidth(int glyphPageWidth)

Sets the width of the backing textures. Default is 512.

setMonoback to summary
public void setMono(boolean mono)
setPaddingAdvanceXback to summary
public void setPaddingAdvanceX(int paddingAdvanceX)

Sets the additional amount to offset glyphs on the x axis. This is typically set to a negative number when left or right padding is used so that glyphs are not spaced too far apart.

setPaddingAdvanceYback to summary
public void setPaddingAdvanceY(int paddingAdvanceY)

Sets the additional amount to offset a line of text on the y axis. This is typically set to a negative number when top or bottom padding is used so that lines of text are not spaced too far apart.

setPaddingBottomback to summary
public void setPaddingBottom(int paddingBottom)

Sets the padding below a glyph on the GlyphPage to allow for effects to be drawn.

setPaddingLeftback to summary
public void setPaddingLeft(int paddingLeft)

Sets the padding to the left of a glyph on the GlyphPage to allow for effects to be drawn.

setPaddingRightback to summary
public void setPaddingRight(int paddingRight)

Sets the padding to the right of a glyph on the GlyphPage to allow for effects to be drawn.

setPaddingTopback to summary
public void setPaddingTop(int paddingTop)

Sets the padding above a glyph on the GlyphPage to allow for effects to be drawn.

setRenderTypeback to summary
public void setRenderType(UnicodeFont.RenderType renderType)
com.badlogic.gdx.tools.hiero.unicodefont back to summary

public final Enum UnicodeFont.RenderType

extends Enum<UnicodeFont.RenderType>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final UnicodeFont.RenderType
public static final UnicodeFont.RenderType
public static final UnicodeFont.RenderType

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static UnicodeFont.RenderType
public static UnicodeFont.RenderType[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

FreeTypeback to summary
public static final UnicodeFont.RenderType FreeType
Javaback to summary
public static final UnicodeFont.RenderType Java
Nativeback to summary
public static final UnicodeFont.RenderType Native

Constructor Detail

RenderTypeback to summary
private RenderType()

Method Detail

valueOfback to summary
public static UnicodeFont.RenderType valueOf(String name)
valuesback to summary
public static UnicodeFont.RenderType[] values()