Package com.aowagie.text
Class Font
- java.lang.Object
-
- com.aowagie.text.Font
-
- All Implemented Interfaces:
java.lang.Comparable
public class Font extends java.lang.Object implements java.lang.ComparableContains all the specifications of a font: fontfamily, size, style and color.Example:
Paragraph p = new Paragraph("This is a paragraph", new Font(Font.HELVETICA, 18, Font.BOLDITALIC, new Color(0, 0, 255)) );
-
-
Field Summary
Fields Modifier and Type Field Description private BaseFontbaseFontthe external fontstatic intBOLDthis is a possible style.(package private) static intBOLDITALICthis is a possible style.private java.awt.Colorcolorthe value of the color.static intCOURIERa possible value of a font family.(package private) static intDEFAULTSIZEthe value of the default size.private intfamilythe value of the fontfamily.static intHELVETICAa possible value of a font family.static intITALICthis is a possible style.static intNORMALthis is a possible style.private floatsizethe value of the fontsize.static intSTRIKETHRUthis is a possible style.private intstylethe value of the style.static intSYMBOLa possible value of a font family.static intTIMES_ROMANa possible value of a font family.static intUNDEFINEDthe value of an undefined attribute.static intUNDERLINEthis is a possible style.static intZAPFDINGBATSa possible value of a font family.
-
Constructor Summary
Constructors Constructor Description Font()Constructs a Font.Font(int family, float size, int style, java.awt.Color color)Constructs a Font.Font(Font other)Copy constructor of a FontFont(BaseFont bf)Constructs a Font.Font(BaseFont bf, float size, int style, java.awt.Color color)Constructs a Font.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(java.lang.Object object)Compares thisFontwith another(package private) Fontdifference(Font font)Replaces the attributes that are equal to null with the attributes of a given font.BaseFontgetBaseFont()Gets theBaseFontinside this object.BaseFontgetCalculatedBaseFont(boolean specialEncoding)Gets theBaseFontthis class represents.(package private) floatgetCalculatedLeading(float linespacing)Gets the leading that can be used with this font.floatgetCalculatedSize()Gets the size that can be used with the calculatedBaseFont.intgetCalculatedStyle()Gets the style that can be used with the calculatedBaseFont.java.awt.ColorgetColor()Gets the color of this font.intgetFamily()Gets the family of this font.private static intgetFamilyIndex(java.lang.String family)Translates aString-value of a certain family into the index that is used for this family in this class.java.lang.StringgetFamilyname()Gets the familyname as a String.floatgetSize()Gets the size of this font.intgetStyle()Gets the style of this font.(package private) static intgetStyleValue(java.lang.String style)Translates aString-value of a certain style into the index value is used for this style in this class.booleanisBold()checks if this font is Bold.booleanisItalic()checks if this font is Bold.booleanisStandardFont()Checks if the properties of this font are undefined or null.booleanisStrikethru()checks if the style of this font is STRIKETHRU.booleanisUnderlined()checks if this font is underlined.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").voidsetSize(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.
-
-
-
Field Detail
-
COURIER
public static final int COURIER
a possible value of a font family.- See Also:
- Constant Field Values
-
HELVETICA
public static final int HELVETICA
a possible value of a font family.- See Also:
- Constant Field Values
-
TIMES_ROMAN
public static final int TIMES_ROMAN
a possible value of a font family.- See Also:
- Constant Field Values
-
SYMBOL
public static final int SYMBOL
a possible value of a font family.- See Also:
- Constant Field Values
-
ZAPFDINGBATS
public static final int ZAPFDINGBATS
a possible value of a font family.- See Also:
- Constant Field Values
-
NORMAL
public static final int NORMAL
this is a possible style.- See Also:
- Constant Field Values
-
BOLD
public static final int BOLD
this is a possible style.- See Also:
- Constant Field Values
-
ITALIC
public static final int ITALIC
this is a possible style.- See Also:
- Constant Field Values
-
UNDERLINE
public static final int UNDERLINE
this is a possible style.- See Also:
- Constant Field Values
-
STRIKETHRU
public static final int STRIKETHRU
this is a possible style.- See Also:
- Constant Field Values
-
BOLDITALIC
static final int BOLDITALIC
this is a possible style.- See Also:
- Constant Field Values
-
UNDEFINED
public static final int UNDEFINED
the value of an undefined attribute.- See Also:
- Constant Field Values
-
DEFAULTSIZE
static final int DEFAULTSIZE
the value of the default size.- See Also:
- Constant Field Values
-
family
private int family
the value of the fontfamily.
-
size
private float size
the value of the fontsize.
-
style
private int style
the value of the style.
-
color
private java.awt.Color color
the value of the color.
-
baseFont
private BaseFont baseFont
the external font
-
-
Constructor Detail
-
Font
public Font(Font other)
Copy constructor of a Font- Parameters:
other- the font that has to be copied
-
Font
public Font(int family, float size, int style, java.awt.Color color)Constructs a Font.- Parameters:
family- the family to which this font belongssize- the size of this fontstyle- the style of this fontcolor- theColorof this font.
-
Font
public Font(BaseFont bf, float size, int style, java.awt.Color color)
Constructs a Font.- Parameters:
bf- the external fontsize- the size of this fontstyle- the style of this fontcolor- theColorof this font.
-
Font
public Font(BaseFont bf)
Constructs a Font.- Parameters:
bf- the external font
-
Font
public Font()
Constructs a Font.
-
-
Method Detail
-
compareTo
public int compareTo(java.lang.Object object)
Compares thisFontwith another- Specified by:
compareToin interfacejava.lang.Comparable- Parameters:
object- the otherFont- Returns:
- a value
-
getFamily
public int getFamily()
Gets the family of this font.- Returns:
- the value of the family
-
getFamilyname
public java.lang.String getFamilyname()
Gets the familyname as a String.- Returns:
- the familyname
-
setFamily
public void setFamily(java.lang.String family)
Sets the family using aString("Courier", "Helvetica", "Times New Roman", "Symbol" or "ZapfDingbats").- Parameters:
family- AStringrepresenting a certain font-family.
-
getFamilyIndex
private static int getFamilyIndex(java.lang.String family)
Translates aString-value of a certain family into the index that is used for this family in this class.- Parameters:
family- AStringrepresenting a certain font-family- Returns:
- the corresponding index
-
getSize
public float getSize()
Gets the size of this font.- Returns:
- a size
-
getCalculatedSize
public float getCalculatedSize()
Gets the size that can be used with the calculatedBaseFont.- Returns:
- the size that can be used with the calculated
BaseFont
-
getCalculatedLeading
float getCalculatedLeading(float linespacing)
Gets the leading that can be used with this font.- Parameters:
linespacing- a certain linespacing- Returns:
- the height of a line
-
setSize
public void setSize(float size)
Sets the size.- Parameters:
size- The new size of the font.
-
getStyle
public int getStyle()
Gets the style of this font.- Returns:
- a size
-
getCalculatedStyle
public int getCalculatedStyle()
Gets the style that can be used with the calculatedBaseFont.- Returns:
- the style that can be used with the calculated
BaseFont
-
isBold
public boolean isBold()
checks if this font is Bold.- Returns:
- a
boolean
-
isItalic
public boolean isItalic()
checks if this font is Bold.- Returns:
- a
boolean
-
isUnderlined
public boolean isUnderlined()
checks if this font is underlined.- Returns:
- a
boolean
-
isStrikethru
public boolean isStrikethru()
checks if the style of this font is STRIKETHRU.- Returns:
- a
boolean
-
setStyle
public void setStyle(int style)
Sets the style.- Parameters:
style- the style.
-
setStyle
public void setStyle(java.lang.String style)
Sets the style using aStringcontaining one of more of the following values: normal, bold, italic, underline, strike.- Parameters:
style- AStringrepresenting a certain style.
-
getStyleValue
static int getStyleValue(java.lang.String style)
Translates aString-value of a certain style into the index value is used for this style in this class.- Parameters:
style- AString- Returns:
- the corresponding value
-
getColor
public java.awt.Color getColor()
Gets the color of this font.- Returns:
- a color
-
setColor
public void setColor(java.awt.Color color)
Sets the color.- Parameters:
color- the new color of the font
-
getBaseFont
public BaseFont getBaseFont()
Gets theBaseFontinside this object.- Returns:
- the
BaseFont
-
getCalculatedBaseFont
public BaseFont getCalculatedBaseFont(boolean specialEncoding)
Gets theBaseFontthis class represents. For the built-in fonts aBaseFontis calculated.- Parameters:
specialEncoding-trueto use the special encoding for Symbol and ZapfDingbats,falseto always useCp1252- Returns:
- the
BaseFontthis class represents
-
isStandardFont
public boolean isStandardFont()
Checks if the properties of this font are undefined or null.If so, the standard should be used.
- Returns:
- a
boolean
-
-