Class Font

java.lang.Object
com.oorian.css.Font

public final class Font extends Object
Mutable configuration class for CSS font properties.

The Font class provides a convenient way to configure multiple font properties (family, size, weight, style, variant) as a single object. It can be constructed from individual values or parsed from a CSS string.

System Font Keywords:

Usage:


 Font font = new Font(FontFamily.ARIAL, 14, FontWeight.BOLD);
 element.setFont(font);

 // Or parse from CSS string
 Font parsed = new Font("font-family: Arial; font-size: 14pt");
 
Since:
2012
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Field Details

  • Constructor Details

    • Font

      public Font()
      Constructs a Font with default inherited values.
    • Font

      public Font(String family, String size)
      Constructs a Font with the specified family and size.
      Parameters:
      family - the font family name
      size - the font size with units
    • Font

      public Font(FontFamily family, String size)
      Constructs a Font with the specified FontFamily enum and size.
      Parameters:
      family - the font family enum value
      size - the font size with units
    • Font

      public Font(String family, float size)
      Constructs a Font with the specified family and size in points.
      Parameters:
      family - the font family name
      size - the font size in points
    • Font

      public Font(FontFamily family, float size)
      Constructs a Font with the specified FontFamily and size in points.
      Parameters:
      family - the font family enum value
      size - the font size in points
    • Font

      public Font(String family, String size, String weight)
      Constructs a Font with family, size, and weight as strings.
      Parameters:
      family - the font family name
      size - the font size with units
      weight - the font weight value
    • Font

      public Font(FontFamily family, float size, FontWeight weight)
      Constructs a Font with FontFamily, size in points, and FontWeight.
      Parameters:
      family - the font family enum value
      size - the font size in points
      weight - the font weight enum value
    • Font

      public Font(String css)
      Constructs a Font by parsing a CSS font string.

      Parses semicolon-separated CSS properties like "font-family: Arial; font-size: 14pt; font-weight: bold".

      Parameters:
      css - the CSS font property string to parse
  • Method Details

    • setFamily

      public final void setFamily(String family)
      Sets the font family by name.
      Parameters:
      family - the font family name
    • setFamily

      public final void setFamily(FontFamily family)
      Sets the font family from a FontFamily enum.
      Parameters:
      family - the font family enum value
    • setSize

      public final void setSize(String size)
      Sets the font size with units.
      Parameters:
      size - the font size with units
    • setSize

      public final void setSize(float size)
      Sets the font size in points.
      Parameters:
      size - the font size in points
    • setWeight

      public final void setWeight(String weight)
      Sets the font weight by value string.
      Parameters:
      weight - the font weight value
    • setWeight

      public final void setWeight(FontWeight weight)
      Sets the font weight from a FontWeight enum.
      Parameters:
      weight - the font weight enum value
    • setStyle

      public final void setStyle(String style)
      Sets the font style by value string.
      Parameters:
      style - the font style value
    • setStyle

      public final void setStyle(FontStyle style)
      Sets the font style from a FontStyle enum.
      Parameters:
      style - the font style enum value
    • setVariant

      public final void setVariant(String variant)
      Sets the font variant by value string.
      Parameters:
      variant - the font variant value
    • setVariant

      public final void setVariant(FontVariant variant)
      Sets the font variant from a FontVariant enum.
      Parameters:
      variant - the font variant enum value
    • getFamily

      public final String getFamily()
      Returns the font family name.
      Returns:
      the font family
    • getSize

      public final String getSize()
      Returns the font size with units.
      Returns:
      the font size
    • getWeight

      public final String getWeight()
      Returns the font weight value.
      Returns:
      the font weight
    • getVariant

      public final String getVariant()
      Returns the font variant value.
      Returns:
      the font variant
    • getStyle

      public final String getStyle()
      Returns the font style value.
      Returns:
      the font style
    • toString

      public String toString()
      Returns the CSS representation of this font configuration.
      Overrides:
      toString in class Object
      Returns:
      CSS font properties as a semicolon-separated string