Class Font

java.lang.Object
com.aowagie.text.Font
All Implemented Interfaces:
Comparable

public class Font extends Object implements Comparable
Contains 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
    static final int
    this is a possible style.
    static final int
    a possible value of a font family.
    static final int
    a possible value of a font family.
    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
    a possible value of a font family.
    static final int
    a possible value of a font family.
    static final int
    the value of an undefined attribute.
    static final int
    this is a possible style.
    static final int
    a possible value of a font family.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a Font.
    Font(int family, float size, int style, Color color)
    Constructs a Font.
    Font(Font other)
    Copy constructor of a Font
    Constructs a Font.
    Font(BaseFont bf, float size, int style, Color color)
    Constructs a Font.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    compareTo(Object object)
    Compares this Font with another
    Gets the BaseFont inside this object.
    getCalculatedBaseFont(boolean specialEncoding)
    Gets the BaseFont this class represents.
    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.
    int
    Gets the family of this font.
    Gets the familyname as a String.
    float
    Gets the size of this font.
    int
    Gets the style of this font.
    boolean
    checks if this font is Bold.
    boolean
    checks if this font is Bold.
    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(Color color)
    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 of more of the following values: normal, bold, italic, underline, strike.

    Methods inherited from class Object

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

    • COURIER

      public static final int COURIER
      a possible value of a font family.
      See Also:
    • HELVETICA

      public static final int HELVETICA
      a possible value of a font family.
      See Also:
    • TIMES_ROMAN

      public static final int TIMES_ROMAN
      a possible value of a font family.
      See Also:
    • SYMBOL

      public static final int SYMBOL
      a possible value of a font family.
      See Also:
    • ZAPFDINGBATS

      public static final int ZAPFDINGBATS
      a possible value of a font family.
      See Also:
    • NORMAL

      public static final int NORMAL
      this is a possible style.
      See Also:
    • BOLD

      public static final int BOLD
      this is a possible style.
      See Also:
    • ITALIC

      public static final int ITALIC
      this is a possible style.
      See Also:
    • UNDERLINE

      public static final int UNDERLINE
      this is a possible style.
      See Also:
    • STRIKETHRU

      public static final int STRIKETHRU
      this is a possible style.
      See Also:
    • UNDEFINED

      public static final int UNDEFINED
      the value of an undefined attribute.
      See Also:
  • Constructor Details

    • 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, Color 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 Color of this font.
    • Font

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

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

      public Font()
      Constructs a Font.
  • Method Details

    • compareTo

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

      public int 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.
    • 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
    • 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 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(String style)
      Sets the style using a String containing one of more of the following values: normal, bold, italic, underline, strike.
      Parameters:
      style - A String representing a certain style.
    • getColor

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

      public void setColor(Color color)
      Sets the color.
      Parameters:
      color - the new color of the font
    • 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