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

Improve vertical alignment of fonts #2724

Merged
merged 7 commits into from
Mar 29, 2023
Merged

Improve vertical alignment of fonts #2724

merged 7 commits into from
Mar 29, 2023

Conversation

lictex
Copy link
Contributor

@lictex lictex commented Feb 12, 2023

try to proper align glyph from different fallback fonts on the baseline without some manually tricky tweaks

i guess in most cases (where no font fallback happens) it should look same as before
FontTweak::scale now should only affect glyphs themselves, not full text layouts (row heights, alignments etc). imo for the latter case is better to change the actual font size instead of using this hacky scale...


test using Cantarell as primary font and Noto Sans CJK as cjk fallback
all font tweak values are default

before after
image image

note the row height is now calculated using the font metrics from the tallest glyph
example: the second row is slightly taller than the first because of the noto cjk glyphs

before after
image image

might also resolve #2700

before after
image image

why theres still some tweaks for the emoji-icon-font
emoji-icon-font notoemoji-regular
image image

note that emoji-icon-font has a significantly lower baseline than other common fonts.
this will make the correct rendering look a bit off center:

image
image taken from libreoffice

...which is not so good

Copy link
Owner

@emilk emilk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks extremely promising - thanks for working on this!

crates/epaint/src/text/font.rs Outdated Show resolved Hide resolved
@lictex lictex marked this pull request as ready for review March 1, 2023 20:43
@emilk emilk merged commit 94f8b02 into emilk:master Mar 29, 2023
@emilk
Copy link
Owner

emilk commented Mar 29, 2023

Thank you!

@emilk emilk added text Problems related to text egui labels Apr 18, 2023
@emilk emilk changed the title improve fallback fonts alignment Improve verticla alignment of fonts Apr 18, 2023
@emilk emilk changed the title Improve verticla alignment of fonts Improve vertical alignment of fonts Apr 18, 2023
emilk added a commit that referenced this pull request Sep 19, 2024
* Closes #4929
* Builds on top of #2724 by @lictex
(ptal!)
* Implement `Center` and `Max` vertical text alignment properly
* Change default vertical alignment of text to centering

The end result is that text centers better in buttons and other places,
especially when mixing in emojis.
Before, mixing text of different heights (e.g. emojis and latin text) in
a label or button would cause the text to jump vertically.

## Before
This is `master`, with custom `FontTweak` to move fonts up and down:
<img width="1714" alt="image"
src="https://github.com/user-attachments/assets/a10e2927-e824-4580-baea-124c0b38a527">
<img width="102" alt="image"
src="https://github.com/user-attachments/assets/cd41f415-197b-42cd-9558-d46d63c21dcb">


## After
This PR, with the default (zero) `FontTweak`

<img width="102" alt="image"
src="https://github.com/user-attachments/assets/15e7d896-66b1-4996-ab58-dd1850b19a63">

<img width="1714" alt="image"
src="https://github.com/user-attachments/assets/54ec708c-7698-4754-b1fc-fea0fd240ec9">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
egui text Problems related to text
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom fonts have vertical offset with unicode symbols
2 participants