Package totalcross.ui.font
Class FontMetrics
- java.lang.Object
-
- totalcross.ui.font.FontMetrics
-
public final class FontMetrics extends java.lang.ObjectFontMetrics used to obtain information about the widths and heights of characters and strings when drawing text on a surface.Here is an example that uses FontMetrics to get the width of a string:
... Font font = Font.getFont("Tiny", true, Font.BIG_SIZE); FontMetrics fm = font.fm; String s = "This is a line of text."; int stringWidth = fm.stringWidth(s); ...
-
-
Field Summary
Fields Modifier and Type Field Description intascentREAD-ONLY member: indicates the average height of this font from the baseline to up.intdescentREAD-ONLY member: indicates the average height of this font from the baseline to down.protected FontfontintheightREAD-ONLY member: total height of this font (ascent+descent).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcharWidth(char c)Returns the width in pixels of the given character.intcharWidth(java.lang.StringBuffer s, int i)Returns the width in pixels of the char located at the given index in the StringBuffer.intgetMaxWidth(java.lang.String[] names, int start, int count)Returns the maximum text width from the given list of names.intsbWidth(java.lang.StringBuffer s)Returns the width in pixels of the given StringBuffer.intsbWidth(java.lang.StringBuffer s, int start, int count)Returns the width in pixels of the given StringBuffer range.intstringWidth(char[] chars, int start, int count)Returns the width in pixels of the given char array range.intstringWidth(java.lang.String s)Returns the width in pixels of the given text string.
-
-
-
Field Detail
-
font
protected Font font
-
ascent
public int ascent
READ-ONLY member: indicates the average height of this font from the baseline to up.
-
descent
public int descent
READ-ONLY member: indicates the average height of this font from the baseline to down.
-
height
public int height
READ-ONLY member: total height of this font (ascent+descent).
-
-
Method Detail
-
charWidth
public int charWidth(char c)
Returns the width in pixels of the given character.
-
stringWidth
public int stringWidth(java.lang.String s)
Returns the width in pixels of the given text string.
-
stringWidth
public int stringWidth(char[] chars, int start, int count)Returns the width in pixels of the given char array range.- Parameters:
chars- the text character arraystart- the start position in arraycount- the number of characters
-
getMaxWidth
public int getMaxWidth(java.lang.String[] names, int start, int count)Returns the maximum text width from the given list of names. It is useful to compute the best x position to place the controls, in order to align them in the container. For example:String []labels = {"Name","Age","Address"}; int xx = this.fm.getMaxWidth(labels, 0, labels.length); add(new Label(labels[0]), LEFT, AFTER); add(edName = new Edit(""),xx, SAME); ...- Parameters:
start- The starting indexcount- The number of elements to check.- Since:
- SuperWaba 5.72
-
sbWidth
public int sbWidth(java.lang.StringBuffer s)
Returns the width in pixels of the given StringBuffer. This method is used to preserve memory, since it avoids the creation of a String just to get the width.- Since:
- TotalCross 1.0
-
sbWidth
public int sbWidth(java.lang.StringBuffer s, int start, int count)Returns the width in pixels of the given StringBuffer range. This method is used to preserve memory, since it avoids the creation of a String just to get the width.- Since:
- TotalCross 1.0
-
charWidth
public int charWidth(java.lang.StringBuffer s, int i)Returns the width in pixels of the char located at the given index in the StringBuffer.- Since:
- TotalCross 1.0
-
-