|
Hi;
I have tried getting the width of some text in
points and I get very different values. In one case 449 vs. 480.
Method 1:
Font font = FontFactory.getFont( "Times New
Roman", "Cp1252", false, 12.0f, Font.BOLD);
BaseFont bf =
font.getBaseFont();
int width = bf.getWidthPoint(
text, 12.0f );
Method 2:
AttributedString as = new
AttributedString(text);
as.addAttribute(TextAttribute.WEIGHT,
TextAttribute.WEIGHT_BOLD, 0, text.length());
as.addAttribute(TextAttribute.FONT, new Font( "Times New Roman", Font.PLAIN, 12.0f, 0, text.length()); AttributedCharacterIterator aci =
as.getIterator();
... AttributedString asBlk = new
AttributedString(aci, 0, text.length());
int width = (int) new TextLayout(asBlk.getIterator(), frc).getAdvance(); Any idea why these are sometimes so
different?
thanks - dave
|
