Class AbstractFont
- Direct Known Subclasses:
Font
AbstractFont class provides base class for font extensions
with some static helper methods and access to the FontHelper
and the system
invalid reference
Ticket
This class cannot be initialized if the FontHelper and/or the
system
invalid reference
Ticket
- Since:
- degu
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe base line alignment constant.static final intThe bottom alignment constant.static final intThe center alignment constant.static final intThe full justification alignment constant.static final intThe vertical alignment flags mask.static final intThe left alignment constant.static final intThe right alignment constant.static final intThe top alignment constant.static final intThe vertical alignment flags mask.static final intRequest bold font stylestatic final intThe draw the character outline constant instructs the font renderer to draw the texts outline and not fill it.static final intThe strikeout style constant.static final intThe underline style constant.static final intThe text drawing style flags.static final intRequest italic font stylestatic final intRequest plain font style (default)static final intThe 180� (clockwise) rotation constant.static final intThe 270� (clockwise) rotation constant.static final intThe 90� (clockwise) rotation constant.static final intThe rotation flags mask.static final intThe odd (?) rotation constant.static final intThe strikeout style constant.static final intThe antialiased font rendering constant.static final intThe TrueType flags maskstatic final intThe old line spacing constant.static final intThe old fonter scaling constant.static final intThe hinting font rendering constant.static final intThe oversampling font rendering constant.static final intDeprecated.since cq3static final intThe underline style constant. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract booleancanDisplay(char c) Checks if this Font has a glyph for the specified character.abstract intcanDisplayUpTo(char[] text, int start, int limit) Indicates whether or not this Font can display the characters in the specified text starting at start and ending at limit.abstract intcanDisplayUpTo(String str) Indicates whether or not this Font can display a specified String.abstract intcanDisplayUpTo(CharacterIterator iter, int start, int limit) Indicates whether or not this Font can display the specified String.static StringcreateFontFileName(String faceName, int size, int style) Constructs and returns a font file name from the font face name, size and style indication.abstract intdrawText(Layer layer, int x, int y, int width, int height, String text, Paint paint, Stroke stroke, int align, double cs, int ls) Render the given text string in the given font to theLayerusing the attributes given.abstract doubleReturns the ascent of thisFontobject, which is the maximal value any glyph of this font ascends above the base line.abstract Fontabstract doubleReturns the descent of thisFontobject, which is the maximal value any glyph of this font descends below the base line.abstract doubleReturns the calculated font height in pixels.abstract Rectangle2DgetTextExtent(int x, int y, int width, int height, String text, int align, double cs, int ls) Calculate the bounding box of the text, if it would be rendered with the rendering attributes given.static intstringToStyle(String style) Converts the font style code to a string.static StringstyleToDescription(int style) Converts the numeric font style code to a descriptive string.static StringstyleToString(int style) Converts the numeric font style code to a string usable for the font name identification.abstract StringtoString()Returns aStringrepresentation of this object containing the font name, the size and style flags.
-
Field Details
-
PLAIN
public static final int PLAINRequest plain font style (default)- See Also:
-
BOLD
public static final int BOLDRequest bold font style- See Also:
-
ITALIC
public static final int ITALICRequest italic font style- See Also:
-
UNDERLINE
public static final int UNDERLINEThe underline style constant. This can be combined with the other style constants (except PLAIN) for mixed styles.Underlining in Java2D is a property of drawing text and not a font style. Thus this constant is valid for any font you choose and takes effect when drawing text - and it works.
- See Also:
-
STRIKEOUT
public static final int STRIKEOUTThe strikeout style constant. This can be combined with the other style constants (except PLAIN) for mixed styles.Striekout in Java2D is a property of drawing text and not a font style. Thus this constant is valid for any font you choose and takes effect when drawing text - and it works.
- See Also:
-
TTFONTERSCALE
public static final int TTFONTERSCALEThe old fonter scaling constant. Set this constant to change the scaling of fonts from the old 72dpi to the default 96dpi.- See Also:
-
TTFONTERLINESPACING
public static final int TTFONTERLINESPACINGThe old line spacing constant. Set this constant to use the new line spacing values instead of the old line spacing values, which tend to be somewhat bigger, than what is intended in the TrueType standard.- See Also:
-
ALIGN_VBASE
public static final int ALIGN_VBASEThe vertical alignment flags mask.- See Also:
-
ALIGN_TOP
public static final int ALIGN_TOPThe top alignment constant. This can be combined with any one of the horizontal alignment and rotation constants to get mixed alignment/rotation style.- See Also:
-
ALIGN_BASE
public static final int ALIGN_BASEThe base line alignment constant. This can be combined with any one of the horizontal alignment and rotation constants to get mixed alignment/rotation style.- See Also:
-
ALIGN_BOTTOM
public static final int ALIGN_BOTTOMThe bottom alignment constant. This can be combined with any one of the horizontal alignment and rotation constants to get mixed alignment/rotation style.- See Also:
-
ALIGN_HBASE
public static final int ALIGN_HBASEThe vertical alignment flags mask.- See Also:
-
ALIGN_LEFT
public static final int ALIGN_LEFTThe left alignment constant. This can be combined with any one of the vertical alignment and rotation constants to get mixed alignment/rotation style.- See Also:
-
ALIGN_CENTER
public static final int ALIGN_CENTERThe center alignment constant. This can be combined with any one of the vertical alignment and rotation constants to get mixed alignment/rotation style.- See Also:
-
ALIGN_RIGHT
public static final int ALIGN_RIGHTThe right alignment constant. This can be combined with any one of the vertical alignment and rotation constants to get mixed alignment/rotation style.- See Also:
-
ALIGN_FULL
public static final int ALIGN_FULLThe full justification alignment constant. This can be combined with any one of the vertical alignment and rotation constants to get mixed alignment/rotation style.- See Also:
-
ROTBASE
public static final int ROTBASEThe rotation flags mask.- See Also:
-
ROTODD
public static final int ROTODDThe odd (?) rotation constant. This can be combined with any one of the vertical and horizontal alignment constants to get mixed alignment/rotation style.- See Also:
-
ROT90
public static final int ROT90The 90� (clockwise) rotation constant. This can be combined with any one of the vertical and horizontal alignment constants to get mixed alignment/rotation style.- See Also:
-
ROT270
public static final int ROT270The 270� (clockwise) rotation constant. This can be combined with any one of the vertical and horizontal alignment constants to get mixed alignment/rotation style.- See Also:
-
ROT180
public static final int ROT180The 180� (clockwise) rotation constant. This can be combined with any one of the vertical and horizontal alignment constants to get mixed alignment/rotation style.- See Also:
-
DRAWBASE
public static final int DRAWBASEThe text drawing style flags.- See Also:
-
DRAW_UNDERLINE
public static final int DRAW_UNDERLINEThe underline style constant. This can be combined with the other style constants (except PLAIN) for mixed styles.Underlining in Java2D is a property of drawing text and not a font style. Thus this constant is valid for any font you choose and takes effect when drawing text - and it works.
- See Also:
-
DRAW_STRIKEOUT
public static final int DRAW_STRIKEOUTThe strikeout style constant. This can be combined with the other style constants (except PLAIN) for mixed styles.Striekout in Java2D is a property of drawing text and not a font style. Thus this constant is valid for any font you choose and takes effect when drawing text - and it works.
- See Also:
-
DRAW_OUTLINE
public static final int DRAW_OUTLINEThe draw the character outline constant instructs the font renderer to draw the texts outline and not fill it. Default is filling the outline. This can be combined with any one of the vertical and horizontal alignment and rotation constants to get mixed alignment/rotation style.- See Also:
-
TTBASE
public static final int TTBASEThe TrueType flags mask- See Also:
-
TTANTIALIASED
public static final int TTANTIALIASEDThe antialiased font rendering constant. This can be combined with any one of the vertical and horizontal alignment and rotation constants to get mixed alignment/rotation style.- See Also:
-
TTHINTED
public static final int TTHINTEDThe hinting font rendering constant. This can be combined with any one of the vertical and horizontal alignment and rotation constants to get mixed alignment/rotation style.- See Also:
-
TTOVERSAMPLING
public static final int TTOVERSAMPLINGThe oversampling font rendering constant. This can be combined with any one of the vertical and horizontal alignment and rotation constants to get mixed alignment/rotation style.By popular demand font oversampling has been added again. For this reason this flag is not deprecated any more.
The factor applied to the text being drawn is set by the
method and has a default value of 16.invalid reference
#setOversamplingFactor(int)- See Also:
-
TTUNHINTED
Deprecated.since cq3The 'do-not-hint' font rendering constant. This can be combined with any one of the vertical and horizontal alignment and rotation constants to get mixed alignment/rotation style.- See Also:
-
-
Constructor Details
-
AbstractFont
public AbstractFont()
-
-
Method Details
-
createFontFileName
Constructs and returns a font file name from the font face name, size and style indication. The file name consists of the face name converted to lower case and blanks replaced by underscores appending the size and style converted to a string withstyleToString(int).Example : The font Times New Romain, size 12, style bold/italic has the font file name times_new_roman12bi.
- Parameters:
faceName- The font face namesize- The size of the fontstyle- The style flags of the fon- Returns:
- The valid font file name
-
styleToDescription
Converts the numeric font style code to a descriptive string.- Parameters:
style- The numeric font style- Returns:
- The descriptive string representation of the font style
-
styleToString
Converts the numeric font style code to a string usable for the font name identification.- Parameters:
style- The numeric font style- Returns:
- The string representation of the font style
-
stringToStyle
Converts the font style code to a string.- Parameters:
style- The string representation of the font style- Returns:
- The numeric font style code.
-
getTextExtent
public abstract Rectangle2D getTextExtent(int x, int y, int width, int height, String text, int align, double cs, int ls) Calculate the bounding box of the text, if it would be rendered with the rendering attributes given. The calculation will be done as if the text would be rendered in the current font object.If the width of the text box is set to some value other than zero, the text is broken to fit lines of the given length. The line breaking algorithm breaking algorithm breaks on whitespace (blank, tab), carriage return and linefeed (CR/LF) in any combination as well as on other characters such as hyphens.
If the text contains carriage return and/or linefeed characters, the text is broken into several lines, regardless of whether the text would be broken because of the text box width setting.
- Parameters:
x- left edge of the text box, requiredy- top edge of the text box, requiredwidth- maximum width of the textbox. If 0 (or negative) the width of the bounding box is dependent of the rendering attributesheight- maximum height of the textbox. If 0 (or negative) the width of the bounding box is dependent of the rendering attributestext- the text string to calculate the bounding box foralign- alignment, rotation and TrueType attributes for the text. UseALIGN_LEFTas default value.cs- extra intercharacter spacing. Use 0 as default value to not add additional space.ls- extra line spacing. Use 0 as default value to not add additional space.- Returns:
- returns a rectangle representing the bounding box, if the text would be rendered in this font using the given additional rendering attributes.
-
drawText
public abstract int drawText(Layer layer, int x, int y, int width, int height, String text, Paint paint, Stroke stroke, int align, double cs, int ls) Render the given text string in the given font to theLayerusing the attributes given. Use the default values given for unspecified values.If the width of the text box is set to some value other than zero, the text is broken to fit lines of the given length. The line breaking algorithm breaking algorithm breaks on whitespace (blank, tab), carriage return and linefeed (CR/LF) in any combination as well as on other characters such as hyphens.
If the text contains carriage return and/or linefeed characters, the text is broken into several lines, regardless of whether the text would be broken because of the text box width setting.
- Parameters:
layer- the layer to draw the text intox- left edge of the text box, requiredy- top edge of the text box, requiredwidth- maximum width of the textbox. If 0 (or negative) the width of the bounding box is dependent of the rendering attributesheight- maximum height of the textbox. If 0 (or negative) the width of the bounding box is dependent of the rendering attributestext- the text string to calculate the bounding box forpaint- ThePaintto use for the text drawing.stroke- TheStroketo use for the text drawing.align- alignment, rotation and TrueType attributes for the text. Useas default value.invalid reference
Font#ALIGN_LEFTcs- extra intercharacter spacing. Use 0 as default value to not add additional space.ls- extra line spacing. Use 0 as default value to not add additional space.- Returns:
- the number of text lines drawn to the layer
-
getHeight
public abstract double getHeight()Returns the calculated font height in pixels.- Returns:
- the calculated font height in pixels.
-
getAscent
public abstract double getAscent()Returns the ascent of thisFontobject, which is the maximal value any glyph of this font ascends above the base line.- Returns:
- The ascent of this
Font.
-
getDescent
public abstract double getDescent()Returns the descent of thisFontobject, which is the maximal value any glyph of this font descends below the base line.- Returns:
- The ascent of this
Font.
-
canDisplay
public abstract boolean canDisplay(char c) Checks if this Font has a glyph for the specified character.- Parameters:
c- a unicode character code- Returns:
trueif this Font can display the character;falseotherwise.
-
canDisplayUpTo
Indicates whether or not this Font can display the specified String. For strings with Unicode encoding, it is important to know if a particular font can display the string. This method returns an offset into the String str which is the first character this Font cannot display without using the missing glyph code . If this Font can display all characters, -1 is returned.- Parameters:
iter- a CharacterIterator objectstart- the specified starting offset into the specified array of characterslimit- the specified ending offset into the specified array of characters- Returns:
- an offset into the String object that can be displayed by this Font.
-
canDisplayUpTo
Indicates whether or not this Font can display a specified String. For strings with Unicode encoding, it is important to know if a particular font can display the string. This method returns an offset into the String str which is the first character this Font cannot display without using the missing glyph code. If the Font can display all characters, -1 is returned.- Parameters:
str- a String object- Returns:
- an offset into str that points to the first character in str that this Font cannot display; or -1 if this Font can display all characters in str.
-
canDisplayUpTo
public abstract int canDisplayUpTo(char[] text, int start, int limit) Indicates whether or not this Font can display the characters in the specified text starting at start and ending at limit. This method is a convenience overload.- Parameters:
text- the specified array of charactersstart- the specified starting offset into the specified array of characterslimit- the specified ending offset into the specified array of characters- Returns:
- an offset into text that points to the first character in text that this Font cannot display; or -1 if this Font can display all characters in text.
-
toString
Returns aStringrepresentation of this object containing the font name, the size and style flags. -
getAwtFont
-