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

Scaling inconsistency between text and glyphs #1056

Closed
3 tasks done
dstoliker opened this issue Jan 19, 2023 · 13 comments · Fixed by #1060
Closed
3 tasks done

Scaling inconsistency between text and glyphs #1056

dstoliker opened this issue Jan 19, 2023 · 13 comments · Fixed by #1060
Milestone

Comments

@dstoliker
Copy link

🗹 Requirements

  • I have searched the issues for my issue and found nothing related and/or helpful
  • I have searched the FAQ for help
  • I have searched the Wiki for help

🎯 Subject of the issue

Experienced behavior:
After upgrading to the latest version of the Hack nerd font via homebrew, there is an an apparent inconsistency between text and glyph scaling. I have a command line prompt configured with Oh My Posh with powerline symbols. After upgrading my font to the latest version, the glyphs no longer line up vertically. The glyphs are now taller. See screenshots below.

Expected behavior:
Text and glyphs should align as they did before the upgrade.

Example symbols:
\ue0b6
\ue0b4

🔧 Your Setup

  • Which font are you using (e.g. Anonymice Powerline Nerd Font Complete.ttf)?
    • Hack Regular Nerd Font Complete.ttf
  • Where did you get the file from (download link, self patched, source downloaded from link...)
    • Mac cask homebrew install
  • Which terminal emulator are you using (e.g. iterm2, urxvt, gnome, konsole)?
    • iterm2
  • Are you using OS X, Linux or Windows? And which specific version or distribution?
    • MacOS 12.6.2 (Monterey)

★ Screenshots (Optional)

Powerline bar as it appeared before font package upgrade:
before update

After upgrade:
after update

iTerm2 font settings:
font settings

@Finii
Copy link
Collaborator

Finii commented Jan 19, 2023

Sorry to hear that. Can see the differences...

image

@Finii
Copy link
Collaborator

Finii commented Jan 19, 2023

Thanks for reporting. And thanks for a complete report with all the details I need to reproduce 👍

@Finii
Copy link
Collaborator

Finii commented Jan 19, 2023

image

image

@Finii
Copy link
Collaborator

Finii commented Jan 19, 2023

Oh man, do I hate the metrics inconsistencies 😒

And whats this
image

@Finii
Copy link
Collaborator

Finii commented Jan 19, 2023

On my machine with tilix

image

When I can see it, it should be 'easy' to fix.

@Finii
Copy link
Collaborator

Finii commented Jan 19, 2023

I think I found the reason.

Introduced a gap-redistribution with #943
The problem is that the gap is always redistributed, even if the font is based on the old WIN metrics. That does not have a gap 🙄

Rewriting the gap stuff right now.

Thanks again for reporting!


Useful links

In fontforge we have (example for ascent)

sourceFont.os2_winascent
sourceFont.os2_typoascent
sourceFont.hhea_ascent
sourceFont.ascent       <=- what is represented by this

@Finii Finii added this to the v2.3.2 milestone Jan 19, 2023
@Finii
Copy link
Collaborator

Finii commented Jan 19, 2023

Systematic examination of all source fonts regarding vertical metrics, one file of each font chosen at random.

find src/unpatched-fonts -iname '*.[ot]tf' | \
  sed -E 's! !\\!g;s!([^/]*/[^/]*/[^/]*).*!\0 \1!' | \
  sort | uniq -f 1 | sed 's! .*!!;s!\\! !g;s!^!"!;s!$!"!' | \
  xargs font-line report
Font hhea/UPM typo/UPM win/UPM use typo metrics gap win/mac note
3270 1.09 1.0 1.09 X X 🟥 forgot to set typo-gap?
Agave 1.12 1.0 1.12 X 🟥
Anonymous 1 1 1 ✔️
Arimo 1.15 1.09 1.15 X ✔️
Aurulent 1.3 1.09 1.3 X ✔️
BigBlue 1 1 1 X ✔️
Bitstream Vera 1.16 1.2 1.16 X ✔️
Cascadia 1.16 1.16 1.32 X ✔️
CodeNewRoman 1.17 1.17 1.17 X ✔️
Couisine 1.13 0.842 1.13 ✔️
DaddyTime 1.25 1.25 1.25 X ✔️
DejaVu 1.16 1.2 1,16 X ✔️
Droid 1.16 1.07 1.16 X ✔️
Fantasque 1.05 1.05 1.05 X X ✔️
Fira 1.23 1.23 1.23 X ✔️
Fira Mono 1.4 1.4 1.4 X ✔️
Gohu 1.18 1.18 1.18 X X ✔️
Go Mono 1.16 1.16 1.16 X ✔️
Hack 1.16 1.2 1.16 X ✔️
Hasklig 1.26 1 1.26 ✔️
HeavyData 1.15 1.09 1.15 X ✔️
Hermit 1.56 1.09 1.56 X X 🟥
iA writer 1.3 1.3 1.3 X ✔️
IBM Plex 1.3 1.3 1.3 X ✔️
InconsolataGo 1.05 1.05 1.05 ✔️
Inconsolata 1.05 1.05 1.46 X ✔️
Inconsolata LGC 1.46 1 1.46 X ✔️
Iosevka 1.25 1.25 1.25 X X ✔️
JetBrains Mono 1.32 1.32 1.32 X ✔️
Lekton 1 1 1.7 🟥
Liberation 1.13 0.842 1.13 ✔️
Lilex 1.3 1.3 1.3 X ✔️
Meslo 1.55 1.59 1.55 X ✔️
Monofur 1 1 1 X ✔️
Monoid 1.33 1.33 1.33 X ✔️
Mononoki 1.12 1.2 1.12 X ✔️
M+ 1.49 1.09 1.49 X ✔️
Noto 1.17 1.17 1.17 ✔️
OpenDyslexic 3.58 1.94 3.58 ✔️
Overpass 1.53 1.27 1.53 X X 🟥
ProFont 1.23 1.23 1.23 ✔️
ProggyClean 0.812 1 0.812 ✔️
Roboto 1.17 1.05 1.2 X 🟥 'alomst ok'
ShareTech 1.13 1.13 1.13 ✔️
SourceCode 1.26 1 1.26 ✔️
SpaceMono 1.48 1.48 1.48 X ✔️
Terminus 1.1 1.09 1.1 X X 🟥 'almost ok'
Tinos 1.15 1.04 1.15 X ✔️
Ubuntu 1.15 1.02 1.15 X ✔️
Ubuntu Mono 1 0.907 1 X ✔️
Victor Mono 1.41 1.41 1.41 X X ✔️

Most crucial is that WIN does use the other gaps?! See https://learn.microsoft.com/en-us/typography/opentype/spec/recom#baseline-to-baseline-distances

@Finii
Copy link
Collaborator

Finii commented Jan 19, 2023

I will combine this with #1055

@Finii Finii changed the title Hack nerd font scaling inconsistency between text and glyphs after update Scaling inconsistency between text and glyphs Jan 20, 2023
Finii added a commit that referenced this issue Jan 20, 2023
[why]
The initial font-patcher used the WIN font metrics to determine the cell
height. What has been found was forced into HHEA metrics but without
observing the USE_TYPO_METRICS flag.
That has been changed to use the TYPO metric instead of the WIN metric
when the font wants that. For that the gap value becomes important.

This is the current code. It still has problems to detect the correct
cell height. A more rigorous approach seem to be needed.

[how]
The baseline to baseline distance is what we need as 'cell height', to
fill it completely with the powerline glyphs. This is a little bit
complicated and not really specified, each font rendering application or
engine can handle the font metrics differently. But there are some
common approaches.

So we try to come up with the correct and congruent height, comparing
different metrics and issuing a warning on problematic fonts.
Afterwards we make all metrics equal (even if they were not before),
because our goal is clear now and we impose it onto all platforms.

[note]
Useful resources:
* https://glyphsapp.com/learn/vertical-metrics
* https://github.com/source-foundry/font-line

Fixes: #1056

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
Finii added a commit that referenced this issue Jan 22, 2023
[why]
The initial font-patcher used the WIN font metrics to determine the cell
height. What has been found was forced into HHEA metrics but without
observing the USE_TYPO_METRICS flag.
That has been changed to use the TYPO metric instead of the WIN metric
when the font wants that. For that the gap value becomes important.

This is the current code. It still has problems to detect the correct
cell height. A more rigorous approach seem to be needed.

[how]
The baseline to baseline distance is what we need as 'cell height', to
fill it completely with the powerline glyphs. This is a little bit
complicated and not really specified, each font rendering application or
engine can handle the font metrics differently. But there are some
common approaches.

So we try to come up with the correct and congruent height, comparing
different metrics and issuing a warning on problematic fonts.
Afterwards we make all metrics equal (even if they were not before),
because our goal is clear now and we impose it onto all platforms.

[note]
Useful resources:
* https://glyphsapp.com/learn/vertical-metrics
* https://github.com/source-foundry/font-line

Fixes: #1056

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
@Finii
Copy link
Collaborator

Finii commented Jan 22, 2023

Problematic cases:

font behavior hhea typo win ymin ymax y height
3270 [2] 2180 2000 2180 406 1626 2032
Agave [2] 2304 2048 2304 512 1792 2304
Hermit [2] 1506 1092 1506 414 1000 1414
Lekton [1] 1000 1000 1697 585 1112 1697
Overpass [2] 1532 1266 1532 378 1062 1440
Roboto [3] 2.5% 2400 2150 2458 555 2163 2718
Terminus [3] 3% 1122 1090 1122 183 845 1028

[1] Mismatch detected, chooses TYPO
[2] Mismatch detected, chooses WIN
[3] Mismatch detected, following USE-TYPO-METRICS

All looks ok, except Lekton, the only font that selects TYPO.
So changing algo to not guess but always use WIN in thoses cases

Finii added a commit that referenced this issue Jan 22, 2023
[why]
When HHEA and (depending on USE-TYPO-METRIC) TYPO or WIN are not
consistent it is unclear which metric we should trust.

In #1056 the complete font bounding box (i.e. yMin and yMax) has been
compared to the baseline to baseline distances, and in all these cases
the WIN values seem to be best (preserve the glyph bounding box).

    font-line report fontname.ttf | grep metrics:
    ttfdump -t head fontname.ttf | grep "yM(in|ax)"

[note]
Roboto will still be clipped?! There seem to be ridiculously high glyphs
in there. Did not check which.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
Finii added a commit that referenced this issue Jan 22, 2023
[why]
When HHEA and (depending on USE-TYPO-METRIC) TYPO or WIN are not
consistent it is unclear which metric we should trust.

In #1056 the complete font bounding box (i.e. yMin and yMax) has been
compared to the baseline to baseline distances, and in all these cases
the WIN values seem to be best (preserve the glyph bounding box).

    font-line report fontname.ttf | grep metrics:
    ttfdump -t head fontname.ttf | grep "yM(in|ax)"

[note]
Roboto will still be clipped?! There seem to be ridiculously high glyphs
in there. Did not check which.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
@tjapro
Copy link

tjapro commented Jan 31, 2023

Sorry, to ask this here but I cannot find what I want ...

@dstoliker Where/What is these glyphs (the ones right in the line begining)?

image

@Finii
Copy link
Collaborator

Finii commented Jan 31, 2023

This rounded line? At 2570:

image

@Finii
Copy link
Collaborator

Finii commented Apr 30, 2023

While doing v3.0.0 ... Lekton is still problematic, too big gaps between lines:

image

Lets have a look at the table from above:

image

Lekton was the only font that selected TYPO but we forced it to WIN, because not all glyphs fit into the values from TYPO.
But that seems to be wrong. Examining the glyphs that are really bigger than the TYPO line spaces, these are only graphical glyphs that shall span multiple lines. So I guess we should revert that change and render Lekton with the TYPO values.

Finii added a commit that referenced this issue Apr 30, 2023
This reverts commit 6210087,
and adapts the code to more recent changes (logging, enums).

[why]
Lekton has a too wide line spacing.

Lekton was the only font that selected TYPO but we forced it to WIN,
because not all glyphs fit into the values from TYPO.
But that seems to be wrong. Examining the glyphs that are really bigger
than the TYPO line spaces, these are only graphical glyphs that shall
span multiple lines. So I guess we should revert that change and render
Lekton with the TYPO values.

[note]
#1056 (comment)
@github-actions
Copy link
Contributor

This issue has been automatically locked since there has not been any recent activity (i.e. last half year) after it was closed. It helps our maintainers focus on the active issues. If you have found a problem that seems similar, please open a new issue, complete the issue template with all the details necessary to reproduce, and mention this issue as reference.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 30, 2023
LNKLEO pushed a commit to LNKLEO/Nerd that referenced this issue Nov 24, 2023
[why]
The initial font-patcher used the WIN font metrics to determine the cell
height. What has been found was forced into HHEA metrics but without
observing the USE_TYPO_METRICS flag.
That has been changed to use the TYPO metric instead of the WIN metric
when the font wants that. For that the gap value becomes important.

This is the current code. It still has problems to detect the correct
cell height. A more rigorous approach seem to be needed.

[how]
The baseline to baseline distance is what we need as 'cell height', to
fill it completely with the powerline glyphs. This is a little bit
complicated and not really specified, each font rendering application or
engine can handle the font metrics differently. But there are some
common approaches.

So we try to come up with the correct and congruent height, comparing
different metrics and issuing a warning on problematic fonts.
Afterwards we make all metrics equal (even if they were not before),
because our goal is clear now and we impose it onto all platforms.

[note]
Useful resources:
* https://glyphsapp.com/learn/vertical-metrics
* https://github.com/source-foundry/font-line

Fixes: ryanoasis#1056

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants