How do I use custom fonts in Function Compute?

Updated at:

Function Compute runtimes include a set of common system fonts. When those fonts don't cover your requirements, you can bundle custom .ttf font files directly in your function code and configure the runtime to load them.

Prerequisites

Before you begin, ensure that you have:

Install a custom font

  1. Log on to the Function Compute console. In the left-side navigation pane, click Functions.

  2. In the top navigation bar, select a region. On the Functions page, click the function you want to configure.

  3. On the function details page, click Upload Code, select an upload method, and upload the sample code. After the upload, your code directory contains the following files:

    Tangerine-xxx.ttf is the example custom font. Replace it with your own .ttf font files as needed.
    /code
    ├── fonts.conf          # Font configuration file
    └── Tangerine-xxx.ttf   # Custom font file (.ttf format)

    fonts-demo

  4. On the function details page, configure fonts.conf as an environment variable for the function. This enables the runtime to locate and load fonts from your custom font directory.

  5. Invoke the function and check the response. If the output includes style=Regular and style=Bold, the fonts are loaded successfully.

    install-fonts-result