1. 程式人生 > >linux加載字體

linux加載字體

nts resource phi puts .class void create throws path

static {
try {
registerNewFont(PatentsConstants.PDF_FONT_PATH + "arialuni.ttf");
registerNewFont(PatentsConstants.PDF_FONT_PATH + "simsun.ttc");
registerNewFont(PatentsConstants.PDF_FONT_PATH + "simsun_bold.ttf");
registerNewFont(PatentsConstants.MY_PDF_FONT_PATH + "MSYH.TTF");
registerNewFont(PatentsConstants.MY_PDF_FONT_PATH + "MSYHBD.TTF");
registerNewFont(PatentsConstants.MY_PDF_FONT_PATH + "SIMHEI.TTF");
registerNewFont(PatentsConstants.MY_PDF_FONT_PATH + "SIMHEIBD.TTF");
registerNewFont(PatentsConstants.MY_PDF_FONT_PATH + "ARIALBI.TTF");
registerNewFont(PatentsConstants.MY_PDF_FONT_PATH + "TIMESBI.TTF");
} catch (Exception e) {

}
}

private static void registerNewFont(String path) throws Exception {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
// 讀取resource中的字體
InputStream in = Object.class.getClassLoader().getResourceAsStream(path);
// 創建字體
Font newFont = Font.createFont(Font.TRUETYPE_FONT, in);
in.close();
// 註冊字體
ge.registerFont(newFont);
}

linux加載字體