Fontpublic class Font extends BaseObj
Fields Summary |
---|
private static final String[] | sSansNames | private static final String[] | sSerifNames | private static final String[] | sMonoNames | private static Map | sFontFamilyMap |
Methods Summary |
---|
private static void | addFamilyToMap(android.renderscript.Font$FontFamily family)
for(int i = 0; i < family.mNames.length; i ++) {
sFontFamilyMap.put(family.mNames[i], family);
}
| public static android.renderscript.Font | create(RenderScript rs, android.content.res.Resources res, java.lang.String familyName, android.renderscript.Font$Style fontStyle, float pointSize)
String fileName = getFontFileName(familyName, fontStyle);
String fontPath = Environment.getRootDirectory().getAbsolutePath();
fontPath += "/fonts/" + fileName;
return createFromFile(rs, res, fontPath, pointSize);
| public static android.renderscript.Font | createFromAsset(RenderScript rs, android.content.res.Resources res, java.lang.String path, float pointSize)
rs.validate();
AssetManager mgr = res.getAssets();
int dpi = res.getDisplayMetrics().densityDpi;
long fontId = rs.nFontCreateFromAsset(mgr, path, pointSize, dpi);
if(fontId == 0) {
throw new RSRuntimeException("Unable to create font from asset " + path);
}
Font rsFont = new Font(fontId, rs);
return rsFont;
| public static android.renderscript.Font | createFromFile(RenderScript rs, android.content.res.Resources res, java.lang.String path, float pointSize)
rs.validate();
int dpi = res.getDisplayMetrics().densityDpi;
long fontId = rs.nFontCreateFromFile(path, pointSize, dpi);
if(fontId == 0) {
throw new RSRuntimeException("Unable to create font from file " + path);
}
Font rsFont = new Font(fontId, rs);
return rsFont;
| public static android.renderscript.Font | createFromFile(RenderScript rs, android.content.res.Resources res, java.io.File path, float pointSize)
return createFromFile(rs, res, path.getAbsolutePath(), pointSize);
| public static android.renderscript.Font | createFromResource(RenderScript rs, android.content.res.Resources res, int id, float pointSize)
String name = "R." + Integer.toString(id);
rs.validate();
InputStream is = null;
try {
is = res.openRawResource(id);
} catch (Exception e) {
throw new RSRuntimeException("Unable to open resource " + id);
}
int dpi = res.getDisplayMetrics().densityDpi;
long fontId = 0;
if (is instanceof AssetManager.AssetInputStream) {
long asset = ((AssetManager.AssetInputStream) is).getNativeAsset();
fontId = rs.nFontCreateFromAssetStream(name, pointSize, dpi, asset);
} else {
throw new RSRuntimeException("Unsupported asset stream created");
}
if(fontId == 0) {
throw new RSRuntimeException("Unable to create font from resource " + id);
}
Font rsFont = new Font(fontId, rs);
return rsFont;
| static java.lang.String | getFontFileName(java.lang.String familyName, android.renderscript.Font$Style style)
initFontFamilyMap();
FontFamily family = sFontFamilyMap.get(familyName);
if(family != null) {
switch(style) {
case NORMAL:
return family.mNormalFileName;
case BOLD:
return family.mBoldFileName;
case ITALIC:
return family.mItalicFileName;
case BOLD_ITALIC:
return family.mBoldItalicFileName;
}
}
// Fallback if we could not find the desired family
return "DroidSans.ttf";
| private static void | initFontFamilyMap()
sFontFamilyMap = new HashMap<String, FontFamily>();
FontFamily sansFamily = new FontFamily();
sansFamily.mNames = sSansNames;
sansFamily.mNormalFileName = "Roboto-Regular.ttf";
sansFamily.mBoldFileName = "Roboto-Bold.ttf";
sansFamily.mItalicFileName = "Roboto-Italic.ttf";
sansFamily.mBoldItalicFileName = "Roboto-BoldItalic.ttf";
addFamilyToMap(sansFamily);
FontFamily serifFamily = new FontFamily();
serifFamily.mNames = sSerifNames;
serifFamily.mNormalFileName = "NotoSerif-Regular.ttf";
serifFamily.mBoldFileName = "NotoSerif-Bold.ttf";
serifFamily.mItalicFileName = "NotoSerif-Italic.ttf";
serifFamily.mBoldItalicFileName = "NotoSerif-BoldItalic.ttf";
addFamilyToMap(serifFamily);
FontFamily monoFamily = new FontFamily();
monoFamily.mNames = sMonoNames;
monoFamily.mNormalFileName = "DroidSansMono.ttf";
monoFamily.mBoldFileName = "DroidSansMono.ttf";
monoFamily.mItalicFileName = "DroidSansMono.ttf";
monoFamily.mBoldItalicFileName = "DroidSansMono.ttf";
addFamilyToMap(monoFamily);
|
|