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
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