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.2.2.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

autosubset-0.2.2-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: autosubset-0.2.2.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.7

File hashes

Hashes for autosubset-0.2.2.tar.gz
Algorithm Hash digest
SHA256 c90397098918550daabdc99f4463cb714325e494fc061eaf518441b616d58422
MD5 848b2af60b199623c22707eaa0a4e3b4
BLAKE2b-256 5363f5b0c28cafd695b3006cc82e7b46067e516a13893f32d278cf94b9f38b9d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: autosubset-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.7

File hashes

Hashes for autosubset-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ad9eda0ac20647785d1010b39d24a0a40c373e15e7d539a740be529e6f7232a3
MD5 004b41767d845456b5c93b1d4b1c54f1
BLAKE2b-256 c636059aa843537be5889edc6b51799af092d3b483de0d4a739431b0f6621dc3

See more details on using hashes here.

Supported by

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