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

Kerning Pairs (monospace image font) can affect the kerning of subsequent characters, off by one pixel #93199

Closed
DarkMarmot opened this issue Jun 15, 2024 · 9 comments · Fixed by #93256
Assignees
Milestone

Comments

@DarkMarmot
Copy link

DarkMarmot commented Jun 15, 2024

Tested versions

  • Reproducible in: Godot v4.3.beta1 - Windows 10.0.22631 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3050 (NVIDIA; 31.0.15.5176) - AMD Ryzen 7 2700 Eight-Core Processor (16 Threads)

System information

Godot v4.3.beta1 - Windows 10.0.22631 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3050 (NVIDIA; 31.0.15.5176) - AMD Ryzen 7 2700 Eight-Core Processor (16 Threads)

Issue description

When using kerning pairs, the space between two characters can be affected by the character that came before them. It appears there is some kind of rounding layout issue, not sure if this is a bug in kerning or in the rendering pipeline.

image

In the example, A and B have different kerning offsets when followed by p. The space between u and p then differs between them.

Steps to reproduce

Open the project and the layout issue is visible in the main scene for preview and run.

Note that this affect can be achieved by changing things like character margins as well to generate inconsistent layouts.

Minimal reproduction project (MRP)

kerning_layout_issue.zip

@DarkMarmot DarkMarmot changed the title Kerning Pairs can affect the kerning of subsequent characters, off by one pixel Kerning Pairs (monospace image font) can affect the kerning of subsequent characters, off by one pixel Jun 15, 2024
@bruvzg
Copy link
Member

bruvzg commented Jun 15, 2024

The issue seems to be how HarfBuzz apply kerning, half is applied to the previous glyph advance, half to the next glyph offset. This works with normal fonts, but with 1px kerning it will result in 0.5 pixel offsets and rounding errors.

@DarkMarmot
Copy link
Author

@bruvzg thanks for working on such quick fixes for this feature! As someone relatively new to Godot, I really appreciate it!

@capnm
Copy link
Contributor

capnm commented Jun 17, 2024

If I hit those 3 bins and reimport, your issue is fixed for me (Linux, v4.3.beta1 or github tip).

Screenshot from 2024-06-17 18-56-25

Screenshot from 2024-06-17 18-56-38

@DarkMarmot
Copy link
Author

@capnm That deletes the kerning pairs, thus removing character specific kerning entirely. This bug report is about the usage of the kerning pairs feature itself.

@capnm
Copy link
Contributor

capnm commented Jun 18, 2024

@capnm That deletes the kerning pairs, thus removing character specific kerning entirely. This bug report is about the usage of the kerning pairs feature itself.

Kerning pairs for monospace fonts? This is IMO a bug – you shouldn't use kerning here at all.

@DarkMarmot
Copy link
Author

Kerning pairs for monospace fonts? This is IMO a bug – you shouldn't use kerning here at all.

The datatype will probably be renamed to bitmap image fonts or such since this feature allows them to no longer be exclusively monospace.

@capnm
Copy link
Contributor

capnm commented Jun 18, 2024

I thought you also needed the *.fnt file for kerning the bitmap files? No?

@bruvzg
Copy link
Member

bruvzg commented Jun 18, 2024

I thought you also needed the *.fnt file for kerning the bitmap files? No?

You can manually specify kernings and custom glyph offsets/advanced in the image import settings, importer should be renamed it was monospace when it was first added, but this is no longer the case. The source image is expected to be uniform character grid (you can't specify arbitrary rect for the character), but the font itself is not monospaced.

@capnm
Copy link
Contributor

capnm commented Jun 18, 2024

I guess that's then the implemented spec...

bmfont -> Block type 5: kerning pairs

https://calligro.ideasalmanac.com/

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

Successfully merging a pull request may close this issue.

5 participants