this post was submitted on 09 Nov 2024
40 points (70.0% liked)

Linux

48372 readers
2228 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

I have been raging about the font rendering on Linux for years. It just sucks. Font has jagged edges and it looks very weird. I dual-boot with windows and the font there is very nice. So, I asked Claude ai to help me and it did a great job and my font is now is actually better than windows. I wanted to share it with everyone in case you have the same issue with the font on Linux.

Here it is:

  1. First, install required packages:
sudo pacman -S freetype2 cairo fontconfig

2. Install better fonts:

sudo pacman -S ttf-dejavu ttf-liberation noto-fonts ttf-roboto ttf-roboto-mono ttf-droid ttf-opensans ttf-hack ttf-fira-code

I have also installed Segoe ui and Segoe UI Variable fonts and that is what I'm using now.

3. Create or edit the font configuration file:

sudo mkdir -p /etc/fonts/conf.d

sudo nano /etc/fonts/local.conf

4. Add this configuration to local.conf:

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<match target="font">
<edit name="antialias" mode="assign">
<bool>true</bool>
</edit>
<edit name="hinting" mode="assign">
<bool>true</bool>
</edit>
<edit name="hintstyle" mode="assign">
<const>hintslight</const>
</edit>
<edit name="rgba" mode="assign">
<const>rgb</const>
</edit>
<edit name="lcdfilter" mode="assign">
<const>lcddefault</const>
</edit>
<edit name="embeddedbitmap" mode="assign">
<bool>false</bool>
</edit>
<edit name="autohint" mode="assign">
<bool>true</bool>
</edit>
</match>
<!-- Increase contrast slightly for all fonts  This is not mandatory and can be commented out-->
<match target="font">
<edit name="weight" mode="assign">
<const>medium</const>
</edit>
</match>
</fontconfig>

5. Create a file for FreeType settings:

sudo nano/etc/profile.d/freetype2.sh

6. Add these export commands (I found it there already, but it was commented out. Just removed the "#"):

export FREETYPE_PROPERTIES="truetype:interpreter-version=40"

7. Enable subpixel rendering: (You might get a message that says "File exist", that's ok. It means it was already there)

sudo ln -s /etc/fonts/conf.avail/70-no-bitmaps.conf /etc/fonts/conf.d/

sudo ln -s /etc/fonts/conf.avail/10-sub-pixel-rgb.conf /etc/fonts/conf.d/

8. Clear and regenerate font cache:

fc-cache -fv

9. For better Java application fonts:

sudo pacman -S jre-openjdk fontconfig

10. Reboot


Additional optional steps: a. For better Firefox font rendering, in about:config: Set

gfx.font_rendering.cleartype_params.rendering_mode

to 5 (This doesn't exist in FF. You create it, set it to "number" and give it a value of 5)

Set

gfx.webrender.all

to true

b. If you use VSCode, add to settings.json:

{
"editor.fontFamily": "'Fira Code, 'Droid Sans Mono', 'monospace'",

"editor.fontLigatures": true
}

Truly hope this help someone. Share it with others if you think it will help them.

Thanks :)

top 33 comments
sorted by: hot top controversial new old
[–] [email protected] 33 points 2 weeks ago* (last edited 2 weeks ago) (2 children)

Freetype2, fontconfig and cairo are going to be pulled in as dependencies when you install just about any desktop app/library eg firefox, gtk so this is a no-op. Same for installing the jre and fontconfig again. Its pointless. The freetype2.sh line is commented out because that has been the default setting for the last 8 years so it makes no difference. The gfx.webrender.all setting in firefox is an override to force something it is most likely already doing based on the detected environment. If you check about:support the chances are you are already using hardware rendering. And its a performance and not quality setting. Half of this makes no sense.

Installing nicer fonts is always a good idea and also setting your desktop and application default fonts.

Some of the local.conf settings could potentially makes a big difference if your desktop environment defaults/user settings aren't good. Don't know a huge amount about freetype settings but I suspect using assign in there might override desktop environment settings which some people might not want. I set mine in a gui like the monkey I am.

My conversation with any llm tends to go, "you got a, b, c wrong, it should be d, e and f" and it says "sorry, ofcourse it should be d, e and f, my mistake, here it is with d, e, f, g and h". Then I say "g and h are wrong it should be i and j". And it keeps going. In the end I write it myself. Huge time wasters.

Edit: didn't pick up on it immediately but the two symbolic link commands are suss (they are for debian based distros). Endeavor is arch based and fontconfig on arch has the configs in /usr/share/fontconfig and the ones in the conf.default directory should already be linked into /etc/fonts/conf.d. 10-sub-pixel-rgb is in /usr/share/fontconfig/conf.default so that is already linked for me so attempting to do another link without deleting it would be an error - another no-op. I don't like rgb sub-pixel rendering so its overridden in my desktop settings. It shouldn't be necessary on high dpi IMO. The proper path for 70-no-bitmaps is in the /usr/share/fontconfig/conf.avail directory if you want to link it properly. If you use the wrong path as Claude suggested, its another no-op. If, like me, you don't have any bitmap fonts installed it won't make any difference anyway. Also /etc/fonts/conf.d is created by the fontconfig package so that is another no-op.

Edit 2: The setting's name might be inaccurate but Cleartype is the name of Microsoft's proprietary font renderer and isn't available on Linux. So possibly gfx.font_rendering.cleartype_params.rendering_mode was picked up from some StackOverflow discussion about Firefox font rendering on Windows. I won't say it doesn't work without reading the Firefox source code and/or trying it but I suspect a setting with that name would not have any effect on Mac or Linux.

[–] [email protected] 13 points 2 weeks ago

My conversation with any llm tends to go, “you got a, b, c wrong, it should be d, e and f” and it says “sorry, ofcourse it should be d, e and f, my mistake, here it is with d, e, f, g and h”. Then I say “g and h are wrong it should be i and j”. And it keeps going. In the end I write it myself. Huge time wasters.

And yet people at work will take its word when asking about things they don't know anything about beforehand and have no real way of fact checking without actually doing the research they are trying to avoid.

[–] Womble 4 points 2 weeks ago

The point you are missing is that yes, asking an LLM about these things is not at the level of advice from someone who knows their stuff. But if you dont know what you are doing and dont know enough to even know what the right things to search for are then even partialy useful advice about the thing you are trying to do is a massive help.

[–] [email protected] 17 points 3 weeks ago (1 children)

Do you have some before and after screenshots? Would be interesting to look at the difference

[–] [email protected] 3 points 3 weeks ago

Unfortunately, I forgot. But I can tell you that the font has really rough edges and it looked very weird. I have two 4k monitors and the font was awful on them. It now looks even better than windows on them.
KDE plasma on endeavour OS is what I'm running, btw.

[–] [email protected] 13 points 2 weeks ago* (last edited 2 weeks ago) (1 children)

This post is fascinating. Most distros have good defaults for font rendering now and I haven't used hacks like infinality to fix font rendering on Linux for years. That project doesn't even exist anymore. I would be really interested to know which setting made the difference for OP and why.

I am writing this on a little HiDPI laptop with over 200dpi and to be honest hinting and sub-pixel rendering are invisible to my eyes on this device. Apple dropped sub-pixel rendering ages ago when all their products moved to retina displays. But its still really useful on low dpi displays and I thought it generally worked well enough out of the box.

A file almost identical to the local.conf has been posted to forums in the past but back then fontconfig often shipped with outdated defaults. My distro defaults have aliasing, slight hinting and sub-pixel rgb enabled out of the box.

Arch has these defaults. Bookworm lacks the sub-pixel-rgb (its just a link away) but my guess is Ubuntu derivatives probably include it:

  • 10-hinting-slight.conf
  • 10-sub-pixel-rgb.conf
  • 10-yes-antialias.conf
  • 11-lcdfilter-default.conf

The differences I see are the last 3 options in local.conf:

  • disabling embedded bitmaps. I think this would change rendering for old MS Office fonts. And perhaps break some emoji fonts. I have Noto Color Emoji but I don't have any old MS fonts. This seems like it would have limited impact.
  • enabling autohinting. If you have slight hinting enabled and the font contains hinting information it should automatically use it. So I thought it made no difference if you have good fonts installed. I might be wrong. But again if you use good fonts I am not sure this has an impact.
  • setting font weight to medium. This is an odd one. Does this mean that every font query returns a medium weight or that if you don't give a weight you get medium? Fattening up thin fonts might be a user preference but you can also select desired font weights in your desktop settings and apps.

Fontconfig is a compiled database for font queries, it doesn't do rendering. Whatever you put in fontconfig, an app like kitty will not implement sub-pixel rgba rendering for performance and implementation reasons but many other terminals will. I think gtk4 might be heading the same way. Depending on variations in colour vision and displays people tend to disagree on the value of sub-pixel rgb but it looks like it is a common distro default anyway.

[–] [email protected] 4 points 2 weeks ago (1 children)

That was a great read, although I didn't understand all of it. All I know is that my font looks fantastic now and is better than it is on windows using the same monitors. I have two 27" 4k monitors and I have been struggling with the font for a long time. No more.

[–] [email protected] 4 points 2 weeks ago* (last edited 2 weeks ago) (1 children)

I don't doubt you. Linux font rendering has been good enough for so long now that its surprising when people say its worse than some other system but I think it is still a reasonably common complaint so there has to be something to it. A lot of distros probably don't have a very good font selection installed out of the box compared with proprietary systems and I am sure that plays a role.

My desktop has a 38" ultrawide and the pixel density is a lot lower than your dual 4k monitors so I want to do everything I can for font rendering and your post has got me asking questions. I am in the process of configuring a minimal, low distraction tiling wm setup for a bit of fun (also another nvim conf spring clean). I hadn't considered changing the font rendering defaults.

I think I have all the fonts you list installed except for Hack. Inter is also a good one for UI. I don't use Fira Code anymore for code/terminal but I keep it around. It is a nice code font with ligature support but it didn't have an Italic variant and I like subtle use of italics in code and docs. Currently using Iosevka for mono but next week it might be something different.

[–] [email protected] 3 points 2 weeks ago (1 children)

I use segoe variable for the system and Jetbrains mono font for the terminal and and whatever the default that comes with jetbrains Rider. KDE plasma a ton of that Noto Sans font. Around 60 if I'm not mistaken. I've deleted a bunch of it with other languages that I don't need (not sure if that's a good idea, but it was annoying scrolling through all these fonts to find the one I want). Whatever Noto Sans that has a country name at the end of it I deleted it.

[–] [email protected] 4 points 2 weeks ago (1 children)

Having comprehensive unicode language coverage on a free OS is amazing. I wish the font system was smart enough to hide Noto variants in creative apps but leave them available for browsers. There is a workaround to do that but its a huge pain. I wouldn't delete any files managed by the package system. They will just keep coming back anyway. There are smaller collections of noto fonts in AUR that will satisfy the noto-fonts dependency which should keep KDE Plasma happy. They should be a straight swap if you are comfortable with an AUR dependency for a functioning desktop. The newer one is noto-fonts-main updated this year or there is an older noto-fonts-lite. Not tried either. Usual stuff about backups and taking advice from strangers on the internet.

Segoe might benefit more from the embedded bitmap or autohint settings than the regular open source fonts I am likely to use. Microsoft would optimise the hell out of it to take advantage of their proprietary, patented font rendering system. I wouldn't be surprised if it rendered poorly with distro defaults. Its the kind of blind spot a lot of open source devs and packagers could easily have. Its probably packed full of embedded bitmaps for small sizes and proprietary hinting stuff that linux won't understand.

[–] [email protected] 2 points 2 weeks ago

Man, this is nice. Having an actual productive conversation on the internet without the battle of upvotes and downvotes. Lol
Anyway, I'll watch the system and see if things are missing after removing those fonts. All what I removed was any

noto sans + <a country whose language I don't speak>
[–] [email protected] 9 points 3 weeks ago (1 children)

Formating of the configuration content under point 4 seems to have spilled out, you might have to use a triple backtick followed by newline if it's a multiline code/content.

[–] [email protected] 1 points 3 weeks ago (1 children)

I appreciate you pointing that out. I used a client called photon and it was awful. So, I fixed it under the mobile app "voyager" and hopefully it's better now? Let me know so I can dig into more.

[–] [email protected] 2 points 2 weeks ago

Now it looks correct:)

[–] Solumbran 9 points 2 weeks ago

"I refused treatment for my cancer based on a YouTube video and I survived!"

[–] [email protected] 9 points 3 weeks ago (2 children)

i never thought to use ai for instruction on system configuration like is and this is brilliant.

i've used it before to give me ideas that serve as a starting place when i work on anything and now i'm going to start doing this when i want to improve my setup; thanks for making me aware of this option.

[–] [email protected] 4 points 3 weeks ago (1 children)

Last night my windows/linux dual boot was broken and i fixed it with instructions from chatgpt. It helped me recreate windows efi partition that i had accidentally deleted.

[–] [email protected] 2 points 3 weeks ago (1 children)

i prompted it the other day to find out what paperwork i need for same day registration for the election; i think it's use for general information is better than for programming.

[–] [email protected] 1 points 2 weeks ago (1 children)

They're freaking fantastic at general info. I almost never Google anything anymore, especially when it needs a long question from me to explain it well. I got a new gas stove and I needed to get rid of a message that was stuck on the screen. ChatGPT gave me the answer right away. Lol

[–] [email protected] 1 points 2 weeks ago

i suspect that's why google and microsoft jumped on it so quickly; their search engines become useless compared to chatgpt and i wonder how they're going to enshitify it in the future to squeeze out more profits.

[–] [email protected] 1 points 2 weeks ago (1 children)

So glad this helped. I use AI a lot for many things, especially those things that require a detailed explanation from me (which googling normally doesn't get right). It is like talking to a super duper googler who can search the whole web for you in seconds and put together a good answer. I've had Claude and chatGPT help me fix so many critical issues on my distro. They almost always get it right. I also use them to generate any reparative code that I need. I also make them do all css and HTML (no one has time to for that shit. Lol). They also help with producing logic if you're stuck on a part of your project. Even if they don't get it right, they give you a good explanation and and a better idea on what to do. One thing they all failed at 100% at a time is negative unit tests. For some reason, I've never been able to get them to give me one successful negative test.

[–] [email protected] 1 points 2 weeks ago (1 children)

They also help with producing logic if you’re stuck on a part of your project. Even if they don’t get it right, they give you a good explanation and and a better idea on what to do.

i now use it at the start of every single project and task that i work on.

[–] [email protected] 2 points 2 weeks ago

Greatly speeds up things. I love it. I've been faster at my projects. I had a project at work that would have taken my at least 1.5 months, and I built in 3 weeks.

[–] [email protected] 7 points 3 weeks ago* (last edited 3 weeks ago) (1 children)

You might want to shrink the headers to ###

And there are quite some more formatting issues :)

[–] [email protected] 4 points 3 weeks ago (1 children)

Thank you for pointing that out. I'll fix it. I used photon client and it has some real issues with styling posts.
And I'm getting downvoted for trying to help. 😂

[–] [email protected] 1 points 3 weeks ago (1 children)
[–] [email protected] 3 points 3 weeks ago (1 children)
[–] [email protected] 2 points 2 weeks ago
[–] [email protected] 3 points 3 weeks ago (1 children)

Well, that really makes a difference!

[–] [email protected] 1 points 2 weeks ago

Very good to hear. It did make a huge difference for me, that's why I shared it right away. I was so happy with the results I couldn't wait to share with everyone.

[–] [email protected] 2 points 3 weeks ago (2 children)

Any idea if this works on Debian?

[–] [email protected] 2 points 2 weeks ago

The local.conf file should work on any distro. It's an opinionated override and might not be ideal for everyone but you can use the settings as a starting point to research further. Don't modify the other files in /etc/fonts as they will be updated by the distro. Claude's other suggestions apart from selecting some better fonts generally do nothing as far as I can tell. I connected to one of my debian machines and the symbolic links Claude gave to /etc/conf.avail are a debianism as I suspected. If you don't install or use bitmap fonts and you override the rgb aliasing in local.conf I don't see the point of either of those symbolic links but whatever meatbag wrote them in a stackoverflow or reddit post intended them for a debian distro.

[–] [email protected] 1 points 3 weeks ago

I'm not sure honestly. I have not used Debian in a long time. I don't see why it wouldn't. Make a backup and try it. It is all the same except the packages downloads commands.