Class AbstractFont
- java.lang.Object
-
- com.day.image.font.AbstractFont
-
- Direct Known Subclasses:
Font
public abstract class AbstractFont extends java.lang.Object
TheAbstractFont
class provides base class for font extensions with some static helper methods and access to theFontHelper
and the systemTicket
to access the ContentBus to its extensions.This class cannot be initialized if the
FontHelper
and/or the systemTicket
are not available.- Since:
- degu
-
-
Field Summary
Fields Modifier and Type Field Description static int
ALIGN_BASE
The base line alignment constant.static int
ALIGN_BOTTOM
The bottom alignment constant.static int
ALIGN_CENTER
The center alignment constant.static int
ALIGN_FULL
The full justification alignment constant.static int
ALIGN_HBASE
The vertical alignment flags mask.static int
ALIGN_LEFT
The left alignment constant.static int
ALIGN_RIGHT
The right alignment constant.static int
ALIGN_TOP
The top alignment constant.static int
ALIGN_VBASE
The vertical alignment flags mask.static int
BOLD
Request bold font stylestatic int
DRAW_OUTLINE
The draw the character outline constant instructs the font renderer to draw the texts outline and not fill it.static int
DRAW_STRIKEOUT
The strikeout style constant.static int
DRAW_UNDERLINE
The underline style constant.static int
DRAWBASE
The text drawing style flags.static int
ITALIC
Request italic font stylestatic int
PLAIN
Request plain font style (default)static int
ROT180
The 180� (clockwise) rotation constant.static int
ROT270
The 270� (clockwise) rotation constant.static int
ROT90
The 90� (clockwise) rotation constant.static int
ROTBASE
The rotation flags mask.static int
ROTODD
The odd (?) rotation constant.static int
STRIKEOUT
The strikeout style constant.static int
TTANTIALIASED
The antialiased font rendering constant.static int
TTBASE
The TrueType flags maskstatic int
TTFONTERLINESPACING
The old line spacing constant.static int
TTFONTERSCALE
The old fonter scaling constant.static int
TTHINTED
The hinting font rendering constant.static int
TTOVERSAMPLING
The oversampling font rendering constant.static int
TTUNHINTED
Deprecated.since cq3static int
UNDERLINE
The underline style constant.
-
Constructor Summary
Constructors Constructor Description AbstractFont()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract boolean
canDisplay(char c)
Checks if this Font has a glyph for the specified character.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.abstract int
canDisplayUpTo(java.lang.String str)
Indicates whether or not this Font can display a specified String.abstract int
canDisplayUpTo(java.text.CharacterIterator iter, int start, int limit)
Indicates whether or not this Font can display the specified String.static java.lang.String
createFontFileName(java.lang.String faceName, int size, int style)
Constructs and returns a font file name from the font face name, size and style indication.abstract int
drawText(Layer layer, int x, int y, int width, int height, java.lang.String text, java.awt.Paint paint, java.awt.Stroke stroke, int align, double cs, int ls)
Render the given text string in the given font to theLayer
using the attributes given.abstract double
getAscent()
Returns the ascent of thisFont
object, which is the maximal value any glyph of this font ascends above the base line.abstract java.awt.Font
getAwtFont()
abstract double
getDescent()
Returns the descent of thisFont
object, which is the maximal value any glyph of this font descends below the base line.abstract double
getHeight()
Returns the calculated font height in pixels.abstract java.awt.geom.Rectangle2D
getTextExtent(int x, int y, int width, int height, java.lang.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 int
stringToStyle(java.lang.String style)
Converts the font style code to a string.static java.lang.String
styleToDescription(int style)
Converts the numeric font style code to a descriptive string.static java.lang.String
styleToString(int style)
Converts the numeric font style code to a string usable for the font name identification.abstract java.lang.String
toString()
Returns aString
representation of this object containing the font name, the size and style flags.
-
-
-
Field Detail
-
PLAIN
public static final int PLAIN
Request plain font style (default)- See Also:
- Constant Field Values
-
BOLD
public static final int BOLD
Request bold font style- See Also:
- Constant Field Values
-
ITALIC
public static final int ITALIC
Request italic font style- See Also:
- Constant Field Values
-
UNDERLINE
public static final int UNDERLINE
The 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:
- Constant Field Values
-
STRIKEOUT
public static final int STRIKEOUT
The 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:
- Constant Field Values
-
TTFONTERSCALE
public static final int TTFONTERSCALE
The old fonter scaling constant. Set this constant to change the scaling of fonts from the old 72dpi to the default 96dpi.- See Also:
- Constant Field Values
-
TTFONTERLINESPACING
public static final int TTFONTERLINESPACING
The 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:
- Constant Field Values
-
ALIGN_VBASE
public static final int ALIGN_VBASE
The vertical alignment flags mask.- See Also:
- Constant Field Values
-
ALIGN_TOP
public static final int ALIGN_TOP
The 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:
- Constant Field Values
-
ALIGN_BASE
public static final int ALIGN_BASE
The 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:
- Constant Field Values
-
ALIGN_BOTTOM
public static final int ALIGN_BOTTOM
The 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:
- Constant Field Values
-
ALIGN_HBASE
public static final int ALIGN_HBASE
The vertical alignment flags mask.- See Also:
- Constant Field Values
-
ALIGN_LEFT
public static final int ALIGN_LEFT
The 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:
- Constant Field Values
-
ALIGN_CENTER
public static final int ALIGN_CENTER
The 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:
- Constant Field Values
-
ALIGN_RIGHT
public static final int ALIGN_RIGHT
The 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:
- Constant Field Values
-
ALIGN_FULL
public static final int ALIGN_FULL
The 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:
- Constant Field Values
-
ROTBASE
public static final int ROTBASE
The rotation flags mask.- See Also:
- Constant Field Values
-
ROTODD
public static final int ROTODD
The 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:
- Constant Field Values
-
ROT90
public static final int ROT90
The 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:
- Constant Field Values
-
ROT270
public static final int ROT270
The 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:
- Constant Field Values
-
ROT180
public static final int ROT180
The 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:
- Constant Field Values
-
DRAWBASE
public static final int DRAWBASE
The text drawing style flags.- See Also:
- Constant Field Values
-
DRAW_UNDERLINE
public static final int DRAW_UNDERLINE
The 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:
- Constant Field Values
-
DRAW_STRIKEOUT
public static final int DRAW_STRIKEOUT
The 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:
- Constant Field Values
-
DRAW_OUTLINE
public static final int DRAW_OUTLINE
The 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:
- Constant Field Values
-
TTBASE
public static final int TTBASE
The TrueType flags mask- See Also:
- Constant Field Values
-
TTANTIALIASED
public static final int TTANTIALIASED
The 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:
- Constant Field Values
-
TTHINTED
public static final int TTHINTED
The 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:
- Constant Field Values
-
TTOVERSAMPLING
public static final int TTOVERSAMPLING
The 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
#setOversamplingFactor(int)
method and has a default value of 16.- See Also:
drawText(Layer, int, int, int, int, String, Paint, Stroke, int, double, int)
,#getOversamplingFactor()
,#setOversamplingFactor(int)
, Constant Field Values
-
TTUNHINTED
@Deprecated public static final int 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:
- Constant Field Values
-
-
Method Detail
-
createFontFileName
public static java.lang.String createFontFileName(java.lang.String faceName, int size, int style)
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
public static java.lang.String styleToDescription(int style)
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
public static java.lang.String styleToString(int style)
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
public static int stringToStyle(java.lang.String style)
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 java.awt.geom.Rectangle2D getTextExtent(int x, int y, int width, int height, java.lang.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_LEFT
as 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, java.lang.String text, java.awt.Paint paint, java.awt.Stroke stroke, int align, double cs, int ls)
Render the given text string in the given font to theLayer
using 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
- ThePaint
to use for the text drawing.stroke
- TheStroke
to use for the text drawing.align
- alignment, rotation and TrueType attributes for the text. UseFont#ALIGN_LEFT
as 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:
- 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 thisFont
object, 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 thisFont
object, 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:
true
if this Font can display the character;false
otherwise.
-
canDisplayUpTo
public abstract int canDisplayUpTo(java.text.CharacterIterator iter, int start, int limit)
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
public abstract int canDisplayUpTo(java.lang.String str)
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
public abstract java.lang.String toString()
Returns aString
representation of this object containing the font name, the size and style flags.- Overrides:
toString
in classjava.lang.Object
- Returns:
- A
String
representation of this object.
-
getAwtFont
public abstract java.awt.Font getAwtFont()
-
-