public class Font
extends java.lang.Object
DisplayFont
defines how text is rendered on a Display
.
A Font
is defined by one or more identifiers, a style and a descriptor. It may or may not be monospaced.
An identifier is an integer and it specifies the font's capabilities. For instance, when a font holds the
LATIN
identifier, that means the font is able to render all Latin languages. If the font holds too the
ARABIC
identifier, that means the font is also able to print Arabic words.
There are 80 predefined identifiers (1 to 80). A font can also hold other special identifiers that provide a useful way to recognize a specific font. For instance, a font that contains some special characters as arrows, smileys, can be tagged by the font's creator with a special identifier.
The style may combine several style attributes such as STYLE_PLAIN
, STYLE_BOLD
,
STYLE_ITALIC
or STYLE_UNDERLINED
.
The descriptor is a helpful string that describes the font.
DisplayFonts are never created by applications, but are rather retrieved from the implementation environment.
An application can get all available fonts with getAllFonts()
, or query for a particular font: in this
case the implementation will return the most appropriate font matching the request.
The height gives the height of a line of text with the font.
Modifier and Type | Field and Description |
---|---|
static int |
ARABIC
Constant for arabic font identifier.
|
static int |
ARMENIAN
Constant for armenian font identifier.
|
static int |
BALINESE
Constant for balinese font identifier.
|
static int |
BAMUM
Constant for bamum font identifier.
|
static int |
BATAK
Constant for batak font identifier.
|
static int |
BENGALI
Constant for bengali font identifier.
|
static int |
BOPOMOFO
Constant for bopomofo font identifier.
|
static int |
BRAILLE
Constant for braille font identifier.
|
static int |
BUGINESE
Constant for buginese font identifier.
|
static int |
BUHID
Constant for buhid font identifier.
|
static int |
CANADIAN_ABORIGINAL
Constant for canadian aboriginal font identifier.
|
static int |
CHAM
Constant for cham font identifier.
|
static int |
CHEROKEE
Constant for cherokee font identifier.
|
static int |
COMMON
Constant for common font identifier.
|
static int |
COPTIC
Constant for coptic font identifier.
|
static int |
CYRILLIC
Constant for cyrillic font identifier.
|
static int |
DEVANAGARI
Constant for devanagari font identifier.
|
static int |
ETHIOPIC
Constant for ethiopic font identifier.
|
static int |
GEORGIAN
Constant for georgian font identifier.
|
static int |
GLAGOLITIC
Constant for glagolitic font identifier.
|
static int |
GREEK
Constant for greek font identifier.
|
static int |
GUJARATI
Constant for gujarati font identifier.
|
static int |
GURMUKHI
Constant for gurmukhi font identifier.
|
static int |
HAN
Constant for han font identifier.
|
static int |
HANGUL
Constant for hangul font identifier.
|
static int |
HANUNOO
Constant for hanunoo font identifier.
|
static int |
HEBREW
Constant for hebrew font identifier.
|
static int |
HIRAGANA
Constant for hiragana font identifier.
|
static int |
INHERITED
Constant for inherited font identifier.
|
static int |
JAVANESE
Constant for javanese font identifier.
|
static int |
KANNADA
Constant for kannada font identifier.
|
static int |
KATAKANA
Constant for katakana font identifier.
|
static int |
KAYAH_LI
Constant for kayah li font identifier.
|
static int |
KHMER
Constant for khmer font identifier.
|
static int |
LAO
Constant for lao font identifier.
|
static int |
LATIN
Constant for latin font identifier.
|
static int |
LEPCHA
Constant for lepcha font identifier.
|
static int |
LIMBU
Constant for limbu font identifier.
|
static int |
LISU
Constant for lisu font identifier.
|
static int |
MALAYALAM
Constant for malayalam font identifier.
|
static int |
MANDAIC
Constant for mandaic font identifier.
|
static int |
MEETEI_MAYEK
Constant for meetei mayek font identifier.
|
static int |
MONGOLIAN
Constant for mongolian font identifier.
|
static int |
MYANMAR
Constant for myanmar font identifier.
|
static int |
NEW_TAI_LUE
Constant for new tai lue font identifier.
|
static int |
NKO
Constant for nko font identifier.
|
static int |
OGHAM
Constant for ogham font identifier.
|
static int |
OL_CHIKI
Constant for ol chiki font identifier.
|
static int |
ORIYA
Constant for oriya font identifier.
|
static int |
PHAGS_PA
Constant for phags pa font identifier.
|
static int |
REJANG
Constant for rejang font identifier.
|
static int |
RUNIC
Constant for runic font identifier.
|
static int |
SAMARITAN
Constant for samaritan font identifier.
|
static int |
SAURASHTRA
Constant for saurashtra font identifier.
|
static int |
SINHALA
Constant for sinhala font identifier.
|
static int |
STYLE_BOLD
The bold style constant.
|
static int |
STYLE_ITALIC
The italic style constant.
|
static int |
STYLE_PLAIN
The plain style constant.
|
static int |
STYLE_RESIZED
The underlined style constant.
|
static int |
STYLE_UNDERLINED
The underlined style constant.
|
static int |
SUNDANESE
Constant for sundanese font identifier.
|
static int |
SYLOTI_NAGRI
Constant for syloti nagri font identifier.
|
static int |
SYRIAC
Constant for syriac font identifier.
|
static int |
TAGALOG
Constant for tagalog font identifier.
|
static int |
TAGBANWA
Constant for tagbanwa font identifier.
|
static int |
TAI_LE
Constant for tai le font identifier.
|
static int |
TAI_THAM
Constant for tai tham font identifier.
|
static int |
TAI_VIET
Constant for tai viet font identifier.
|
static int |
TAMIL
Constant for tamil font identifier.
|
static int |
TELUGU
Constant for telugu font identifier.
|
static int |
THAANA
Constant for thaana font identifier.
|
static int |
THAI
Constant for thai font identifier.
|
static int |
TIBETAN
Constant for tibetan font identifier.
|
static int |
TIFINAGH
Constant for tifinagh font identifier.
|
static int |
VAI
Constant for vai font identifier.
|
static int |
YI
Constant for yi font identifier.
|
Modifier and Type | Method and Description |
---|---|
int |
charsWidth(char[] ch,
int offset,
int length)
Gets the width of the characters in
ch from offset to offset+length with
this font and its x ratio.The width is the horizontal distance that would be occupied if the length characters were drawn
using this font. |
int |
charWidth(char ch)
Gets the width of the specified character with this font and its x ratio.
The width is the horizontal distance that would be occupied if ch was drawn using this font. |
boolean |
equals(java.lang.Object obj) |
static Font[] |
getAllFonts()
Gets an array containing all available DisplayFonts in the system.
|
int |
getBaselinePosition()
Gets the distance in pixels from the top of the text to the text's baseline.
|
static Font |
getDefaultFont()
Gets the default font for all Displays.
This method may return null if no font is declared in the system. |
java.lang.String |
getDescriptor()
Returns the descriptor of the font or
null if no descriptor is available. |
static Font |
getFont(int identifier,
int height,
int style)
Gets a
DisplayFont matching the requested characteristics as close as possible. |
int |
getHeight()
Gets the height of a line of text with this font and its y ratio.
|
int[] |
getIdentifiers()
Gets an array of identifiers supported by the font.
|
int |
getStyle()
Gets the style of the font.
The returned value may only be a combination of the following style constants: STYLE_BOLD ,
SYTLE_ITALIC , STYLE_UNDERLINED or STYLE_PLAIN . |
float |
getXRatio()
Gets x ratio.
|
float |
getYRatio()
Gets y ratio.
|
int |
hashCode() |
boolean |
isBold()
Gets whether the font is bold or not.
|
boolean |
isIdentifierSupported(int identifier)
Checks whether the font supports the given identifier or not.
|
boolean |
isItalic()
Gets whether the font is italic or not.
|
boolean |
isMonospaced()
Gets whether the font is monospaced or not.
|
boolean |
isPlain()
Gets whether the font is plain or not.
|
boolean |
isUnderlined()
Gets whether the font is underlined or not.
|
void |
resetRatios()
Resets x and y ratios at their original value (construction value).
|
void |
setRatios(float xRatio,
float yRatio)
Sets x and y ratios.
|
int |
stringWidth(java.lang.String str)
Gets the width of the given string with this font and its x ratio.
The width is the horizontal distance that would be occupied if the string was drawn using this font. |
int |
substringWidth(java.lang.String str,
int offset,
int len)
Gets the width of the string from
offset to offset+len with this font and its x ratio. |
public static final int STYLE_PLAIN
Value 0
is assigned to STYLE_PLAIN
.
public static final int STYLE_BOLD
Value 1
is assigned to STYLE_BOLD
.
public static final int STYLE_ITALIC
Value 2
is assigned to STYLE_ITALIC
.
public static final int STYLE_UNDERLINED
Value 4
is assigned to STYLE_UNDERLINED
.
public static final int STYLE_RESIZED
Value 8
is assigned to STYLE_RESIZED
.
public static final int ARABIC
Value 1
is assigned to ARABIC
.
public static final int ARMENIAN
Value 2
is assigned to ARMENIAN
.
public static final int BALINESE
Value 3
is assigned to BALINESE
.
public static final int BENGALI
Value 4
is assigned to BENGALI
.
public static final int BOPOMOFO
Value 5
is assigned to BOPOMOFO
.
public static final int BRAILLE
Value 6
is assigned to BRAILLE
.
public static final int BUGINESE
Value 7
is assigned to BUGINESE
.
public static final int BUHID
Value 8
is assigned to BUHID
.
public static final int CANADIAN_ABORIGINAL
Value 9
is assigned to CANADIAN_ABORIGINAL
.
public static final int CHEROKEE
Value 10
is assigned to CHEROKEE
.
public static final int COPTIC
Value 11
is assigned to COPTIC
.
public static final int CYRILLIC
Value 14
is assigned to CYRILLIC
.
public static final int DEVANAGARI
Value 16
is assigned to DEVANAGARI
.
public static final int ETHIOPIC
Value 17
is assigned to ETHIOPIC
.
public static final int GEORGIAN
Value 18
is assigned to GEORGIAN
.
public static final int GLAGOLITIC
Value 19
is assigned to GLAGOLITIC
.
public static final int GREEK
Value 21
is assigned to GREEK
.
public static final int GUJARATI
Value 22
is assigned to GUJARATI
.
public static final int GURMUKHI
Value 23
is assigned to GURMUKHI
.
public static final int HAN
Value 24
is assigned to HAN
.
public static final int HANGUL
Value 25
is assigned to HANGUL
.
public static final int HANUNOO
Value 26
is assigned to HANUNOO
.
public static final int HEBREW
Value 27
is assigned to HEBREW
.
public static final int HIRAGANA
Value 28
is assigned to HIRAGANA
.
public static final int KANNADA
Value 29
is assigned to KANNADA
.
public static final int KATAKANA
Value 30
is assigned to KATAKANA
.
public static final int KHMER
Value 32
is assigned to KHMER
.
public static final int LAO
Value 33
is assigned to LAO
.
public static final int LATIN
Value 34
is assigned to LATIN
.
public static final int LIMBU
Value 35
is assigned to LIMBU
.
public static final int MALAYALAM
Value 36
is assigned to MALAYALAM
.
public static final int MONGOLIAN
Value 37
is assigned to MONGOLIAN
.
public static final int MYANMAR
Value 38
is assigned to MYANMAR
.
public static final int NEW_TAI_LUE
Value 39
is assigned to NEW_TAI_LUE
.
public static final int NKO
Value 40
is assigned to NKO
.
public static final int OGHAM
Value 41
is assigned to OGHAM
.
public static final int ORIYA
Value 42
is assigned to ORIYA
.
public static final int PHAGS_PA
Value 44
is assigned to PHAGS_PA
.
public static final int RUNIC
Value 46
is assigned to RUNIC
.
public static final int SINHALA
Value 48
is assigned to SINHALA
.
public static final int SYLOTI_NAGRI
Value 49
is assigned to SYLOTI_NAGRI
.
public static final int SYRIAC
Value 50
is assigned to SYRIAC
.
public static final int TAGALOG
Value 51
is assigned to TAGALOG
.
public static final int TAGBANWA
Value 52
is assigned to TAGBANWA
.
public static final int TAI_LE
Value 53
is assigned to TAI_LE
.
public static final int TAMIL
Value 54
is assigned to TAMIL
.
public static final int TELUGU
Value 55
is assigned to TELUGU
.
public static final int THAANA
Value 56
is assigned to THAANA
.
public static final int THAI
Value 57
is assigned to THAI
.
public static final int TIBETAN
Value 58
is assigned to TIBETAN
.
public static final int TIFINAGH
Value 59
is assigned to TIFINAGH
.
public static final int YI
Value 61
is assigned to YI
.
public static final int COMMON
Value 62
is assigned to COMMON
.
public static final int INHERITED
Value 63
is assigned to INHERITED
.
public static final int SUNDANESE
Value 64
is assigned to SUNDANESE
.
public static final int LEPCHA
Value 65
is assigned to LEPCHA
.
public static final int OL_CHIKI
Value 66
is assigned to OL_CHIKI
.
public static final int VAI
Value 67
is assigned to VAI
.
public static final int SAURASHTRA
Value 68
is assigned to SAURASHTRA
.
public static final int KAYAH_LI
Value 69
is assigned to KAYAH_LI
.
public static final int REJANG
Value 70
is assigned to REJANG
.
public static final int CHAM
Value 71
is assigned to CHAM
.
public static final int TAI_THAM
Value 72
is assigned to TAI_THAM
.
public static final int TAI_VIET
Value 73
is assigned to TAI_VIET
.
public static final int SAMARITAN
Value 74
is assigned to SAMARITAN
.
public static final int LISU
Value 75
is assigned to LISU
.
public static final int BAMUM
Value 76
is assigned to BAMUM
.
public static final int JAVANESE
Value 77
is assigned to JAVANESE
.
public static final int MEETEI_MAYEK
Value 78
is assigned to MEETEI_MAYEK
.
public static final int BATAK
Value 79
is assigned to BATAK
.
public static final int MANDAIC
Value 80
is assigned to MANDAIC
.
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public int[] getIdentifiers()
public boolean isIdentifierSupported(int identifier)
identifier
- the identifier to check.true
if the font supports the given identifier, false
otherwise.public int getStyle()
STYLE_BOLD
,
SYTLE_ITALIC
, STYLE_UNDERLINED
or STYLE_PLAIN
.public java.lang.String getDescriptor()
null
if no descriptor is available.null
.public boolean isPlain()
true
if the font is plain, false
otherwise.public boolean isBold()
true
if the font is bold, false
otherwise.public boolean isItalic()
true
if the font is italic, false
otherwise.public boolean isUnderlined()
true
if the font is underlined, false
otherwise.public boolean isMonospaced()
A monospaced font is a font which all characters have the same width.
true
if the font is monospaced, false
otherwise.public int charWidth(char ch)
ch
was drawn using this font. It also
includes the horizontal space that would be added after ch
to separate it appropriately from the
following characters.ch
- the character to measurech
with this fontgetXRatio()
public int charsWidth(char[] ch, int offset, int length)
ch
from offset
to offset+length
with
this font and its x ratio.length
characters were drawn
using this font. It also includes the horizontal spaces between characters to separate them appropriately.ch
- an array of charactersoffset
- the index of the first character to measurelength
- the number of characters to measurech
java.lang.ArrayIndexOutOfBoundsException
- if offset
and length
are out of ch
rangejava.lang.NullPointerException
- if ch
is nullgetXRatio()
public int stringWidth(java.lang.String str)
str
- the string to measurejava.lang.NullPointerException
- if the given string is null
getXRatio()
public int substringWidth(java.lang.String str, int offset, int len)
offset
to offset+len
with this font and its x ratio.
str
- the string to measureoffset
- index of the first character in the substringlen
- length of the substringstr
java.lang.StringIndexOutOfBoundsException
- if offset
and length
are out of str
rangejava.lang.NullPointerException
- if str
is nullgetXRatio()
public static Font getDefaultFont() throws java.lang.IllegalStateException
null
if no font is declared in the system.java.lang.IllegalStateException
- if MicroUI is not startedpublic static Font[] getAllFonts() throws java.lang.IllegalStateException
java.lang.IllegalStateException
- if MicroUI is not startedpublic static Font getFont(int identifier, int height, int style) throws java.lang.IllegalStateException
DisplayFont
matching the requested characteristics as close as possible.
Font is requested by specifying the required identifier, height and style. If no available font exactly matches the request, the system will attempt to provide the most appropriate font.
The implementation should use the following rules to determine a suitable font:
identifier
- the required identifier of the font.height
- the required height of the font.style
- the required combination of style constants.DisplayFont
object or null
.java.lang.IllegalStateException
- if MicroUI is not started.public void setRatios(float xRatio, float yRatio)
xRatio
- the x ratio to set.yRatio
- the y ratio to set.public float getXRatio()
public float getYRatio()
public void resetRatios()
public int getHeight()
The height includes the size of the font as well as sufficient spacing below the text to ensure that lines of text drawn at this distance will be spaced appropriately.
getYRatio()
public int getBaselinePosition()