Skip to content
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

Glyph placing is odd #5

Open
davidgiga1993 opened this issue Dec 12, 2021 · 4 comments
Open

Glyph placing is odd #5

davidgiga1993 opened this issue Dec 12, 2021 · 4 comments

Comments

@davidgiga1993
Copy link

I've noticed that using roboto-regular the glyph placing is a bit odd.

This is a sample render using the shader from msdf-gen and the texture has been generated with this utility.

image

As you can see the B is placed a bit too high as well as the l and the L. The D also looks a bit off.
The issues persists when scaling the font to any size, so my guess is that the font generation messes something up?

@maltaisn
Copy link
Owner

I can reproduce this issue with roboto-regular with 32 px size. The issue disappears at 48 px size.

It's been some time since I've taken at look at this, but it seems I knew this was an issue judging by this comment:

* Note that font and glyph metrics seems kinda off sometimes. I used:
* - https://github.com/libgdx/libgdx/tree/aff6dd4a2622d64a62196111eb018d4699a19c8a/extensions/gdx-tools/src/com/badlogic/gdx/tools/hiero
* - https://github.com/soimy/msdf-bmfont-xml/blob/ff3669c2bfffd06f29bacedcdf3f073379b45e7e/index.js
* To guess which font metrics would work but it might not work for all fonts.

The issue gets worse at smaller font sizes. One solution is to manually adjust the yoffset field for problematic characters in the generated .fnt file. For example, the t character (id=116) has a very noticeable offset in the roboto-16 example font, but it looks fine after changing yoffset=4 to yoffset=3 (smaller number moves the glyph up).

@davidgiga1993
Copy link
Author

davidgiga1993 commented Dec 14, 2021

I already tried adjusting the yoffset but 1px step size is not fine granular enough. That's probably why the issue disappears with larger fonts. A proper solution would be to use float as yoffset (and make libgdx use float as well).
Since I'm already running my own fork of libgdx I'll do some experiments, maybe that already solves the issue?

@rafaskb
Copy link

rafaskb commented Dec 20, 2023

Hey @davidgiga1993 were you able to fix that issue by any chance? I'm running into the same problem and everything points to msdf-gdx-gen being the culprit (Hiero always outputs a valid font, even with SDF).

I'm trying to understand the code to maybe try some things and hopefully fix it, but I'm having a hard time understanding where this offset is calculated. Would appreciate if anyone could point me to some directions here.

@davidgiga1993
Copy link
Author

Hey @davidgiga1993 were you able to fix that issue by any chance? I'm running into the same problem and everything points to msdf-gdx-gen being the culprit (Hiero always outputs a valid font, even with SDF).

I'm trying to understand the code to maybe try some things and hopefully fix it, but I'm having a hard time understanding where this offset is calculated. Would appreciate if anyone could point me to some directions here.

Nope, not really. I moved away from the idea of using msdf and rather generate a dynamic font texture atlas on-demand which works well enough for my use case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants