Print problem

R

Ralph Curtis

I'm trying to print some columnar character data. I use monospace font in
which all characters are the same width. I try to get the character width
and from there calculate the number of characters per line. Simple stuff but
it doesn't work reliably. The problem is that I am not always getting the
correct rendering widths for the monospaced fonts depending on the font size
I use.

I use:

double charWidth = printingFont.getStringBounds("w",
g2d.getFontRenderContext()).getWidth();

to get the rendered character widths. But the value returned is wrong.

font size 10 -> width 6.0 (pretty good for a page with 1 inch margins - 468
imageable width)
font size 9 -> width 5.0 (should be closer to 5.4)
font size 8 -> width 5.0 (should be close to 4.8)

I have tried getting the width of a full line of n chars but it just ends up
being (n * the width) shown above.

What am I doing wrong?
How do I get the true rendered character widths?

Any hints or pointers in the right direction are appreciated.

Ralph
 

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

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,281
Latest member
Pedroaciny

Latest Threads

Top