http://www.eteks.com

com.eteks.awt
Class PJAFontData

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

public class PJAFontData
extends java.lang.Object
implements java.io.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
Version:
2.3
Author:
Emmanuel Puybaret
See Also:
PJAGraphicsManager, PJAFontPeer, PJAFontCapture, Serialized Form

Field Summary
static java.lang.String PJAF1_1_FILE_HEADER
           
static java.lang.String PJAF1_1_FONT_HEADER
           
 
Constructor Summary
PJAFontData(java.awt.Font font, int minChar, int maxChar)
          Creates a font data from font.
PJAFontData(java.io.InputStream in)
          Creates a font data from the in stream with read () method.
 
Method Summary
 boolean equals(java.lang.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.
 java.lang.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(java.io.InputStream in)
          Reads the fields of this object from in.
static java.lang.String styleToString(int style)
           
 java.lang.String toString()
           
 void write(java.io.OutputStream out)
          Writes the fields of this object to out.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

PJAF1_1_FILE_HEADER

public static final java.lang.String PJAF1_1_FILE_HEADER

PJAF1_1_FONT_HEADER

public static final java.lang.String PJAF1_1_FONT_HEADER
Constructor Detail

PJAFontData

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

PJAFontData

public PJAFontData(java.awt.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 java.lang.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)

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)

write

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

read

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

equals

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

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

styleToString

public static java.lang.String styleToString(int style)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

© 1997-2001 eTeks - All rights reserved