More work for the weekend...
Best Regards,
Paulo Soares
> -Original Message-
> From: Erwin Achermann [SMTP:[EMAIL PROTECTED]]
> Sent: Friday, April 26, 2002 13:58
> To: iText ML (E-Mail)
> Subject: [iText-questions] PdfGraphics2D: how to get the text width
>
> Hi all,
>
> I am using PdfGraphics2D in place of an old PrinterGraphics2D. In my code
> I have the following snippet:
>
> width = g2d.getFontMetrics().getStringBounds(txt, flushIndex, flushIndex
> + flushLen, g2d).getWidth();
>
> to compute the horizontal extension of some string. This seems to be the
> culprit in my case. It seems as if this sequence used on PdfGraphics2D is
> not yielding the correct width. Can you affirm this observation? Is there
> a more elegant way to find out the exact width of some rendered text? As a
> workaround I extended my own PdfGraphics2D by the method:
>
> public double getWidthPoint(java.lang.String s) {
> return (double)baseFont.getWidthPoint(s,fontSize);
> }
>
> and my code snipped reads, now:
>
> // width = g2d.getFontMetrics().getStringBounds(txt, flushIndex,
> flushIndex + flushLen, g2d).getWidth();
> java.lang.String tmp = new java.lang.String(txt,flushIndex,
> flushLen);
> PdfGraphics2D pg = (PdfGraphics2D)g2d;
> width = pg.getWidthPoint(tmp);
>
> In my cases this fixes the problem. But I'm not totally calm, because the
> idea of PdfGraphics2D was to have be able to use it as any other
> Graphics2D Object given this situation, that goal is not attained :(
> Also my PdfGraphics2D.getWidthPoint(s) is not taking into consideration
> that the font itself may carry an AffineTransform different from identity,
> which will of course affect the resulting width. Any better solutions?
>
> Thanks and Cheers
> Erwin
>
> ___
> iText-questions mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/itext-questions
___
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions