Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > There is no font characteristic in java.text.LineBreakMeasure class?

Reply
Thread Tools

There is no font characteristic in java.text.LineBreakMeasure class?

 
 
MaoXuePeng
Guest
Posts: n/a
 
      01-10-2005
Hello, erveryone!
I want to draw mutil-paragraphy strings in a image. My code is:
Font font = new Font("宋体",Font.PLAIN,15);
String str_test =
"看看效果吧,怎样,还行不?不行的话再修改罗!!";
java.text.AttributedString att_str = new
java.text.AttributedString(str_test);
FontRenderContext context = g2.getFontRenderContext();
TextLayout layout = new TextLayout(str_test,font,context);
float begin_x = 40f;
float begin_y = 50f;
System.out.println(g2.getFont());
layout.draw(g2,40f,50f);//Can draw with correct font
java.text.AttributedCharacterIterator it = att_str.getIterator();
java.awt.font.LineBreakMeasurer measure =
new java.awt.font.LineBreakMeasurer(it,context);
float x=0,y=0;
float formatWidth = image.getWidth() - begin_x;
int begin = it.getBeginIndex();
int end = it.getEndIndex();
measure.setPosition(begin);
//g2.setFont(font);
System.out.println(g2.getFont());
while(measure.getPosition()<end)
{
layout = measure.nextLayout(formatWidth);
//No font infomation? Why?

if(!layout.isLeftToRight())
{
x = formatWidth - layout.getAdvance();
}
else
{
x = 0;
}
y += layout.getAscent();
layout.draw(g2,x,y);
y += layout.getDescent() + layout.getLeading();
}
javax.imageio.ImageIO.write(image,"png",new
java.io.File("str_test.png"));
}

It seems that "layout = new TextLayout(...)" can retain the font
information and draw, but "layout = measure.nextLayout(..)" can
not(measure is a instance of LineBreakMeasure), Why?
Can somebody help me?

Thanks advance!
MaoXuePeng.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Swing Font, it's Java Font? ot native? how install new font? mttc Java 2 07-03-2009 07:29 PM
Ideal characteristic curve for digital printing Marc Wossner Digital Photography 3 04-13-2008 04:10 PM
How to get the text in html tag.like<div...><font...>Text</font></ =?Utf-8?B?Tmlja3k=?= ASP .Net 2 02-20-2005 03:03 PM
What is the Characteristic Curve function of a digital camera? Roger N. Clark (change username to rnclark) Digital Photography 9 01-31-2005 03:29 PM
Font class, external font files question Karl Hungus ASP .Net 1 02-04-2004 04:26 PM



Advertisments