Wrong width using Graphics.getFontMetrics().getStringBounds() forItalic font

M

Martin Chan

When I use Graphics.getFontMetrics().getStringBounds() to calculate the
width of the string for Italic fonts, some portion of the last character
are cut. How to prevent it?

Any better method to calculate the width with different font style?

Thanks,
Martin Chan
 
G

Gregory A. Swarthout

Martin Chan said:
When I use Graphics.getFontMetrics().getStringBounds() to calculate the
width of the string for Italic fonts, some portion of the last character
are cut. How to prevent it?

Any better method to calculate the width with different font style?

Thanks,
Martin Chan

Show us your code.
 
M

Mark Thornton

Martin said:
When I use Graphics.getFontMetrics().getStringBounds() to calculate the
width of the string for Italic fonts, some portion of the last character
are cut. How to prevent it?

Any better method to calculate the width with different font style?

Thanks,
Martin Chan

This is the same as the Font.getStringBounds method:

http://java.sun.com/j2se/1.4.2/docs...lang.String, java.awt.font.FontRenderContext)

the bounds returned is the logical bounds. To obtain the visual bounds
use the getVisualBounds method on GlyphVector, or the getPixelBounds
method for a specific render context.

Mark Thornton
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top