-
Notifications
You must be signed in to change notification settings - Fork 824
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
TextField vertical alignment differs between bitmap font and ttf #902
Comments
I had similar issues with Starling 1.8 - bitmap fonts where never perfectly aligned and I had to add these micro adjustments to make them look good. |
Thanks for the report! For best results, bitmap fonts should be displayed in the same size you defined on export; otherwise, some values I'm reading from the XML are simply not correct. For example, all In a quick test, I could reproduce your findings, even though the difference is less severe. I will see if there's something I can do about it. |
Okay, after looking into it, I think the difference comes from the 2 pixel gutter that's added by Flash TextFields. It's mentioned in the documentation of the TextLineMetrics class. My BitmapFont implementation does not add that gutter, and I'm unsure why it's there, in the first place. However, testing it, the results seem more similar to native TrueType rendering: Left: Bitmap Font However, I'm a little unsure about how to proceed. If I simply add this, a lot of users will suddenly have their text moved 2 points right and downwards — I don't think everybody will love that. 😉 What I'm considering is adding a property ( Opinions? |
Thanks for identifying the source! Adding an accessible gutter property would probably be appropriate solution. |
Thanks for your comments!
That would need to be set once per BitmapFont. If the BitmapFont is created by the AssetManager, you'd get it via |
Ahhhh, that would make sense. One thought on default value: I know, a bit counter-intuitive for people like you actually coding Starling...but might make more sense to users? Just a thought... |
Ah, no, it doesn't add any gutter right now! The gutter I mentioned is only used by Flash's native TextField, and thus by Starling's TextField if it uses a TrueType font (since in that case, I'm simply rendering a native TextField into a Bitmap). A TextField that uses a BitmapFont doesn't have any gutter right now — and that's exactly why there's the difference to a TrueType TextField. Thus, the default value on BitmapFont would be zero, and that means the appearance is unchanged. |
That should do it! 😄 |
Thanks! Based on the previous behavior, this approach only corrects vAlign.TOP properly. Would it help for you to have my generated fnt and png for the font? |
In that case, my guess is that the font data that's output by your tool is not the same I'm getting. I used "Glyph Designer" on the Mac, and got the following output (font size is '12'): Could you compare this with your files? Which tool have you been using? Did you export the font with a size of 12? |
Yeah, yours looks much better! I have been using Littera's online bitmap font creator...perhaps I need to use a better tool to get more satisfactory results. |
Littera is definitely not a bad tool, but I guess there's some interpretation involved about how convert certain settings when creating the Bitmap font — thus, different tools will yield different results. Glyph Designer seems to be closer to what Flash does, apparently. Perhaps you can ask the author of Littera to see if there's a way to fix that? In the Starling forum, his name is "Kvazar". You could send him a private message, he's very approachable! 😄 |
Problem:
When using bitmap fonts, the TextField vertically aligns text slightly higher than True type fonts (see attached pic for sample output showing vertical alignments of Top, Center, and Bottom).
Sample code:
for center vert alignment (I created a test bitmap font (using Littera) of Verdana for the sake of comparing here):
var normalFont:TextField = new TextField(120, 30, "Hello world");
normalFont.format.setTo("Verdana", 12, 0x000000, Align.CENTER, Align.CENTER);
var bitmapFont:TextField = new TextField(120, 30, "Hello world");
bitmapFont.format.setTo("VerdanaTest", 12, 0x000000, Align.CENTER, Align.CENTER);
Issue versions:
It does this using 2.0.1 swc (and I have pulled the src from here today and tried with the same result)
Add'n info:
This is an issue for me when trying to make "slim" textfields (so the height of the textfield is just slightly larger than the text) because the bitmap font requires more space because of the extra bottom padding it appears to be adding. It is particularly noticeable when the textfield border = true.
The text was updated successfully, but these errors were encountered: