Package snap.gfx
Class Font
java.lang.Object
snap.props.PropObject
snap.gfx.Font
- All Implemented Interfaces:
PropChange.DoChange
,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 Summary
Modifier and TypeFieldDescriptionstatic Font
static Font
static Font
static Font
static Font
static Font
static final String
static final String
Fields inherited from class snap.props.PropObject
_pcs, EMPTY_OBJECT
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
canDisplay
(char aChar) Returns if this font can display the given char.double
charAdvance
(char aChar) Returns the char advance for the given char.copyForScale
(double aScale) Returns a font with the same family as the receiver but with size adjusted by given scale factor.copyForSize
(double aPointSize) Returns a font with the same family as the receiver but with the given size.boolean
Standard equals implementation.fromXML
(XMLArchiver anArchiver, XMLElement anElement) XML unarchival.double
Returns the max distance above the baseline that this font goes.getBold()
Returns the bold version of this font.double
getCharAdvance
(char aChar, boolean isFractional) Returns the char advance for a given character.getCharBounds
(char aChar) Returns the bounds for a given character.double
getCharKern
(char aChar1, char aChar2) Returns the kerning for the given pair of characters (no way to do this in Java!).getCharPath
(char aChar) Returns the path for a given character.static Font
Returns a good code font (at 12 pt).static Font
getCodeFontForSize
(double pointSize) Returns a good code font at given point size.static Font
Returns the user's default font.double
Returns the max distance below the baseline that this font goes.Returns the family name of this font.Returns the family name of this font in English.static String[]
Returns a list of all system family names.static Font
Returns the font for the given name and size.Returns the font file for this font.static String[]
Returns a list of all system font names.static String[]
getFontNames
(String aFamilyName) Returns a list of all font names for a given family name.getGlyphBounds
(String aString) Returns the bounds rect for glyphs in given string.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.getName()
Returns the name of this font.Returns the name of this font in English.Returns the native version of this font.getOutline
(CharSequence aStr, double aX, double aY, double aCharSpace) Returns the path for given string with character spacing.getPropValue
(String aPropName) Override to support props for this class.Returns the PostScript name of this font.double
getSize()
Returns the font size of this font.double
Returns the distance above the baseline that a strikethrough should be drawn.double
getStringAdvance
(String aString) Returns the horizontal distance spanned by the given string when rendered in this font.getStringBounds
(String aString) Returns the bounds rect for given string.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
hashCode()
Standard hashcode implementation.protected void
Override to support props for this class.boolean
isBold()
Returns whether this font is considered bold.boolean
isItalic()
Returns whether this font is considered italic.boolean
Returns whether font had to substitute because name wasn't found.static Font
Tries to return a font from given object.toString()
Returns the font name, size and family for this font.toXML
(XMLArchiver anArchiver) XML archival.Methods inherited from class snap.props.PropObject
addDeepChangeListener, addPropChangeListener, addPropChangeListener, clone, firePropChange, firePropChange, firePropChange, getPropDefault, getPropForName, getPropParent, getPropSet, getPropsForArchival, getPropsForArchivalExtra, getPropsString, isPropDefault, processPropChange, removeDeepChangeListener, removePropChangeListener, removePropChangeListener, setPropsString, setPropValue, setPropValues, toStringProps
-
Field Details
-
Name_Prop
- See Also:
-
Size_Prop
- See Also:
-
Arial10
-
Arial11
-
Arial12
-
Arial13
-
Arial14
-
Arial16
-
-
Constructor Details
-
Font
public Font()Constructor (really only used for unarchival). -
Font
Constructor for given font file and point size. -
Font
Constructor for given name and size.
-
-
Method Details
-
getName
Returns the name of this font. -
getNameEnglish
Returns the name of this font in English. -
getSize
public double getSize()Returns the font size of this font. -
getFamily
Returns the family name of this font. -
getFamilyEnglish
Returns the family name of this font in English. -
getPSName
Returns the PostScript name of this font. -
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
Returns the path for a given character. -
getCharBounds
Returns the bounds for a given character. -
getStringAdvance
Returns the horizontal distance spanned by the given string when rendered in this font. -
getStringBounds
Returns the bounds rect for given string. -
getGlyphBounds
Returns the bounds rect for glyphs in given string. -
getOutline
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
Returns the bold version of this font. -
getItalic
Returns the italic version of this font. -
copyForSize
Returns a font with the same family as the receiver but with the given size. -
copyForScale
Returns a font with the same family as the receiver but with size adjusted by given scale factor. -
equals
Standard equals implementation. -
hashCode
public int hashCode()Standard hashcode implementation. -
initProps
Override to support props for this class.- Overrides:
initProps
in classPropObject
-
getPropValue
Override to support props for this class.- Overrides:
getPropValue
in classPropObject
-
toXML
XML archival.- Specified by:
toXML
in interfaceXMLArchiver.Archivable
-
fromXML
XML unarchival.- Specified by:
fromXML
in interfaceXMLArchiver.Archivable
-
toString
Returns the font name, size and family for this font.- Overrides:
toString
in classPropObject
-
getNative
Returns the native version of this font. -
getFont
Returns the font for the given name and size. -
getDefaultFont
Returns the user's default font. -
getCodeFont
Returns a good code font (at 12 pt). -
getCodeFontForSize
Returns a good code font at given point size. -
getFontNames
Returns a list of all system font names. -
getFamilyNames
Returns a list of all system family names. -
getFontNames
Returns a list of all font names for a given family name. -
of
Tries to return a font from given object.
-