Variable Fonts support
Overview
Fonts with Variations allow one to change the font appearance (weight, spacing, etc.) over a continuous range of values, all with just one font file. For an more information see this tutorial.
Our font rendering stack now includes support for font variations (harfbuzz (1.4), pango (1.41.1), freetype (2.8/2.9).
References
Specifications
Browser Support
- Chrome: Supported
- Safari: Supported (haven't tested)
- Firefox: In Nightly but must be enabled.
- Edge: ?
Firefox nightly does not support "named" variations.
Note: Chrome also supports 'font-weight' values that are not multiples of 100 (CSS Fonts Level 4 changes the allowed values of 'font-weight' to include all integers from 1 to 1000):
Google's FontView proof-of-concept
FontView is a demo program written by Google engineers to demonstrate the variable font technologies recently added to harfbuzz and freetype. This is the same stuff we'll use in inkscape soon. The project sources are available at https://github.com/googlei18n/fontview
On Fedora: dnf install wxGTK3-devel
Inkscape
Linked to recent libraries, Inkscape can use "named" variations out-of-the box (i.e., one font file provides multiple styles).
Reading of 'font-variation-settings' implemented. Needs fixing (incorrect parsing, parsing not robust against variations in white-space). FIXED.
Rendering implemented. Requires Pango >= 1.41.1; FreeType >= 2.8 (2.9?). Axes values are not yet clamped to allowed range.
GUI not implemented.
Notes
Gettting a FreeType Font Handle
Pango handles font variations via the Pango Font Description however the FreeType font retrieved via:
pango_fc_font_lock_face() (which calls pango_ft2_font_get_face())
using the descriptor does not have the 'variation' axes set. We must do that ourselves. In principle this works with FreeType 2.8 but I seemed to need 2.9 to get it to work.
Internal Pango Support
This works:
pango-view --font="Noto Sans @wght=900" --text=Test
Pango passes the font variation info onto HarfBuzz via hb_font_set_variations() in pangofc-shape.c for shaping. But this is used only to get glyph positions.
Pango uses a different mechanism for handling variations from 'font-feature-settings'. Variations are handled in the Pango font description while features are handled by setting attributes.
Harfbuzz Support
From 1.4.2 Change Log (23 Jan 2017):
- Implement OpenType Font Variation tables avar/fvar/HVAR/VVAR. - hb-shape and hb-view now accept --variations. - New API: hb_variation_t hb_variation_from_string() hb_variation_to_string() hb_font_set_variations() hb_font_set_var_coords_design() hb_font_get_var_coords_normalized() hb-ot-var.h: hb_ot_var_axis_t hb_ot_var_has_data() hb_ot_var_get_axis_count() hb_ot_var_get_axes() hb_ot_var_find_axis() hb_ot_var_normalize_variations() hb_ot_var_normalize_coords() - MVAR to be implemented later. Access to named instances to be implemented later as well.
Compiling/Linking
To compile and link with libraries in /usr/local execute:
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
before running cmake in the Inkscape build directory.
Building and using freetype is a bit more complicated:
- To build:
- mkdir build
- cd build
- cmake -D BUILD_SHARED_LIBS:BOOL=true ..
- make
- sudo make install
- To use:
- export LD_LIBRARY_PATH=/usr/local/lib
User Interface
On the UI, I've been thinking of sliders as the dumb-obvious solution to select values for a variable font axes, but I also think it would be cool to think of a user-defined "palette" of varfont instances. Because you have pretty much infinite variations that can be chosen in a varfont, but you'd want to pick some and use them on your document and then be able to tweak one of the instances and then see the change affecting all places where that was used. So, a varfont can have typedesigner-specified named instances, but I think we should also offer user-defined instances. And these should show up on the font selector just like nowadays we have a drop-down for Regular/Bold/Italics. Felipe "Juca" Sanches (talk)