Class SnapFont

java.lang.Object
com.inductiveautomation.snap.gfx.SnapFont

public class SnapFont extends Object
This class represents a font for use in rich text. Currently this is necessary because Java fonts are missing so much basic typographic information.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static SnapFont
     
    static SnapFont
     
    static SnapFont
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an empty font (really only used for unarchival).
    SnapFont(String aName, double aSize)
    Returns the font for the given name and size (with an option to substitute Arial if not found).
  • Method Summary

    Modifier and Type
    Method
    Description
    awt()
    Returns the awt font.
    boolean
    canDisplay(char aChar)
    Returns if this font can display the given char.
    double
    charAdvance(char aChar)
    Returns the char advance for the given char.
    double
    charKern(char aChar1, char aChar2)
    Returns the kerning for the given pair of characters (no way to do this in Java!).
    deriveFont(double aPointSize)
    Returns a font with the same family as the receiver but with the given size.
    boolean
    equals(Object anObj)
    Standard equals implementation.
    Returns the bold version of this font.
    double
    getCharAdvance(char aChar, boolean isFractional)
    Returns the char advance for a given character.
    Returns the family name of this font.
    Returns the family name of this font in English.
    Returns the font file for this font.
    Returns the name of this font.
    Returns the name of this font in English.
    double
    Returns the height of this font.
    Returns the italic version of this font.
    double
    Returns the default distance between lines for this font.
    double
    Returns the distance from the top of a line of text to the to top of a successive line of text.
    double
    Returns the height for a line of text in this font.
    double
    Returns the max distance above the baseline that this font goes.
    double
    Returns the max distance below the baseline that this font goes.
    Returns the PostScript name of this font.
    double
    Returns the font size of this font.
    double
    Returns the distance above the baseline that a strikethrough should be drawn.
    double
    Returns the distance below the baseline that an underline should be drawn.
    double
    Returns the default thickness that an underline should be drawn.
    int
    Standard hashcode implementation.
    boolean
    Returns whether this font is considered bold.
    boolean
    Returns whether this font is considered italic.
    boolean
    Returns whether font had to substitute because name wasn't found.
    scaleFont(double aScale)
    Returns a font with the same family as the receiver but with size adjusted by given scale factor.
    double
    Returns the horizontal distance spanned by the given string when rendered in this font.
    Returns the font name, size and family for this font.

    Methods inherited from class java.lang.Object

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

    • Helvetica10

      public static SnapFont Helvetica10
    • Helvetica12

      public static SnapFont Helvetica12
    • Helvetica14

      public static SnapFont Helvetica14
  • Constructor Details

    • SnapFont

      public SnapFont()
      Creates an empty font (really only used for unarchival).
    • SnapFont

      public SnapFont(String aName, double aSize)
      Returns the font for the given name and size (with an option to substitute Arial if not found).
  • Method Details

    • getFontName

      public String getFontName()
      Returns the name of this font.
    • getFontNameEnglish

      public String getFontNameEnglish()
      Returns the name of this font in English.
    • getSize

      public double getSize()
      Returns the font size of this font.
    • getFamily

      public String getFamily()
      Returns the family name of this font.
    • getFamilyEnglish

      public String getFamilyEnglish()
      Returns the family name of this font in English.
    • getPSName

      public String getPSName()
      Returns the PostScript name of this font.
    • getFontFile

      public SnapFontFile getFontFile()
      Returns the font file for this font.
    • charAdvance

      public double charAdvance(char aChar)
      Returns the char advance for the given char.
    • getCharAdvance

      public double getCharAdvance(char aChar, boolean isFractional)
      Returns the char advance for a given character.
    • charKern

      public double charKern(char aChar1, char aChar2)
      Returns the kerning for the given pair of characters (no way to do this in Java!).
    • stringAdvance

      public double stringAdvance(String aString)
      Returns the horizontal distance spanned by the given string when rendered in this font.
    • getMaxAscent

      public double getMaxAscent()
      Returns the max distance above the baseline that this font goes.
    • getMaxDescent

      public double getMaxDescent()
      Returns the max distance below the baseline that this font goes.
    • getLeading

      public double getLeading()
      Returns the default distance between lines for this font.
    • getHeight

      public double getHeight()
      Returns the height of this font.
    • getLineHeight

      public double getLineHeight()
      Returns the height for a line of text in this font.
    • getLineAdvance

      public double getLineAdvance()
      Returns the distance from the top of a line of text to the to top of a successive line of text.
    • getUnderlineOffset

      public double getUnderlineOffset()
      Returns the distance below the baseline that an underline should be drawn.
    • getUnderlineThickness

      public double getUnderlineThickness()
      Returns the default thickness that an underline should be drawn.
    • getStrikethroughOffset

      public double getStrikethroughOffset()
      Returns the distance above the baseline that a strikethrough should be drawn.
    • isBold

      public boolean isBold()
      Returns whether this font is considered bold.
    • isItalic

      public boolean isItalic()
      Returns whether this font is considered italic.
    • isSubstitute

      public boolean isSubstitute()
      Returns whether font had to substitute because name wasn't found.
    • canDisplay

      public boolean canDisplay(char aChar)
      Returns if this font can display the given char.
    • getBold

      public SnapFont getBold()
      Returns the bold version of this font.
    • getItalic

      public SnapFont getItalic()
      Returns the italic version of this font.
    • deriveFont

      public SnapFont deriveFont(double aPointSize)
      Returns a font with the same family as the receiver but with the given size.
    • scaleFont

      public SnapFont scaleFont(double aScale)
      Returns a font with the same family as the receiver but with size adjusted by given scale factor.
    • equals

      public boolean equals(Object anObj)
      Standard equals implementation.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Standard hashcode implementation.
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Returns the font name, size and family for this font.
      Overrides:
      toString in class Object
    • awt

      public Font awt()
      Returns the awt font.