Wednesday, October 8, 2008

Font selection for web fonts on Linux

Mozilla uses Pango for font handling on Linux because it is the best library in existence for international text-shaping with OpenType fonts.

Currently Pango's PangoFcFontMap is used for font selection via pango_itemize() . These APIs provide font-selection through fontconfig from fonts installed on the system, including fonts specific to each user.

When adding support for document-specified automatically-downloaded fonts to a web browser, it is important that font families created for one document do not change the behavior of other documents. However, these existing font-selection APIs currently only support application-specific fonts if they are added to fontconfig's application-global default configuration. In a web browser, adding document fonts in this way would lead to them sometimes being used in other documents, potentially leading to the rendering of completely inappropriate glyphs.

So, to implement web fonts, font selection is being implemented within Mozilla in a way that retains the benefits of fontconfig. Because Pango's design is modular, its text-shaping abilities can still be exercised by implementing a PangoFcFont with which Pango's shapers know how to interact.

Text layout currently contributes to a large proportion of the resources used by the browser. The speed of text layout, including font selection, benefits from caching the data that is likely to be reused. This does come at a cost, however, as these caches can be memory-intensive.

Implementing font selection in Mozilla provides an opportunity to design and tune the caching for Mozilla's usage patterns. Work to-date has already reduced Firefox's memory use on Linux by 10%, but still something like 30% of memory is used for low-level font handling, so there's plenty of room for further improvements here.

Monday, October 6, 2008

Eternity

What does the worker gain from his toil? I have seen the burden God has laid on men. He has made everything beautiful in its time. He has also set eternity in the hearts of men; yet they cannot fathom what God has done from beginning to end. I know that there is nothing better for men than to be happy and do good while they live. That everyone may eat and drink, and find satisfaction in all his toil—this is the gift of God. I know that everything God does will endure forever; nothing can be added to it and nothing taken from it. God does it so that men will revere him.
Ecclesiastes 3:9-14 NIV