public class

Font

extends Object
java.lang.Object
   ↳ android.renderscript.Font

Class Overview

This class gives users a simple way to draw hardware accelerated text. Internally, the glyphs are rendered using the Freetype library and an internal cache of rendered glyph bitmaps is maintained. Each font object represents a combination of a typeface, and point size. You can create multiple font objects to represent styles such as bold or italic text, faces, and different font sizes. During creation, the Android system quieries device's screen DPI to ensure proper sizing across multiple device configurations.

Fonts are rendered using screen-space positions and no state setup beyond binding a font to the Renderscript is required. A note of caution on performance, though the state changes are transparent to the user, they do happen internally, and it is more efficient to render large batches of text in sequence. It is also more efficient to render multiple characters at once instead of one by one to improve draw call batching.

Font color and transparency are not part of the font object and you can freely modify them in the script to suit the user's rendering needs. Font colors work as a state machine. Every new call to draw text uses the last color set in the script.

Summary

Nested Classes
enum Font.Style  
Public Methods
static Font create(RenderScript rs, Resources res, String familyName, Font.Style fontStyle, float pointSize)
Accepts one of the following family names as an argument and will attemp to produce the best match with a system font "sans-serif" "arial" "helvetica" "tahoma" "verdana" "serif" "times" "times new roman" "palatino" "georgia" "baskerville" "goudy" "fantasy" "cursive" "ITC Stone Serif" "monospace" "courier" "courier new" "monaco" Returns default font if no match could be found
static Font createFromAsset(RenderScript rs, Resources res, String path, float pointSize)
static Font createFromFile(RenderScript rs, Resources res, String path, float pointSize)
Takes a specific file name as an argument
static Font createFromFile(RenderScript rs, Resources res, File path, float pointSize)
static Font createFromResource(RenderScript rs, Resources res, int id, float pointSize)
synchronized void destroy()
destroy disconnects the object from the native object effectivly rendering this java object dead.
void setName(String name)
setName assigns a name to an object.
Protected Methods
void finalize()
Called before the object's memory is reclaimed by the VM.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public static Font create (RenderScript rs, Resources res, String familyName, Font.Style fontStyle, float pointSize)

Since: API Level 11

Accepts one of the following family names as an argument and will attemp to produce the best match with a system font "sans-serif" "arial" "helvetica" "tahoma" "verdana" "serif" "times" "times new roman" "palatino" "georgia" "baskerville" "goudy" "fantasy" "cursive" "ITC Stone Serif" "monospace" "courier" "courier new" "monaco" Returns default font if no match could be found

public static Font createFromAsset (RenderScript rs, Resources res, String path, float pointSize)

Since: API Level 11

public static Font createFromFile (RenderScript rs, Resources res, String path, float pointSize)

Since: API Level 11

Takes a specific file name as an argument

public static Font createFromFile (RenderScript rs, Resources res, File path, float pointSize)

Since: API Level 11

public static Font createFromResource (RenderScript rs, Resources res, int id, float pointSize)

Since: API Level 11

public synchronized void destroy ()

Since: API Level 11

destroy disconnects the object from the native object effectivly rendering this java object dead. The primary use is to force immediate cleanup of resources when its believed the GC will not respond quickly enough.

public void setName (String name)

Since: API Level 11

setName assigns a name to an object. This object can later be looked up by this name. This name will also be retained if the object is written to an A3D file.

Parameters
name The name to assign to the object.

Protected Methods

protected void finalize ()

Since: API Level 11

Called before the object's memory is reclaimed by the VM. This can only happen once the garbage collector has detected that the object is no longer reachable by any thread of the running application.

The method can be used to free system resources or perform other cleanup before the object is garbage collected. The default implementation of the method is empty, which is also expected by the VM, but subclasses can override finalize() as required. Uncaught exceptions which are thrown during the execution of this method cause it to terminate immediately but are otherwise ignored.

Note that the VM does guarantee that finalize() is called at most once for any object, but it doesn't guarantee when (if at all) finalize() will be called. For example, object B's finalize() can delay the execution of object A's finalize() method and therefore it can delay the reclamation of A's memory. To be safe, use a ReferenceQueue, because it provides more control over the way the VM deals with references during garbage collection.

Throws
Throwable