Typeface
public
class
Typeface
extends Object
| java.lang.Object | |
| ↳ | 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 | |
|---|---|
class |
Typeface.Builder
A builder class for creating new Typeface instance. |
Constants | |
|---|---|
int |
BOLD
|
int |
BOLD_ITALIC
|
int |
ITALIC
|
int |
NORMAL
|
Fields | |
|---|---|
public
static
final
Typeface |
DEFAULT
The default NORMAL typeface object |
public
static
final
Typeface |
DEFAULT_BOLD
The default BOLD typeface object. |
public
static
final
Typeface |
MONOSPACE
The NORMAL style of the default monospace typeface. |
public
static
final
Typeface |
SANS_SERIF
The NORMAL style of the default sans serif typeface. |
public
static
final
Typeface |
SERIF
The NORMAL style of the default serif typeface. |
Public methods | |
|---|---|
static
Typeface
|
create(Typeface family, int style)
Create a typeface object that best matches the specified existing typeface and the specified Style. |
static
Typeface
|
create(String familyName, int style)
Create a typeface object given a family name, and option style information. |
static
Typeface
|
createFromAsset(AssetManager mgr, String path)
Create a new typeface from the specified font data. |
static
Typeface
|
createFromFile(File path)
Create a new typeface from the specified font file. |
static
Typeface
|
createFromFile(String path)
Create a new typeface from the specified font file. |
static
Typeface
|
defaultFromStyle(int style)
Returns one of the default typeface objects, based on the specified style |
boolean
|
equals(Object o)
Indicates whether some other object is "equal to" this one. |
int
|
getStyle()
Returns the typeface's intrinsic style attributes |
int
|
hashCode()
Returns a hash code value for the object. |
final
boolean
|
isBold()
Returns true if getStyle() has the BOLD bit set. |
final
boolean
|
isItalic()
Returns true if getStyle() has the ITALIC bit set. |
Protected methods | |
|---|---|
void
|
finalize()
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. |
Inherited methods | |
|---|---|
java.lang.Object
| |
Constants
Fields
DEFAULT_BOLD
Typeface DEFAULT_BOLD
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
Typeface MONOSPACE
The NORMAL style of the default monospace typeface.
SANS_SERIF
Typeface SANS_SERIF
The NORMAL style of the default sans serif typeface.
Public methods
create
Typeface create (Typeface family, int style)
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.
| Parameters | |
|---|---|
family |
Typeface: May be null. The name of the existing type face. |
style |
int: The style (normal, bold, italic) of the typeface.
e.g. NORMAL, BOLD, ITALIC, BOLD_ITALIC |
| Returns | |
|---|---|
Typeface |
The best matching typeface. |
create
Typeface create (String familyName, int style)
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 |
| Returns | |
|---|---|
Typeface |
The best matching typeface. |
createFromAsset
Typeface createFromAsset (AssetManager mgr, String path)
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 |
| Returns | |
|---|---|
Typeface |
The new typeface. |
createFromFile
Typeface createFromFile (File path)
Create a new typeface from the specified font file.
| Parameters | |
|---|---|
path |
File: The path to the font data.This value may be |
| Returns | |
|---|---|
Typeface |
The new typeface. |
createFromFile
Typeface createFromFile (String path)
Create a new typeface from the specified font file.
| Parameters | |
|---|---|
path |
String: The full path to the font data.This value may be |
| Returns | |
|---|---|
Typeface |
The new typeface. |
defaultFromStyle
Typeface defaultFromStyle (int style)
Returns one of the default typeface objects, based on the specified style
| Parameters | |
|---|---|
style |
int |
| Returns | |
|---|---|
Typeface |
the default typeface that corresponds to the style |
equals
boolean equals (Object o)
Indicates whether some other object is "equal to" this one.
The equals method implements an equivalence relation
on non-null object references:
- It is reflexive: for any non-null reference value
x,x.equals(x)should returntrue. - It is symmetric: for any non-null reference values
xandy,x.equals(y)should returntrueif and only ify.equals(x)returnstrue. - It is transitive: for any non-null reference values
x,y, andz, ifx.equals(y)returnstrueandy.equals(z)returnstrue, thenx.equals(z)should returntrue. - It is consistent: for any non-null reference values
xandy, multiple invocations ofx.equals(y)consistently returntrueor consistently returnfalse, provided no information used inequalscomparisons on the objects is modified. - For any non-null reference value
x,x.equals(null)should returnfalse.
The equals method for class Object implements
the most discriminating possible equivalence relation on objects;
that is, for any non-null reference values x and
y, this method returns true if and only
if x and y refer to the same object
(x == y has the value true).
Note that it is generally necessary to override the hashCode
method whenever this method is overridden, so as to maintain the
general contract for the hashCode method, which states
that equal objects must have equal hash codes.
| Parameters | |
|---|---|
o |
Object: the reference object with which to compare. |
| Returns | |
|---|---|
boolean |
true if this object is the same as the obj
argument; false otherwise. |
getStyle
int getStyle ()
Returns the typeface's intrinsic style attributes
| Returns | |
|---|---|
int |
|
hashCode
int hashCode ()
Returns a hash code value for the object. This method is
supported for the benefit of hash tables such as those provided by
HashMap.
The general contract of hashCode is:
- Whenever it is invoked on the same object more than once during
an execution of a Java application, the
hashCodemethod must consistently return the same integer, provided no information used inequalscomparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application. - If two objects are equal according to the
equals(Object)method, then calling thehashCodemethod on each of the two objects must produce the same integer result. - It is not required that if two objects are unequal
according to the
equals(java.lang.Object)method, then calling thehashCodemethod on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
As much as is reasonably practical, the hashCode method defined by
class Object does return distinct integers for distinct
objects. (This is typically implemented by converting the internal
address of the object into an integer, but this implementation
technique is not required by the
Java™ programming language.)
| Returns | |
|---|---|
int |
a hash code value for this object. |
isBold
boolean isBold ()
Returns true if getStyle() has the BOLD bit set.
| Returns | |
|---|---|
boolean |
|
isItalic
boolean isItalic ()
Returns true if getStyle() has the ITALIC bit set.
| Returns | |
|---|---|
boolean |
|
Protected methods
finalize
void finalize ()
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
A subclass overrides the finalize method to dispose of
system resources or to perform other cleanup.
The general contract of finalize is that it is invoked
if and when the Java™ virtual
machine has determined that there is no longer any
means by which this object can be accessed by any thread that has
not yet died, except as a result of an action taken by the
finalization of some other object or class which is ready to be
finalized. The finalize method may take any action, including
making this object available again to other threads; the usual purpose
of finalize, however, is to perform cleanup actions before
the object is irrevocably discarded. For example, the finalize method
for an object that represents an input/output connection might perform
explicit I/O transactions to break the connection before the object is
permanently discarded.
The finalize method of class Object performs no
special action; it simply returns normally. Subclasses of
Object may override this definition.
The Java programming language does not guarantee which thread will
invoke the finalize method for any given object. It is
guaranteed, however, that the thread that invokes finalize will not
be holding any user-visible synchronization locks when finalize is
invoked. If an uncaught exception is thrown by the finalize method,
the exception is ignored and finalization of that object terminates.
After the finalize method has been invoked for an object, no
further action is taken until the Java virtual machine has again
determined that there is no longer any means by which this object can
be accessed by any thread that has not yet died, including possible
actions by other objects or classes which are ready to be finalized,
at which point the object may be discarded.
The finalize method is never invoked more than once by a Java
virtual machine for any given object.
Any exception thrown by the finalize method causes
the finalization of this object to be halted, but is otherwise
ignored.
| Throws | |
|---|---|
Throwable |
|
Interfaces
Classes
- Bitmap
- BitmapFactory
- BitmapFactory.Options
- BitmapRegionDecoder
- BitmapShader
- BlurMaskFilter
- Camera
- Canvas
- Color
- ColorFilter
- ColorMatrix
- ColorMatrixColorFilter
- ColorSpace
- ColorSpace.Connector
- ColorSpace.Rgb
- ColorSpace.Rgb.TransferParameters
- ComposePathEffect
- ComposeShader
- CornerPathEffect
- DashPathEffect
- DiscretePathEffect
- DrawFilter
- EmbossMaskFilter
- ImageFormat
- Interpolator
- LightingColorFilter
- LinearGradient
- MaskFilter
- Matrix
- Movie
- NinePatch
- Outline
- Paint
- Paint.FontMetrics
- Paint.FontMetricsInt
- PaintFlagsDrawFilter
- Path
- PathDashPathEffect
- PathEffect
- PathMeasure
- Picture
- PixelFormat
- Point
- PointF
- PorterDuff
- PorterDuffColorFilter
- PorterDuffXfermode
- RadialGradient
- Rect
- RectF
- Region
- RegionIterator
- Shader
- SumPathEffect
- SurfaceTexture
- SweepGradient
- Typeface
- Typeface.Builder
- Xfermode
- YuvImage
Enums
- Bitmap.CompressFormat
- Bitmap.Config
- BlurMaskFilter.Blur
- Canvas.EdgeType
- Canvas.VertexMode
- ColorSpace.Adaptation
- ColorSpace.Model
- ColorSpace.Named
- ColorSpace.RenderIntent
- Interpolator.Result
- Matrix.ScaleToFit
- Paint.Align
- Paint.Cap
- Paint.Join
- Paint.Style
- Path.Direction
- Path.FillType
- Path.Op
- PathDashPathEffect.Style
- PorterDuff.Mode
- Region.Op
- Shader.TileMode
Exceptions