public final class Font extends AbstractFont
Font class is a wrapper for the
com.day.image.Font class which provides the functionality to
seamlessly support multiple font formats and sources. All API methods are
delegated to an instance of (an extension of) the
com.day.image.Font class which is setup in the constructor.
The constructor tries a list of configured font providers to get the
delegatee and falls back to the com.day.image.Font class if
none of the configured font providers can provide the desired font.
While the list of font providers and their order is configurable, the fallback to the base class is hard coded and cannot be switched of. This way it is guaranteed, that instances of this class always contain a valid delegatee.
This class cannot be initialized if the FontHelper and/or the
system com.day.cq.contentbus.Ticket are not available.
ALIGN_BASE, ALIGN_BOTTOM, ALIGN_CENTER, ALIGN_FULL, ALIGN_HBASE, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_TOP, ALIGN_VBASE, BOLD, DRAW_OUTLINE, DRAW_STRIKEOUT, DRAW_UNDERLINE, DRAWBASE, ITALIC, PLAIN, ROT180, ROT270, ROT90, ROTBASE, ROTODD, STRIKEOUT, TTANTIALIASED, TTBASE, TTFONTERLINESPACING, TTFONTERSCALE, TTHINTED, TTOVERSAMPLING, TTUNHINTED, UNDERLINE| Constructor and Description |
|---|
Font(java.lang.String faceName,
int size)
Creates a font wrapper for the given font.
|
Font(java.lang.String faceName,
int size,
int style)
Creates an instance of the font wrapper with a delegatee provided by one
of the font providers or the base class.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
canDisplay(char c)
Checks if this Font has a glyph for the specified character.
|
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.
|
int |
canDisplayUpTo(java.text.CharacterIterator iter,
int start,
int limit)
Indicates whether or not this Font can display the specified String.
|
int |
canDisplayUpTo(java.lang.String str)
Indicates whether or not this Font can display a specified String.
|
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 the
Layer
using the attributes given. |
double |
getAscent()
Returns the ascent of this
Font object, which is the
maximal value any glyph of this font ascends above the base line. |
java.awt.Font |
getAwtFont() |
double |
getDescent()
Returns the descent of this
Font object, which is the
maximal value any glyph of this font descends below the base line. |
static java.util.List<FontListEntry> |
getFontList()
Returns the list of available fonts known to all registered font
providers and the
com.day.image.Font class. |
double |
getHeight()
Returns the calculated font height in pixels.
|
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.
|
java.lang.String |
toString()
Returns a
String representation of this object containing
the font name, the size and style flags. |
createFontFileName, stringToStyle, styleToDescription, styleToStringpublic Font(java.lang.String faceName,
int size,
int style)
The font providers are asked in configuration order for the given font.
The first provider not returning null is taken. If none of
the providers may provide the desired font, the constructor falls back to
asking the base class for the font instance.
faceName - Name of the font as known to the user. This generally is
not the same as the name of the font file. In fact this MUST
be the name of the Font family. That is "Times New Roman" and
not "Times New Roman Bold" is expected.size - Size in points for the font to openstyle - Style flags for the new fontjava.awt.Font javadoc page for details of this
call."public Font(java.lang.String faceName,
int size)
Font(String, int, int) with a style of
Font.PLAIN.faceName - Name of the font as known to the user. This generally is
not the same as the name of the font file.size - Size in points for the font to openjava.awt.Font javadoc page for details of this
call.",
Font(String, int, int)public static java.util.List<FontListEntry> getFontList()
com.day.image.Font class.public java.awt.geom.Rectangle2D getTextExtent(int x,
int y,
int width,
int height,
java.lang.String text,
int align,
double cs,
int ls)
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.
getTextExtent in class AbstractFontx - 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.
Use AbstractFont.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.public 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)
Layer
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.
drawText in class AbstractFontlayer - 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 - The Paint to use for the text drawing.stroke - The Stroke to use for the text drawing.align - alignment, rotation and TrueType attributes for the text.
Use AbstractFont.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.public double getHeight()
getHeight in class AbstractFontpublic double getAscent()
Font object, which is the
maximal value any glyph of this font ascends above the base line.getAscent in class AbstractFontFont.public double getDescent()
Font object, which is the
maximal value any glyph of this font descends below the base line.getDescent in class AbstractFontFont.public boolean canDisplay(char c)
canDisplay in class AbstractFontc - a unicode character codetrue if this Font can display the character;
false otherwise.public int canDisplayUpTo(java.text.CharacterIterator iter,
int start,
int limit)
canDisplayUpTo in class AbstractFontiter - a CharacterIterator objectstart - the specified starting offset into the specified array of
characterslimit - the specified ending offset into the specified array of
characterspublic int canDisplayUpTo(java.lang.String str)
canDisplayUpTo in class AbstractFontstr - a String objectpublic int canDisplayUpTo(char[] text,
int start,
int limit)
canDisplayUpTo in class AbstractFonttext - the specified array of charactersstart - the specified starting offset into the specified array of
characterslimit - the specified ending offset into the specified array of
characterspublic java.lang.String toString()
String representation of this object containing
the font name, the size and style flags.toString in class AbstractFontString representation of this object.public java.awt.Font getAwtFont()
getAwtFont in class AbstractFontCopyright © 2010 - 2023 Adobe. All Rights Reserved