org.foray.font.format
Class Kerning

java.lang.Object
  extended by org.foray.font.format.Kerning
All Implemented Interfaces:
Serializable

public class Kerning
extends Object
implements Serializable

Manages the storage and retrieval of kerning information for a font. Use addKerningEntry(int, int, short) to add kerning pairs. When all pairs have been added, use lock() to lock the instance. Kerning information cannot be retrieved until the instance is locked. Once it is locked, no more kerning entries can be added to it.

See Also:
Serialized Form

Field Summary
static long serialVersionUID
          Constant needed for serialization.
 
Constructor Summary
Kerning(int expectedPairs)
          Constructor.
 
Method Summary
 void addCapacity(int pairsToAdd)
          Increases the size of the arrays by pairsToAdd.
 void addKerningEntry(int glyphIndex1, int glyphIndex2, short kernAmount)
          Adds a kerning pair.
 int getCapacity()
          Returns the current capacity.
 char getGlyphIndex1(int index)
          The first glyph index of a given kerning pair.
 char getGlyphIndex2(int index)
          The second glyph index of a given kerning pair.
 short getKernAmount(int index)
          The kerning amount of a given kerning pair.
 int getLength()
          Returns the number of kerning pairs.
 boolean isEmpty()
          Indicates whether there is any kerning information.
 int kern(int glyphIndex1, int glyphIndex2)
          Computes the kerning needed between two glyphs in this font.
 void lock()
          Run this method when all kerning entries have been added (using addKerningEntry(int, int, short)).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

public static final long serialVersionUID
Constant needed for serialization.

See Also:
Constant Field Values
Constructor Detail

Kerning

public Kerning(int expectedPairs)
Constructor.

Parameters:
expectedPairs - The number of kerning pairs that are expected to be created. Setting this value to the proper amount will improve performance.
Method Detail

addCapacity

public void addCapacity(int pairsToAdd)
Increases the size of the arrays by pairsToAdd.

Parameters:
pairsToAdd - The amount by which to increase the number of kerning pairs that can be stored.

addKerningEntry

public void addKerningEntry(int glyphIndex1,
                            int glyphIndex2,
                            short kernAmount)
Adds a kerning pair. Note that this method is a silent no-op if the Kerning instance is locked (see lock().

Parameters:
glyphIndex1 - The glyph index of the first (left in left-to-right) glyph in the kerning pair.
glyphIndex2 - The glyph index of the second (right in left-to-right) glyph in the kerning pair.
kernAmount - The amount, in raw font units (millipoints for Type 1), that the glyphs should be kerned. A positive amount indicates that the glyphs should be moved apart, a negative amount indicates that they should be moved together.

lock

public void lock()
Run this method when all kerning entries have been added (using addKerningEntry(int, int, short)). The Kerning instance is not usable until it has been locked.


kern

public int kern(int glyphIndex1,
                int glyphIndex2)
Computes the kerning needed between two glyphs in this font. Note that this method silently returns zero if the Kerning instance is not locked (see lock().

Parameters:
glyphIndex1 - The glyph index of the first (left in a left-to-right system) glyph.
glyphIndex2 - The glyph index of the second (right in left-to-right system) glyph.
Returns:
The distance in raw font units (millipoints for Type 1 fonts) of the kerning. A positive amount means that the characters should be moved farther apart, and a negative amount means that they should be moved closer together.

isEmpty

public boolean isEmpty()
Indicates whether there is any kerning information.

Returns:
True iff this has no kerning information at all.

getLength

public int getLength()
Returns the number of kerning pairs.

Returns:
The number of kerning pairs.

getCapacity

public int getCapacity()
Returns the current capacity.

Returns:
The number of kerning pairs that can be stored without resizing.

getGlyphIndex1

public char getGlyphIndex1(int index)
The first glyph index of a given kerning pair.

Parameters:
index - The index of the kerning pair.
Returns:
The first glyph index for the kerning pair at index.

getGlyphIndex2

public char getGlyphIndex2(int index)
The second glyph index of a given kerning pair.

Parameters:
index - The index of the kerning pair.
Returns:
The second glyph index for the kerning pair at index.

getKernAmount

public short getKernAmount(int index)
The kerning amount of a given kerning pair.

Parameters:
index - The index of the kerning pair.
Returns:
The kerning amount for the kerning pair at index.


Copyright © 2017. All rights reserved.