Class Font

java.lang.Object
com.itextpdf.text.Font
All Implemented Interfaces:
Comparable<Font>

public class Font extends Object implements 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 Classes
    Modifier and Type
    Class
    Description
    static enum 
    Enum describing the font family
    static enum 
    FontStyle.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    this is a possible style.
    static final int
    this is a possible style.
    static final int
    the value of the default size.
    static final int
    this is a possible style.
    static final int
    this is a possible style.
    static final int
    this is a possible style.
    static final int
    the value of an undefined attribute.
    static final int
    this is a possible style.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a Font.
    Font(Font other)
    Copy constructor of a Font
    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.
    Font(BaseFont bf, float size)
    Constructs a Font.
    Font(BaseFont bf, float size, int style)
    Constructs a Font.
    Font(BaseFont bf, float size, int style, BaseColor color)
    Constructs a Font.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Compares this Font with another
    Replaces the attributes that are equal to null with the attributes of a given font.
    Gets the BaseFont inside this object.
    getCalculatedBaseFont(boolean specialEncoding)
    Gets the BaseFont this class represents.
    float
    getCalculatedLeading(float multipliedLeading)
    Gets the leading that can be used with this font.
    float
    Gets the size that can be used with the calculated BaseFont .
    int
    Gets the style that can be used with the calculated BaseFont .
    Gets the color of this font.
    Gets the family of this font.
    getFamily(String family)
    Translates a String -value of a certain family into the FontFamily enum that is used for this family in this class.
    Gets the familyname as a String.
    float
    Gets the size of this font.
    int
    Gets the style of this font.
    static int
    Translates a String -value of a certain style into the index value is used for this style in this class.
    boolean
    checks if this font is Bold.
    boolean
    checks if this font is italic.
    boolean
    Checks if the properties of this font are undefined or null.
    boolean
    checks if the style of this font is STRIKETHRU.
    boolean
    checks if this font is underlined.
    void
    setColor(int red, int green, int blue)
    Sets the color.
    void
    Sets the color.
    void
    setFamily(String family)
    Sets the family using a String ("Courier", "Helvetica", "Times New Roman", "Symbol" or "ZapfDingbats").
    void
    setSize(float size)
    Sets the size.
    void
    setStyle(int style)
    Sets the style.
    void
    Sets the style using a String containing one or more of the following values: normal, bold, italic, oblique, underline, line-through

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • Font

      public Font(Font other)
      Copy constructor of a Font
      Parameters:
      other - the font that has to be copied
    • Font

      public Font(Font.FontFamily family, float size, int style, BaseColor color)
      Constructs a Font.
      Parameters:
      family - the family to which this font belongs
      size - the size of this font
      style - the style of this font
      color - the BaseColor of this font.
      Since:
      iText 5.0.1 (first parameter has been replaced with enum)
    • Font

      public Font(BaseFont bf, float size, int style, BaseColor color)
      Constructs a Font.
      Parameters:
      bf - the external font
      size - the size of this font
      style - the style of this font
      color - the BaseColor of this font.
    • Font

      public Font(BaseFont bf, float size, int style)
      Constructs a Font.
      Parameters:
      bf - the external font
      size - the size of this font
      style - the style of this font
    • Font

      public Font(BaseFont bf, float size)
      Constructs a Font.
      Parameters:
      bf - the external font
      size - the size of this font
    • Font

      public Font(BaseFont bf)
      Constructs a Font.
      Parameters:
      bf - the external font
    • Font

      public Font(Font.FontFamily family, float size, int style)
      Constructs a Font.
      Parameters:
      family - the family to which this font belongs
      size - the size of this font
      style - the style of this font
      Since:
      iText 5.0.1 (first parameter has been replaced with enum)
    • Font

      public Font(Font.FontFamily family, float size)
      Constructs a Font.
      Parameters:
      family - the family to which this font belongs
      size - the size of this font
      Since:
      iText 5.0.1 (first parameter has been replaced with enum)
    • Font

      public Font(Font.FontFamily family)
      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

      public int compareTo(Font font)
      Compares this Font with another
      Specified by:
      compareTo in interface Comparable<Font>
      Parameters:
      font - the other Font
      Returns:
      a value
    • getFamily

      public Font.FontFamily getFamily()
      Gets the family of this font.
      Returns:
      the value of the family
    • getFamilyname

      public String getFamilyname()
      Gets the familyname as a String.
      Returns:
      the familyname
    • setFamily

      public void setFamily(String family)
      Sets the family using a String ("Courier", "Helvetica", "Times New Roman", "Symbol" or "ZapfDingbats").
      Parameters:
      family - A String representing a certain font-family.
    • getFamily

      public static Font.FontFamily getFamily(String family)
      Translates a String -value of a certain family into the FontFamily enum that is used for this family in this class.
      Parameters:
      family - A String representing 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 calculated BaseFont .
      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 calculated BaseFont .
      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

      public void setStyle(String style)
      Sets the style using a String containing one or more of the following values: normal, bold, italic, oblique, underline, line-through
      Parameters:
      style - A String representing a certain style.
    • getStyleValue

      public static int getStyleValue(String style)
      Translates a String -value of a certain style into the index value is used for this style in this class. Supported styles are in Font.FontStyle values are checked on Font.FontStyle.getValue()
      Parameters:
      style - A String
      Returns:
      the corresponding value
    • getColor

      public BaseColor getColor()
      Gets the color of this font.
      Returns:
      a color
    • setColor

      public void setColor(BaseColor color)
      Sets the color.
      Parameters:
      color - the new color of the font
    • setColor

      public void setColor(int red, int green, int blue)
      Sets the color.
      Parameters:
      red - the red-value of the new color
      green - the green-value of the new color
      blue - the blue-value of the new color
    • getBaseFont

      public BaseFont getBaseFont()
      Gets the BaseFont inside this object.
      Returns:
      the BaseFont
    • getCalculatedBaseFont

      public BaseFont getCalculatedBaseFont(boolean specialEncoding)
      Gets the BaseFont this class represents. For the built-in fonts a BaseFont is calculated.
      Parameters:
      specialEncoding - true to use the special encoding for Symbol and ZapfDingbats, false to always use Cp1252
      Returns:
      the BaseFont this 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

      public Font difference(Font font)
      Replaces the attributes that are equal to null with the attributes of a given font.
      Parameters:
      font - the font of a lower element class (ex. this - paragraph font, font - chunk font)
      Returns:
      a Font