Login | Register
My pages Projects Community openCollabNet

gef
Reply to message

* = Required fields
* Subject
* Body
Attachments
Send reply to
Topic
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
               Component|gef
                 Version|current
                Platform|All
                     URL|
              OS/Version|All
                  Status|NEW
       Status whiteboard|
                Keywords|
              Resolution|
              Issue type|DEFECT
                Priority|P3
            Subcomponent|core
             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
                .getText()).getIterator();
        LineBreakMeasurer lbm = new LineBreakMeasurer(aci, frc);
        // No autowrapping - use a wide width
        TextLayout tl = lbm.nextLayout(5000);
        return tl.getBounds().getBounds();
    }