com.lowagie.text.rtf.style
Class RtfFont

java.lang.Object
  extended bycom.lowagie.text.Font
      extended bycom.lowagie.text.rtf.style.RtfFont
All Implemented Interfaces:
Comparable, RtfBasicElement, RtfExtendedElement

public class RtfFont
extends Font
implements RtfExtendedElement

The RtfFont class stores one font for an rtf document. It extends Font, so can be set as a font, to allow adding of fonts with arbitrary names. BaseFont fontname handling contributed by Craig Fleming. Version: $Id: RtfFont.java,v 1.14 2005/02/02 16:15:40 hallm Exp $

Author:
Mark Hall (mhall@edu.uni-klu.ac.at), Craig Fleming

Field Summary
private  int charset
          The character set to use for this font
private  RtfColor color
          The colour of this font
private  RtfDocument document
          The RtfDocument this RtfFont belongs to;
private static byte[] FONT_BOLD
          Constant for the bold flag
private static byte[] FONT_CHARSET
          Constant for the charset
private static byte[] FONT_FAMILY
          Constant for the font family to use ("froman")
private static byte[] FONT_ITALIC
          Constant for the italic flag
static byte[] FONT_SIZE
          Constant for the font size
private static byte[] FONT_STRIKETHROUGH
          Constant for the strikethrough flag
private static byte[] FONT_UNDERLINE
          Constant for the underline flag
private  String fontName
          The font name.
private  int fontNumber
          The number of this font
private  int fontSize
          The font size.
private  int fontStyle
          The font style.
static int STYLE_BOLD
          Constant for a bold font
static int STYLE_ITALIC
          Constant for an italic font
static int STYLE_NONE
          Constant for a plain font
static int STYLE_STRIKETHROUGH
          Constant for a strikethrough font
static int STYLE_UNDERLINE
          Constant for an underlined font
 
Fields inherited from class com.lowagie.text.Font
BOLD, BOLDITALIC, COURIER, DEFAULTSIZE, HELVETICA, ITALIC, NORMAL, STRIKETHRU, SYMBOL, TIMES_ROMAN, UNDEFINED, UNDERLINE, ZAPFDINGBATS
 
Fields inherited from interface com.lowagie.text.rtf.RtfBasicElement
CLOSE_GROUP, COMMA_DELIMITER, DELIMITER, OPEN_GROUP, TWIPS_FACTOR
 
Constructor Summary
  RtfFont(RtfDocument doc, Font font)
          Constructs a RtfFont from a com.lowagie.text.Font
protected RtfFont(RtfDocument doc, int fontNumber)
          Special constructor for the default font
  RtfFont(String fontName)
          Constructs a RtfFont with the given font name and all other properties at their default values.
  RtfFont(String fontName, float size)
          Constructs a RtfFont with the given font name and font size and all other properties at their default values.
  RtfFont(String fontName, float size, int style)
          Constructs a RtfFont with the given font name, font size and font style and the default color.
  RtfFont(String fontName, float size, int style, Color color)
          Constructs a RtfFont with the given font name, font size, font style and color.
 
Method Summary
 Font difference(Font font)
          Replaces the attributes that are equal to null with the attributes of a given font.
 boolean equals(Object obj)
          Tests for equality of RtfFonts.
 String getFamilyname()
          Gets the familyname as a String.
 String getFontName()
          Gets the font name of this RtfFont
 int getFontNumber()
          Gets the font number of this RtfFont
 int getFontSize()
          Gets the font size of this RtfFont
 int getFontStyle()
          Gets the font style of this RtfFont
 int hashCode()
          Returns the hash code of this RtfFont.
private  byte[] intToByteArray(int i)
          Transforms an integer into its String representation and then returns the bytes of that string.
 void setInHeader(boolean inHeader)
          Unused
 void setInTable(boolean inTable)
          Unused
 void setRtfDocument(RtfDocument doc)
          Sets the RtfDocument this RtfFont belongs to
 byte[] write()
          Unused
 byte[] writeBegin()
          Writes the font beginning
 byte[] writeDefinition()
          Writes the font definition
 byte[] writeEnd()
          Write the font end
 
Methods inherited from class com.lowagie.text.Font
color, compareTo, family, getBaseFont, getCalculatedBaseFont, getCalculatedSize, getCalculatedStyle, getFamilyIndex, getStyleValue, isBold, isItalic, isStandardFont, isStrikethru, isUnderlined, leading, setColor, setColor, setFamily, setSize, setStyle, setStyle, size, style
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FONT_FAMILY

private static final byte[] FONT_FAMILY
Constant for the font family to use ("froman")


FONT_CHARSET

private static final byte[] FONT_CHARSET
Constant for the charset


FONT_SIZE

public static final byte[] FONT_SIZE
Constant for the font size


FONT_BOLD

private static final byte[] FONT_BOLD
Constant for the bold flag


FONT_ITALIC

private static final byte[] FONT_ITALIC
Constant for the italic flag


FONT_UNDERLINE

private static final byte[] FONT_UNDERLINE
Constant for the underline flag


FONT_STRIKETHROUGH

private static final byte[] FONT_STRIKETHROUGH
Constant for the strikethrough flag


STYLE_NONE

public static final int STYLE_NONE
Constant for a plain font

See Also:
Constant Field Values

STYLE_ITALIC

public static final int STYLE_ITALIC
Constant for an italic font

See Also:
Constant Field Values

STYLE_BOLD

public static final int STYLE_BOLD
Constant for a bold font

See Also:
Constant Field Values

STYLE_UNDERLINE

public static final int STYLE_UNDERLINE
Constant for an underlined font

See Also:
Constant Field Values

STYLE_STRIKETHROUGH

public static final int STYLE_STRIKETHROUGH
Constant for a strikethrough font

See Also:
Constant Field Values

fontName

private String fontName
The font name. Defaults to "Times New Roman"


fontSize

private int fontSize
The font size. Defaults to 10


fontStyle

private int fontStyle
The font style. Defaults to STYLE_NONE


fontNumber

private int fontNumber
The number of this font


color

private RtfColor color
The colour of this font


charset

private int charset
The character set to use for this font


document

private RtfDocument document
The RtfDocument this RtfFont belongs to;

Constructor Detail

RtfFont

public RtfFont(String fontName)
Constructs a RtfFont with the given font name and all other properties at their default values.

Parameters:
fontName - The font name to use

RtfFont

public RtfFont(String fontName,
               float size)
Constructs a RtfFont with the given font name and font size and all other properties at their default values.

Parameters:
fontName - The font name to use
size - The font size to use

RtfFont

public RtfFont(String fontName,
               float size,
               int style)
Constructs a RtfFont with the given font name, font size and font style and the default color.

Parameters:
fontName - The font name to use
size - The font size to use
style - The font style to use

RtfFont

public RtfFont(String fontName,
               float size,
               int style,
               Color color)
Constructs a RtfFont with the given font name, font size, font style and color.

Parameters:
fontName - The font name to use
size - the font size to use
style - The font style to use
color - The font color to use

RtfFont

protected RtfFont(RtfDocument doc,
                  int fontNumber)
Special constructor for the default font

Parameters:
doc - The RtfDocument this font appears in
fontNumber - The id of this font

RtfFont

public RtfFont(RtfDocument doc,
               Font font)
Constructs a RtfFont from a com.lowagie.text.Font

Parameters:
doc - The RtfDocument this font appears in
font - The Font to use as a base
Method Detail

writeDefinition

public byte[] writeDefinition()
Writes the font definition

Specified by:
writeDefinition in interface RtfExtendedElement
Returns:
A byte array with the font definition

writeBegin

public byte[] writeBegin()
Writes the font beginning

Returns:
A byte array with the font start data

writeEnd

public byte[] writeEnd()
Write the font end

Returns:
A byte array with the end of font data

write

public byte[] write()
Unused

Specified by:
write in interface RtfBasicElement
Returns:
an empty byte array

equals

public boolean equals(Object obj)
Tests for equality of RtfFonts. RtfFonts are equal if their fontName, fontSize, fontStyle and fontSuperSubscript are equal

Parameters:
obj - The RtfFont to compare with this RtfFont
Returns:
True if the RtfFonts are equal, false otherwise

hashCode

public int hashCode()
Returns the hash code of this RtfFont. The hash code is the hash code of the string containing the font name + font size + "-" + the font style + "-" + the font super/supscript value.

Returns:
The hash code of this RtfFont

getFontName

public String getFontName()
Gets the font name of this RtfFont

Returns:
The font name

getFamilyname

public String getFamilyname()
Description copied from class: Font
Gets the familyname as a String.

Overrides:
getFamilyname in class Font
Returns:
the familyname
See Also:
Font.getFamilyname()

getFontSize

public int getFontSize()
Gets the font size of this RtfFont

Returns:
The font size

getFontStyle

public int getFontStyle()
Gets the font style of this RtfFont

Returns:
The font style

getFontNumber

public int getFontNumber()
Gets the font number of this RtfFont

Returns:
The font number

setRtfDocument

public void setRtfDocument(RtfDocument doc)
Sets the RtfDocument this RtfFont belongs to

Specified by:
setRtfDocument in interface RtfBasicElement
Parameters:
doc - The RtfDocument to use

setInTable

public void setInTable(boolean inTable)
Unused

Specified by:
setInTable in interface RtfBasicElement
Parameters:
inTable -

setInHeader

public void setInHeader(boolean inHeader)
Unused

Specified by:
setInHeader in interface RtfBasicElement
Parameters:
inHeader -

intToByteArray

private byte[] intToByteArray(int i)
Transforms an integer into its String representation and then returns the bytes of that string.

Parameters:
i - The integer to convert
Returns:
A byte array representing the integer

difference

public Font difference(Font font)
Replaces the attributes that are equal to null with the attributes of a given font.

Overrides:
difference in class Font
Parameters:
font - The surrounding font
Returns:
A RtfFont