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

Hack Font too high compared to other terminals #7596

Closed
W4RH4WK opened this issue Sep 10, 2020 · 8 comments
Closed

Hack Font too high compared to other terminals #7596

W4RH4WK opened this issue Sep 10, 2020 · 8 comments
Labels
Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing.

Comments

@W4RH4WK
Copy link

W4RH4WK commented Sep 10, 2020

Environment

Windows build number: Microsoft Windows [Version 10.0.18363.1082]
Windows Terminal version (if applicable): 1.2.2381.0

wsl-terminal, mintty 3.1.6

Steps to reproduce

Use Hack font (size 10) in Windows Terminal and wsl-terminal and compare them side-by-side.

Expected behavior

Content of both terminals should look identical.

Actual behavior

The font seems to be out of proportion in Windows Terminal.
The following screenshot compares them side by side.

winterm_font_1

Here wsl-terminal's transparency setting is set to high and wsl-terminal was moved right over Windows Terminal for better comparison. In Windows Terminal, the characters are taller while having the same width.

winterm_font_2

@ghost ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Sep 10, 2020
@DHowett
Copy link
Member

DHowett commented Sep 10, 2020

after you read this, see #7596 (comment) for a bit more information. I don't necessarily think Hack is incorrect. I'm keeping the original comment body for posterity.

This is an unfortunate result of the way the Hack font is authored.

There was, for a long time, a divide in font rendering technology on Windows and other platforms. Because of this, fonts had separate fields for "how big is a character?" on Windows and all other platforms.

That disparity was fixed in approximately 2009 when Windows 7 shipped with DirectWrite, our modern font rendering technology.

Because of that, the "Windows" measurements are considered legacy.

Unfortunately, the Hack font contains the following measurements and flags:

    <sTypoAscender value="1556"/>    <!-- modern measurements -->
    <sTypoDescender value="-492"/>
    <usWinAscent value="1901"/>      <!-- legacy measurements -->
    <usWinDescent value="483"/>
    <fsSelection value="00000000 01000000"/>
    <!--                         ^ if this is a 0, use the legacy measurements. if 1, use the modern ones. -->

Following the legacy measurements, a single cell in this font is 2384 units tall. Following the modern measurements, it is 2048 units tall.

WT uses DirectWrite, which has a strict interpretation of this flag. It is following the legacy measurements because the font told it to.

mintty's renderer seems to be behaving out-of-spec:

Some legacy applications use the usWinAscent and usWinDescent values to determine default line spacing. This is strongly discouraged. The sTypo* fields should be used for this purpose.
OS/2 and Windows Metrics Table specification

Emphasis mine. The line measurer in use in mintty appears to be disregarding the discouragement and it results in a tighter line spacing than it should.


It looks like gvim also "follows the rules"; the line spacing matches Terminal, even though gvim uses GDI (legacy) for measurement:

image

@DHowett
Copy link
Member

DHowett commented Sep 10, 2020

I am clearly deluded about the vim thing. That's definitely not the same.

I had accidentally returned my font to Cascadia Code and tried to measure again. Hack is working as in my screenshot.

@DHowett DHowett added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Sep 10, 2020
@ghost ghost added the No-Recent-Activity This issue/PR is going stale and may be auto-closed without further activity. label Sep 14, 2020
@ghost
Copy link

ghost commented Sep 14, 2020

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

@ghost ghost removed the No-Recent-Activity This issue/PR is going stale and may be auto-closed without further activity. label Sep 14, 2020
@W4RH4WK
Copy link
Author

W4RH4WK commented Sep 15, 2020

This seems to be a miss-configuration of the font itself. I've opened an issue, but the project seems rather inactive at the moment. I'd welcome an option (maybe as temporary workaround) to switch the rendering engine to use legacy measurement --- similar to the way mintty handles it. However, I fully understand that this may not be technically feasible or desired by the devs as it is basically a hack.

@ghost ghost added Needs-Attention The core contributors need to come back around and look at this ASAP. and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels Sep 15, 2020
@DHowett
Copy link
Member

DHowett commented Sep 15, 2020

So, this might not work. If you want to give it a shot, it should result in a version of Hack named Hack Patched.

prerequisites

Install fonttools (in WSL)

apt install -yy fonttools

Move to a folder that contains Hack-Regular.ttf

steps

ttx -o Hack-Patched.ttx Hack-Regular.ttf
sed -i -e '/Hack-/s/Hack/HackPatched/g; s/Hack\b/Hack Patched/g; /fsSelection/s/01000000/11000000/g; /sTypoLineGap/s/410/0/' Hack-Patched.ttx
ttx Hack-Patched.ttx
  1. decompile the font to xml
  2. sed script to do 3 things:
    1. Change the name of the font to Hack Patched (first two substitutions)
    2. Change fsSelection's 7th bit (0-indexed, count from the right) to 1 to indicate "use the typographic metrics"
    3. Zap the typographic line gap to 0 (from 410 design units). This makes the font very tight.
  3. recompile the font from xml

Here's what it looks line in my terminal.

(before on the left, after on the right)

image

This modification comes with no warranty; the font is MIT-licensed and does not appear to have a RFN; if it blows up in other applications, consider yourself warned.

@DHowett DHowett removed the Needs-Attention The core contributors need to come back around and look at this ASAP. label Sep 15, 2020
@DHowett
Copy link
Member

DHowett commented Sep 15, 2020

For our side, I'm gonna close this as a /duplicate of #3498.

I'm no longer certain it's the font that's wrong. That "line gap" value actually makes it render exactly the same in [legacy] mode as it does in [modern] mode. An application that is ignoring the "line gap" value is, to a rough first approximation, incorrect. I do think it should be configurable, though.

@ghost
Copy link

ghost commented Sep 15, 2020

Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!

@ghost ghost closed this as completed Sep 15, 2020
@ghost ghost added Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing. and removed Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Sep 15, 2020
@W4RH4WK
Copy link
Author

W4RH4WK commented Sep 15, 2020

Thank you for describing how to patch the font.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing.
Projects
None yet
Development

No branches or pull requests

2 participants