Class Font


  • public final class Font
    extends java.lang.Object
    Font 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.
    1. 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.
    2. You may create new fonts based on the TrueType fonts using the tool tc.tools.FontGenerator.
    3. 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.
    4. 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.
    5. 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 int baseChar
      For internal use only.
      static int BIG_SIZE
      A big-sized font (2 above the normal size)
      static java.lang.String DEFAULT
      The default font name.
      FontMetrics fm  
      java.lang.Object hv_UserFont  
      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).
      static int MIN_FONT_SIZE
      The minimum font size: 7.
      java.lang.String name
      Read only field that contains the font's name.
      static int NORMAL_SIZE
      A normal-sized font
      int size
      Read only field that contains the font's size.
      int style
      Read only field that contains the font's style.
      static int TAB_SIZE
      When 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
      Font adjustedBy​(int delta)
      Returns a font with the size changed with that delta.
      Font adjustedBy​(int delta, boolean bold)
      Returns a font with the size changed with that delta and the given bold style.
      Font asBold()
      Returns this font as Bold
      static int getDefaultFontSize()
      Returns the default font size, based on the screen's size.
      static Font getFont​(boolean boldStyle, int size)
      Gets the instance of the default font, with the given style and size.
      static Font getFont​(int size)
      Gets the instance of the default font, normal style and with the given size.
      static Font getFont​(java.lang.String name, boolean boldStyle, int size)
      Gets the instance of a font of the given name, style and size.
      boolean isBold()
      Returns if this font is bold.
      Font percentBy​(int percent)
      Returns a font with the size changed with that percentage.
      Font percentBy​(int percent, boolean bold)
      Returns a font with the size changed with that percentage and the given bold style.
      void removeFromCache()
      Used internally.
      void removeFromCache4D()  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • 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
      • 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 range Font.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 range Font.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 range Font.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:
        toString in class java.lang.Object