邓华

BlogJava 联系 聚合 管理
  48 Posts :: 0 Stories :: 149 Comments :: 0 Trackbacks

为了解决linux上的中方问题,今天在google上搜索了一圈, 发现都是需要在linux的全局加入字体,在java中引用才能解决。不死心,因为在原来的PHP程序中可以直接使用TTF字体,在JAVA类库中有了发现。

呵呵,不多写了,直接帖上测试原码。

 

import java.io.File;
import java.awt.*;

public class testFont {

  private static String fontpath = "D:\\work\\WORK\\fonts\\";
  private static java.io.File file = new java.io.File(fontpath + "simhei.ttf");

  public testFont() {
  }

  public static void main(String args[]) {

    if (!file.exists()) {
      System.out.println("file not found");
      return;
    }
    try {
      java.io.FileInputStream fi = new java.io.FileInputStream(file);
      java.io.BufferedInputStream fb = new java.io.BufferedInputStream(fi);
      Font nf = Font.createFont(Font.TRUETYPE_FONT, fb);

      nf = nf.deriveFont(Font.BOLD, 10);
      System.out.println(nf.getFontName());
      System.out.println(nf.getSize());
    }
    catch (Exception e) {
      System.out.println(e.getMessage());
    }
  }

}

 

posted on 2006-03-16 11:58 邓华的碎碎念 阅读(723) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: