com.lowagie.text.rtf.style

Class RtfFont

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. Various fixes Renaud Michel, Werner Daehn. Version: $Id: RtfFont.java 4008 2009-07-07 09:56:52Z blowagie $

Author: Mark Hall (Mark.Hall@mail.room3b.eu) Craig Fleming (rythos@rhana.dhs.org) Renaud Michel (r.michel@immedia.be) Werner Daehn (Werner.Daehn@BusinessObjects.com) Lidong Liu (tmslld@gmail.com) Thomas Bickel (tmb99@inode.at)

Field Summary
intcharset
The character set to use for this font
RtfColorcolor
The color of this font
protected RtfDocumentdocument
The RtfDocument this RtfFont belongs to.
static StringDEFAULT_FONT
Default font
StringfontName
The font name.
intfontNumber
The number of this font
intfontSize
The font size.
intfontStyle
The font style.
static byte[]FONT_BOLD
Constant for the bold flag
static byte[]FONT_CHARSET
Constant for the charset
static byte[]FONT_DOUBLE_STRIKETHROUGH
Constant for the double strikethrough flag
static byte[]FONT_EMBOSSED
Constant for the embossed flag
static byte[]FONT_ENGRAVED
Constant for the engraved flag
static byte[]FONT_FAMILY
Constant for the font family to use ("froman")
static byte[]FONT_HIDDEN
Constant for hidden text flag
static byte[]FONT_ITALIC
Constant for the italic flag
static byte[]FONT_OUTLINE
Constant for the outline flag
static byte[]FONT_SHADOW
Constant for the shadow flag
static byte[]FONT_SIZE
Constant for the font size
static byte[]FONT_STRIKETHROUGH
Constant for the strikethrough flag
static byte[]FONT_UNDERLINE
Constant for the underline flag
static intSTYLE_BOLD
Constant for a bold font
static intSTYLE_DOUBLE_STRIKETHROUGH
Constant for a double strikethrough font
static intSTYLE_EMBOSSED
Constant for an embossed font
static intSTYLE_ENGRAVED
Constant for an engraved font
static intSTYLE_HIDDEN
Constant for a font that hides the actual text.
static intSTYLE_ITALIC
Constant for an italic font
static intSTYLE_NONE
Constant for a plain font
static intSTYLE_OUTLINE
Constant for an outlined font
static intSTYLE_SHADOW
Constant for a shadowed font
static intSTYLE_STRIKETHROUGH
Constant for a strikethrough font
static intSTYLE_UNDERLINE
Constant for an underlined font
Constructor Summary
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.
RtfFont(String fontName, float size, int style, Color color, int charset)
Constructs a RtfFont with the given font name, font size, font style, color and charset.
protected RtfFont(RtfDocument doc, int fontNumber)
Special constructor for the default font
RtfFont(RtfDocument doc, Font font)
Constructs a RtfFont from a com.lowagie.text.Font
Method Summary
intcompareTo(Object object)
Compares this RtfFont to either a Font or an RtfFont.
Fontdifference(Font font)
Replaces the attributes that are equal to null with the attributes of a given font.
booleanequals(Object obj)
Tests for equality of RtfFonts.
intgetCharset()
Gets the charset used for constructing this RtfFont.
StringgetFamilyname()
StringgetFontName()
Gets the font name of this RtfFont
intgetFontNumber()
Gets the font number of this RtfFont
intgetFontSize()
Gets the font size of this RtfFont
intgetFontStyle()
Gets the font style of this RtfFont
inthashCode()
Returns the hash code of this RtfFont.
protected byte[]intToByteArray(int i)
Transforms an integer into its String representation and then returns the bytes of that string.
booleanisStandardFont()
The RtfFont is never a standard font.
voidsetCharset(int charset)
Sets the charset used for constructing this RtfFont.
voidsetColor(Color color)
voidsetColor(int red, int green, int blue)
voidsetFamily(String family)
protected voidsetFontName(String fontName)
Sets the font name of this RtfFont.
voidsetInHeader(boolean inHeader)
Unused
voidsetInTable(boolean inTable)
Unused
voidsetRtfDocument(RtfDocument doc)
Sets the RtfDocument this RtfFont belongs to
voidsetSize(float size)
voidsetStyle(int style)
voidsetStyle(String style)
voidsetToDefaultFamily(String familyname)
Sets the correct font name from the family name.
voidwriteBegin(OutputStream result)
Writes the font beginning
voidwriteContent(OutputStream out)
unused
voidwriteDefinition(OutputStream result)
Writes the font definition
voidwriteEnd(OutputStream result)
Write the font end

Field Detail

charset

private int charset
The character set to use for this font

color

private RtfColor color
The color of this font

document

protected RtfDocument document
The RtfDocument this RtfFont belongs to.

DEFAULT_FONT

public static final String DEFAULT_FONT
Default font

Since: 2.1.7

fontName

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

fontNumber

private int fontNumber
The number of this font

fontSize

private int fontSize
The font size. Defaults to 10

fontStyle

private int fontStyle
The font style. Defaults to STYLE_NONE

FONT_BOLD

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

FONT_CHARSET

private static final byte[] FONT_CHARSET
Constant for the charset

FONT_DOUBLE_STRIKETHROUGH

private static final byte[] FONT_DOUBLE_STRIKETHROUGH
Constant for the double strikethrough flag

FONT_EMBOSSED

private static final byte[] FONT_EMBOSSED
Constant for the embossed flag

FONT_ENGRAVED

private static final byte[] FONT_ENGRAVED
Constant for the engraved flag

FONT_FAMILY

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

FONT_HIDDEN

private static final byte[] FONT_HIDDEN
Constant for hidden text flag

FONT_ITALIC

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

FONT_OUTLINE

private static final byte[] FONT_OUTLINE
Constant for the outline flag

FONT_SHADOW

private static final byte[] FONT_SHADOW
Constant for the shadow flag

FONT_SIZE

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

FONT_STRIKETHROUGH

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

FONT_UNDERLINE

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

STYLE_BOLD

public static final int STYLE_BOLD
Constant for a bold font

STYLE_DOUBLE_STRIKETHROUGH

public static final int STYLE_DOUBLE_STRIKETHROUGH
Constant for a double strikethrough font

STYLE_EMBOSSED

public static final int STYLE_EMBOSSED
Constant for an embossed font

STYLE_ENGRAVED

public static final int STYLE_ENGRAVED
Constant for an engraved font

STYLE_HIDDEN

public static final int STYLE_HIDDEN
Constant for a font that hides the actual text.

STYLE_ITALIC

public static final int STYLE_ITALIC
Constant for an italic font

STYLE_NONE

public static final int STYLE_NONE
Constant for a plain font

STYLE_OUTLINE

public static final int STYLE_OUTLINE
Constant for an outlined font

STYLE_SHADOW

public static final int STYLE_SHADOW
Constant for a shadowed font

STYLE_STRIKETHROUGH

public static final int STYLE_STRIKETHROUGH
Constant for a strikethrough font

STYLE_UNDERLINE

public static final int STYLE_UNDERLINE
Constant for an underlined font

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

public RtfFont(String fontName, float size, int style, Color color, int charset)
Constructs a RtfFont with the given font name, font size, font style, color and charset. This can be used when generating non latin-1 text.

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 charset The charset of the font content

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

compareTo

public int compareTo(Object object)
Compares this RtfFont to either a Font or an RtfFont.

Since: 2.1.0

difference

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

Parameters: font The surrounding font

Returns: A RtfFont

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

getCharset

public int getCharset()
Gets the charset used for constructing this RtfFont.

Returns: The charset of this RtfFont.

getFamilyname

public String getFamilyname()

See Also: getFamilyname

getFontName

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

Returns: The font name

getFontNumber

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

Returns: The font number

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

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

intToByteArray

protected 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

isStandardFont

public boolean isStandardFont()
The RtfFont is never a standard font.

Since: 2.1.0

setCharset

public void setCharset(int charset)
Sets the charset used for constructing this RtfFont.

Parameters: charset The charset to use.

setColor

public void setColor(Color color)

See Also: setColor

setColor

public void setColor(int red, int green, int blue)

See Also: Font

setFamily

public void setFamily(String family)

See Also: setFamily

setFontName

protected void setFontName(String fontName)
Sets the font name of this RtfFont.

Parameters: fontName The font name to use

setInHeader

public void setInHeader(boolean inHeader)
Unused

Parameters: inHeader

setInTable

public void setInTable(boolean inTable)
Unused

Parameters: inTable

setRtfDocument

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

Parameters: doc The RtfDocument to use

setSize

public void setSize(float size)

See Also: Font

setStyle

public void setStyle(int style)

See Also: Font

setStyle

public void setStyle(String style)

See Also: setStyle

setToDefaultFamily

private void setToDefaultFamily(String familyname)
Sets the correct font name from the family name.

Parameters: familyname The family name to set the name to.

writeBegin

public void writeBegin(OutputStream result)
Writes the font beginning

Parameters: result The OutputStream to write to.

Throws: IOException On i/o errors.

writeContent

public void writeContent(OutputStream out)
unused

writeDefinition

public void writeDefinition(OutputStream result)
Writes the font definition

writeEnd

public void writeEnd(OutputStream result)
Write the font end

Parameters: result The OutputStream to write to.

Throws: IOException On i/o errors.