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

Resolve several major issues: Vertical Metrics, Monospace Recognition #227

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

ottta
Copy link

@ottta ottta commented May 26, 2024

This PR only tweaks all vertical metrics and font info on each .glyphs file

1. Avoid write lastChange and displayString to version control

2. Check Use Typo Metrics to get more consistent vertical metrics
- https://learn.microsoft.com/en-us/typography/opentype/spec/os2#fsselection
- https://googlefonts.github.io/gf-guide/metrics.html#5-use_typo_metrics-must-be-enabled

3. Resolve #21 #37 #169
- #21 #37 "Hanging Font": Miss configure typo and hhea value. Adjust this value will "centering" glyphs across the vertical bounding box.
- #169 Probably same as above, tweaking typo and hhea does resolve the line-height or leading default to 1.2 or 120% from the upm value.

Note that "Gcommaaccent" may be truncated in environments that have overflow: hidden.

Please see these documentation:
- https://googlefonts.github.io/gf-guide/metrics.html#6-winascent-and-windescent-values-must-be-the-same-as-the-familys-tallestdeepest-ymin-and-ymax-bounding-box-values
- https://googlefonts.github.io/gf-guide/metrics.html#11-the-sum-of-the-fonts-vertical-metric-values-absolute-should-be-20-30-greater-than-the-fonts-upm

4. Resolve #111 not recognized as monospace font
Because isFixedPitch is not set, the record in the POST Table isFixedPitch has zero value.
Please refer to these:
- https://learn.microsoft.com/en-us/typography/opentype/spec/post#header
- https://googlefonts.github.io/gf-guide/requirements.html#monospace-fonts

These images below illustrate Aring on the overflow: hidden environment

Before: Top of Aring seems clipping because miss configuration typo/hhea
before-argon-bold

After: Resolve clipping and vertically balance basic latin
after-argon-bold

ottta added 6 commits May 26, 2024 20:27
- Display string can be heavy process while opening the .glyphs file
- lastChange possibly adding new unnecessary record history, such as last saved file or hit cmd + s
Highest & Lowest glyphs on each file:
- Monaspace Xenon Var.glyphs — Uring (2011.0), Gcommaaccent (-786.0)
- Monaspace Xenon.glyph — Uring (2011.0), Gcommaaccent (-786.0)

- Monaspace Argon Var.glyph — lacute (1988.0), Gcommaaccent (-786.0)
- Monaspace Argon.glyph — lacute (1988.0), Gcommaaccent (-786.0)

- Monaspace Krypton Var.glyph — lacute (1988.0), Gcommaaccent (-786.0)
- Monaspace Krypton.glyph — lacute (1988.0), Gcommaaccent (-786.0)

- Monaspace Neon Var.glyph — lacute (1988.0), Gcommaaccent (-786.0)
- Monaspace Neon.glyph — lacute (1988.0), Gcommaaccent (-786.0)

Please refer to these documentation:
- winAscent: https://learn.microsoft.com/en-us/typography/opentype/spec/os2#uswinascent
- winDescent: https://learn.microsoft.com/en-us/typography/opentype/spec/os2#uswindescent
- https://googlefonts.github.io/gf-guide/metrics.html#6-winascent-and-windescent-values-must-be-the-same-as-the-familys-tallestdeepest-ymin-and-ymax-bounding-box-values
- githubnext#21 githubnext#37 "Hanging Font": Miss configure `typo` and `hhea` value. Adjust this value will "centering" glyphs across the vertical bounding box.

- githubnext#169  Probably same as above, tweaking `typo` and `hhea` does resolve the `line-height` or `leading` default to `1.2` or `120%` from the upm value.

UPM = 2000
(typo/hhea)Ascenders = 1930
(typo/hhea)Descenders = -470
(typo/hhea)LineGap = 0

Total:
ascender + abs(descenders) + linegap = 2400

Note that "Gcommaaccent" may be truncated in environments that have `overflow: hidden`

Please see these documentation:
- https://googlefonts.github.io/gf-guide/metrics.html#6-winascent-and-windescent-values-must-be-the-same-as-the-familys-tallestdeepest-ymin-and-ymax-bounding-box-values
- https://googlefonts.github.io/gf-guide/metrics.html#11-the-sum-of-the-fonts-vertical-metric-values-absolute-should-be-20-30-greater-than-the-fonts-upm
@@ -53,6 +53,10 @@ value = 0;
{
name = "Use Typo Metrics";
value = 1;
},
{
name = isFixedPitch;
Copy link
Contributor

Choose a reason for hiding this comment

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

That would be automatically set if it would be valid iirc.

Forcing the value to 1 while the font is not isFixedPitch can lead to problems, see for example google/fonts#225

Anyhow, the root cause should be in

and supposedly it is fixed now. But it is not. I can redo the search for offending glyphs if need be.

Here the isFixedPitch value in the font file:

fini@Air ~ % showttf ~/Downloads/monaspace-v1.101/fonts/otf/MonaspaceArgon-Regular.otf | tail -n +1065 | head
Required tables: glyf and loca have been replaced by CFF => OpenType
post table (at 7312)
	 format=00030000
	 italicAngle=0
	 underlinePos=-70
	 underlineWidth=72
	 fixedpitch=0
	 mem1=0
	 mem2=0
	 mem3=0
	 mem4=0
fini@Air ~ %

Here a screenshot of the "warning" to set it in Glyphs ;-)

Screenshot 2024-06-07 at 17 13 21

@Finii
Copy link
Contributor

Finii commented Jun 7, 2024

Comment on commit 972eb52 Check Use Typo Metrics to get more consistent vertical metrics

More important would be to just make all 3 metrices the same (already the case), and avoid using gap values.

Hmm, and then the released font does already have that set, see here:

fini@Air ~ % font-line report ~/Downloads/monaspace-v1.101/fonts/otf/MonaspaceArgon-Regular.otf
=== /Users/fini/Downloads/monaspace-v1.101/fonts/otf/MonaspaceArgon-Regular.otf ===
Version 1.101 (Monaspace Argon)
SHA1: 02edd009f5cf7e196e311e7167dbf62b6fac3806

::::::::::::::::::::::::::::::::::::::::::::::::::
  Metrics
::::::::::::::::::::::::::::::::::::::::::::::::::
[head] Units per Em:   2000
[head] yMax:           1951
[head] yMin:          -760
[OS/2] CapHeight:      1460
[OS/2] xHeight:        1027
[OS/2] TypoAscender:   1565
[OS/2] TypoDescender: -435
[OS/2] WinAscent:      1878
[OS/2] WinDescent:     522
[hhea] Ascent:         1565
[hhea] Descent:       -435

[hhea] LineGap:        400
[OS/2] TypoLineGap:    400

::::::::::::::::::::::::::::::::::::::::::::::::::
  Ascent to Descent Calculations
::::::::::::::::::::::::::::::::::::::::::::::::::
[hhea] Ascent to Descent:              2000
[OS/2] TypoAscender to TypoDescender:  2000
[OS/2] WinAscent to WinDescent:        2400

::::::::::::::::::::::::::::::::::::::::::::::::::
  Delta Values
::::::::::::::::::::::::::::::::::::::::::::::::::
[hhea] Ascent to [OS/2] TypoAscender:       0
[hhea] Descent to [OS/2] TypoDescender:     0
[OS/2] WinAscent to [OS/2] TypoAscender:    313
[OS/2] WinDescent to [OS/2] TypoDescender:  87

::::::::::::::::::::::::::::::::::::::::::::::::::
  Baseline to Baseline Distances
::::::::::::::::::::::::::::::::::::::::::::::::::
hhea metrics: 2400
typo metrics: 2400
win metrics:  2400

[OS/2] fsSelection USE_TYPO_METRICS bit set: True

::::::::::::::::::::::::::::::::::::::::::::::::::
  Ratios
::::::::::::::::::::::::::::::::::::::::::::::::::
hhea metrics / UPM:  1.2
typo metrics / UPM:  1.2
win metrics  / UPM:  1.2
fini@Air ~ %

@ottta
Copy link
Author

ottta commented Jun 7, 2024

Comment on commit 972eb52 Check Use Typo Metrics to get more consistent vertical metrics

More important would be to just make all 3 metrices the same (already the case), and avoid using gap values.

Hmm, and then the released font does already have that set, see here:

fini@Air ~ % font-line report ~/Downloads/monaspace-v1.101/fonts/otf/MonaspaceArgon-Regular.otf
=== /Users/fini/Downloads/monaspace-v1.101/fonts/otf/MonaspaceArgon-Regular.otf ===
Version 1.101 (Monaspace Argon)
SHA1: 02edd009f5cf7e196e311e7167dbf62b6fac3806

::::::::::::::::::::::::::::::::::::::::::::::::::
  Metrics
::::::::::::::::::::::::::::::::::::::::::::::::::
[head] Units per Em:   2000
[head] yMax:           1951
[head] yMin:          -760
[OS/2] CapHeight:      1460
[OS/2] xHeight:        1027
[OS/2] TypoAscender:   1565
[OS/2] TypoDescender: -435
[OS/2] WinAscent:      1878
[OS/2] WinDescent:     522
[hhea] Ascent:         1565
[hhea] Descent:       -435

[hhea] LineGap:        400
[OS/2] TypoLineGap:    400

::::::::::::::::::::::::::::::::::::::::::::::::::
  Ascent to Descent Calculations
::::::::::::::::::::::::::::::::::::::::::::::::::
[hhea] Ascent to Descent:              2000
[OS/2] TypoAscender to TypoDescender:  2000
[OS/2] WinAscent to WinDescent:        2400

::::::::::::::::::::::::::::::::::::::::::::::::::
  Delta Values
::::::::::::::::::::::::::::::::::::::::::::::::::
[hhea] Ascent to [OS/2] TypoAscender:       0
[hhea] Descent to [OS/2] TypoDescender:     0
[OS/2] WinAscent to [OS/2] TypoAscender:    313
[OS/2] WinDescent to [OS/2] TypoDescender:  87

::::::::::::::::::::::::::::::::::::::::::::::::::
  Baseline to Baseline Distances
::::::::::::::::::::::::::::::::::::::::::::::::::
hhea metrics: 2400
typo metrics: 2400
win metrics:  2400

[OS/2] fsSelection USE_TYPO_METRICS bit set: True

::::::::::::::::::::::::::::::::::::::::::::::::::
  Ratios
::::::::::::::::::::::::::::::::::::::::::::::::::
hhea metrics / UPM:  1.2
typo metrics / UPM:  1.2
win metrics  / UPM:  1.2
fini@Air ~ %

It appears to be identical, but it is not. See the differences below.

The released version (old files: fonts/otf/*.otf)

before-argon-bold
Ascenders Descenders LineGap UPM
1565 -435 400 2000

(Ascender + Abs(Descender) + LineGap) / UPM = LineHeight
(1565 + Abs(-435) + 400) / 2000 = 1.2

Note: LineGap value 400

However, the above metrics caused Latin Capital Letter to not vertically center across the vertical bounding box:

Reference: https://googlefonts.github.io/gf-guide/metrics.html#9-uppercases-should-be-centered-in-the-text-line

The tweaked version (this PR: fonts/ttf/*.ttf)

after-argon-bold
Ascenders Descenders LineGap UPM
1930 -470 0 2000

(Ascender + Abs(Descender) + LineGap) / UPM = LineHeight
(1930 + Abs(-470) + 0) / 2000 = 1.2

Note: LineGap value 0

Even though I changed the Ascenders, Descenders, and LineGap values, the line-height values remained the same as before and are consistent accross platforms.

Reference: https://googlefonts.github.io/gf-guide/metrics.html#8-linegap-values-must-be-0

@Finii
Copy link
Contributor

Finii commented Jun 7, 2024

Well, the matrices were all the same, at least the baseline to baseline distance. 🤷‍♀️

More important would be to just make all 3 metrices the same (already the case), and avoid using gap values.

That's what you did, and what I said one should do. Set gaps to zero, they are a headache for fonts that are intended for terminals anyhow.

If the matrices are the same they will be rendered the same and "use typo metrics" (which is useless anyhow, as you know if you read all the documentation) is superfluous. The problem is that some terminals ignore GAP, some put it half top and bottom, some on the bottom, some on the top. That also affects this "not vertically centered"; the problem depends on the terminal used and how it interprets (if at all) the GAP.

Just setting the use-typo-metrics usually does not change anything, as the typo values ought to be used in any case ;-)

Google fonts has some "suggestions" that one can follow or not, like this one

Screenshot 2024-06-07 at 23 46 24

If you think Google is God, of course one needs to follow.

And why do you link this, as like, it contradicts what I said, when it is exactly my point?

Screenshot 2024-06-07 at 23 46 40

I don't get it.
Ciao.

@ottta
Copy link
Author

ottta commented Jun 8, 2024

Have you tried the .ttf files? And don't you see the difference?

Old MonaspaceArgonVarVF[wght,wdth,slnt].ttf

iTerm2
Screenshot 2024-06-08 at 9 10 17 PM

MacOS Terminal
Screenshot 2024-06-08 at 9 11 21 PM

New MonaspaceKryptonVarVF.ttf exported from GlyphsApp (not in this PR)

iTerm2
Screenshot 2024-06-08 at 9 10 44 PM

MacOS Terminal
Screenshot 2024-06-08 at 9 12 02 PM

Or from default HTML Button component

Google Chrome (Version 125.0.6422.142)
Screenshot 2024-06-08 at 10 06 53 PM

Safari (Version 17.4.1)
Screenshot 2024-06-08 at 10 08 50 PM

Firefox (Version 122.0.1)
Screenshot 2024-06-08 at 10 09 23 PM

Opera (Version: 109.0.5097.68)
Screenshot 2024-06-08 at 10 09 59 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
2 participants