FileDocCategorySizeDatePackage
Typeface.javaAPI DocAndroid 1.5 API5646Wed May 06 22:42:00 BST 2009android.graphics

Typeface

public class Typeface extends Object
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).

Fields Summary
public static final Typeface
DEFAULT
The default NORMAL typeface object
public static final 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.
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 static final Typeface
MONOSPACE
The NORMAL style of the default monospace typeface.
private static Typeface[]
sDefaults
int
native_instance
public static final int
NORMAL
public static final int
BOLD
public static final int
ITALIC
public static final int
BOLD_ITALIC
Constructors Summary
private Typeface(int ni)

        native_instance = ni;
    
Methods Summary
public static android.graphics.Typefacecreate(java.lang.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.

param
familyName May be null. The name of the font family.
param
style The style (normal, bold, italic) of the typeface. e.g. NORMAL, BOLD, ITALIC, BOLD_ITALIC
return
The best matching typeface.

        return new Typeface(nativeCreate(familyName, style));
    
public static android.graphics.Typefacecreate(android.graphics.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.

param
family May be null. The name of the existing type face.
param
style The style (normal, bold, italic) of the typeface. e.g. NORMAL, BOLD, ITALIC, BOLD_ITALIC
return
The best matching typeface.

        int ni = 0;        
        if (family != null) {
            ni = family.native_instance;
        }
        return new Typeface(nativeCreateFromTypeface(ni, style));
    
public static android.graphics.TypefacecreateFromAsset(android.content.res.AssetManager mgr, java.lang.String path)
Create a new typeface from the specified font data.

param
mgr The application's asset manager
param
path The file name of the font data in the assets directory
return
The new typeface.

        return new Typeface(nativeCreateFromAsset(mgr, path));
    
public static android.graphics.TypefacedefaultFromStyle(int style)
Returns one of the default typeface objects, based on the specified style

return
the default typeface that corresponds to the style

        return sDefaults[style];
    
protected voidfinalize()

        DEFAULT         = create((String)null, 0);
        DEFAULT_BOLD    = create((String)null, Typeface.BOLD);
        SANS_SERIF      = create("sans-serif", 0);
        SERIF           = create("serif", 0);
        MONOSPACE       = create("monospace", 0);
        
        sDefaults = new Typeface[] {
            DEFAULT,
            DEFAULT_BOLD,
            create((String)null, Typeface.ITALIC),
            create((String)null, Typeface.BOLD_ITALIC),
        };
    
        nativeUnref(native_instance);
    
public intgetStyle()
Returns the typeface's intrinsic style attributes


           
       
        return nativeGetStyle(native_instance);
    
public final booleanisBold()
Returns true if getStyle() has the BOLD bit set.

        return (getStyle() & BOLD) != 0;
    
public final booleanisItalic()
Returns true if getStyle() has the ITALIC bit set.

        return (getStyle() & ITALIC) != 0;
    
private static native intnativeCreate(java.lang.String familyName, int style)

private static native intnativeCreateFromAsset(android.content.res.AssetManager mgr, java.lang.String path)

private static native intnativeCreateFromTypeface(int native_instance, int style)

private static native intnativeGetStyle(int native_instance)

private static native voidnativeUnref(int native_instance)