Class SwingFontUtil

java.lang.Object
com.dua3.utility.swing.SwingFontUtil
All Implemented Interfaces:
com.dua3.utility.text.FontUtil<Font>

public class SwingFontUtil extends Object implements com.dua3.utility.text.FontUtil<Font>
Utility class for getting font properties through AWT. This class should normally not used directly by user code as the functionality should be available in the TextUtil utility class which in turn uses this class via SPI (Java ServiceProvider interface). See usage of FontUtil in TextUtil for details.
  • Constructor Details

    • SwingFontUtil

      public SwingFontUtil()
  • Method Details

    • stringBounds

      public Rectangle2D stringBounds​(CharSequence text, com.dua3.utility.text.Font font)
      Calculate the string bounds of a text using the font passed as argument.
      Parameters:
      text - the text
      font - the font
      Returns:
      the text's bounds (positioned at the origin)
    • stringBounds

      public Rectangle2D stringBounds​(CharSequence text, Font awtFont)
      Calculate the string bounds of a text using the font passed as argument.
      Parameters:
      text - the text
      awtFont - the font
      Returns:
      the text's bounds (positioned at the origin)
    • getTextBounds

      public com.dua3.utility.text.FontUtil.Bounds getTextBounds​(CharSequence text, Font awtFont)
      Calculate the string bounds of a text using the font passed as argument.
      Parameters:
      text - the text
      awtFont - the font
      Returns:
      the text's bounds (positioned at the origin)
    • getTextHeight

      public double getTextHeight​(CharSequence text, Font awtFont)
      Calculate the height of a text using the font passed as argument.
      Parameters:
      text - the text
      awtFont - the font
      Returns:
      the text's bounds (positioned at the origin)
    • getTextWidth

      public double getTextWidth​(CharSequence text, Font awtFont)
      Calculate the width of a text using the font passed as argument.
      Parameters:
      text - the text
      awtFont - the font
      Returns:
      the text's bounds (positioned at the origin)
    • getTextBounds

      public com.dua3.utility.text.FontUtil.Bounds getTextBounds​(CharSequence s, com.dua3.utility.text.Font f)
      Specified by:
      getTextBounds in interface com.dua3.utility.text.FontUtil<Font>
    • getTextHeight

      public double getTextHeight​(CharSequence s, com.dua3.utility.text.Font f)
      Specified by:
      getTextHeight in interface com.dua3.utility.text.FontUtil<Font>
    • loadFont

      public Optional<com.dua3.utility.text.Font> loadFont​(String type, InputStream in) throws IOException
      Specified by:
      loadFont in interface com.dua3.utility.text.FontUtil<Font>
      Throws:
      IOException
    • getTextWidth

      public double getTextWidth​(CharSequence s, com.dua3.utility.text.Font f)
      Specified by:
      getTextWidth in interface com.dua3.utility.text.FontUtil<Font>
    • convert

      public Font convert​(com.dua3.utility.text.Font font)
      Specified by:
      convert in interface com.dua3.utility.text.FontUtil<Font>