= The Font Backends = WebKitGTK+ currently supports two font backends: FreeType and Pango. This is somewhat of a misnomer, because even though the FreeType backend uses Fontconfig for selection and Freetype for reading font data / creating custom fonts, it still uses Pango (specifically PangoCairo) for complex text layout (WebCore/platform/graphics/gtk/FontGtk.cpp). Currently there are quite a few issues related to font layout and selection. = Goals = 1. '''Proper CSS font selection''' The CSS standard has a fairly rigorous [http://www.w3.org/TR/css3-fonts/#font-matching-algorithm|detailed algorithm] for selecting the appropriate font for text. Instead of properly falling back according to the list of fonts in CSS, WebKitGTK+ lets Fontconfig or Pango to supply what it thinks is an appropriate replacement. 2. '''Use HarfBuzz directly''' PangoCairo uses HarfBuzz internally, but switching away from PangoCairo has benefits. Behdad Esfahbod, author of HarfBuzz, also summarizes why it is best for [http://behdad.org/text/| browsers to use HarfBuzz directly]: Firefox uses Pango. Firefox 2 was hacked to use PangoLayout API. That was very abusive and inherently inefficient. Firefox 3 has got a new layout engine that is completely based on cairo. The Linux port subclasses PangoFcFontMap to be able to support both CSS text selection as well as web fonts. By doing that it is essentially reimplementing most of Pango and only using the shaping logic. It makes much more sense to use HarfBuzz directly, and Mozilla is now working on getting HarfBuzz ready for that. Additionally, using HarfBuzz directly will allow us to share layout and shaping code with Chromium. === Caveats for replacing PangoCairo with HarfBuzz === {{{ (02:49:36 PM) mrobinson: Xan was saying that you mentioned something the GTK+ port does well, perhaps even better than Chromium. (02:49:47 PM) evmar: complex text, definitely (02:49:53 PM) evmar: we don't use pango (02:49:55 PM) mrobinson: Ah. (02:49:57 PM) mrobinson: The shaping? (02:50:02 PM) evmar: it turns out that harfbuzz is just one small piece of the complex text stack (02:50:13 PM) evmar: and that there's a bunch of stuff in pango that is annoying to replicate (02:51:06 PM) mrobinson: Hrm. I know that HarfBuzz can do things like form ligatures and conbine glyphs. (02:51:12 PM) mrobinson: What sort of thing can't it do? (02:51:23 PM) evmar: yeah, that is the sort of thinking we did, too :) (02:51:37 PM) evmar: uh (02:51:45 PM) evmar: mirroring (like parenthesis) (02:52:05 PM) evmar: dealing with broken fonts (we had to hack around bad advances in some arabic font, i forget how it works now) (02:52:32 PM) evmar: renormalizing text (harfbuzz expects "correct" text, i think pango knows to reorder it before giving it to harfbuzz) }}} 3. '''Remove the Pango backend''' Maintaining the Pango backend is a serious support burden and since we'll be using HarfBuzz to do layout and shaping, is very redundant. For GTK+ ports that do not want to depend on Fontconfig, there is the option of using native Win32 font selection. The WinCairo port is already using this. = Font Bugs = A collection of font-related bugs from Bugzilla: * [https://bugs.webkit.org/show_bug.cgi?id=26741 Share complex text support with Chromium Linux] (the switch to HarfBuzz) * [https://bugs.webkit.org/show_bug.cgi?id=30532 Wrong font size calculated on google.com] (likely an Epiphany bug) These two may well be related. They both deal with fallback CJK fonts: * [https://bugs.webkit.org/show_bug.cgi?id=37984 WebKit freetype backend doesn't support "locl" tables] * [https://bugs.webkit.org/show_bug.cgi?id=26003 Has inconsistent font selection behavior compared with other GTK2 apps] These have patches pending review: * [https://bugs.webkit.org/show_bug.cgi?id=33299 CSS font-style: italic behavior] * [https://bugs.webkit.org/show_bug.cgi?id=41091 (GTK) Complex text rendering does not render custom fonts] Possibly fixed: * [https://bugs.webkit.org/show_bug.cgi?id=42400 TypeKit (web) fonts not rendered] == Pango backend bugs == * [https://bugs.webkit.org/show_bug.cgi?id=18546 Can't load some non-latin fonts with pango backend] * [https://bugs.webkit.org/show_bug.cgi?id=18552 Downloadable fonts don't work with pango backend] * [https://bugs.webkit.org/show_bug.cgi?id=18552 WebKit crashes when running acid3 on Linux using font backend Pango]