Package totalcross.ui.font
Class Font
- java.lang.Object
-
- totalcross.ui.font.Font
-
public final class Font extends java.lang.ObjectFont is the character font used when drawing text on a surface. Fonts can be antialiased, and usually range from size 7 to 38. In OpenGL platforms, they are 8bpp antialiased fonts ranging up indefinedly.- To see if the font you created is installed in the target device, query its name after the creation. If the font is not found, its name is changed to match the default font.
- You may create new fonts based on the TrueType fonts using the tool tc.tools.FontGenerator.
- There are two font sets: the one before TotalCross 1.3, and the one after TotalCross 1.3. The font set is choosen using Settings.useNewFont.
- The default font size is based in the device's DPI. This allows the font to have the same physical size in inches on different devices.
- In JavaSE you can choose the default font size passing
/fontsize <size>as argument, before the application's name.
-
-
Field Summary
Fields Modifier and Type Field Description static intbaseCharFor internal use only.static intBIG_SIZEA big-sized font (2 above the normal size)static java.lang.StringDEFAULTThe default font name.FontMetricsfmjava.lang.Objecthv_UserFontstatic intMAX_FONT_SIZEThe maximum font size: 48 for Windows32, unlimited for OpenGL platforms (the number here will be 80, since this is the size that the base font was created; you can specify something higher, but it will use upscaling, which usually results in a smooth font).static intMIN_FONT_SIZEThe minimum font size: 7.java.lang.StringnameRead only field that contains the font's name.static intNORMAL_SIZEA normal-sized fontintsizeRead only field that contains the font's size.intstyleRead only field that contains the font's style.static intTAB_SIZEWhen the vm draws a character and founds the tab char, it will draw a set of spaces.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description FontadjustedBy(int delta)Returns a font with the size changed with that delta.FontadjustedBy(int delta, boolean bold)Returns a font with the size changed with that delta and the given bold style.FontasBold()Returns this font as Boldstatic intgetDefaultFontSize()Returns the default font size, based on the screen's size.static FontgetFont(boolean boldStyle, int size)Gets the instance of the default font, with the given style and size.static FontgetFont(int size)Gets the instance of the default font, normal style and with the given size.static FontgetFont(java.lang.String name, boolean boldStyle, int size)Gets the instance of a font of the given name, style and size.booleanisBold()Returns if this font is bold.FontpercentBy(int percent)Returns a font with the size changed with that percentage.FontpercentBy(int percent, boolean bold)Returns a font with the size changed with that percentage and the given bold style.voidremoveFromCache()Used internally.voidremoveFromCache4D()java.lang.StringtoString()
-
-
-
Field Detail
-
name
public java.lang.String name
Read only field that contains the font's name. Note that changing this directly will have no effect.
-
style
public int style
Read only field that contains the font's style. Note that changing this directly will have no effect. For bold fonts, style == 1.
-
size
public int size
Read only field that contains the font's size. Note that changing this directly will have no effect.
-
hv_UserFont
public java.lang.Object hv_UserFont
-
fm
public FontMetrics fm
-
DEFAULT
public static final java.lang.String DEFAULT
The default font name. If a specified font is not found, this one is used instead.- See Also:
- Constant Field Values
-
MIN_FONT_SIZE
public static int MIN_FONT_SIZE
The minimum font size: 7.
-
MAX_FONT_SIZE
public static int MAX_FONT_SIZE
The maximum font size: 48 for Windows32, unlimited for OpenGL platforms (the number here will be 80, since this is the size that the base font was created; you can specify something higher, but it will use upscaling, which usually results in a smooth font).
-
baseChar
public static int baseChar
For internal use only.
-
NORMAL_SIZE
public static final int NORMAL_SIZE
A normal-sized font
-
BIG_SIZE
public static final int BIG_SIZE
A big-sized font (2 above the normal size)
-
TAB_SIZE
public static int TAB_SIZE
When the vm draws a character and founds the tab char, it will draw a set of spaces. You can define the number of spaces that will be drawn setting this field. It defaults to 3, but you can change at any time.
-
-
Method Detail
-
getDefaultFontSize
public static int getDefaultFontSize()
Returns the default font size, based on the screen's size.
-
getFont
public static Font getFont(boolean boldStyle, int size)
Gets the instance of the default font, with the given style and size.- Parameters:
boldStyle- If true, a bold font is used. Otherwise, a plain font is used.size- If you want a text bigger than the standard size, use Font.NORMAL_SIZE+x; or if you want a text smaller than the standard size, use Font.NORMAL_SIZE-x. Size is adjusted to be in the rangeFont.MIN_FONT_SIZE ... Font.MAX_FONT_SIZE. That is, passing a value out of the bounds won't throw an exception, will only use the minimum default size if the size passed is less than it or use the maximum default size if the size passed is greater than it.
-
getFont
public static Font getFont(int size)
Gets the instance of the default font, normal style and with the given size.- Parameters:
boldStyle- If true, a bold font is used. Otherwise, a plain font is used.size- If you want a text bigger than the standard size, use Font.NORMAL_SIZE+x; or if you want a text smaller than the standard size, use Font.NORMAL_SIZE-x. Size is adjusted to be in the rangeFont.MIN_FONT_SIZE ... Font.MAX_FONT_SIZE. That is, passing a value out of the bounds won't throw an exception, will only use the minimum default size if the size passed is less than it or use the maximum default size if the size passed is greater than it.
-
getFont
public static Font getFont(java.lang.String name, boolean boldStyle, int size)
Gets the instance of a font of the given name, style and size. Font styles are defined in this class. Font.DEFAULT will be used if the font is not installed on the device. This method can be used to check if the created font is in fact installed on the device.- Parameters:
name- Font.DEFAULT is the default font. You must install other fonts if you want to use them.boldStyle- If true, a bold font is used. Otherwise, a plain font is used.size- If you want a text bigger than the standard size, use Font.NORMAL_SIZE+x; or if you want a text smaller than the standard size, use Font.NORMAL_SIZE-x. Size is adjusted to be in the rangeFont.MIN_FONT_SIZE ... Font.MAX_FONT_SIZE. That is, passing a value out of the bounds won't throw an exception, will only use the minimum default size if the size passed is less than it or use the maximum default size if the size passed is greater than it.
-
asBold
public Font asBold()
Returns this font as Bold
-
adjustedBy
public Font adjustedBy(int delta)
Returns a font with the size changed with that delta. The new size is thisFont.size+delta. delta can be positive or negative. The new size won't pass the minimum nor the maximum sizes.- Since:
- TotalCross 1.3
-
adjustedBy
public Font adjustedBy(int delta, boolean bold)
Returns a font with the size changed with that delta and the given bold style. The new size is thisFont.size+delta. delta can be positive or negative. The new size won't pass the minimum nor the maximum sizes.- Since:
- TotalCross 1.3
-
percentBy
public Font percentBy(int percent)
Returns a font with the size changed with that percentage. The new size is thisFont.size * percent / 100. delta can be positive or negative. The new size won't pass the minimum nor the maximum sizes.
-
percentBy
public Font percentBy(int percent, boolean bold)
Returns a font with the size changed with that percentage and the given bold style. The new size is thisFont.size * percent / 100. delta can be positive or negative. The new size won't pass the minimum nor the maximum sizes.
-
isBold
public boolean isBold()
Returns if this font is bold.- Since:
- TotalCross 1.53
-
removeFromCache
public void removeFromCache()
Used internally.
-
removeFromCache4D
public void removeFromCache4D()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-