Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: TextLayout.getBounds() bug?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: TextLayout.getBounds() bug?



We've successfully used TextLayouts for some time with our own text boxes... Macs definitely have some issues, but nothing we couldn't [eventually] wiggle around. So don't give up hope... but do be patient. :)

The worst bug we've found so far is if your TextLayout contains anything italic, then the carets (and possibly other info) are severely off. (The word "severely" doesn't do justice... they're unusable screen clutter at this point.) If your text contains italics, that might be related.

We never actually call getBounds()... have you tried constructing the bounds yourself?

Below I copied & pasted snippets of code that should probably get you the width and height of your text for an array of TextLayout's:

float textHeight = 0;
float width = 0;
for(int a = 0; a<layouts.length; a++) {
if(a==0) {
textHeight+=layouts[a].getAscent() + layouts[a].getDescent();
} else {
textHeight+=layouts[a-1].getLeading()+layouts[a].getAscent() + layouts[a].getDescent();
}
width = Math.max(width,layouts[a].getVisibleAdvance());
}


Also as a possible test, you might try getting the glyph shape of that TextLayout, wrapping it an a java.awt.geom.Area, and asking the bounds of that area. Depending on the complexity of your use, this is probably waaaaaay too expensive to use in your final release... but it might be useful for debugging.

On Nov 1, 2005, at 3:36 PM, Jean-Michel Decombe wrote:

On Nov 1, 2005, at 3:17 PM, Drago Goricanec wrote:

In writing my application I've come across what I think is a bug in
Apple's implementation of java.awt.font.TextLayout's getBounds() method. I
am trying to find the bounds of rendered text (i.e., a rectangle that
describes all pixels that will be modified for a given String). I'm using
the example from TextLayout Javadoc. However, I cannot make sense of the
information returned. The Y coordinate does not describe either the top
left corner, nor the origin of the baseline.

I have not had time to file bugs on that yet, but there are definitely bugs in that area of the API. For instance, when I use a TextLayout object to render text on multiple lines through iteration over a LineBreakMeasurer object, some lines overflow to the right, as if there was a problem in character sequence measurement.


So I would definitely file bugs if I were you. I will try to file mine ASAP.

JM

. . .
Jean-Michel Decombe <email@hidden>
Chief Technology Officer
Groxis, Inc. <http://www.groxis.com>

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden


This email sent to email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. Java-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >TextLayout.getBounds() bug? (From: "Drago Goricanec" <email@hidden>)
 >Re: TextLayout.getBounds() bug? (From: Jean-Michel Decombe <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.