Login | Register
My pages Projects Community openCollabNet

Reply to message

* = Required fields
* Subject
* Body
Send reply to
Author (directly in email)
Please type the letters in the image above.

Original message

Author tfmorris
Full name Tom Morris
Date 2009-01-12 10:08:34 PST
Message http://gef.tigris.or​g/issues/show_bug.cg​i?id=337
                 Issue #|337
                 Summary|Text bounds calculated incorrectly
       Status whiteboard|
              Issue type|DEFECT
             Assigned to|issues@gef
             Reported by|tfmorris

------- Additional comments from tfmorris at tigris dot org Mon Jan 12 10:08:32 -0800 2009 -------
The calcBounds method incorrectly calculates the bounding box. It doesn't take
into account the fact that the baseline (where the text is positioned) is almost
always inside the bounding box and it usually undermeasures the width of the text.

It shouldn't be doing the measuring by hand anyway. It should be using the Java
facilities for doing this. Something similar to the following from ArgoUML's
PathItemPlacement could be used as a template for implementation.

    private Rectangle remeasureText(Graphics g, FigText textFig) {
        FontRenderContext frc = ((Graphics2D) g).getFontRenderContext();
        AttributedCharacterIterator aci = new AttributedString(textFig
        LineBreakMeasurer lbm = new LineBreakMeasurer(aci, frc);
        // No autowrapping - use a wide width
        TextLayout tl = lbm.nextLayout(5000);
        return tl.getBounds().getBounds();