|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectewe.fx.FontMetrics
FontMetrics computes font metrics including string width and height.
FontMetrics are usually used to obtain information about the widths and heights of characters and strings when drawing text on a surface. A FontMetrics object references a font and surface since fonts may have different metrics on different surfaces.
Here is an example that uses FontMetrics to get the width of a string:
...
Font font = new Font("Helvetica", Font.BOLD, 10);
FontMetrics fm = getFontMetrics();
String s = "This is a line of text.";
int stringWidth = fm.getTextWidth(s);
...
| Constructor Summary | |
FontMetrics(Font font,
ISurface surface)
Constructs a font metrics object referencing the given font and surface. |
|
| Method Summary | |
boolean |
equals(Object other)
Returns if this object is considered equal to the other object. |
int |
getAscent()
Returns the ascent of the font. |
int |
getCharWidth(char c)
Returns the width of the given character in pixels. |
int |
getDescent()
Returns the descent of a font. |
Font |
getFont()
|
int[] |
getFormattedTextPositions(String s,
FormattedTextSpecs fts,
int[] positions)
Returns the positions of each individual character in a formatted String. |
int |
getHeight()
Returns the height of the referenced font. |
int |
getLeading()
Returns the external leading which is the space between lines. |
FontMetrics |
getNewFor(Font f)
Get a new FontMetrics for a different font but the same ISurface. |
int |
getTextWidth(char[] chars,
int start,
int count)
Returns the width of the given text in pixels. |
int |
getTextWidth(String s)
Returns the width of the given text string in pixels. |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, hashCode, toString |
| Constructor Detail |
public FontMetrics(Font font,
ISurface surface)
If you are trying to create a font metrics object in a Control subclass, use the getFontMetrics() method in the Control class.
Control.getFontMetrics(ewe.fx.Font font)| Method Detail |
public int getAscent()
public int getCharWidth(char c)
public int getDescent()
public int getHeight()
public int getLeading()
public int getTextWidth(String s)
public int[] getFormattedTextPositions(String s,
FormattedTextSpecs fts,
int[] positions)
s - The string to displayfts - Options for the formatted text.positions - This is the destination for the positions of each character. If this is null or not big enough
to hold all the widths, a new one will be created which is big enough and returned. The value at index 0, will be
the position of the character at index 1. The position of the character at index 0 is always 0.
public int getTextWidth(char[] chars,
int start,
int count)
chars - the text character arraystart - the start position in arraycount - the number of characterspublic Font getFont()
public FontMetrics getNewFor(Font f)
f - the new Font.
public boolean equals(Object other)
Object
equals in class Objectother - Another object to compare to.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||