-
Notifications
You must be signed in to change notification settings - Fork 823
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
Bitmap font and TextField autoSize ignore lineHeight #1002
Comments
Ok, I for a long time this is not a bug, I think this is a feature... :-) /** This text bounds respect font lineHeight and it height can be only (lineHeight*scale * N). */
private function getTrueTextBounds(out:Rectangle = null):Rectangle
{
out ||= new Rectangle();
out.setEmpty();
// for TrueType fonts
var mesh:Mesh = getChildAt(0) as Mesh;
var font:BitmapFont = getCompositor(format.font) as BitmapFont;
if (font == null)
{
mesh.getBounds(this, out);
out.inflate(-2, -2);
return out;
}
// for empty text field
var scale:Number = format.size / font.size;
var numDrawableChars:int = mesh.numVertices / 4;
if (numDrawableChars == 0)
{
out.setTo(0, 0, 0, font.lineHeight * scale);
return out;
}
if (autoScale) scale = NaN;
// find anchor chars
var leftmostCharLeft:Number = NaN;
var rightmostCharRight:Number = NaN;
var bottommostCharTop:Number = NaN;
var topmostCharTop:Number = NaN;
var numNonDrawableChars:int = 0;
for (var i:int = 0; i < text.length; i++)
{
var charID:int = text.charCodeAt(i);
var char:BitmapChar = font.getChar(charID);
var charQuadIndex:int = i - numNonDrawableChars;
if (charQuadIndex >= numDrawableChars) break;
var charIsDrawable:Boolean = char != null && (char.width != 0 && char.height != 0);
if (charIsDrawable)
{
if (scale != scale)
{
var quadHeight:Number = mesh.getVertexPosition(charQuadIndex*4 + 3, _sPoint).y
- mesh.getVertexPosition(charQuadIndex*4 + 0, _sPoint).y;
scale = quadHeight / char.height;
}
var charLeft:Number = mesh.getVertexPosition(charQuadIndex*4 + 0, _sPoint).x - char.xOffset*scale;
if (charLeft < leftmostCharLeft || leftmostCharLeft != leftmostCharLeft)
leftmostCharLeft = charLeft;
var charRight:Number = mesh.getVertexPosition(charQuadIndex*4 + 1, _sPoint).x;
if (charRight > rightmostCharRight || rightmostCharRight != rightmostCharRight)
rightmostCharRight = charRight;
var charTop:Number = _sPoint.y - char.yOffset*scale;
if (charTop > bottommostCharTop || bottommostCharTop != bottommostCharTop)
bottommostCharTop = charTop;
if (charTop < topmostCharTop || topmostCharTop != topmostCharTop)
topmostCharTop = charTop;
}
else
numNonDrawableChars++;
}
// find width & height
var lineHeight:Number = font.lineHeight*scale;
var leading:Number = format.leading*scale;
var numLines:int = 1 + int((bottommostCharTop-topmostCharTop) / (lineHeight+leading));
var width:Number = rightmostCharRight - leftmostCharLeft;
var height:Number = numLines*lineHeight + (numLines-1)*leading;
out.setTo(leftmostCharLeft, topmostCharTop, width, height);
return out;
} This not give 100% good result there are some problems with different fonts without addition small changes. But this method is dirty hack because TextField do not provides any text metrics such num lines etc. |
…height (refs #1002) Instead, the last line now only verifies that there's enough room for the _font size_.
I just fixed that the text was not drawn at all if there was not enough space for the next As for the Right now, auto-sizing is not even done by the Instead, what you can always do is not use |
Yes, when I read One thing I do not like is "artistic" termin is not defined explicit, this generate various misunderstandings in text rendering. As I write into msdf-bmfont issue, simple change After deep into typography text metrics I uderstand what can be mean under "artistic" - render font respect body height (from descender line to ascender line) ignore shoulders. Current This may causes text dancing even on only number text field on fonts like Georgia. TL;DRI do not suggest change any Starling text render code. /** An offset that moves any generated text along the x-axis (in points).
* Useful to make up for incorrect font data. @default 0. */
public function get offsetX():Number { return _offsetX; }
public function set offsetX(value:Number):void { _offsetX = value; }
/** An offset that moves any generated text along the y-axis (in points).
* Useful to make up for incorrect font data. @default 0. */
public function get offsetY():Number { return _offsetY; }
public function set offsetY(value:Number):void { _offsetY = value; } This feature allow prepare font asset correctly and avoid usage this values. |
Yes, I understand the problem — and I agree with you that the current behaviour is not what some people might expect. I've got a proposal: what if I add new Those would leave the x and y values of the QuadBatch that displays the glyphs untouched, and would only change the width / height of the TextField so that it takes up just enough space as needed. I'm aware that especially the term "right" is not ideal when talking about RTL-fonts. But since the Starling TextField doesn't do much in those terms, anyway ... 😬 |
I do not think this is a good idea :-) I fix all my problems use extended text field with overriden And again, I do not suggest any starling's change right now, I do not have much experience in it. Daniel, you commit f67a204 have mistake, which break my code: if (fontSize <= containerHeight) This is not valid condition because if (_size <= containerHeight) |
Ah, damn — sorry for that! I just fixed that error. Thanks for making me aware of it! I do not think this is a good idea :-) Ah, okay, I see! Let me know if you change your mind — or, anyone else reading this, tell me if you want to see that happen. |
There are issues reported lately:
soimy/msdf-bmfont-xml#8
feathersui/feathersui-starling#1633
When Textfield set to
autoSize = VERTICAL
, textField's height is cropped tobodyHeight
andlineGap
(shoulder) is ignored.In this case font.fnt metrics are:
fontSize: 42
lineHeight: 50
baseline: 32
lineGap: 8
(EqualslineHeight - fontSize
)Case 1:
autoSize = VERTICAL
Smallest Textfield's height is
lineHeight
(50), smaller height will remove all text render.Case 2:
autoSize = BOTH_DIRECTION
Textfield's height is
fontSize+1
(43)Maybe it's better to make textfield's height consistent between these two cases.
The text was updated successfully, but these errors were encountered: