• Post Reply Bookmark Topic Watch Topic
  • New Topic

LineBreakMeasurer and Fonts  RSS feed

 
Thomas Strunzer
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,
i've a method, which draws Strings in a graphiccontext, bounded by a given dimension,
it works good, here's it:
public void drawText(Graphics2D g, String text, float width, float height, float xPos, float yPos) {
g.setFont(new Font("Arial", 0, 14));
FontRenderContext fCtx = g.getFontRenderContext();
LineBreakMeasurer linebreaker = new LineBreakMeasurer(
new AttributedString(text).getIterator(), fCtx);
float y = yPos;
while (linebreaker.getPosition() < text.length() && y < yPos + height) {
TextLayout tl = linebreaker.nextLayout(width);
y += tl.getAscent();
tl.draw(g, xPos, y);
y += tl.getDescent() + tl.getLeading();
}
}
Unfortunately the "g.setFont(new Font("Arial", 0, 14));" don't work. It has no effect.
So please, how can i change the font?
Thanks in advance,
Thomas
[ November 05, 2002: Message edited by: Thomas Strunzer ]
 
Thomas Strunzer
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
cause there's no answer yet, it won't be possible
really!?
 
Thomas Strunzer
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
it works now.
Apparently the TextLayout doesn't care what font the Graphics2D object has. I had to set it in the AttributeString:
addAttribute(TextAttribute.FONT, font);
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!