import java.awt.Font
import java.io.File
import java.io.FileInputStream
public class Loadfont
{
public static Font loadFont(String fontFileName, float fontSize) //第一个参数是外部字体名,第兄凯二个是字体大小
{
try
{
File file = new File(fontFileName)
FileInputStream aixing = new FileInputStream(file)
Font dynamicFont = Font.createFont(Font.TRUETYPE_FONT, aixing)
Font dynamicFontPt = dynamicFont.deriveFont(fontSize)
aixing.close()
return dynamicFontPt
}
catch(Exception e)//异常处理
{
e.printStackTrace()
return new java.awt.Font("宋体羡渣唤", Font.PLAIN, 14)
}
}
public static java.awt.Font Font(){
String root=System.getProperty("user.dir")//项目根目录路梁基径
Font font = Loadfont.loadFont(root+"/data/PRISTINA.ttf", 18f)//调用
return font//返回字体
}
public static java.awt.Font Font2(){
String root=System.getProperty("user.dir")//项目根目录路径
Font font = Loadfont.loadFont(root+"/data/XXXX.ttf", 18f)
return font//返回字体
}
}
2.转换:
public static String ascii2native(String ascii) {
int n = ascii.length() / 6
StringBuilder sb = new StringBuilder(n)
for (int i = 0, j = 2i <ni++, j += 6) {
String code = ascii.substring(j, j + 4)
char ch = (char) Integer.parseInt(code, 16)
sb.append(ch)
}
return sb.toString()
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)