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

Some symbol glyphs show up as clipped. #442

Closed
ffernand opened this issue Feb 17, 2020 · 27 comments
Closed

Some symbol glyphs show up as clipped. #442

ffernand opened this issue Feb 17, 2020 · 27 comments
Labels
Milestone

Comments

@ffernand
Copy link

ffernand commented Feb 17, 2020

🎯 Some symbole glyphs show up as clipped.

v2.0.0 of the Ubuntu Mono Nerd Font Complete (double-width version, not mono-version) now truncates/clips certain glyphs.

An example is the battery glyph (which I think comes from font-awesome). The top of the image below represents the font generated by nerd-font v2.0.0... and the bottom image with the clipped glyphs represents the font generated using nerd-font v2.1.0

20200216T151526_maim

Using git-bisect, I was able to trace the problem to this commit: cf625d4

After playing with the content of the commit against v2.1.0 of font-patcher, the following patch fixes the problem for me. It removes the negative bearings after setting the glyph width (undoing the partial change in that commit). But at this point, I'm out of my element. I'm not sure why this fix works for me, or if it introduces other problems.

diff --git a/font-patcher b/font-patcher
index b30b0a0c..8ec21c8f 100755
--- a/font-patcher
+++ b/font-patcher
@@ -762,10 +762,6 @@ class font_patcher:
             align_matrix = psMat.translate(x_align_distance, y_align_distance)
             self.sourceFont.transform(align_matrix)
 
-            # Ensure after horizontal adjustments and centering that the glyph
-            # does not overlap the bearings (edges)
-            self.remove_glyph_neg_bearings(self.sourceFont[currentSourceFontGlyph])
-
             # Needed for setting 'advance width' on each glyph so they do not overlap,
             # also ensures the font is considered monospaced on Windows by setting the
             # same width for all character glyphs. This needs to be done for all glyphs,
@@ -773,6 +769,10 @@ class font_patcher:
             # it should come after setting the glyph bearings
             self.set_glyph_width_mono(self.sourceFont[currentSourceFontGlyph])
 
+            # Ensure after horizontal adjustments and centering that the glyph
+            # does not overlap the bearings (edges)
+            self.remove_glyph_neg_bearings(self.sourceFont[currentSourceFontGlyph])
+
             # reset selection so iteration works properly @TODO fix? rookie misunderstanding?
             # This is likely needed because the selection was changed when the glyph was copy/pasted
             if symbolFontStart == 0:

The only clue for the change was a comment included in the original commit that suggested the opposite messed up glyph widths somehow...

# moved this after changing the bearings because i think it was
# messing up the glyph width to have it before
sourceFont[currentSourceFontGlyph].width = font_dim['width']

🔧 Your Setup

  • ArchLinux (i3wm)
  • SublimeText 3, i3blocks, xfce-terminal
  1. Which font are you using?
    Ubuntu Mono Nerd Font Complete.ttf (double-width)

  2. Which terminal emulator are you using?
    xfce4-terminal

  3. Are you using OS X, Linux or Windows? And which specific version or distribution?
    ArchLinux (latest updates)

@ffernand ffernand changed the title Some FontAwesome glyphs show up as clipped. Some symbol glyphs show up as clipped. Feb 17, 2020
@ryanoasis
Copy link
Owner

thanks for all the details and even digging into this! really appreciate it

@arbaes
Copy link

arbaes commented May 15, 2020

I just ran into the same issue myself, it seems some glyphs are slightly off center for some reasons, resulting in a clipping when rendered:
image

EDIT:
reverting to v2.0.0 fixed it for me too

@demfabris
Copy link

why this seems to happen with people using arch linux and some twm?
Every nerd font except Fira Code is having the 'fi' ligature bug that shkws a telefone icon

@AntonFriberg
Copy link

On Sway and using Waybar I am having issue with Fira Code as well, although it is slightly better than Hack. (Notice the Battery icon "")
scrn-2020-05-25-13-31-01

@GladOSkar
Copy link

GladOSkar commented Feb 23, 2021

Not to pile on top of plenty of reports but I think i have the same issue. I just updated from an ancient version of Fura Code Regular NerdFont Complete (where double-width glyphs actually moved the cursor 2 mono-widths) to the latest version (which is now called Fira Code Regular NerdFont Complete) but now the double-width glyphs only move the cursor by one mono-width, requiring a space after every double-width glyph.

Since a picture speaks a thousand words:
Before:
image
Now:
image

But it seems like you're already keeping track of this. Looking forward to the 2.2.0 release with the fix :)

@siduck
Copy link

siduck commented May 22, 2021

On Sway and using Waybar I am having issue with Fira Code as well, although it is slightly better than Hack. (Notice the Battery icon "")
scrn-2020-05-25-13-31-01}

looks fine for me :

image

@omar2205
Copy link

omar2205 commented Aug 6, 2021

I fixed this issue by adding an extra character
image

I then copied the output (2 characters).
Note there might be warn: Dropping unmatched character

@siduck
Copy link

siduck commented Aug 6, 2021

I fixed this issue by adding an extra character
image

I then copied the output (2 characters).
Note there might be warn: Dropping unmatched character

same :)

@siduck
Copy link

siduck commented Aug 28, 2021

@ffernand do you still face this issue?

@ffernand
Copy link
Author

@siduck76 In my original post, I have a patch that I used to rebuild nerd-fonts and had no issues since then.

I found the problem using git-bisect, but I was reluctant to create a PR out of the patch because it's not clear to me why it works. Not that the patch is suspect, just that I know little of how font-patcher works 😅

So I leave the patch here as a clue for devs on how to fix this problem.

@siduck
Copy link

siduck commented Aug 28, 2021

ughh

@siduck76 In my original post, I have a patch that I used to rebuild nerd-fonts and had no issues since then.

I found the problem using git-bisect, but I was reluctant to create a PR out of the patch because it's not clear to me why it works. Not that the patch is suspect, just that I know little of how font-patcher works

So I leave the patch here as a clue for devs on how to fix this problem.

ughh when's the next release :( . Been waiting for it since ages now lol. It'll come with updated version of linux distro logos which I needed so kinda excited.

@fuegoio
Copy link

fuegoio commented Aug 30, 2021

I have been using this patch for a year now, and never saw any issue. The fonts are working perfectly. I even changed my icon font several times, and they all worked perfectly. Great work, and I think it could be merged :)

bmease added a commit to bmease/Dotfiles that referenced this issue Dec 26, 2021
Nerd fonts have a bug where glyphs are cut off.

 - Switch to mono fonts
 - Increase size

See: ryanoasis/nerd-fonts#442
@Finii
Copy link
Collaborator

Finii commented Aug 22, 2022

Would be solved by #764

@petermarks
Copy link

@Finii, is there a set of zips like https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/*.zip built with your patch? I'm using NixOS, so can alter the package spec to pull a patched release, but don't have the setup to build the fonts myself. I'd really like to test whether this solves the issue I experienced. I'm currently pinned to 2.0.0 as 2.1.0 is unusable for me.

@Finii
Copy link
Collaborator

Finii commented Aug 29, 2022

@petermarks

I'm currently pinned to 2.0.0 as 2.1.0 is unusable for me.

Unfortunately no. Which font are you after?

@petermarks
Copy link

@Finii

Which font are you after?

I use DejaVu Sans Mono Nerd Font in Polybar and Hasklug in my terminal and editor. However, the NixOS package installs the whole set of fonts.

Don't worry about it, I have no need for anything that 2.0.0 doesn't have. I just thought I'd test it out to see if this resolves the issue for me.

@Finii
Copy link
Collaborator

Finii commented Aug 30, 2022

is there a set of zips

DejaVu Sans Mono Nerd Font in Polybar and Hasklug

I can create you these, so you can try them and it helps us decide how to handle that in the future?

@petermarks
Copy link

I can create you these, so you can try them

Sure, if you can send me URLs where the package manager can pull them from, I'll give it a try.

@Finii
Copy link
Collaborator

Finii commented Sep 7, 2022

Probably fixed with v2.2.2

@Finii Finii closed this as completed Sep 7, 2022
@patrick96
Copy link

Can anyone confirm that this fixed it for them?

In xfce4 terminal, I am still getting clipped icons with UbuntuMono 2.2.2:

2022-09-27-203603_726x209_scrot

In addition, in polybar, UbuntuMono and Hack (non-mono) also still have the clipping, see polybar/polybar#991

Hack:

hack

UbuntuMono:

ubuntu

@fiskhest
Copy link

I'm still seeing issues in polybar.

@Finii
Copy link
Collaborator

Finii commented Sep 28, 2022

@patrick96 From the images you provided that is not clipped.

What you miss is to insert a blank after the symbol like

$ echo "a\uf240 abc"
  • You use a Nerd Font variant (not Nerd Font Mono) which means you want symbols bigger than one 'cell'
  • These symbols need to extend into the next cell
  • Any char in the next cell will overwrite the symbol (partially) of course

@fiskhest I must admit I do not know polybar. I guess that is a GUI thingy? Screenshots would always be helpful. Possibly the explanation in #940 is useful for these use in proportional contexts. Is the font 'hard coded' in that polybar, or did you choose that somehow?

@Finii
Copy link
Collaborator

Finii commented Sep 28, 2022

Maybe we should (really, soon) add a Nerd Font Proportional for people who want big symbols in proportional contexts (like GUI elements). Otoh these GUIs should rather use the Symbols-Only font for the symbols, this is kind of a misconception.

@patrick96
Copy link

@Finii Thanks for the clarification, #940 cleared up some things for me. Do I understand correctly that the non-mono fonts basically have wide icons that extend over more than one cell (but still single cell text characters) and it's the terminal emulator's job (or any other application wanting to display them) to add the appropriate spacing after the wide icons?

polybar is a status bar where the user can basically put arbitrary text. Just so you can get an idea, here is a screenshot of my polybar:

2022-09-28-222457_767x36_scrot

Many of our users use nerd fonts because they get a font that has all the icons they want and can also render text. Text and icons can be arbitrarily mixed, so conceptually polybar has to do a similar job as terminal emulators (just on a single line).

The fonts used by polybar are user-defined, so we can easily advise people to adapt their font choices. If I understood everything correctly, advising people to use a non-nerd-fonts font for text rendering and add Symbols Nerd Font as a fallback would fix this issue (and from my limited local testing this is indeed the case).

What I don't quite understand is why Symbols Nerd Font (non-mono) doesn't have the same issue. Do the symbols not extend into the next cell because the cells are bigger?

@Finii
Copy link
Collaborator

Finii commented Sep 30, 2022

@patrick96 Thanks for the Polybar explanations and link. I will have a look there.

Many of our users use nerd fonts because they get a font that has all the icons they want and can also render text. Text and icons can be arbitrarily mixed, so conceptually polybar has to do a similar job as terminal emulators (just on a single line).

Well, I do not know for sure, but I guess Polybar is more like an 'proportional' environment. Which means that the Symbols should have an advance-width that covers the full symbol, and not more. If you would go the terminal emulator way, a bigger symbol would be 2 'calls' wide in advance width, but only cover 1.5 widths in reality, left aligned. So you can never center anything properly.

Another data point is maybe this comment: #731 (comment)

I believe the 2-font-setup (one 'normal' text font and the Symbols Only font as fallback) is kind of ... something for Nerds ;-D
Technically this is possible of course, but if it has to be done by the end-user (as opposed to maybe the Polybar maintainers) this is something I would not expect.
Rather I guess what is needed is a 3rd variant of fonts. Let me restate the possible variants:

  • A) Text monospaced (i.e. 'i' and 'M' same width), symbols scaled down to also fit into that width (Nerd Font Mono)
  • B) Text monospaced, symbols big (but pretend to be small, left aligned) (Nerd Font v2.1 and v2.2.2)
  • C) Text spacing does not care, symbols proportional (advance width equals visible size) (Nerd Font v2.2.0)

A and B are useful in terminal emulators or other 'strict text grid' usecases. C is good for proportional context like 'create a presentation' or 'MS word text file' or 'A book with symbols' or often GUI contexts.

In the past we had Issues that people expect B and got C; while in other times people expected C and got B. I see a roughly equal request for B and C, it is just a different audience. Technically the C people could obtain their goals in different ways, while B can not be achieved easily and consistently by other means (then providing it here).

Historically Nerd Fonts came from the terminal emulator (A/B) context, but meanwhile GUI use is not uncommon anymore. For this reason my ... target would be to provide all 3 variants here - in the future. And then educate users which font they really want. And even then this would have side effects that need careful planning and code changes and maybe a different distribution model.

Well. Interesting as it is, let me first answer this question

Do the symbols not extend into the next cell because the cells are bigger?

The Symbols Only font is proportional. The 'cell' size is different for each glyph in that font, and the size/width matches the symbol's width. This is like a 'normal' (say Times Roman) font in a Libre-Writer text. The M is wide and the i is small, and there is never overlap, the cursor advances exactly behind the letter you just typed in.

The Symbols Only font is created with the font-patcher option --variable-width-glyphs, that is used nowhere else (in the prepatched fonts). It is needed there, because there are no 'preexisting letters' or something that we can use to determine the cell width. We would need to come up with some cell width. That would be possible, but as that font is specifically there to fulfill different needs including GUI usage, it has the advance width of each individual symbol set to that symbol's width - i.e. it is not monospaced at all.

If we want to provide the C fonts, or if someone wants to self-patch them, it is easy by just adding that --variable-width-glyphs option to the call.

See also

These are more comment for ME, so that I do not forget

@patrick96 Your input is welcome (as everyone's), maybe visit new discussion -=> #951

Edit: Add secondary packaging consideration point
Edit: Add link to discussion topic

@Finii
Copy link
Collaborator

Finii commented Sep 30, 2022

What I don't quite understand is why Symbols Nerd Font (non-mono) doesn't have the same issue.

When you write this here, I wonder how Symbols Nerd Font Mono is generated. I never thought much about it. Just have an (almost) empty font that is normally (*) patched, in all 4 flavors.

Connect #658

@github-actions
Copy link
Contributor

github-actions bot commented Apr 3, 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 Apr 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests