-
Notifications
You must be signed in to change notification settings - Fork 313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MOAITextLabel:getTextBounds it was the execution result, the return value is incorrect. #1006
Comments
Looks like the new implementation returns bounds relative to center of the rect - a bug. Another issue that I was facing is how the height is calculated. For many use cases (like crossing text) height should be taken as line height instead of each glyph's bounding box. |
Will look into this, guys. Thanks! |
Here is what I use locally (to get constant line height irrespective to the actual rendered glyphs): for ( u32 i = spanIdx; i < end; ++i ) {
MOAITextSprite& sprite = this->mSprites [ i ];
MOAIGlyph& glyph = *sprite.mGlyph;
if ( glyph.mWidth > 0.0f ) {
ZLRect glyphRect = glyph.GetRect ( sprite.mPen.mX, sprite.mPen.mY, sprite.mScale.mX, sprite.mScale.mY );
// Update the glyphRect with glyphset's metrics,
// Taking into the account line ascent and lineHeight to properly
// handle descenders and ascenders: p j q g l i
float fontSize = sprite.mStyle->GetSize ();
MOAIGlyphSet* glyphSet = sprite.mStyle->GetFont ()->GetGlyphSet ( fontSize );
float deckHeight = glyphSet->GetHeight () * sprite.mScale.mY;
float deckAscent = glyphSet->GetAscent () * sprite.mScale.mY;
glyphRect.mYMax = sprite.mPen.mY - deckAscent;
glyphRect.mYMin = glyphRect.mYMax - deckHeight;
if ( result ) {
rect.Grow ( glyphRect );
}
else {
rect = glyphRect;
result = true;
}
}
} |
I'll need to expose a way to get either. I redid some of that stuff so I could line up billboarded text correctly with the original text in an SVG, but I understand why you'd need the other height. |
OK, re the centered textbox, the behavior did but the value is correct (for the new implementation). getStringBounds/getTextBounds returns the bounds in model space. To make the 'autoflip' textbox behavior easier to implement, I now center the glyphs around the origin. Would it be worth modifying that method to return the coords in 'text space' vs model space? |
Is 'text space' a top-left origin, y facing down? Then definitely not. I expect values to be in model space. In Makoto's post he have textbox rect non-centered, with origin in top-left (or bottom-right). But getStringBounds returns bounds as if origin was centered. Maybe we should apply offset before returning bounds? For centered bounds (what I use) the behaviour will be the same. |
I was a little more testing.
I think that is better to behave as before desirable. If possible. I by this problem, some of the components (TextInput) did not work. As a workaround, setRect always center is set to 0. |
Thank you everyone. As a new external specification, what should be the getTextBounds / getStringBounds function? |
MOAITextLabel:getTextBounds it was the execution result, the return value is incorrect.
The text was updated successfully, but these errors were encountered: