Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 306053

Summary: Patches for media-libs/freetype and media-libs/fontconfig to improve font rendering on LCD displays
Product: Gentoo Linux Reporter: Giacomo Perale <ghepeu>
Component: Current packagesAssignee: Gentoo Fonts Team <fonts>
Status: RESOLVED NEEDINFO    
Severity: enhancement CC: brebs, cardoe, cruzki123, dabbott, laurento.frittella, notordoktor, pacho, peter, tomaszg
Priority: High    
Version: unspecified   
Hardware: All   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---
Attachments: cairo-1.8.8-lcd-filter-ubuntu.patch
cairo-1.8.8-ebuild.patch
fontconfig-2.8.0-lcdfilter-config.patch
freetype-2.3.12-gentoo-lcdfilter.patch

Description Giacomo Perale 2010-02-20 13:37:29 UTC
I was reading a few mailing list discussions about subpixel filtering and I decided to check what was being done in Gentoo. The current situation is IMHO suboptimal: at the moment there's only one patch, conditionally applied to cairo on +cleartype, who removes the default intra-pixel filter and replaces it with an hard-coded 5-taps FIR filter.

The series of patches against cairo, freetype and fontconfig that I'm going to attach to this bug report will allow instead to use all the subpixel filters provided by recent (2.3ish) releases of freetype and to dynamically switch the active subpixel filter at runtime using fontconfig, like it already happens with most other font rendering-related options.

The largest patch in the series is already shipped by a few other distros (I took it from the ubuntu package) and modifies cairo to use the Freetype 2 API to filter the fonts instead of using its default intra-pixel filter lifted from Xft. Recent Freetype 2 releases provide additional filters engineered to better display fonts on LCD screens (similarly to what Cleartype allows in Windows); the suggested 'default' filter is a 5-taps FIR filter who takes advantage of the theoretical 3x horizontal resolution (thanks to the RGB subcomponents of each pixel) to better render fonts reducing the annoying color fringing typical of previous filters. The selection of the active LCD filter is then demanded to the fontconfig property 'lcdfilter' available, IIRC, since the 2.6 series releases.

As far as I can see this patch series shouldn't change anything for users who didn't enable the 'cleartype' USE flag, and should require only a minor configuration change for the users who enabled it. I'd like however to receive independent confirmation.

This approach is IMHO the best approach currently available; there were talks of including the filters directly in cairo instead of depending on freetype, but it's not sure this is going to happen anytime soon.

A very good examination of the font rendering state in Linux is provided in this document: http://freddie.witherden.org/pages/font-rasterisation/; I recommend reading it.
Comment 1 Giacomo Perale 2010-02-20 13:38:27 UTC
Created attachment 220463 [details, diff]
cairo-1.8.8-lcd-filter-ubuntu.patch

This patch, taken from the Ubuntu cairo package, replaces the old cairo-1.2.4-lcd-filter-1.patch. It removes the hardcoded intra-pixel filter from cairo and makes the library use the Freetype-provided filters (default, light and legacy, the former equivalent to the intra-pixel filter) according to the runtime Fontconfig setting 'lcdfilter'. The default filter is the legacy one.
Comment 2 Giacomo Perale 2010-02-20 13:38:52 UTC
Created attachment 220465 [details, diff]
cairo-1.8.8-ebuild.patch

Small diff for the ebuild, applies the cairo-1.8.8-lcd-filter-ubuntu.patch, removes the 'cleartype' USE flag and adds a warning telling the users that they need to enable the fontconfig file '11-lcdfilter-default.conf' (more on this later) to get back the lcd filter previously applied with the flag. It also raises the dependencies to the patched -r1 version of fontconfig 2.8.0 and freetype 2.3.12.
Comment 3 Giacomo Perale 2010-02-20 13:39:23 UTC
Created attachment 220467 [details, diff]
fontconfig-2.8.0-lcdfilter-config.patch

This patch adds to fontconfig three new config files, '11-lcdfilter-default.conf', '11-lcdfilter-legacy.conf' and '11-lcdfilter-light.conf', who enable respectively the lcddefault (5-taps FIR), lcdlegacy (intra-pixel filter) and lcdlight (3-taps FIR) filters provided by Freetype 2.3. 'eautoreconf' must be run in the ebuild for the patch to work.
Comment 4 Giacomo Perale 2010-02-20 13:39:49 UTC
Created attachment 220469 [details, diff]
freetype-2.3.12-gentoo-lcdfilter.patch

The freetype 'default' filter doesn't use the same coefficients of the filter introduced by the old cairo-1.2.4-lcd-filter-1.patch; as a consequence the output is slightly different. This patch replaces the freetype coefficients with the old "Gentoo" coefficients, to ensure that nothing will change for the people who used to build cairo with the 'cleartype' flag. It's pretty much a personal taste thing; for what is worth I prefer "our" filter to the freetype one.
Comment 5 Paul Bredbury 2010-02-21 06:55:09 UTC
This is old news:
http://forums.gentoo.org/viewtopic-t-511382.html

The issue that scares the pants off distros other than the mighty Ubuntu is: patent laws.
Comment 6 RĂ©mi Cardona (RETIRED) gentoo-dev 2010-02-21 09:12:07 UTC
None of those packages belong to the x11 herd.

And as far as I'm concerned, I won't take patches that haven't been accepted by upstream first.

Thanks
Comment 7 Giacomo Perale 2010-02-21 09:30:21 UTC
(In reply to comment #5)
> This is old news:
> http://forums.gentoo.org/viewtopic-t-511382.html
> 
> The issue that scares the pants off distros other than the mighty Ubuntu is:
> patent laws.
> 

Gentoo's already shipping all the supposedly patented code with "-bindist cleartype". This just makes it more easily available.
Comment 8 Doktor Notor 2010-02-21 12:56:32 UTC
There was already Bug 260076 about this (WONTFIX), and Bug 254444 (WONTFIX as well). Why are you opening this over and over again< BTW, cairo already has USE=cleartype, this Ubuntu stuff (which is in xeffects or whatever) is just a collection of random patches. 
Comment 9 Giacomo Perale 2010-02-21 13:38:51 UTC
(In reply to comment #8)
> There was already Bug 260076 about this (WONTFIX), and Bug 254444 (WONTFIX as
> well). Why are you opening this over and over again< BTW, cairo already has
> USE=cleartype, this Ubuntu stuff (which is in xeffects or whatever) is just a
> collection of random patches. 
> 

Did you check the patches or you just spouting random crap having read only the summary?
Comment 10 Doktor Notor 2010-02-21 14:12:37 UTC
(In reply to comment #9)
> Did you check the patches or you just spouting random crap having read only the
> summary?

Yeah, I actually did. It's (save for a few bytes in cairoint.h ) identical to  
cairo-ubuntu-04_lcd_filter.patch from devnull overlay. The debate on FDO bug #10301 has been going just for just a few days short of 3 years... And the main  problem with all these patches is that they break all the time and will keep breaking until accepted upstream (like in Bug 302066).
Comment 11 Giacomo Perale 2010-02-21 14:33:34 UTC
(In reply to comment #9)
> 
> Did you check the patches or you just spouting random crap having read only the
> summary?
> 

Ok, counted to 300 a couple times.

This patches have nothing to do with neither Bug 260076 nor Bug 254444. I explained this twice already but it seems it's not enough.

1) Freetype 2.3.x already offers subpixel filtering. To be more precise it offers three subpixel filters: legacy, that is the Xft filter, default a 5-taps FIR filter and light, a 3-taps FIR filter. The only thing here that touches fretype is the last patch, which is optional and just slightly modifies the coefficients to use the ones Gentoo's using now.

2) the fontconfig patch I'm proposing is simply adding three new conf files (10 lines each) and changing the Makefile so that they're installed in /etc/fonts/conf.avail without enabling them by default.

3) the official cairo provides a single subpixel filter, that is the intra-pixel filter copied from Xft. The cleartype patch Gentoo is already shipping removes this filter and hard-codes the 5-taps filter in its place.

4) the Ubuntu patch, which isn't "random", removes the hard-coded Xft filter and instead of replacing it with a new filter makes cairo call freetype to filter the glyphs, using one of the three available filters according to the value of the lcdfilter properties that is already included in fontconfig. That patch is only apparently big, if you had read it you would've seen that most of the line counts is simply a couple functions moving around.

5) All of this makes it possible to dynamically change the subpixel filter instead of having to recompile cairo enabling and disabling the USE flag. It also permits to use different filters for different fonts. While most fonts benefit from subpixel filtering with a FIR filter (better shapes, no color fringing, etc.) the Bitstream/DejaVu fonts were designed to work well with the Xft filters and the corefonts fonts shouldn't use a subpixel filter because they were designed to be heavily hinted: with these patches it is possible to ensure that each font always uses the right filter.
Comment 12 Giacomo Perale 2010-02-21 14:42:15 UTC
(In reply to comment #10)
 
> Yeah, I actually did. It's (save for a few bytes in cairoint.h ) identical to  
> cairo-ubuntu-04_lcd_filter.patch from devnull overlay. The debate on FDO bug
> #10301 has been going just for just a few days short of 3 years... And the main
>  problem with all these patches is that they break all the time and will keep
> breaking until accepted upstream (like in Bug 302066).
> 

Of course it is identical, it's the ubuntu version of the patch (there's a shorter version written by David Turner from Freetype that's slighty less invasive). It's not "breaking all the time", it still works on the 1.8 branch, including 1.8.10 released yesterday and has been working for more than 1 year.
Comment 13 Ryan Hill (RETIRED) gentoo-dev 2010-03-02 01:23:23 UTC
(In reply to comment #5)
> This is old news:
> http://forums.gentoo.org/viewtopic-t-511382.html
> 
> The issue that scares the pants off distros other than the mighty Ubuntu is:
> patent laws.
> 

FYI said patents have expired.
Comment 14 Ryan Hill (RETIRED) gentoo-dev 2010-03-02 01:35:23 UTC
for fontconfig and freetype, i'm hesitant to include any patches which have not been accepted upstream.  this is our general policy though it's up to the individual maintainer (eg. cleartype and cairo).

since the cairo discussion is already ongoing, as a next step i would suggest starting a discussion on the fontconfig ml.
Comment 15 Dror Levin (RETIRED) gentoo-dev 2010-03-26 18:12:36 UTC
The patch attached here looks awfully like the patch attached to bug 303421, and since this bug is newer I'm marking it as a duplicate of the other one (and since the issue is the cairo patch and not the fontconfig/freetype patches).

*** This bug has been marked as a duplicate of bug 303421 ***
Comment 16 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2010-03-31 02:46:35 UTC
I have submitted the lcdfilter-config.patch to upstream:
http://bugs.freedesktop.org/show_bug.cgi?id=27385

I don't agree with the gentoo-lcdfilter changes in constants however, but I'm going to ask the freetype upstream to make a customizable FIR filter to end the entire debate about those constants, as this is at least the 4th set of values I've seen for them.
Comment 17 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2010-03-31 02:59:50 UTC
Upstream bug for making the Freetype FIR filter values configurable:
https://bugs.freedesktop.org/show_bug.cgi?id=27386
Comment 18 Ryan Hill (RETIRED) gentoo-dev 2010-03-31 06:54:26 UTC
thanks robin.  reopening to track.
Comment 19 Nikos Chantziaras 2010-05-06 19:15:24 UTC
I think Gentoo developers should sometime focus on what users want too rather than just they *personally* want.
Comment 20 Paul Bredbury 2010-05-29 12:26:30 UTC
(In reply to comment #13)
> FYI said patents have expired.

What, all of these?
http://david.freetype.org/cleartype-patents.html

This contradicts you:
http://en.wikipedia.org/wiki/Subpixel_rendering#Patents

Not that I care about said patents. I'm just clarifying.
Comment 21 Ryan Hill (RETIRED) gentoo-dev 2010-05-29 20:11:56 UTC
Yes, I realized after that I was thinking of the Apple Truetype hinting patents but didn't feel the need to fill this bug with more unrelated chatter.  Thanks though.
Comment 22 Ben de Groot (RETIRED) gentoo-dev 2013-02-01 13:05:31 UTC
Since the infinality patches are now included, is there anything here we still would need to add?