Package snap.gfx

Class Font

All Implemented Interfaces:
PropChange.DoChange, XMLArchiver.Archivable

public class Font extends PropObject implements XMLArchiver.Archivable
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 Details

  • Constructor Details

    • Font

      public Font()
      Constructor (really only used for unarchival).
    • Font

      protected Font(FontFile aFontFile, double aPointSize)
      Constructor for given font file and point size.
    • Font

      public Font(String aName, double aSize)
      Constructor for given name and size.
  • Method Details

    • getName

      public String getName()
      Returns the name of this font.
    • getNameEnglish

      public String getNameEnglish()
      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 FontFile 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.
    • getCharKern

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

      public Shape getCharPath(char aChar)
      Returns the path for a given character.
    • getCharBounds

      public Rect getCharBounds(char aChar)
      Returns the bounds for a given character.
    • getStringAdvance

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

      public Rect getStringBounds(String aString)
      Returns the bounds rect for given string.
    • getGlyphBounds

      public Rect getGlyphBounds(String aString)
      Returns the bounds rect for glyphs in given string.
    • getOutline

      public Shape getOutline(CharSequence aStr, double aX, double aY, double aCharSpace)
      Returns the path for given string with character spacing.
    • getAscent

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

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

      public double getLeading()
      Returns the default distance between lines for 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 Font getBold()
      Returns the bold version of this font.
    • getItalic

      public Font getItalic()
      Returns the italic version of this font.
    • copyForSize

      public Font copyForSize(double aPointSize)
      Returns a font with the same family as the receiver but with the given size.
    • copyForScale

      public Font copyForScale(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
    • initProps

      protected void initProps(PropSet aPropSet)
      Override to support props for this class.
      Overrides:
      initProps in class PropObject
    • getPropValue

      public Object getPropValue(String aPropName)
      Override to support props for this class.
      Overrides:
      getPropValue in class PropObject
    • toXML

      public XMLElement toXML(XMLArchiver anArchiver)
      XML archival.
      Specified by:
      toXML in interface XMLArchiver.Archivable
    • fromXML

      public Object fromXML(XMLArchiver anArchiver, XMLElement anElement)
      XML unarchival.
      Specified by:
      fromXML in interface XMLArchiver.Archivable
    • toString

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

      public Object getNative()
      Returns the native version of this font.
    • getFont

      public static Font getFont(String aName, double aSize)
      Returns the font for the given name and size.
    • getDefaultFont

      public static Font getDefaultFont()
      Returns the user's default font.
    • getCodeFont

      public static Font getCodeFont()
      Returns a good code font (at 12 pt).
    • getCodeFontForSize

      public static Font getCodeFontForSize(double pointSize)
      Returns a good code font at given point size.
    • getFontNames

      public static String[] getFontNames()
      Returns a list of all system font names.
    • getFamilyNames

      public static String[] getFamilyNames()
      Returns a list of all system family names.
    • getFontNames

      public static String[] getFontNames(String aFamilyName)
      Returns a list of all font names for a given family name.
    • of

      public static Font of(Object anObj)
      Tries to return a font from given object.