Skip to main content

Automatically create an optimized subset font using fonttool's pyftsubset

Project description

autosubset – Automatically subset a font based on actual text

autosubset creates a subset font exactly for the set of characters that you actually use.

Usage

Just pipe the text into autosubset and specify the font.

Assuming all your text is in the HTML files in the current directory:

html2text *.html | autosubset.py MyFont.woff2

autosubset analyzes the content, extracts the characters used and uses pyftsubst from fonttools to create a matching subset.

After that, just add lines like the following to your web site:

  • HTML: Preload the font for faster availability.
    <link rel="preload" href="MyFont.subset.woff2" as="font" type="font/woff2">
    
  • CSS: Define and use the font.
    @font-face {
      font-family: "My Font";
      src: local("Tenor Sans"), url("MyFont.subset.woff2") format("woff2");
      font-display: fallback;
    }
    @body {
      font-family: "My Font", "System Fallback Font", sans;
    }
    

Whenever you change your text, make sure to rerun autosubst. This ensures that the browser does not need to substitute characters from the fallback fonts.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

autosubset-0.3.0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

autosubset-0.3.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file autosubset-0.3.0.tar.gz.

File metadata

  • Download URL: autosubset-0.3.0.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for autosubset-0.3.0.tar.gz
Algorithm Hash digest
SHA256 aa36d9f95dc22279db201259bfc26c4840d3764b2cd7870ddad6b0c6829a64fd
MD5 eda78b4d397b3591161e1cc391e58564
BLAKE2b-256 5e9acbef31056f9a562d40e4c75086fb08ce5486f8106e5ebf923d7cebdb113c

See more details on using hashes here.

File details

Details for the file autosubset-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: autosubset-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for autosubset-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8e6cd48ce70b34d7c52cd5a9690e83b02357f9698b80396286a612b03782048e
MD5 6366f792d2f2820da043cbd8900816a1
BLAKE2b-256 77e596541b43d65082e8ee7922c169c763ce3402f70c499b70a89bd0da369569

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page