linux加载字体

    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);
    }

posted @ 2017-10-09 08:38  剑神西门吹雪  阅读(411)  评论(0编辑  收藏  举报