`

linux使用中文字体

 
阅读更多

先将中文字体上传到jdkInstall/jre/fonts里,就可以自动使用,或者可用固定目录的形式使用,比如:

    public static Font getDefinedFont(String fontUrl, float fs) {  
    	Font definedFont = null;   
//        String fontUrl="C:/Users/Administrator/Desktop/STKAITI.TTF";  
//        String fontUrl="C:/Users/Administrator/Desktop/msyh.ttc";  
        if (definedFont == null) {    
            InputStream is = null;    
            BufferedInputStream bis = null;    
            try {    
                is =new FileInputStream(new File(fontUrl));  
                bis = new BufferedInputStream(is);    
                definedFont = Font.createFont(Font.TRUETYPE_FONT, is);  
                //设置字体大小,float型  
               definedFont = definedFont.deriveFont(fs);  
            } catch (FontFormatException e) {    
                e.printStackTrace();    
            } catch (IOException e) {    
                e.printStackTrace();    
            } finally {   
               try {    
                    if (null != bis) {    
                        bis.close();    
                    }    
                    if (null != is) {    
                        is.close();    
                    }    
                } catch (IOException e) {    
                    e.printStackTrace();    
                }  
            }    
        }    
        return definedFont;    
    }

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics