This patch makes Freetype's (http://www.freetype.org) Truetype interpreter render fonts similarly to MS Cleartype. It is not perfect, and needs some work on certain fonts, however, in my opinion it renders much, much better than the bi-level Freetype hinting does when doing subpixel rendering. Anything previous to this that I've worked on is simply a hack. This is the real thing finally.
This patch is different than all previous so-called "cleartype fixes" for Linux. The reason is that the MS truetype interpreter does subpixel filtering, but also subpixel hinting, which has never been done before in Freetype. ("Subpixel hinting" means that the outlines of the letters are rounded to subpixel boundaries instead of pixel boundaries. "Subpixel filtering" means that the part of the renderer that chooses which pixels to light up does so with the idea of subpixel boundaries instead of pixel boundaries.) The Freetype library has hitherto only done subpixel filtering, and WHOLE pixel hinting. This looks great when using non-antialised fonts (circa Win98), but looks bad on legacy fonts when doing antialiasing and subpixel filtering, because the legacy fonts were designed with the idea of bi-level (monochrome) hinting in mind, not subpixel (antialiased) hinting. The MS TT interpreter in Windows XP and later works around this by ignoring certain Truetype instructions contained in the font. This patch attempts to duplicate that functionality. Modern free fonts like Liberation and DejaVu also look good with this too, because they were designed with subpixel hinting in mind.
Another benefit to this is that this is modifying the default (native) hinter of Freetype, which all programs should use by default. This means that oo.org, WINE, Xft, Qt and just about everything else will be using this by default. In other words, almost all programs will render fonts the same good way.
Please feel free to make suggestions and criticisms of the approach and implementation. My goal is to make this patch quality and accurate, and get it into the freetype tree if possible. There are plenty of improvements that can still be made, in features and implementation. This is an all-in-one patch that should cleanly patch freetype-2.4.2, enable LCD filtering, subpixel rendering, and the new subpixel hinting.
Latest Versions (2010-09-06)
- x86_64 - http://www.infinality.net/fedora/linux/13/x86_64/
- i386 - http://www.infinality.net/fedora/linux/13/i386/
- Patch - http://www.infinality.net/files/subpixel-hinting-20100903-1.patch
I strongly recommended to:
- Use this /etc/fonts/local.conf (or know what you are doing otherwise)
- Remove/disable your ~/.fonts.conf
- Use cairo and libXft packages that make use of LCD FIR filtering (such as the ones here: http://www.infinality.net/blog/?p=5 )
Please make sure you have done these things before asking why something isn't working. Here is a good resource that explains how to set up and modify a /etc/fonts/local.conf to your personal taste:
http://wiki.archlinux.org/index.php/Font_Configuration
(Updated 2010-09-06) PACKAGE UPDATE – This update fixes the LD_PRELOAD issues in the recent packages. Let me know if problems continue! Also, I will soon have an updated patch that will be cleaner, allow enabling / disabling with a #define macro, and some additional features, including the ability to tweak the hinting on specific fonts, sizes, and glyphs. I will then see about submitting it to Freetype.
(Updated 2010-09-03) PACKAGE AND PATCH UPDATE – This version includes updates that the Gentoo people did for 2.4.2 (http://forums.gentoo.org/viewtopic-p-6350322.html#6350322), as well as a tweak that I made on the synthetic emboldening that Freetype does. This should make synthetically emboldend fonts look spectacular compared to the default. Basically, it disables emboldening in the Y direction, which was causing a lot of smeary looking fonts. Here is a sample of this enhacement, using Andale Mono, which has no bold version available:

http://www.infinality.net/fedora/linux/13/x86_64/freetype-subpixel-2.4.2-2.fc13.x86_64.rpm
http://www.infinality.net/fedora/linux/13/i386/freetype-subpixel-2.4.2-2.fc13.i386.rpm
http://www.infinality.net/files/subpixel-hinting-20100903-1.patch
(Updated 2010-06-17) http://www.infinality.net/fedora/linux/13/x86_64/freetype-subpixel-2.3.12-3.fc13.rpm Also…. It's strongly recommended to use this /etc/fonts/local.conf, and to remove/disable your ~/.fonts.conf, not to mention using the cairo and libXft packages available at that link.
(Updated 2010-04-24) http://www.infinality.net/files/subpixel-hinting-20100424-1.patch
There are a few more tweaks I need to make the patch acceptable for inclusion into Freetype. In the meantime here are the Fedora 13 RPMS. They safely install alongside the system freetype, and use LD_PRELOAD to override system libraries. You may get LD_PRELOAD warnings / errors when running from command-line. These will go away eventually once this patch is in freetype.
Here is a DejaVu Sans sample, rendered with Freetype, using this patch:

Here is a Tahoma sample, rendered with Freetype, using this patch:

Here is an Arial sample, rendered with Freetype, using this patch:

Here is a Liberation Sans sample, rendered with Freetype, using this patch:

« Make Your Fonts Render Better Than Any Other Operating System Renders Them

This sounds very nice. Too bad I don’t have the slightest idea how to use the .patch file!
What Linux are you running? Wouldn’t be too difficult for me to create Fedora packages.
I was planning to install F13 64bit soon.
I gather that the patch is used to modify sources and then I guess rpmbuild is involved at some point, but obviously the specifics of the process are beyond me.
I’m a newbie to Linux fonts appearance. My Fedora is 12 x86.
I just want my Linux fonts become more readable and beautiful. I have done with your guide at http://www.infinality.net/blog/?p=5. Should I do continually with this?
Any chance this will be in 13, or at the least, does the author have any plans to make 13-compatible rpms available?
“It is an all-in-one patch that should cleanly patch freetype-2.3.12″
Could someone be kind to a noob and explain how to do it?
Hi Moony,
Freetype compiles without a single warning for me, but if I apply your patch, then I get this warnings:
/freetype-2.3.12/src/truetype/ttgload.c: In function ‘compute_glyph_metrics’:
/freetype-2.3.12/src/truetype/ttgload.c:1647: warning: suggest parentheses around && within ||
/freetype-2.3.12/src/truetype/ttinterp.c: In function ‘Ins_MIRP’:
/freetype-2.3.12/src/truetype/ttinterp.c:6173: warning: suggest parentheses around && within ||
/freetype-2.3.12/src/truetype/ttinterp.c:6178: warning: suggest parentheses around && within ||
/freetype-2.3.12/src/truetype/ttinterp.c:6179: warning: suggest parentheses around && within ||
/freetype-2.3.12/src/truetype/ttinterp.c:6178: warning: suggest explicit braces to avoid ambiguous ‘else’
/freetype-2.3.12/src/truetype/ttinterp.c:6111: warning: unused variable ‘orig_round_state’
/freetype-2.3.12/src/truetype/ttinterp.c: In function ‘TT_RunIns’:
/freetype-2.3.12/src/truetype/ttinterp.c:6107: warning: ‘distance’ may be used uninitialized in this function
/freetype-2.3.12/src/truetype/ttinterp.c:6107: note: ‘distance’ was declared here
It would be very nice if you could rework your patch to not produce any warning.
Working on a cleaner version as we speak….
Finally as I understood, we got one patch for freetype instead many for freetype/cairo/xft…
Is there any chance for this patch to make to the rpmfusion freetype-freeworld if not to the official?
I’d tested patch and made fedora 13 freetype-freeworld rpms.
Except for qt apps, that looked very nice, other apps (gtk) didn’t rendered fonts as expected which led me to reintroduce your cairo and libXft patches again.
Also I had to make statement about lcdfilter in ~/.Xresources and ~/.fonts.conf, along with disabled autohinting.
Funny thing about this freetype patch is that after applying it, I don’t have crisp nonantialiased fonts any more for Tahoma or Lucida Sans or other “well formed” true type fonts.
I also tried the patch but I’m not seeing much difference in F13. I may not have done it right…
Does anyone have F13 (64 bit) packages? Or otherwise, any hint on how to apply the F12 patch in F13? I tried it a while ago and my fonts got really ugly, and I was never able to get them back to normal without reinstalling…
Please make F13 x64 packages!! PLEASE!!!!!!!!!!!!!
F13 packages will be available shortly!
Fedora 13 packages are available for this now.
Now that freetype's package name has been changed to freetype-subpixel, I get this error:
ERROR: ld.so: object '/usr/lib/freetype-freeworld/libfreetype.so.6' from LD_PRELOAD cannot be preloaded: ignored.
Because LD_PRELOAD shell variable still has freetype-freeworld path along with new freetype-subpixel path. Is it a problem on my side or the package needs a bit tweaking?
Yeah, the LD_PRELOAD warnings do happen. I have the cairo package including freetype-freeworld in ld.so.conf.d, so that is what's causing it. If you can tolerate the warnings for now, and it's still working properly visually, then just ignore it. Those will go away once this patch is in freetype. ;)
It's tolerable, but still pretty annoying. Especially, when you spend most time in a terminal. The reason behind this change is not very clear to me. If reverting to the old name is all it takes to get rid of the warnings and if it's not going to break anything, why not stick to it?

So far, rendering seems to work perfectly. Thank you for you work. Will be nice to see it in freetype, since Apple's bytecode interpreter code, patents on which expired in 2009, is already in there. Stock 13's rendering looks better now, but not good enough
One more thing I wanted to ask. Are there any changes that need to be made, except for local.conf? In F12, I think, I also had to use ~/.Xresources and make symlinks in /etc/fonts/conf.d/ before rendering started to work.
The reason I called it freetype-subpixel was to not interfere with the rpmfusion package called freetype-freeworld, since they are doing two different things. If you don't have freetype-freeworld installed, you could do something like this as root:
ln -s /usr/lib/freetype-subpixel /usr/lib/freetype-freeworld
That's assuming you are running 32-bit. If you are running 64-bit, then you will still get that error, as I haven't yet figured out how to disable the ld stuff based on the program being loaded, as opposed to the arch you are running.
I would still recommend using this as your ~/.Xresources:
Xft.autohint: 1
Xft.lcdfilter: lcddefault
Xft.hintstyle: hintslight
Xft.hinting: 1
Xft.antialias: 1
Xft.dpi: 96
Xft.rgba: rgb
Oh, the other thing is that it would be a good idea to install Apple and Windows fonts, as my local.conf assumes they are installed.
I see, then.
Well, since I'm running 32-bit version, symlink did the trick for me.
Sans font that is used in GNOME interface by default looks to be the same as DejaVu Sans Book, so here's the screenshot I made with your 3 packages installed and local.conf in place.
http://i.imgur.com/4eaze.png
Btw, what are qtcurve* packages for?
Yes, the screenshot does look like its rendering properly, and I believe there is a rule somewhere that makes "sans" be "dejavu sans", so yes to that too. Qtcurve is a style for KDE / gnome that makes them look similar.
http://kde-look.org/content/show.php?content=40492
Its really customizable and is basically its own theme engine. I just build the packages because they don't do it fast enough at Fedora after a new version is released. ;)
http://koji.fedoraproject.org/koji/search?match=glob&type=package&terms=qtcurve*
Hello Moony!
I've installed packages – LibXft, freetype-subpixel,cairo-freeworld , and put local.conf to /etc/fonts.
I have read the above comment about the error "ERROR: ld.so: object '/ usr/lib/freetype-freeworld/libfreetype.so.6' from LD_PRELOAD". What have I to do to avoid this error? – I'm using Fedora13 64bit
Thank you
Hello Moony! Your patch works well, but I have a question. Not all fonts looks the same (the difference is in comparison, Cyrillic fonts looks less smooth). – Is that all okay, or it?s mistake on my side? – I?ve installed all additional packages as need (cairo-freeworld, libXft,qtcurve-gtk2), I've put your local.conf, and .Xresources as you written above in comments. There is a screenshot http://img404.imageshack.us/img404/928/screenshot0623201005203.png Thank you for answer.
I've got these RPMs. I can't see no difference than using the freetype-freeworld from rpmfusion alone.
Hi Alexander- It appears that your screenshot is showing the text rendered with the patch. The fact that some vertical stems don’t align with pixel boundaries (i.e. blurriness on some letters) is in fact a feature and not a bug.
You can modify the .fonts.conf to have that particular font use “autohint” instead, or try a similar font, like Verdana, Lucida Grande, Tahoma or Droid Sans. Eventually I’d like to figure out the apparent stem-snapping that the MS renderer does, but it has so far eluded me.
Hi Emilio- Do you have some before / after screenshots? I may be able to determine what the problem is that way.
have you found answer, how to disable errors in terminal on Fedora 64bit after installing freetype-subpixel ?
Hi Alexander…. Still looking. Supposedly some systems support LD_PRELOAD_32 and LD_PRELOAD_64 but I'm not having that much success with that. You may just try tolerating it for awhile! You could uninstall the 32 bit libs if you don't use 32 bit progs.
I think, that I have an answer how to fix this error. (for me)
First of all, I reinstalled the system
Then I've installed required packages from your repo, and I've typed a few commands at random in this sequence:
ln -s /usr/lib/freetype-subpixel /usr/lib/freetype-freeworld
ln -s /usr/lib64/freetype-subpixel /usr/lib64/freetype-freeworld
ln -s /usr/lib/freetype-subpixel /usr/lib64/freetype-freeworld
reboot
After that, an error was gone!
Hi! I'm add your patched freetype, cairo etc in my system (f13, x86) it's look awesome in more apps,
but some fonts make ugly after add /etc/fonts/local.conf, see attached screenshot:
http://img535.imageshack.us/img535/9840/fontslocalbug.png
this is Liberation Mono 10pt .
Thanx for great work and sorry for my english
The cairo packages have been updated so that they no longer will cause the freetype-freeworld error. It was a bad idea for me to put it in there anyway!
Hi nickm…. Yes, that certainly looks bad! I'm guessing that you either have a ~/.fonts.conf that is interfering with it, or something in /etc/fonts/conf.d/ is interfering. Here are the ones that are enabled in my /etc/fonts/conf.d:
20-fix-globaladvance.conf
20-unhint-small-dejavu-sans.conf
20-unhint-small-dejavu-sans-mono.conf
20-unhint-small-dejavu-serif.conf
20-unhint-small-vera.conf
25-no-bitmap-fedora.conf
25-unhint-nonlatin.conf
30-metric-aliases.conf
30-urw-aliases.conf
40-nonlatin.conf
45-latin.conf
49-sansserif.conf
50-user.conf
51-local.conf
57-dejavu-sans.conf
57-dejavu-sans-mono.conf
57-dejavu-serif.conf
57-paratype-pt-sans.conf
60-latin.conf
61-stix.conf
65-0-un-core-dotum.conf
65-0-wqy-zenhei.conf
65-1-vlgothic-gothic.conf
65-fonts-persian.conf
65-lklug.conf
65-nonlatin.conf
65-sil-padauk.conf
66-lohit-assamese.conf
66-lohit-bengali.conf
66-lohit-devanagari.conf
66-lohit-gujarati.conf
66-lohit-kannada.conf
66-lohit-oriya.conf
66-lohit-punjabi.conf
66-lohit-tamil.conf
66-lohit-telugu.conf
66-smc-meera.conf
67-kacst-art.conf
67-kacst-book.conf
67-kacst-decorative.conf
67-kacst-digital.conf
67-kacst-farsi.conf
67-kacst-letter.conf
67-kacst-naskh.conf
67-kacst-office.conf
67-kacst-one.conf
67-kacst-pen.conf
67-kacst-poster.conf
67-kacst-qurn.conf
67-kacst-screen.conf
67-kacst-title.conf
67-kacst-titlel.conf
67-paktype-naqsh.conf
67-paktype-tehreer.conf
69-unifont.conf
80-delicious.conf
90-smc-meera.conf
90-synthetic.conf
README
Also, you might want to make sure your ~/.Xresources has this in it somewhere:
Xft.autohint: 1
Xft.lcdfilter: lcddefault
Xft.hintstyle: hintslight
Xft.hinting: 1
Xft.antialias: 1
Xft.dpi: 96
Xft.rgba: rgb
I'm excited to try this out, but I'm on Arch and while I could build a package that extracts the files from your RPMs, it'd be easier to just use the patch you used on a naked Freetype.
Did you use subpixel-hinting-20100424-1.patch to build the packages posted on 06-17?
Hello Moony! I would like to know, will be other programms use (native) hinter of freetype by default in future versions of your patch? – It is very convinient and helpful feature.By the way, now I can work in Opera, O.oo, with good fonts that it was impossible to use before.
Hello. I'm trying to improve my fonts on FreeBSD. So far I have compiled freetype2 with your patch. I'm not sure about cairo and libxft, I can't seem to find any patches for them around here. Could you please email them to me ? I would be grateful.
Thank you.
Moony -
Excellent work, sir. I can finally use Fedora without going blind. Please keep it up.
Here's an all-in-one patch for freetype 2.4.0:
http://forums.gentoo.org/viewtopic-p-6350912.html#6350912
Now in the Arch Linux AUR repository also:
http://bbs.archlinux.org/viewtopic.php?pid=791657#p791657
Hi,
I gave a look at your patch and, AFAICT, the subpixel field you added in theTT_ExecContextRec structure is the same as the existing grayscale field. Furthermore, the compatible_widths field seems to be always false.
Can you explain that ?
Thanks,
Olivier
Hi guys- thanks for keeping the patches up-to-date. I’m still intending to maintain this patch but I haven’t gotten around to it lately.
Yes, currently I am making the subpixel hinting be enabled for grayscale hinting, until I can add a flag to handle subpixel hinting. This allows the patch to be used as a drop-in replacement for the time being. Also, the MS-specific GETINFO() instructions have been hard-coded for the same reason. Anyone who wants to add and enhance this patch may by all means do so! These things need to be added before Werner Lemberg will allow this patch into the main trunk.
If you guys want to contribute, I can set up a small SVN project for the patch.
Here is the conversation I had with Werner:
WERNER – We need a method to activate ClearType hinting. The most natural
thing would be to define an FT_LOAD_CLEARTYPE_HINTING flag, I think.
In addition to that a new function should be added to
activate/deactivate ClearType hinting globally. What do you think? Can you implement that?
MOONY – Yes, I can do that. Perhaps I use FT_LOAD_SUBPIXEL_HINTING instead?
Or do you want to use FT_LOAD_CLEARTYPE_HINTING so that people understand
what this is attempting to duplicate? Just looking at it from a trademark
point-of-view. I would also like to get others to test the patch before
formally submitting anything, to make sure I’m approaching it as generally
as possible, and not specific to the fonts I like.
MOONY – Yes, I can do that. Perhaps I use FT_LOAD_SUBPIXEL_HINTING instead?
WERNER – Oh, yes, definitely better.
WERNER – If the default rendering modes don’t change (this is, users have to
explicitly activate subpixel hinting), it’s much easier for me to
integrate your changes directly even if they aren’t perfect yet.
A few features I think would be nice to be added (but I’m not sure exactly how) would be:
1) Vertical stem snapping around pixels (not forcing the stem to 1px wide,just centering it around a pixel, regardless of width.)
2) Ability to apply / remove some of the “tricks” in this patch on a font-by-font (and glyph-by-glyph) basis, within the freetype code. I know this is dirty, and wrong, however I’m pretty sure that MS is doing this in certain cases. It would have to be disabled by default because a lot of people wouldn’t like running that kind of code.
I imagine there would be a list of exception fonts/glyphs that it would get run against, and if there was a match it would apply / prevent certain code.
3) The skipx and skipy variables were put in place to eventually allow this code to work both with horizontal and vertical text. Currently, they are useless as you found out. But a feature that would be nice is to make this work with vertical text too.
4) Symmetrical smoothing when fonts call for it (or perhaps on demand, with a flag and fontconfig setting?).
5) Corrections for some glyph artifacts (like in Trebuchet e, Verdana Bold 0, Courier New Bold C D, etc.) that happen because the TT hinting programs in these fonts misbehave in order to make pixels light up in B/W rendering mode. This may fall into the previous #2 a bit too.
6) Gamma correction. This is more of a XRENDER issue, AFAICT, but it’s something that would make fonts look great.
Everything in this patch (including above) would need a flag to set it in freetype, and probably a corresponding flag in fontconfig. I’ve only looked very briefly at fontconfig, but I think it would be pretty straightforward.
A quick question. I know I should install the Microsoft and Apple fonts to get the correct replacements. I've installed the Microsoft ones following http://www.mjmwired.net/resources/mjm-fedora-f13.html#ttf (I hope this is the intended way). How do I get the Apple fonts? I haven't got nice fonts with the patch in some programs and I suspect this may be the reason.
The way I found most of my fonts were with Google. Since I have a Windows Vista/7 license, I just copied them over from that. For Apple fonts, you could start with a reference page like this:
http://en.wikipedia.org/wiki/List_of_typefaces_included_with_Mac_OS_X
Then, do a search on google for something like this:
"lucida grande" ttf intitle:"index of"
This will usually produce a ton of results for the font you are looking for. Then just go around and collect them like that. Of course, to be perfectly legit you probably need to have a license of OSX to use them. :)
The other thing you could do is look at my local.conf file, and find the fonts that I've specifically used in there. That should give you a good starting point if you want to find fonts that work with it. I'd glady put up the zip of fonts that I have, but I'm thinking that is probably illegal or some shit. So, I'm not going to. :)
Thanks for the anser Moony, and thanks for all this work!
One more question. I like your rendering of almost all fonts, but I really like better how Ubuntu's DejaVu Sans is rendered. At least in my case, with your packages they look somehow smallish to my taste. See the difference:
http://img269.imageshack.us/img269/9168/screenshotubuntu.png (this is Ubuntu's)
http://img695.imageshack.us/img695/8246/screenshotinfinality.png (this is Infinality's)
See also the difference in the monospace font. I've tried tinkering with the local.conf file but to be honest I'm not even sure where to start. (Is the rendering I got with your package the intended one?)
Of course, there is no “right way” to render fonts; it’s a matter of personal opinion. If you like the autohinter way of DejaVu Sans rendering better, then that it better. It looks like the DejaVu Sans Mono is not rendering using my patch. You would want to make sure something like the following was near the end of your local.conf (and make sure you don’t have a ~/.fonts.conf that is overriding it).
Thank you, again, Moony! Now it looks just great (to my taste at least).
Stupid question but– how in the world do I get this for Ubuntu?
After update freetype in Fedora from Infinality repo, the fonts in some Gnome applications (like Rhytmbox and etc.) looks too thin, and rough. And error in terminal like in a comment above.