本文整理了Java中android.graphics.Typeface.createFromFile()
方法的一些代码示例,展示了Typeface.createFromFile()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Typeface.createFromFile()
方法的具体详情如下:
包路径:android.graphics.Typeface
类名称:Typeface
方法名:createFromFile
暂无
代码示例来源:origin: ankidroid/Anki-Android
public static Typeface getTypeface(Context ctx, String path) {
try {
if (path.startsWith(fAssetPathPrefix)) {
return Typeface.createFromAsset(ctx.getAssets(), path.replaceFirst("/android_asset/", ""));
} else {
return Typeface.createFromFile(path);
}
} catch (RuntimeException e) {
Timber.w(e, "Runtime error in getTypeface for File: %s", path);
if (!corruptFonts.contains(path)) {
// Show warning toast
String name = new File(path).getName();
Resources res = AnkiDroidApp.getAppResources();
Toast toast = Toast.makeText(ctx, res.getString(R.string.corrupt_font, name), Toast.LENGTH_LONG);
toast.show();
// Don't warn again in this session
corruptFonts.add(path);
}
return null;
}
}
代码示例来源:origin: commonsguy/cw-omnibus
@Override
public void onCreate(Bundle state) {
super.onCreate(state);
setContentView(R.layout.main);
TextView tv=(TextView)findViewById(R.id.custom);
Typeface face=
Typeface.createFromAsset(getAssets(), "fonts/HandmadeTypewriter.ttf");
tv.setTypeface(face);
File font=
new File(Environment.getExternalStorageDirectory(), "MgOpenCosmeticaBold.ttf");
if (font.exists()) {
tv=(TextView)findViewById(R.id.file);
face=Typeface.createFromFile(font);
tv.setTypeface(face);
}
else {
findViewById(R.id.filerow).setVisibility(View.GONE);
}
}
}
代码示例来源:origin: igreenwood/SimpleCropView
typeface = Typeface.createFromFile(fontFilePath);
new File(fontFilePath).delete();
} catch (IOException e) {
代码示例来源:origin: termux/termux-app
void checkForFontAndColors() {
try {
@SuppressLint("SdCardPath") File fontFile = new File("/data/data/com.termux/files/home/.termux/font.ttf");
@SuppressLint("SdCardPath") File colorsFile = new File("/data/data/com.termux/files/home/.termux/colors.properties");
final Properties props = new Properties();
if (colorsFile.isFile()) {
try (InputStream in = new FileInputStream(colorsFile)) {
props.load(in);
}
}
TerminalColors.COLOR_SCHEME.updateWith(props);
TerminalSession session = getCurrentTermSession();
if (session != null && session.getEmulator() != null) {
session.getEmulator().mColors.reset();
}
updateBackgroundColor();
final Typeface newTypeface = (fontFile.exists() && fontFile.length() > 0) ? Typeface.createFromFile(fontFile) : Typeface.MONOSPACE;
mTerminalView.setTypeface(newTypeface);
} catch (Exception e) {
Log.e(EmulatorDebug.LOG_TAG, "Error in checkForFontAndColors()", e);
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void createFromFile_withFile_shouldCreateTypeface() {
Typeface typeface = Typeface.createFromFile(fontFile);
assertThat(typeface.getStyle()).isEqualTo(Typeface.NORMAL);
assertThat(shadowOf(typeface).getFontDescription().getFamilyName()).isEqualTo("myFont.ttf");
}
代码示例来源:origin: robolectric/robolectric
@Test
public void createFromFile_withPath_shouldCreateTypeface() {
Typeface typeface = Typeface.createFromFile(fontFile.getPath());
assertThat(typeface.getStyle()).isEqualTo(Typeface.NORMAL);
assertThat(shadowOf(typeface).getFontDescription().getFamilyName()).isEqualTo("myFont.ttf");
assertThat(shadowOf(typeface).getFontDescription().getStyle()).isEqualTo(Typeface.NORMAL);
}
代码示例来源:origin: weexteam/weex-hackernews
private static boolean loadLocalFontFile(String path, String fontFamily) {
if (TextUtils.isEmpty(path) || TextUtils.isEmpty(fontFamily)) {
return false;
}
try {
File file = new File(path);
if (!file.exists()) {
return false;
}
Typeface typeface = Typeface.createFromFile(path);
if (typeface != null) {
FontDO fontDo = sCacheMap.get(fontFamily);
if (fontDo != null) {
fontDo.setState(FontDO.STATE_SUCCESS);
fontDo.setTypeface(typeface);
if(WXEnvironment.isApkDebugable()) {
WXLogUtils.d(TAG, "load local font file success");
}
return true;
}
} else {
WXLogUtils.e(TAG, "load local font file failed, can't create font.");
}
} catch (Exception e) {
WXLogUtils.e(TAG, e.toString());
}
return false;
}
代码示例来源:origin: Gamelab-Istanbul/NgdroidApp
public void setBaseFont(int fontNo, String path) {
basefont[fontNo] = Typeface.createFromFile(path);
}
代码示例来源:origin: codekidX/storage-chooser
public static Typeface getSCTypeface(Context context, String path, boolean assets) {
if (assets) {
return Typeface.createFromAsset(context.getAssets(),
path);
}
return Typeface.createFromFile(path);
}
代码示例来源:origin: zom/Zom-Android
public static void setTypefaceFromFile (Context context, String path)
{
File fileFont = new File(path);
if (fileFont.exists())
mTypeface = Typeface.createFromFile(fileFont);
}
代码示例来源:origin: marzika/Snapprefs
public static Typeface get(File name) {
Typeface tf = fontCache.get(name);
if(tf == null) {
try {
tf = Typeface.createFromFile(name);
}
catch (Exception e) {
return null;
}
fontCache.put(name, tf);
}
return tf;
}
}
代码示例来源:origin: whinc/FontTextView
private Typeface createTypefaceFromFile(String fontPath) {
SoftReference<Typeface> typefaceRef = mCache.get(fontPath);
Typeface typeface = null;
if (typefaceRef == null || (typeface = typefaceRef.get()) == null) {
typeface = Typeface.createFromFile(fontPath);
typefaceRef = new SoftReference<>(typeface);
mCache.put(fontPath, typefaceRef);
}
return typeface;
}
代码示例来源:origin: PrivacyApps/document-viewer
@Override
protected Typeface loadTypeface(final FontFamilyType type, final FontInfo fi) {
final File f = getFontFile(fi);
try {
return f.exists() ? Typeface.createFromFile(f) : null;
} catch (final Throwable th) {
th.printStackTrace();
}
return null;
}
}
代码示例来源:origin: termux/termux-float
void checkForFont() {
try {
@SuppressLint("SdCardPath") File fontFile = new File("/data/data/com.termux/files/home/.termux/font.ttf");
final Typeface newTypeface = (fontFile.exists() && fontFile.length() > 0) ? Typeface.createFromFile(fontFile) : Typeface.MONOSPACE;
mTerminalView.setTypeface(newTypeface);
} catch (Exception e) {
Log.e(EmulatorDebug.LOG_TAG, "Error in checkForFont()", e);
}
}
代码示例来源:origin: ydcx/KooReader
private static Typeface createTypefaceFromFile(Typeface[] typefaces, String family, int style) {
final File[] files = getFontFileMap(false).get(family);
if (files == null) {
return null;
}
try {
if (files[style] != null) {
return Typeface.createFromFile(files[style]);
}
for (int i = 0; i < 4; ++i) {
if (files[i] != null) {
if (typefaces[i] == null) {
typefaces[i] = Typeface.createFromFile(files[i]);
}
return typefaces[i];
}
}
} catch (Throwable e) {
}
return null;
}
代码示例来源:origin: osfans/trime
public Typeface getFont(String key) {
String name = getString(key);
if (name != null) {
File f = new File(getResDataDir("fonts"), name);
if (f.exists()) return Typeface.createFromFile(f);
}
return Typeface.DEFAULT;
}
代码示例来源:origin: MCMrARM/revolution-irc
public Typeface getChatFont() {
if (mCachedFont != null)
return mCachedFont;
String font = mPreferences.getString(PREF_CHAT_FONT, "default");
if (ListWithCustomSetting.isPrefCustomValue(font)) {
File file = ListWithCustomSetting.getCustomFile(mContext, PREF_CHAT_FONT, font);
try {
mCachedFont = Typeface.createFromFile(file);
return mCachedFont;
} catch (Exception ignored) {
}
}
if (font.equals("monospace"))
return Typeface.MONOSPACE;
else if (font.equals("serif"))
return Typeface.SERIF;
else
return Typeface.DEFAULT;
}
代码示例来源:origin: lltvcn/FreeText
public static Typeface getTypeface(String name){
if(contain(fileFonts,name)){
return Typeface.createFromFile(FileUtil.getFontPath(name));
}else if(contain(assetFonts,name)){
return Typeface.createFromAsset(context.getAssets(),"ttf/"+name);
}else {
return null;
}
}
代码示例来源:origin: Jiangzqts/EpubRead
private static Typeface getOrCreateEmbeddedTypeface(SystemInfo systemInfo, FontEntry entry, boolean bold, boolean italic) {
final Spec spec = new Spec(entry, bold, italic);
Object cached = ourCachedEmbeddedTypefaces.get(spec);
if (cached == null) {
final FileInfo fileInfo = entry.fileInfo(bold, italic);
if (fileInfo != null) {
final String realFileName = alias(systemInfo, entry.Family, bold, italic);
if (copy(fileInfo, realFileName)) {
try {
cached = Typeface.createFromFile(realFileName);
} catch (Throwable t) {
// ignore
}
}
new File(realFileName).delete();
}
ourCachedEmbeddedTypefaces.put(spec, cached != null ? cached : NULL_OBJECT);
}
return cached instanceof Typeface ? (Typeface)cached : null;
}
代码示例来源:origin: ydcx/KooReader
private static Typeface getOrCreateEmbeddedTypeface(SystemInfo systemInfo, FontEntry entry, boolean bold, boolean italic) {
final Spec spec = new Spec(entry, bold, italic);
Object cached = ourCachedEmbeddedTypefaces.get(spec);
if (cached == null) {
final FileInfo fileInfo = entry.fileInfo(bold, italic);
if (fileInfo != null) {
final String realFileName = alias(systemInfo, entry.Family, bold, italic);
if (copy(fileInfo, realFileName)) {
try {
cached = Typeface.createFromFile(realFileName);
} catch (Throwable t) {
// ignore
}
}
new File(realFileName).delete();
}
ourCachedEmbeddedTypefaces.put(spec, cached != null ? cached : NULL_OBJECT);
}
return cached instanceof Typeface ? (Typeface)cached : null;
}
内容来源于网络,如有侵权,请联系作者删除!