Class Font
java.lang.Object
com.itextpdf.text.Font
- All Implemented Interfaces:
Comparable<Font>
Contains all the specifications of a font: fontfamily, size, style and color.
Example:
Paragraph p = new Paragraph("This is a paragraph", new
Font(FontFamily.HELVETICA, 18, Font.BOLDITALIC, new BaseColor(0, 0, 255)) );
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumEnum describing the font familystatic enumFontStyle. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate BaseFontthe external fontstatic final intthis is a possible style.static final intthis is a possible style.private BaseColorthe value of the color.static final intthe value of the default size.private Font.FontFamilythe value of the fontfamily.static final intthis is a possible style.static final intthis is a possible style.private floatthe value of the fontsize.static final intthis is a possible style.private intthe value of the style.static final intthe value of an undefined attribute.static final intthis is a possible style. -
Constructor Summary
ConstructorsConstructorDescriptionFont()Constructs a Font.Copy constructor of a FontFont(Font.FontFamily family) Constructs a Font.Font(Font.FontFamily family, float size) Constructs a Font.Font(Font.FontFamily family, float size, int style) Constructs a Font.Font(Font.FontFamily family, float size, int style, BaseColor color) Constructs a Font.Constructs a Font.Constructs a Font.Constructs a Font.Constructs a Font. -
Method Summary
Modifier and TypeMethodDescriptionintCompares thisFontwith anotherdifference(Font font) Replaces the attributes that are equal to null with the attributes of a given font.Gets theBaseFontinside this object.getCalculatedBaseFont(boolean specialEncoding) Gets theBaseFontthis class represents.floatgetCalculatedLeading(float multipliedLeading) Gets the leading that can be used with this font.floatGets the size that can be used with the calculatedBaseFont.intGets the style that can be used with the calculatedBaseFont.getColor()Gets the color of this font.Gets the family of this font.static Font.FontFamilyTranslates aString-value of a certain family into the FontFamily enum that is used for this family in this class.Gets the familyname as a String.floatgetSize()Gets the size of this font.intgetStyle()Gets the style of this font.static intgetStyleValue(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 italic.booleanChecks if the properties of this font are undefined or null.booleanchecks if the style of this font is STRIKETHRU.booleanchecks if this font is underlined.voidsetColor(int red, int green, int blue) Sets the color.voidSets the color.voidSets the family using aString("Courier", "Helvetica", "Times New Roman", "Symbol" or "ZapfDingbats").voidsetSize(float size) Sets the size.voidsetStyle(int style) Sets the style.voidSets the style using aStringcontaining one or more of the following values: normal, bold, italic, oblique, underline, line-through
-
Field Details
-
NORMAL
public static final int NORMALthis is a possible style.- See Also:
-
BOLD
public static final int BOLDthis is a possible style.- See Also:
-
ITALIC
public static final int ITALICthis is a possible style.- See Also:
-
UNDERLINE
public static final int UNDERLINEthis is a possible style.- See Also:
-
STRIKETHRU
public static final int STRIKETHRUthis is a possible style.- See Also:
-
BOLDITALIC
public static final int BOLDITALICthis is a possible style.- See Also:
-
UNDEFINED
public static final int UNDEFINEDthe value of an undefined attribute.- See Also:
-
DEFAULTSIZE
public static final int DEFAULTSIZEthe value of the default size.- See Also:
-
family
the value of the fontfamily. -
size
private float sizethe value of the fontsize. -
style
private int stylethe value of the style. -
color
the value of the color. -
baseFont
the external font
-
-
Constructor Details
-
Font
Copy constructor of a Font- Parameters:
other- the font that has to be copied
-
Font
Constructs a Font.- Parameters:
family- the family to which this font belongssize- the size of this fontstyle- the style of this fontcolor- theBaseColorof this font.- Since:
- iText 5.0.1 (first parameter has been replaced with enum)
-
Font
-
Font
Constructs a Font.- Parameters:
bf- the external fontsize- the size of this fontstyle- the style of this font
-
Font
Constructs a Font.- Parameters:
bf- the external fontsize- the size of this font
-
Font
-
Font
Constructs a Font.- Parameters:
family- the family to which this font belongssize- the size of this fontstyle- the style of this font- Since:
- iText 5.0.1 (first parameter has been replaced with enum)
-
Font
Constructs a Font.- Parameters:
family- the family to which this font belongssize- the size of this font- Since:
- iText 5.0.1 (first parameter has been replaced with enum)
-
Font
Constructs a Font.- Parameters:
family- the family to which this font belongs- Since:
- iText 5.0.1 (first parameter has been replaced with enum)
-
Font
public Font()Constructs a Font.
-
-
Method Details
-
compareTo
Compares thisFontwith another- Specified by:
compareToin interfaceComparable<Font>- Parameters:
font- the otherFont- Returns:
- a value
-
getFamily
-
getFamilyname
-
setFamily
Sets the family using aString("Courier", "Helvetica", "Times New Roman", "Symbol" or "ZapfDingbats").- Parameters:
family- AStringrepresenting a certain font-family.
-
getFamily
Translates aString-value of a certain family into the FontFamily enum that is used for this family in this class.- Parameters:
family- AStringrepresenting a certain font-family- Returns:
- the corresponding FontFamily
- Since:
- 5.0.1
-
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
public float getCalculatedLeading(float multipliedLeading) Gets the leading that can be used with this font.- Parameters:
multipliedLeading- a certain multipliedLeading- 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 italic.- 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
Sets the style using aStringcontaining one or more of the following values: normal, bold, italic, oblique, underline, line-through- Parameters:
style- AStringrepresenting a certain style.
-
getStyleValue
Translates aString-value of a certain style into the index value is used for this style in this class. Supported styles are inFont.FontStylevalues are checked onFont.FontStyle.getValue()- Parameters:
style- AString- Returns:
- the corresponding value
-
getColor
-
setColor
-
setColor
public void setColor(int red, int green, int blue) Sets the color.- Parameters:
red- the red-value of the new colorgreen- the green-value of the new colorblue- the blue-value of the new color
-
getBaseFont
-
getCalculatedBaseFont
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
-
difference
-