org.jrabbit.base.graphics.font.renderer
Class UnicodeRenderer.GlyphPage

java.lang.Object
  extended by org.jrabbit.base.graphics.font.renderer.UnicodeRenderer.GlyphPage
All Implemented Interfaces:
Destroyable
Enclosing class:
UnicodeRenderer

protected static class UnicodeRenderer.GlyphPage
extends java.lang.Object
implements Destroyable

A GlyphPage controls a group of Glyphs. It manages loading them and it contains them on a collective texture.

Author:
Chris Molini

Field Summary
static int MAX_GLYPH_SIZE
          The maximum size of an individual glyph.
protected  boolean orderAscending
          True if the glyphs are ordered.
protected  java.util.List<UnicodeRenderer.Glyph> pageGlyphs
          The list of glyphs on this page.
protected  int pageHeight
          The height of this page's image.
protected  Image pageImage
          The image containing the glyphs.
protected  int pageWidth
          The width of this page's image.
protected  int pageX
          The x position of the page.
protected  int pageY
          The y position of the page.
static java.awt.font.FontRenderContext renderContext
          The render context in which the glyphs will be generated.
protected  int rowHeight
          The height of the last row on the page.
protected static java.nio.ByteBuffer scratchByteBuffer
          A temporary working buffer.
protected static java.awt.Graphics2D scratchGraphics
          The graphics context form the temporary image.
protected static java.awt.image.BufferedImage scratchImage
          A temporary image used to generate the glyph page.
protected static java.nio.IntBuffer scratchIntBuffer
          A temporary working buffer.
 
Constructor Summary
UnicodeRenderer.GlyphPage(int pageWidth, int pageHeight)
          Create a new page of glyphs.
 
Method Summary
 void destroy()
          Eradicates the texture that contains glyph data.
static java.awt.Graphics2D getScratchGraphics()
          Get the scratch graphics used to generate the page of glyphs.
protected  java.util.Iterator<UnicodeRenderer.Glyph> iter(java.util.List<UnicodeRenderer.Glyph> glyphs)
          Returns an iterator for the specified glyphs, sorted either ascending or descending.
 int loadGlyphs(java.util.List<UnicodeRenderer.Glyph> glyphs, int maxGlyphsToLoad, UnicodeRenderer.GlyphPainter painter)
          Loads glyphs to the backing texture and sets the image on each loaded glyph.
protected  void renderGlyph(UnicodeRenderer.Glyph glyph, UnicodeRenderer.GlyphPainter painter)
          Loads a single glyph to the backing texture, if it fits.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_GLYPH_SIZE

public static final int MAX_GLYPH_SIZE
The maximum size of an individual glyph. If a glyph is attempted that has a larger dimension, its size is cropped to this value.

See Also:
Constant Field Values

scratchByteBuffer

protected static java.nio.ByteBuffer scratchByteBuffer
A temporary working buffer.


scratchIntBuffer

protected static java.nio.IntBuffer scratchIntBuffer
A temporary working buffer.


scratchImage

protected static java.awt.image.BufferedImage scratchImage
A temporary image used to generate the glyph page.


scratchGraphics

protected static java.awt.Graphics2D scratchGraphics
The graphics context form the temporary image.


renderContext

public static java.awt.font.FontRenderContext renderContext
The render context in which the glyphs will be generated.


pageWidth

protected final int pageWidth
The width of this page's image.


pageHeight

protected final int pageHeight
The height of this page's image.


pageImage

protected final Image pageImage
The image containing the glyphs.


pageX

protected int pageX
The x position of the page.


pageY

protected int pageY
The y position of the page.


rowHeight

protected int rowHeight
The height of the last row on the page.


orderAscending

protected boolean orderAscending
True if the glyphs are ordered.


pageGlyphs

protected final java.util.List<UnicodeRenderer.Glyph> pageGlyphs
The list of glyphs on this page.

Constructor Detail

UnicodeRenderer.GlyphPage

public UnicodeRenderer.GlyphPage(int pageWidth,
                                 int pageHeight)
Create a new page of glyphs. This initializes a texture of the supplied size.

Parameters:
pageWidth - The width of the backing texture.
pageHeight - The height of the backing texture.
Method Detail

getScratchGraphics

public static java.awt.Graphics2D getScratchGraphics()
Get the scratch graphics used to generate the page of glyphs.

Returns:
The scratch graphics used to build the page.

destroy

public void destroy()
Eradicates the texture that contains glyph data.

Specified by:
destroy in interface Destroyable

loadGlyphs

public int loadGlyphs(java.util.List<UnicodeRenderer.Glyph> glyphs,
                      int maxGlyphsToLoad,
                      UnicodeRenderer.GlyphPainter painter)
Loads glyphs to the backing texture and sets the image on each loaded glyph. Loaded glyphs are removed from the list. If this page already has glyphs and maxGlyphsToLoad is -1, then this method will return 0 if all the new glyphs don't fit. This reduces texture binds when drawing since glyphs loaded at once are typically displayed together.

Parameters:
glyphs - The glyphs to load.
maxGlyphsToLoad - This is the maximum number of glyphs to load from the list. Set to -1 to attempt to load all the glyphs.
painter - The painter to render the glyphs.
Returns:
The number of glyphs that were actually loaded.

renderGlyph

protected void renderGlyph(UnicodeRenderer.Glyph glyph,
                           UnicodeRenderer.GlyphPainter painter)
Loads a single glyph to the backing texture, if it fits. To place the glyph onto a texture, the shape is rendered via the GlyphPainter, and then the pixel data is copied onto a texture.

Parameters:
glyph - The glyph to be rendered.
painter - The painter to render the glyphs.

iter

protected java.util.Iterator<UnicodeRenderer.Glyph> iter(java.util.List<UnicodeRenderer.Glyph> glyphs)
Returns an iterator for the specified glyphs, sorted either ascending or descending.

Parameters:
glyphs - The glyphs to iterate through.
Returns:
An iterator through the sorted list of glyphs.