# Manage font files

## Introduction

Sources like Figma and Tokens Studio manages `textStyle` and `font` token types as parameters applied to the fonts available on the host machine.&#x20;

For both technical and legal reasons, Specify cannot extract font files from those sources, even though the [SDTF](https://docs.specifyapp.com/concepts/sdtf-client/sdtf-engine) is able to manage font files natively.

To bridge that gap, we'll share with you some techniques you can leverage to keep your font files in sync with your font and text styles tokens.

## Prerequisites

Before we start you need:

* A Specify account with a repository
* One or more font files in the following formats: `ttf`, `woff`, `woff2`, `otf`, `eot`.

## #1 The easy way: upload font files in Specify

{% embed url="<https://youtu.be/ilsoqs3DX1k>" %}

## #2 Add font files by creating your own SDTF graph

### 1. Host your font files

You are free to host your font files anywhere you can grab a public link to give Specify the ability to fetch the binaries.

We recommend using a company cloud storage like Amazon S3.

### 2. Create a SDTF tokens file

To register your font files to Specify, you need to create a SDTF JSON file containing your font tokens with the URLs from your cloud provider.

{% tabs %}
{% tab title="Example" %}

<pre class="language-json" data-title="tokens.json"><code class="lang-json">{
  <a data-footnote-ref href="#user-content-fn-1">"Fonts"</a>: {
    <a data-footnote-ref href="#user-content-fn-2">"Inter Regular"</a>: {
      "$type": "font",
      "$value": {
        "default": {
          "family": "Inter Regular",
          "postScriptName": "Inter Regular",
          "weight": "regular",
          "style": "normal",
          "files": [
            {
              <a data-footnote-ref href="#user-content-fn-3">"format"</a>: "ttf",
              "url": "https://static.specifyapp.com/sdtf-seeds/inter-regular.ttf",
              "provider": "external"
            }
          ]
        }
      }
    }
  }
}
</code></pre>

{% endtab %}

{% tab title="Type signature" %}

```typescript
type Font = {
  $type: 'font';
  $value: {
    [mode: string]: {
      family: string;
      postScriptName: string;
      weight:
        | 'thin'
        | 'hairline'
        | 'extra-light'
        | 'ultra-light'
        | 'light'
        | 'normal'
        | 'plain'
        | 'standard'
        | 'regular'
        | 'roman'
        | 'book'
        | 'medium'
        | 'semi-bold'
        | 'demi-bold'
        | 'bold'
        | 'extra-bold'
        | 'ultra-bold'
        | 'black'
        | 'heavy'
        | 'extra-black'
        | 'ultra-black'
        | number; // [100-1000]
      style: 'normal' | 'italic';
      files: Array<{
        url: string;
        format: 'ttf' | 'woff' | 'woff2' | 'otf' | 'eot';
        provider: 'external' | 'Specify' | 'Google Fonts' | 'Adobe Fonts';
      }>;
    };
  };
};
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
Note that you want to make the `family` property to match the font family used by your TextStyle or Font tokens.
{% endhint %}

### 3. Host your SDTF tokens file

To let Specify synchronize the font tokens into your repository, the SDTF JSON file must be hosted either privately or publicly.

#### Hosting on GitHub

1. Create a new public or private repository on [github.com](https://github.com/).
2. Add your SDTF JSON file containing the font tokens

<figure><img src="https://4265043194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3998FFntXKzDmFTxxiPd%2Fuploads%2FBtMUVjrCw2hvAEfyfxtY%2FGH-repo.jpg?alt=media&#x26;token=72769c56-9c8c-47e0-be75-7ba28b67aa03" alt=""><figcaption><p>A private GitHub repository containing the tokens.json file</p></figcaption></figure>

3. Grab the raw file URL by accessing the raw file over your browser

<figure><img src="https://4265043194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3998FFntXKzDmFTxxiPd%2Fuploads%2FyBn4skOKcx4eY9cYVECI%2FGH-raw-file-link.jpg?alt=media&#x26;token=cdb7c856-8731-49ac-9782-c686363f1520" alt=""><figcaption><p>Details over the tokens.json file to grab its raw file url</p></figcaption></figure>

#### Hosting on JSONBin

1. Create a new private or public bin on [https://jsonbin.io](https://jsonbin.io/).
2. Place the content of your SDTF JSON file within it

<div align="left"><figure><img src="https://4265043194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3998FFntXKzDmFTxxiPd%2Fuploads%2FZwtEsHAlv52bwAmQFnEM%2FJSONBin-add-file.jpg?alt=media&#x26;token=1cb92dfb-d002-4452-80b1-777e0b862a77" alt="" width="473"><figcaption><p>A bin content with font tokens</p></figcaption></figure></div>

3. Grab the URL&#x20;

<div align="left"><figure><img src="https://4265043194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3998FFntXKzDmFTxxiPd%2Fuploads%2Fk4XJpY1oxE8eg9pn7pAN%2FJSONBin-copy-url.jpg?alt=media&#x26;token=5c158c37-f26e-4cd7-abd1-656cf2c93803" alt="" width="499"><figcaption></figcaption></figure></div>

### 4. Synchronize your tokens with Specify

You can now navigate to your Specify repository and head to "Sources" -> "Create source"

1. Select the "Remote URL - Tokens Studio"

<figure><img src="https://4265043194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3998FFntXKzDmFTxxiPd%2Fuploads%2FCCQ42YJc6tvoiXQdILx1%2FSpecify-create-source.jpg?alt=media&#x26;token=fb9d1818-fad9-415b-9769-a18332c242a2" alt=""><figcaption><p>Specify web app - choose source step</p></figcaption></figure>

2. Provide the URL to the font tokens file you created at step 3.

<figure><img src="https://4265043194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3998FFntXKzDmFTxxiPd%2Fuploads%2FhT0LbfLVpsnj427bhliG%2FSpecify-remote-url.jpg?alt=media&#x26;token=04f830de-3251-4bee-b3d6-ee1f1f95fba7" alt=""><figcaption><p>Specify web app - provide url step</p></figcaption></figure>

3. (Optional) Provide authentication credentials for your provider. Read more about managing [URL providers authentication](https://help.specifyapp.com/en/articles/8413311-add-tokens-studio-json-as-a-source#h_6e2b8b5fcf).
4. Select the "Specify Design Tokens Format" option

<figure><img src="https://4265043194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3998FFntXKzDmFTxxiPd%2Fuploads%2FBbmtvn8dumTew6BDn360%2FSpecify-file-format.jpg?alt=media&#x26;token=c0846c28-4c9b-4e08-aabe-30311f2cdcc4" alt=""><figcaption><p>Specify web app - select design token format</p></figcaption></figure>

5. Create the source. The sync is executed on the source creation and should take few seconds.

### 5. Sync the font files in your codebase

Once your new font tokens are synced into your Specify repository, you can start pulling the font-files to your codebase.

Let's have a look to one of the [parser rule](https://docs.specifyapp.com/reference/parsers-engine#parserrule) that can be used into any configuration file:

<pre class="language-json" data-title="Font Files parser rule"><code class="lang-json">{
  "name": "Font files",
  "parsers": [
    {
      "name": "filter",
      "options": {
        "query": {
          "where": { "group": <a data-footnote-ref href="#user-content-fn-4">"^Fonts$"</a>, "select": { "children": true } }
        }
      }
    },
    {
      "name": "change-case",
      "options": {
        "change": "names",
        "toCase": <a data-footnote-ref href="#user-content-fn-5">"kebabCase"</a>
      }
    },
    {
      "name": "to-file",
      "options": {
        "filenameTemplate": <a data-footnote-ref href="#user-content-fn-6">"fonts/{{name}}{{extension}}"</a>
      },
      "output": {
        "type": "directory",
        "directoryPath": "./public"
      }
    }
  ]
}
</code></pre>

Once executed, the font files are available within the `./public/fonts` directory.

[^1]: The name of the top level group in your Specify repository

[^2]: Add as many fonts has you need to match your TextStyles

[^3]: Add as many formats you need for your distribution

[^4]: We exactly match the "Fonts" group we initially created.

[^5]: We transform the group and the font token names into kebab-case to turn them url friendly.

[^6]: We use the template to describe the filename format.
