Package com.lowagie.text.rtf.style
Class RtfFont
- java.lang.Object
-
- com.lowagie.text.Font
-
- com.lowagie.text.rtf.style.RtfFont
-
- All Implemented Interfaces:
RtfBasicElement,RtfExtendedElement,RtfElementInterface,java.lang.Comparable
- Direct Known Subclasses:
RtfParagraphStyle
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
Fields Modifier and Type Field Description private intcharsetThe character set to use for this fontprivate RtfColorcolorThe color of this fontstatic java.lang.StringDEFAULT_FONTDefault fontprotected RtfDocumentdocumentThe RtfDocument this RtfFont belongs to.private static byte[]FONT_BOLDConstant for the bold flagprivate static byte[]FONT_CHARSETConstant for the charsetprivate static byte[]FONT_DOUBLE_STRIKETHROUGHConstant for the double strikethrough flagprivate static byte[]FONT_EMBOSSEDConstant for the embossed flagprivate static byte[]FONT_ENGRAVEDConstant for the engraved flagprivate static byte[]FONT_FAMILYConstant for the font family to use ("froman")private static byte[]FONT_HIDDENConstant for hidden text flagprivate static byte[]FONT_ITALICConstant for the italic flagprivate static byte[]FONT_OUTLINEConstant for the outline flagprivate static byte[]FONT_SHADOWConstant for the shadow flagstatic byte[]FONT_SIZEConstant for the font sizeprivate static byte[]FONT_STRIKETHROUGHConstant for the strikethrough flagprivate static byte[]FONT_UNDERLINEConstant for the underline flagprivate java.lang.StringfontNameThe font name.private intfontNumberThe number of this fontprivate intfontSizeThe font size.private intfontStyleThe font style.static intSTYLE_BOLDConstant for a bold fontstatic intSTYLE_DOUBLE_STRIKETHROUGHConstant for a double strikethrough fontstatic intSTYLE_EMBOSSEDConstant for an embossed fontstatic intSTYLE_ENGRAVEDConstant for an engraved fontstatic intSTYLE_HIDDENConstant for a font that hides the actual text.static intSTYLE_ITALICConstant for an italic fontstatic intSTYLE_NONEConstant for a plain fontstatic intSTYLE_OUTLINEConstant for an outlined fontstatic intSTYLE_SHADOWConstant for a shadowed fontstatic intSTYLE_STRIKETHROUGHConstant for a strikethrough fontstatic intSTYLE_UNDERLINEConstant 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
Constructors Modifier Constructor Description protectedRtfFont(RtfDocument doc, int fontNumber)Special constructor for the default fontRtfFont(RtfDocument doc, Font font)Constructs a RtfFont from a com.lowagie.text.FontRtfFont(java.lang.String fontName)Constructs a RtfFont with the given font name and all other properties at their default values.RtfFont(java.lang.String fontName, float size)Constructs a RtfFont with the given font name and font size and all other properties at their default values.RtfFont(java.lang.String fontName, float size, int style)Constructs a RtfFont with the given font name, font size and font style and the default color.RtfFont(java.lang.String fontName, float size, int style, java.awt.Color color)Constructs a RtfFont with the given font name, font size, font style and color.RtfFont(java.lang.String fontName, float size, int style, java.awt.Color color, int charset)Constructs a RtfFont with the given font name, font size, font style, color and charset.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(java.lang.Object object)Fontdifference(Font font)Replaces the attributes that are equal to null with the attributes of a given font.booleanequals(java.lang.Object obj)Tests for equality of RtfFonts.intgetCharset()Gets the charset used for constructing this RtfFont.java.lang.StringgetFamilyname()Gets the familyname as a String.java.lang.StringgetFontName()Gets the font name of this RtfFontintgetFontNumber()Gets the font number of this RtfFontintgetFontSize()Gets the font size of this RtfFontintgetFontStyle()Gets the font style of this RtfFontinthashCode()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()TheRtfFontis never a standard font.voidsetCharset(int charset)Sets the charset used for constructing this RtfFont.voidsetColor(int red, int green, int blue)Sets the color.voidsetColor(java.awt.Color color)Sets the color.voidsetFamily(java.lang.String family)Sets the family using aString("Courier", "Helvetica", "Times New Roman", "Symbol" or "ZapfDingbats").protected voidsetFontName(java.lang.String fontName)Sets the font name of this RtfFont.voidsetInHeader(boolean inHeader)UnusedvoidsetInTable(boolean inTable)UnusedvoidsetRtfDocument(RtfDocument doc)Sets the RtfDocument this RtfFont belongs tovoidsetSize(float size)Sets the size.voidsetStyle(int style)Sets the style.voidsetStyle(java.lang.String style)Sets the style using aStringcontaining one of more of the following values: normal, bold, italic, underline, strike.private voidsetToDefaultFamily(java.lang.String familyname)Sets the correct font name from the family name.voidwriteBegin(java.io.OutputStream result)Writes the font beginningvoidwriteContent(java.io.OutputStream out)unusedvoidwriteDefinition(java.io.OutputStream result)Writes the font definitionvoidwriteEnd(java.io.OutputStream result)Write the font end-
Methods inherited from class com.lowagie.text.Font
getBaseFont, getCalculatedBaseFont, getCalculatedLeading, getCalculatedSize, getCalculatedStyle, getColor, getFamily, getFamilyIndex, getSize, getStyle, getStyleValue, isBold, isItalic, isStrikethru, isUnderlined
-
-
-
-
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
-
FONT_DOUBLE_STRIKETHROUGH
private static final byte[] FONT_DOUBLE_STRIKETHROUGH
Constant for the double strikethrough flag
-
FONT_SHADOW
private static final byte[] FONT_SHADOW
Constant for the shadow flag
-
FONT_OUTLINE
private static final byte[] FONT_OUTLINE
Constant for the outline 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_HIDDEN
private static final byte[] FONT_HIDDEN
Constant for hidden text flag
-
STYLE_NONE
public static final int STYLE_NONE
Constant for a plain 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_ITALIC
public static final int STYLE_ITALIC
Constant for an italic 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
-
STYLE_DOUBLE_STRIKETHROUGH
public static final int STYLE_DOUBLE_STRIKETHROUGH
Constant for a double strikethrough font- See Also:
- Constant Field Values
-
STYLE_SHADOW
public static final int STYLE_SHADOW
Constant for a shadowed font- See Also:
- Constant Field Values
-
STYLE_OUTLINE
public static final int STYLE_OUTLINE
Constant for an outlined font- See Also:
- Constant Field Values
-
STYLE_EMBOSSED
public static final int STYLE_EMBOSSED
Constant for an embossed font- See Also:
- Constant Field Values
-
STYLE_ENGRAVED
public static final int STYLE_ENGRAVED
Constant for an engraved font- See Also:
- Constant Field Values
-
STYLE_HIDDEN
public static final int STYLE_HIDDEN
Constant for a font that hides the actual text.- See Also:
- Constant Field Values
-
DEFAULT_FONT
public static final java.lang.String DEFAULT_FONT
Default font- Since:
- 2.1.7
- See Also:
- Constant Field Values
-
fontName
private java.lang.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 color of this font
-
charset
private int charset
The character set to use for this font
-
document
protected RtfDocument document
The RtfDocument this RtfFont belongs to.
-
-
Constructor Detail
-
RtfFont
public RtfFont(java.lang.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(java.lang.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 usesize- The font size to use
-
RtfFont
public RtfFont(java.lang.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 usesize- The font size to usestyle- The font style to use
-
RtfFont
public RtfFont(java.lang.String fontName, float size, int style, java.awt.Color color)Constructs a RtfFont with the given font name, font size, font style and color.- Parameters:
fontName- The font name to usesize- the font size to usestyle- The font style to usecolor- The font color to use
-
RtfFont
public RtfFont(java.lang.String fontName, float size, int style, java.awt.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 usesize- the font size to usestyle- The font style to usecolor- The font color to usecharset- 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 infontNumber- 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 infont- The Font to use as a base
-
-
Method Detail
-
writeDefinition
public void writeDefinition(java.io.OutputStream result) throws java.io.IOExceptionWrites the font definition- Specified by:
writeDefinitionin interfaceRtfExtendedElement- Parameters:
result- TheOutputStreamto write the element definition to- Throws:
java.io.IOException
-
writeBegin
public void writeBegin(java.io.OutputStream result) throws java.io.IOExceptionWrites the font beginning- Parameters:
result- TheOutputStreamto write to.- Throws:
java.io.IOException- On i/o errors.
-
writeEnd
public void writeEnd(java.io.OutputStream result) throws java.io.IOExceptionWrite the font end- Parameters:
result- TheOutputStreamto write to.- Throws:
java.io.IOException- On i/o errors.
-
writeContent
public void writeContent(java.io.OutputStream out) throws java.io.IOExceptionunused- Specified by:
writeContentin interfaceRtfBasicElement- Parameters:
out- TheOutputStreamto write the content to- Throws:
java.io.IOException
-
equals
public boolean equals(java.lang.Object obj)
Tests for equality of RtfFonts. RtfFonts are equal if their fontName, fontSize, fontStyle and fontSuperSubscript are equal- Overrides:
equalsin classjava.lang.Object- Parameters:
obj- The RtfFont to compare with this RtfFont- Returns:
Trueif the RtfFonts are equal,falseotherwise
-
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.- Overrides:
hashCodein classjava.lang.Object- Returns:
- The hash code of this RtfFont
-
getFontName
public java.lang.String getFontName()
Gets the font name of this RtfFont- Returns:
- The font name
-
setFontName
protected void setFontName(java.lang.String fontName)
Sets the font name of this RtfFont.- Parameters:
fontName- The font name to use
-
getFamilyname
public java.lang.String getFamilyname()
Description copied from class:FontGets the familyname as a String.- Overrides:
getFamilynamein classFont- Returns:
- the familyname
- See Also:
Font.getFamilyname()
-
setFamily
public void setFamily(java.lang.String family)
Description copied from class:FontSets the family using aString("Courier", "Helvetica", "Times New Roman", "Symbol" or "ZapfDingbats").- Overrides:
setFamilyin classFont- Parameters:
family- AStringrepresenting a certain font-family.- See Also:
Font.setFamily(String)
-
setToDefaultFamily
private void setToDefaultFamily(java.lang.String familyname)
Sets the correct font name from the family name.- Parameters:
familyname- The family name to set the name to.
-
getFontSize
public int getFontSize()
Gets the font size of this RtfFont- Returns:
- The font size
-
setSize
public void setSize(float size)
Description copied from class:FontSets the size.- Overrides:
setSizein classFont- Parameters:
size- The new size of the font.- See Also:
Font.setSize(float)
-
getFontStyle
public int getFontStyle()
Gets the font style of this RtfFont- Returns:
- The font style
-
setStyle
public void setStyle(int style)
Description copied from class:FontSets the style.- Overrides:
setStylein classFont- Parameters:
style- the style.- See Also:
Font.setStyle(int)
-
setStyle
public void setStyle(java.lang.String style)
Description copied from class:FontSets the style using aStringcontaining one of more of the following values: normal, bold, italic, underline, strike.- Overrides:
setStylein classFont- Parameters:
style- AStringrepresenting a certain style.- See Also:
Font.setStyle(String)
-
getCharset
public int getCharset()
Gets the charset used for constructing this RtfFont.- Returns:
- The charset of this RtfFont.
-
setCharset
public void setCharset(int charset)
Sets the charset used for constructing this RtfFont.- Parameters:
charset- The charset to use.
-
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:
setRtfDocumentin interfaceRtfBasicElement- Parameters:
doc- The RtfDocument to use
-
setInTable
public void setInTable(boolean inTable)
Unused- Specified by:
setInTablein interfaceRtfBasicElement- Parameters:
inTable-
-
setInHeader
public void setInHeader(boolean inHeader)
Unused- Specified by:
setInHeaderin interfaceRtfBasicElement- Parameters:
inHeader-
-
setColor
public void setColor(java.awt.Color color)
Description copied from class:FontSets the color.- Overrides:
setColorin classFont- Parameters:
color- the new color of the font- See Also:
Font.setColor(Color)
-
setColor
public void setColor(int red, int green, int blue)Description copied from class:FontSets the color.- Overrides:
setColorin classFont- Parameters:
red- the red-value of the new colorgreen- the green-value of the new colorblue- the blue-value of the new color- See Also:
Font.setColor(int, int, int)
-
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
-
difference
public Font difference(Font font)
Replaces the attributes that are equal to null with the attributes of a given font.- Overrides:
differencein classFont- Parameters:
font- The surrounding font- Returns:
- A RtfFont
-
isStandardFont
public boolean isStandardFont()
TheRtfFontis never a standard font.- Overrides:
isStandardFontin classFont- Returns:
- a
boolean - Since:
- 2.1.0
-
-