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.
public class Font extends BaseObj
Modifier and Type | Class and Description |
---|---|
static class |
Font.Style
Deprecated.
in API 16
|
Modifier and Type | Method and Description |
---|---|
static Font |
create(RenderScript rs,
Resources res,
String familyName,
Font.Style fontStyle,
float pointSize)
Deprecated.
in API 16
Accepts one of the following family names as an argument
and will attempt 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)
Deprecated.
in API 16
|
static Font |
createFromFile(RenderScript rs,
Resources res,
File path,
float pointSize)
Deprecated.
in API 16
|
static Font |
createFromFile(RenderScript rs,
Resources res,
String path,
float pointSize)
Deprecated.
in API 16
Takes a specific file name as an argument
|
static Font |
createFromResource(RenderScript rs,
Resources res,
int id,
float pointSize)
Deprecated.
in API 16
|
public static Font createFromFile(RenderScript rs, Resources res, String path, float pointSize)
public static Font createFromFile(RenderScript rs, Resources res, File path, float pointSize)
public static Font createFromAsset(RenderScript rs, Resources res, String path, float pointSize)
public static Font createFromResource(RenderScript rs, Resources res, int id, float pointSize)
public static Font create(RenderScript rs, Resources res, String familyName, Font.Style fontStyle, float pointSize)