Cloud fonts

The cloud fonts feature provides on-demand access to thousands of fonts. Just choose the fonts you want to use and they will be downloaded automatically, and registered so that they can be accessed by their family name. Downloaded fonts are cached locally, so they only need to be downloaded again if they are updated on the server.

To use cloud fonts, start by obtaining a CloudFontCollection:

const cfc = ca.cgjennings.graphics.cloudfonts.CloudFonts.getDefaultCollection();

A collection consists of a number of cloud font families. Each family is a set of one or more related fonts. (For example, a family might include separate fonts for the regular, bold, and italic variants.) The first time you use the collection to access a family, there will be a delay as a small metadata file is downloaded. The metadata provides information about the available fonts without having to download the fonts themselves.

You can examine all of the available fonts by calling the collection’s getFamilies() method, or if you already know the name of the family you want, you can get it directly:

// get an array of all of the currently available families
let families = cfc.getFamilies();

// get a specific family
let firaSans = cfc.getFamily("Fira Sans");

This returns a CloudFontFamily, which can be used to get more information about the family and the fonts that it contains. For example, you can find out which open license it is made available under, and information about the general categories it belongs to (such as display, serif, or sans serif). You can also get Font objects for the individual fonts that make up the family. Most commonly, though, you will simply register() the desired family. This will download fonts as necessary, and then register the entire family similarly to ResourceKit.registerFontFamily() or the equivalent script library function. Then the font will be available by its family name in markup boxes, when using the Font constructor, and elsewhere.

Tips