`
lucene321
  • 浏览: 175807 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

SWT font set

    博客分类:
  • java
阅读更多
    when generate a image for chinese character, if your computer has no song ti font style, should read a system file to load the font style.

find following file.
c:\windows\fonts\simsun.ttc

coding as follows:
font ttffont = font.createfont(font.truetype_font, new file("c:\windows\fonts\simsun.ttc"));

font ttfreal = ttffont.derivefont(font.plain, 12);
image = new bufferedimage(width, height, bufferedimage.type_int_rgb);
graphics2d g2 = (graphics2d) image.getgraphics();
g2.setbackground(color.yellow);
g2.clearrect(0, 0, width, height);
g2.setpaint(color.black);
fontrendercontext context = g2.getfontrendercontext();
rectangle2d bounds = ttfreal.getstringbounds(name, context);
double x = (width - bounds.getwidth()) / 2;
double y = (height - bounds.getheight()) / 2;
double ascent = -bounds.gety();
double basey = y + ascent;
g2.setfont(ttfreal);
g2.drawstring(name, (int) x, (int) basey); 
0
2
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics