Class FontInfo

  • All Implemented Interfaces:
    IFontInfo

    public class FontInfo
    extends java.lang.Object
    implements IFontInfo
    Font information class for the UI. The values are the styles that govern the font information and contains the font family, weight, style and line height.
    Author:
    Christopher Mindus
    • Constructor Summary

      Constructors 
      ConstructorDescription
      FontInfo​(java.lang.String family, java.lang.String size)
      Constructor from family and size.
      FontInfo​(java.lang.String family, java.lang.String size, java.lang.String weight, java.lang.String style, java.lang.String lineHeight, java.lang.String letterSpacing)
      Constructor from discrete values.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and TypeMethodDescription
      booleanequals​(java.lang.Object o)
      If two font informations are equal.
      static FontInfofrom​(UIComp comp)
      Gets the font information from a component.
      static FontInfofrom​(UIComp comp, boolean recurseParents)
      Gets the font information from a component.
      doublegetAverageWidth()
      Gets the font average character width.
      doublegetEM()
      Gets the EM size.
      doublegetEX()
      Gets the EX size.
      java.lang.StringgetFamily()
      The font family, null for default.
      doublegetHeight()
      Gets the font height.
      doublegetInputCharWidth()
      Gets the input character width used in calculations of HTML elements that are "input" tag based.
      java.lang.StringgetLetterSpacing()
      Letter spacing as in CSS, null for default.
      java.lang.StringgetLineHeight()
      Line height as in CSS, null for default.
      doublegetLineHeightPX()
      Gets the line height in pixels.
      doublegetMaxWidth()
      Gets the maximum character width.
      doublegetPT()
      Gets the PT size.
      java.lang.StringgetSize()
      The font size with unit as in CSS, e.g.
      intgetStringWidth​(KString text)
      Gets the string width of the specified unwrapped string (no line breaks).
      java.lang.StringgetStyle()
      The font style as in CSS, e.g.
      java.lang.StringgetWeight()
      The font weight as in CSS, e.g.
      inthashCode()
      The hash code.
      static voidinitialize()
      Initializes the resolver.
      static voidshutdown()
      Shuts down the instance, saves current data in workspace properties.
      java.lang.StringtoString()
      Debug output string.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • DEFAULT_DESKTOP

        public static final FontInfo DEFAULT_DESKTOP
        The default font information for desktop.
      • DEFAULT_MOBILE

        public static final FontInfo DEFAULT_MOBILE
        The default font information for mobile.
      • DEFAULT_WINDOWS_MOBILE

        public static final FontInfo DEFAULT_WINDOWS_MOBILE
        The default font information for Windows Mobile.
    • Constructor Detail

      • FontInfo

        public FontInfo​(java.lang.String family,
                        java.lang.String size)
        Constructor from family and size.
        Parameters:
        family - Font family, null for default.
        size - Font size with unit as in CSS, e.g. 12px, 110% or 14pt, null for default.
      • FontInfo

        public FontInfo​(java.lang.String family,
                        java.lang.String size,
                        java.lang.String weight,
                        java.lang.String style,
                        java.lang.String lineHeight,
                        java.lang.String letterSpacing)
        Constructor from discrete values.
        Parameters:
        family - Font family, null for default.
        size - Font size with unit as in CSS, e.g. 12px, 110% or 14pt, null for default.
        weight - Font weight as in CSS, e.g. bold, thin or 800, null for default.
        style - Font style as in CSS, e.g. italic or oblique, null for default.
        lineHeight - Line height as in CSS, null for default.
        letterSpacing - Letter spacing as in CSS, null for default.
    • Method Detail

      • initialize

        public static void initialize()
        Initializes the resolver.
      • shutdown

        public static void shutdown()
        Shuts down the instance, saves current data in workspace properties.
      • from

        public static FontInfo from​(UIComp comp)
        Gets the font information from a component.

        The font information is extracted from the component's styles and/or the parents of the component.

        Returns:
        The font information.
      • from

        public static FontInfo from​(UIComp comp,
                                    boolean recurseParents)
        Gets the font information from a component.

        The font information is extracted from the component's styles and/or the parents of the component.

        Parameters:
        comp - The component.
        recurseParents - The recurse flag, if the parent(s) should be requested to fill in missing/inherited values.
        Returns:
        The font information.
      • getFamily

        public java.lang.String getFamily()
        The font family, null for default.
        Specified by:
        getFamily in interface IFontInfo
        Returns:
        The family name, null for default.
      • getSize

        public java.lang.String getSize()
        The font size with unit as in CSS, e.g. 12px, 110% or 14pt, null for default.
        Specified by:
        getSize in interface IFontInfo
        Returns:
        e.g. 12px, 110% or 14pt, null for default.
      • getWeight

        public java.lang.String getWeight()
        The font weight as in CSS, e.g. bold, thin or 800, null for default.
        Specified by:
        getWeight in interface IFontInfo
        Returns:
        e.g. bold, thin or 800, null for default.
      • getStyle

        public java.lang.String getStyle()
        The font style as in CSS, e.g. italic or oblique, null for default.
        Specified by:
        getStyle in interface IFontInfo
        Returns:
        e.g. italic or oblique, null for default.
      • getLineHeight

        public java.lang.String getLineHeight()
        Line height as in CSS, null for default.
        Specified by:
        getLineHeight in interface IFontInfo
        Returns:
        Line height, null for default.
      • getLetterSpacing

        public java.lang.String getLetterSpacing()
        Letter spacing as in CSS, null for default.
        Specified by:
        getLetterSpacing in interface IFontInfo
        Returns:
        Letter spacing, null for default.
      • equals

        public boolean equals​(java.lang.Object o)
        If two font informations are equal.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        o - The other object to compare with.
        Returns:
        The equals flag.
      • hashCode

        public int hashCode()
        The hash code.
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Debug output string.
        Overrides:
        toString in class java.lang.Object
      • getHeight

        public double getHeight()
        Gets the font height.
        Specified by:
        getHeight in interface IFontInfo
        Returns:
        The font height.
      • getMaxWidth

        public double getMaxWidth()
        Gets the maximum character width.
      • getAverageWidth

        public double getAverageWidth()
        Gets the font average character width.
        Specified by:
        getAverageWidth in interface IFontInfo
        Returns:
        The average width.
      • getEM

        public double getEM()
        Gets the EM size.
        Specified by:
        getEM in interface IFontInfo
        Returns:
        EM size.
      • getEX

        public double getEX()
        Gets the EX size.
        Specified by:
        getEX in interface IFontInfo
        Returns:
        EX size.
      • getPT

        public double getPT()
        Gets the PT size.
        Specified by:
        getPT in interface IFontInfo
        Returns:
        The point size.
      • getInputCharWidth

        public double getInputCharWidth()
        Gets the input character width used in calculations of HTML elements that are "input" tag based.
        Specified by:
        getInputCharWidth in interface IFontInfo
        Returns:
        The input character width.
      • getLineHeightPX

        public double getLineHeightPX()
        Gets the line height in pixels.
      • getStringWidth

        public int getStringWidth​(KString text)
        Gets the string width of the specified unwrapped string (no line breaks).
        Specified by:
        getStringWidth in interface IFontInfo
        Parameters:
        text - The text to measure.
        Returns:
        The width in pixels in the current font.