Typeface
open class Typeface
kotlin.Any | |
↳ | android.graphics.Typeface |
The Typeface class specifies the typeface and intrinsic style of a font. This is used in the paint, along with optionally Paint settings like textSize, textSkewX, textScaleX to specify how text appears when drawn (and measured).
Summary
Nested classes | |
---|---|
A builder class for creating new Typeface instance. |
|
A builder class for creating new Typeface instance. |
Constants | |
---|---|
static Int | |
static Int | |
static Int | |
static Int |
Public methods | |
---|---|
open static Typeface! |
Create a typeface object given a family name, and option style information. |
open static Typeface! |
Create a typeface object that best matches the specified existing typeface and the specified Style. |
open static Typeface |
Creates a typeface object that best matches the specified existing typeface and the specified weight and italic style |
open static Typeface! |
createFromAsset(mgr: AssetManager!, path: String!) Create a new typeface from the specified font data. |
open static Typeface! |
createFromFile(file: File?) Create a new typeface from the specified font file. |
open static Typeface! |
createFromFile(path: String?) Create a new typeface from the specified font file. |
open static Typeface! |
defaultFromStyle(style: Int) Returns one of the default typeface objects, based on the specified style |
open Boolean | |
open Int |
getStyle() Returns the typeface's intrinsic style attributes |
String? |
Returns the system font family name if the typeface was created from a system font family, otherwise returns null. |
open Int |
Returns the typeface's weight value |
open Int |
hashCode() |
Boolean |
isBold() Returns true if getStyle() has the BOLD bit set. |
Boolean |
isItalic() Returns true if getStyle() has the ITALIC bit set. |
Properties | |
---|---|
static Typeface! |
The default NORMAL typeface object |
static Typeface! |
The default BOLD typeface object. |
static Typeface! |
The NORMAL style of the default monospace typeface. |
static Typeface! |
The NORMAL style of the default sans serif typeface. |
static Typeface! |
The NORMAL style of the default serif typeface. |
Constants
Public methods
create
open static fun create(
familyName: String!,
style: Int
): Typeface!
Create a typeface object given a family name, and option style information. If null is passed for the name, then the "default" font will be chosen. The resulting typeface object can be queried (getStyle()) to discover what its "real" style characteristics are.
Parameters | |
---|---|
familyName |
String!: May be null. The name of the font family. |
style |
Int: The style (normal, bold, italic) of the typeface. e.g. NORMAL, BOLD, ITALIC, BOLD_ITALIC Value is android.graphics.Typeface#NORMAL , android.graphics.Typeface#BOLD , android.graphics.Typeface#ITALIC , or android.graphics.Typeface#BOLD_ITALIC |
Return | |
---|---|
Typeface! |
The best matching typeface. |
create
open static fun create(
family: Typeface!,
style: Int
): Typeface!
Create a typeface object that best matches the specified existing typeface and the specified Style. Use this call if you want to pick a new style from the same family of an existing typeface object. If family is null, this selects from the default font's family.
This method is not thread safe on API 27 or before. This method is thread safe on API 28 or after.
Parameters | |
---|---|
family |
Typeface!: An existing Typeface object. In case of null , the default typeface is used instead. |
style |
Int: The style (normal, bold, italic) of the typeface. e.g. NORMAL, BOLD, ITALIC, BOLD_ITALIC Value is android.graphics.Typeface#NORMAL , android.graphics.Typeface#BOLD , android.graphics.Typeface#ITALIC , or android.graphics.Typeface#BOLD_ITALIC |
Return | |
---|---|
Typeface! |
The best matching typeface. |
create
open static fun create(
family: Typeface?,
weight: Int,
italic: Boolean
): Typeface
Creates a typeface object that best matches the specified existing typeface and the specified weight and italic style
Below are numerical values and corresponding common weight names.
Value | Common weight name |
---|---|
100 | Thin |
200 | Extra Light |
300 | Light |
400 | Normal |
500 | Medium |
600 | Semi Bold |
700 | Bold |
800 | Extra Bold |
900 | Black |
This method is thread safe.
Parameters | |
---|---|
family |
Typeface?: An existing Typeface object. In case of null , the default typeface is used instead. |
weight |
Int: The desired weight to be drawn. Value is between 1 and 1000 inclusive |
italic |
Boolean: true if italic style is desired to be drawn. Otherwise, false |
Return | |
---|---|
Typeface |
A Typeface object for drawing specified weight and italic style. Never returns null |
See Also
createFromAsset
open static fun createFromAsset(
mgr: AssetManager!,
path: String!
): Typeface!
Create a new typeface from the specified font data.
Parameters | |
---|---|
mgr |
AssetManager!: The application's asset manager |
path |
String!: The file name of the font data in the assets directory |
Return | |
---|---|
Typeface! |
The new typeface. |
createFromFile
open static fun createFromFile(file: File?): Typeface!
Create a new typeface from the specified font file.
Parameters | |
---|---|
file |
File?: The path to the font data. This value may be null . |
Return | |
---|---|
Typeface! |
The new typeface. |
createFromFile
open static fun createFromFile(path: String?): Typeface!
Create a new typeface from the specified font file.
Parameters | |
---|---|
path |
String?: The full path to the font data. This value may be null . |
Return | |
---|---|
Typeface! |
The new typeface. |
defaultFromStyle
open static fun defaultFromStyle(style: Int): Typeface!
Returns one of the default typeface objects, based on the specified style
Parameters | |
---|---|
style |
Int: Value is android.graphics.Typeface#NORMAL , android.graphics.Typeface#BOLD , android.graphics.Typeface#ITALIC , or android.graphics.Typeface#BOLD_ITALIC |
Return | |
---|---|
Typeface! |
the default typeface that corresponds to the style |
equals
open fun equals(other: Any?): Boolean
Parameters | |
---|---|
obj |
the reference object with which to compare. |
Return | |
---|---|
Boolean |
true if this object is the same as the obj argument; false otherwise. |
getStyle
open fun getStyle(): Int
Returns the typeface's intrinsic style attributes
Return | |
---|---|
Int |
Value is android.graphics.Typeface#NORMAL , android.graphics.Typeface#BOLD , android.graphics.Typeface#ITALIC , or android.graphics.Typeface#BOLD_ITALIC |
getSystemFontFamilyName
fun getSystemFontFamilyName(): String?
Returns the system font family name if the typeface was created from a system font family, otherwise returns null.
getWeight
open fun getWeight(): Int
Returns the typeface's weight value
Return | |
---|---|
Int |
Value is between 0 and 1000 inclusive |
hashCode
open fun hashCode(): Int
Return | |
---|---|
Int |
a hash code value for this object. |
isItalic
fun isItalic(): Boolean
Returns true if getStyle() has the ITALIC bit set.
Properties
DEFAULT_BOLD
static val DEFAULT_BOLD: Typeface!
The default BOLD typeface object. Note: this may be not actually be bold, depending on what fonts are installed. Call getStyle() to know for sure.
MONOSPACE
static val MONOSPACE: Typeface!
The NORMAL style of the default monospace typeface.
SANS_SERIF
static val SANS_SERIF: Typeface!
The NORMAL style of the default sans serif typeface.
SERIF
static val SERIF: Typeface!
The NORMAL style of the default serif typeface.