com.eteks.awt
Class PJAFontData

java.lang.Object
  |
  +--com.eteks.awt.PJAFontData
All Implemented Interfaces:
Serializable

public class PJAFontData
extends Object
implements Serializable

Pure Java AWT Font data. From version 1.1, this class keeps all the data of a font to avoid using PJAFontMetrics which extends java.awt.FontMetrics (java.awt.FontMetrics requires awt library to be loaded). This class implements Serializable ; it implements readObject (ObjectInputStream) and writeObject (ObjectOutputStream) methods in such a way that they call the methods read (InputStream) and write (OutputStream) respectively of this class. As The methods read () and write () don't use serialization process, they can be use to restore and save the state of an instance of PJAFontData in Java environments where serialization isn't available (Java 1.0 and J2ME).

Since:
PJA1.1
Author:
Emmanuel Puybaret
See Also:
PJAGraphicsManager, PJAFontPeer, PJAFontCapture, Serialized Form

Inner Class Summary
private static class PJAFontData.FastBitSet
          A bitset implementation that is much faster than java.util.BitSet.
 
Field Summary
private  int allCharsWidth
           
private  int ascent
           
private  PJAFontData.FastBitSet charsBits
           
private  int[] charsOffset
           
private  short[] charsOffsetAtBaseline
           
private  short[] charsWidth
           
private  int descent
           
private  int leading
           
private  int maxAdvance
           
private  int maxAscent
           
private  int maxChar
           
private  int maxDescent
           
private  int minChar
           
private  String name
           
static String PJAF1_1_FILE_HEADER
           
static String PJAF1_1_FONT_HEADER
           
private  int size
           
private  int style
           
 
Constructor Summary
PJAFontData(Font font, int minChar, int maxChar)
          Creates a font data from font.
PJAFontData(InputStream in)
          Creates a font data from the in stream with read () method.
 
Method Summary
private  void checkCharacterRange(char ch)
           
 boolean equals(Object object)
          Returns true if this font peer and object have the same name, style and size.
 int getAscent()
          Returns the ascent of this font.
protected  int[] getCharBits()
          Provides direct access to bitset array for this font's pixels.
protected  int getCharBitsOffset(char ch)
          Retrieves the offset for the bit representing top-left pixel in the given char, within the bitset.
protected  int getCharBitsScanSize()
          Retrieves the scansize of the linear bit array, i.e., the number of bits in each very long scanline of pixels stored sequentially in the bitset
protected  int getCharOffsetAtBaseline(char ch)
          Returns the offset of the character ch to add at baseline.
protected  int[] getCharPixels(char ch)
          Returns the pixels array of the character ch.
protected  int getCharPixelsWidth(char ch)
          Returns the scansize of the pixels array of the character ch.
 int getCharsWidth(char[] data, int offset, int len)
          Returns the string width of a string in this font.
 int getCharWidth(int ch)
          Returns the char width of the character ch in this font.
 int getDescent()
          Returns the descent of this font.
 int getLeading()
          Returns the leading of this font.
 int getMaxAdvance()
          Returns the max advance of this font.
 int getMaxAscent()
          Returns the max ascent of this font.
 int getMaxDescent()
          Returns the max descent of this font.
 String getName()
          Returns the name of this font.
 int getSize()
          Returns the size of this font.
 int getStyle()
          Returns the style of this font.
 int hashCode()
           
 void read(InputStream in)
          Reads the fields of this object from in.
private  void readObject(ObjectInputStream in)
           
static String styleToString(int style)
           
 String toString()
           
 void write(OutputStream out)
          Writes the fields of this object to out.
private  void writeObject(ObjectOutputStream out)
           
 
Methods inherited from class java.lang.Object
, clone, finalize, getClass, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

PJAF1_1_FILE_HEADER

public static final String PJAF1_1_FILE_HEADER

PJAF1_1_FONT_HEADER

public static final String PJAF1_1_FONT_HEADER

name

private String name

style

private int style

size

private int size

leading

private int leading

ascent

private int ascent

descent

private int descent

maxAscent

private int maxAscent

maxDescent

private int maxDescent

maxAdvance

private int maxAdvance

minChar

private int minChar

maxChar

private int maxChar

charsWidth

private short[] charsWidth

charsOffset

private int[] charsOffset

charsOffsetAtBaseline

private short[] charsOffsetAtBaseline

allCharsWidth

private int allCharsWidth

charsBits

private PJAFontData.FastBitSet charsBits
Constructor Detail

PJAFontData

public PJAFontData(InputStream in)
            throws IOException
Creates a font data from the in stream with read () method.
Parameters:
in - An opened input stream.
Throws:
EOFException - End of in is reached.
IOException - The object fields couldn't be read correctly from in.
See Also:
read(java.io.InputStream)

PJAFontData

public PJAFontData(Font font,
                   int minChar,
                   int maxChar)
Creates a font data from font. The pixels of all the characters between minChar and maxChar are grabbed and stored in internal fields.
Parameters:
font - A valid font object.
minChar - The first character to be grabbed.
maxChar - The last character to be grabbed.
Method Detail

getName

public String getName()
Returns the name of this font.

getStyle

public int getStyle()
Returns the style of this font.

getSize

public int getSize()
Returns the size of this font.

getLeading

public int getLeading()
Returns the leading of this font.
See Also:
PJAGraphicsExtension.getFontLeading()

getAscent

public int getAscent()
Returns the ascent of this font.
See Also:
PJAGraphicsExtension.getFontAscent()

getDescent

public int getDescent()
Returns the descent of this font.
See Also:
PJAGraphicsExtension.getFontDescent()

getMaxAscent

public int getMaxAscent()
Returns the max ascent of this font.
See Also:
PJAGraphicsExtension.getFontMaxAscent()

getMaxDescent

public int getMaxDescent()
Returns the max descent of this font.
See Also:
PJAGraphicsExtension.getFontMaxDescent()

getMaxAdvance

public int getMaxAdvance()
Returns the max advance of this font.
See Also:
PJAGraphicsExtension.getFontMaxAdvance()

getCharWidth

public int getCharWidth(int ch)
Returns the char width of the character ch in this font.
Parameters:
ch - The character to measure.
See Also:
PJAGraphicsExtension.getCharWidth(char)

getCharsWidth

public int getCharsWidth(char[] data,
                         int offset,
                         int len)
Returns the string width of a string in this font.
See Also:
PJAGraphicsExtension.getStringWidth(java.lang.String)

checkCharacterRange

private void checkCharacterRange(char ch)

getCharPixels

protected int[] getCharPixels(char ch)
Returns the pixels array of the character ch.
See Also:
PJAGraphics.drawString(java.lang.String, int, int), getCharPixelsWidth(char)

getCharBits

protected int[] getCharBits()
Provides direct access to bitset array for this font's pixels.
Returns:
array of ints containing a linear sequence of bits, which represent the pixels all the characters in this font displayed side by side and scanned horizontally left-to-right and then top-to-bottom
Since:
PJA2.3

getCharBitsOffset

protected int getCharBitsOffset(char ch)
Retrieves the offset for the bit representing top-left pixel in the given char, within the bitset.
Since:
PJA2.3

getCharBitsScanSize

protected int getCharBitsScanSize()
Retrieves the scansize of the linear bit array, i.e., the number of bits in each very long scanline of pixels stored sequentially in the bitset
Since:
PJA2.3

getCharPixelsWidth

protected int getCharPixelsWidth(char ch)
Returns the scansize of the pixels array of the character ch.
See Also:
PJAGraphics.drawString(java.lang.String, int, int), getCharPixels(char)

getCharOffsetAtBaseline

protected int getCharOffsetAtBaseline(char ch)
Returns the offset of the character ch to add at baseline. When font is italic, some characters have some pixels at the left of the x coordinate of their drawing point.
See Also:
PJAGraphics.drawString(java.lang.String, int, int), getCharPixels(char)

writeObject

private void writeObject(ObjectOutputStream out)
                  throws IOException

write

public void write(OutputStream out)
           throws IOException
Writes the fields of this object to out. It does the same as serialization.

readObject

private void readObject(ObjectInputStream in)
                 throws IOException,
                        ClassNotFoundException

read

public void read(InputStream in)
          throws IOException
Reads the fields of this object from in. It does the same as serialization.

equals

public boolean equals(Object object)
Returns true if this font peer and object have the same name, style and size.
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

styleToString

public static String styleToString(int style)

toString

public String toString()
Overrides:
toString in class Object