Just before Christmas, I spent some time in New York to continue font work with Behdad that we had begun earlier this year.
As you may remember from my last post on fonts, our goal was to support OpenType font variations. The Linux text rendering stack has multiple components: freetype, fontconfig, harfbuzz, cairo, pango. Achieving our goal required a number of features and fixes in all these components.
Getting all the required changes in place is a bit time-consuming, but the results are finally starting to come together. If you use the master branches of freetype, fontconfig, harfbuzz, cairo, pango and GTK+, you can try this out today.
But beyond variations, we want to improve font support in general. To start off, we fixed a few bugs in the color Emoji support in cairo and GTK+.
Next was small improvements to the font chooser, such as a cleaner look for the font list, type-to-search and maintaining the sensitivity of the select button:
I also spent some time on OpenType features, and making them accessible to users. When I first added feature support in Pango, I wrote a GTK+ demo that shows them in action, but without a ready-made GTK+ dialog, basically no applications have picked this up.
Time to change this! After some experimentation, I came up with what I think is an acceptable UI for customizing features of a font:
It is still somewhat limited since we only show features that are supported by the selected font and make sense for entire documents or paragraphs of text. Many OpenType features can really only be selected for smaller ranges of text, such as fractions or subscripts. Support for those may come at a later time.
Part of the necessary plumbing for making this work nicely was to implement the font-feature-settings CSS property, which brings GTK+ closer to full support for level 3 of the CSS font module. For theme authors, this means that all OpenType font features are accessible from CSS.
One thing to point out here is that font feature settings are not part of the PangoFont object, but get specified via attributes (or markup, if you like). For the font chooser, this means that we’ve had to add new API to return the selected features: pango_font_chooser_get_font_features(). Applications need to apply the returned features to their text by wrapping them in a PangoAttribute.
Once we had this ‘tweak page’ added to the font chooser, it was the natural place to expose variations as well, so this is what we did next. Remember that variations define number of ‘axes’ for the font, along which the characteristics of the font can be continuously changed. In UI terms, this means we that we add sliders similar to the one we already have for the font size:
Again, fully supporting variations meant implementing the corresponding font-variation-settings CSS property (yes, there is a level 4 of the CSS fonts module). This will enable some fun experiments, such as animating font changes:
All of this work would be hard to do without some debugging and exploration tools. gtk-demo already contained the Font Features example. During the week in New York, I’ve made it handle variations as well, and polished it in various ways.
To reflect that it is no longer just about font features, it is now called Font Explorer. One fun thing I added is a combined weight-width plane, so you can now explore your fonts in 2 dimensions:
As always, there is more work to do. Here is an unsorted list of ideas for next steps:
- Backport the font chooser improvements to GTK+ 3. Some new API is involved, so we’ll have to see about it.
- Add pango support for variable families. The current font chooser code uses freetype and harfbuzz APIs to find out about OpenType features and variations. It would be nice to have some API in pango for this.
- Improve font filtering. It would be nice to support filtering by language or script in the font chooser. I have code for this, but it needs some more pango API to perform acceptably.
- Better visualization for features. It would be nice to highlight the parts of a string that are affected by certain features. harfbuzz does not currently provide this information though.
- More elaborate feature support. For example, it would be nice to have a way to enable character-level features such as fractions or superscripts.
- Support for glyph selection. Several OpenType features provide (possibly multiple) alternative glyphs, with the expectation that the user will be presented with a choice. harfbuzz does not have convenient API for implementing this.
- Add useful font metadata to fontconfig, such as ‘Is this a serif, sans-serif or handwriting font ?’ and use it to offer better filtering
- Implement @font-face rules in CSS and use them to make customized fonts first-class objects.
Help with any of this is more than welcome!
2 thoughts on “More fun with fonts”
Keep on fonting! Appreciate your work 🙂
For fontconfig stuff, https://bugs.freedesktop.org/show_bug.cgi?id=29497 might helps to see the classification of the typefaces.
Comments are closed.