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 characters stretched when font size is <= 11 #612

Closed
gnojus opened this issue Apr 22, 2021 · 22 comments
Closed

Hack characters stretched when font size is <= 11 #612

gnojus opened this issue Apr 22, 2021 · 22 comments

Comments

@gnojus
Copy link

gnojus commented Apr 22, 2021

🎯 Subject of the issue

When font size is below or equal to 11 the patched Hack font is stretched and noticeably differs from original font.

Happens in terminals and native (probably gtk) font picker, but not in libre-office

🔧 Your Setup

  • Font: Hack Regular Nerd Font Complete.ttf
  • Terminal: xfce4-terminal and tilda
  • OS: Linux, Debian 10, xfce4

★ Optional

I attach a gif displaying this behavior:
fonts

Thanks!

@vaijab
Copy link

vaijab commented Jan 6, 2022

I have the same exact issue too. It seem that the patched fonts size is actually 11.5 instead of 11.

@Finii
Copy link
Collaborator

Finii commented Jan 7, 2022

Strange.

  1. I can not see the current Hack Regular Nerd Font Complete.ttf in the font chooser at all
  2. If I prepare a patched Hack font manually, I do not see the issue:

Peek 2022-01-07 16-09

Where did you get the Hack Regular Nerd Font Complete.ttf that is recognized as monospaced by the font chooser?

@Finii
Copy link
Collaborator

Finii commented Jan 7, 2022

Also strange, why does the Nerd Font show up as 'Regular' 'Bold' etc in the chooser and the original Hack isn't?
I assume you installed only the Regular font files in both cases?

@gnojus
Copy link
Author

gnojus commented Jan 7, 2022

Hack Regular Nerd Font Complete.ttf I downloaded from this repo.

It is indeed strange that Hack Nerd Font has multiple styles - right now I see the same regular/bold/italic options, even though I have only Hack Regular Nerd Font Complete.ttf in ~/.fonts and fc-list only lists Regular also.

When recording my original gif, I probably had other original Hack variants deleted to make animation easier.

@Finii
Copy link
Collaborator

Finii commented Jan 7, 2022

Interestingly xfce4-terminal shows the 4 variants (although not installed thus they would be autogenerated), but still, no issue:

Peek 2022-01-07 16-38

@Finii
Copy link
Collaborator

Finii commented Jan 7, 2022

Let me search for a 'new' Hack Nerd Font that you could try... I believe I have some in a branch.

@gnojus
Copy link
Author

gnojus commented Jan 7, 2022

Could it be DPI related?
Mine is at 96.

@Finii
Copy link
Collaborator

Finii commented Jan 7, 2022

Same here. My guess was... maybe the hinting antialiasing goes wrong, but then I tried a lot different settings to no avail.

image

Let me upload the file I patched half an hour ago somewhere.

@Finii
Copy link
Collaborator

Finii commented Jan 7, 2022

Btw, did you use the original Hack from this repo? i.e. https://github.com/ryanoasis/nerd-fonts/blob/master/src/unpatched-fonts/Hack/Regular/Hack-Regular.ttf

If you have a different original version that could also be an explanation.

So I installed that file (in this comment, top) and the patched one I put here:
https://github.com/ryanoasis/nerd-fonts/blob/experimental/hack-small-size-issue/patched-fonts/Hack/Regular/complete/Hack%20Regular%20Nerd%20Font%20Complete.ttf

Maybe you want to compare these two. These are exactly the files I used.

@gnojus
Copy link
Author

gnojus commented Jan 7, 2022

Yes the original Hack-Regular.ttf files are identical.

I tried with the one you linked, and issue is exactly the same.

Attaching output of font-manager's font-viewer:

Hack-Regular.ttf:
hack-2
Hack Regular Nerd Font Complete.ttf provided by you:
hack-nerd-2

I vaguely remember trying to repatch these myself, but just getting Hack through font-forge was enough to mess them up, so I eventually gave up.

@gnojus
Copy link
Author

gnojus commented Jan 7, 2022

It's strange that you don't see this issue.

Also, the patched fonts from this repo built in recent days do not work for me at all, probably something's wrong with them.

@Finii
Copy link
Collaborator

Finii commented Jan 7, 2022

There are even horizontal sub-pixel changes in the 14px rendering :-o

Peek 2022-01-07 18-09

These are your images at 400% in Gimp as layers, changing the opacity of the top image so that we can see the lower one.

And the dots move, and that by a whole pixel this is not subpixel stuff?

@Finii
Copy link
Collaborator

Finii commented Jan 7, 2022

Maybe try if greyscale antialising fixes this? Could be that the subpixel LCD antialising assumes the wrong colour sequence? The the antialising would make it worse not better. In former times there was a way to select the colour sequence? Hmm.

@gnojus
Copy link
Author

gnojus commented Jan 7, 2022

Yes, hinting it is!
I am using BGR anti-aliasing for my monitor, but switching to grayscale had the same issue.
However, when switching from full hinting to slight in my xfce4-font settings, the issue is no longer visible.

@Finii
Copy link
Collaborator

Finii commented Jan 7, 2022

Reproducible 🎉

Peek 2022-01-07 18-34

I swear, I did try 'full' in the comment 2 hours ago 😬

Ok. Lets see if there is something with the hinting tables.

@Finii Finii added the confirmed label Jan 7, 2022
@Finii
Copy link
Collaborator

Finii commented Jan 7, 2022

image

image

The glyphs look unhinted, but this is contradicted by the version information that contains ttfautohint:

image

@Finii
Copy link
Collaborator

Finii commented Jan 7, 2022

image

instructions depend on size ... hmm.

@Finii
Copy link
Collaborator

Finii commented Jan 7, 2022

It is the head.flags:

$ showttf ~/git/nerd-fonts/Hack\ Regular\ Nerd\ Font\ Complete_prior.ttf | grep flags
	flags=1f baseline_at_0 lsb_at_0 instrs_depend_on_size ppem_to_int instr_set_width 
$ showttf ~/.local/share/fonts/Hack-Regular.ttf | grep flags                       
	flags=6 lsb_at_0 instrs_depend_on_size 

If I force it to be 6 in the generated font, the Issue is gone.

diff --git a/fontforge/tottf.c b/fontforge/tottf.c
index 811711e67..dbfd1bc6d 100644
--- a/fontforge/tottf.c
+++ b/fontforge/tottf.c
@@ -3565,7 +3565,7 @@ static void redohead(struct alltabs *at) {
     putlong(at->headf,at->head.revision);
     putlong(at->headf,at->head.checksumAdj);
     putlong(at->headf,at->head.magicNum);
-    putshort(at->headf,at->head.flags);
+    putshort(at->headf, 6);
     putshort(at->headf,at->head.emunits);
     putlong(at->headf,at->head.createtime[1]);
     putlong(at->headf,at->head.createtime[0]);

Let's see how we can influence the flags in an official way ;-)

@gnojus
Copy link
Author

gnojus commented Jan 10, 2022

Maybe something like this?

from fontTools import ttLib

originalTTF = ttLib.TTFont("Hack-Regular.ttf")
patchedTTF = ttLib.TTFont("Hack Regular Nerd Font Complete.ttf")

patchedTTF['head'].flags = originalTTF['head'].flags
patchedTTF.save("Hack Regular Nerd Font Complete Fixed.ttf")

@Finii
Copy link
Collaborator

Finii commented Jan 11, 2022

Yes, almost. And we also need to copy the lowestRecPPEM.
And then I do not like to pull another dependency in that all users of font-patcher would need.

Rather something like this ;)

source = TableHEADWriter(sys.argv[1])
source.calc_table_checksum(True)
source.close()

dest = TableHEADWriter(sys.argv[2])
dest.calc_table_checksum(True)
dest.calc_full_checksum(True)

if source.flags & 0x08 == 0 and dest.flags & 0x08 != 0:
    print("Changing flags from 0x{:X} to 0x{:X}".format(dest.flags, dest.flags & ~0x08))
    dest.putshort(dest.flags & ~0x08, 'flags') # clear 'ppem_to_int'

if source.lowppem != dest.lowppem:
    print("Changing lowestRecPPEM from {} to {}".format(dest.lowppem, source.lowppem))
    dest.putshort(source.lowppem, 'lowestRecPPEM')

if dest.modified:                                                                                                                                                                                                    
    print("Correcting checksums")                                                                                                                                                                                    
    dest.reset_table_checksum()                                                                                                                                                                                      
    dest.reset_full_checksum()                                                                                                                                                                                       
else:                                                                                                                                                                                                                
    print("Nothing to be done")                                                                                                                                                                                      
                                                                                                                                                                                                                     
dest.close()

Where TableHEADWriter is just a small class without dependencies.

After the holdidays today normal work begun so time dwindles away... 🙄

@Finii
Copy link
Collaborator

Finii commented Feb 1, 2023

Autoclosing by the PR #761 did not work, doing manually now.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 7, 2023

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 Aug 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants