Skip to main content

No project description provided

Project description

OkFonts

Make font metrics predictable on the web. Given a font file, it adjusts vertical metrics so that:

  • CSS font-size: Npx makes capitals exactly N pixels high
  • CSS line-height: 1 makes single-line block elements exactly N pixels high
  • Capitals are perfectly centered within their lines

It does this by setting both UPM and ascender to the font's cap height, and descender to 0. Glyph coordinates are not scaled.

Supports TTF and WOFF2.

Install

uv add okfonts

CLI

uvx okfonts input.ttf -o output.ttf

Programmatic usage

from fontTools.ttLib import TTFont
from okfonts import process

font = TTFont("input.ttf")
process(font)
font.save("output.ttf")

Public proxy

OkFonts includes a proxy server that acts as a drop-in replacement for Google Fonts. It intercepts CSS responses, downloads and processes every referenced font file, and serves the result with rewritten URLs.

A public instance is available at okfonts.matvei.is. Use it as a drop-in replacement for Google Fonts:

<link
  href="https://okfonts.matvei.is/v1/css2?family=Inter&display=swap"
  rel="stylesheet"
/>

Self-hosted proxy

Install with the proxy extra:

uv add 'okfonts[proxy]'

Run:

okfonts-proxy

The proxy exposes two routes:

  • /v1/css2 — proxies CSS requests to Google Fonts
  • /v1/font/{filename} — serves processed font files from cache

To use it, replace fonts.googleapis.com with your proxy host:

<link
  href="https://your-proxy/v1/css2?family=Inter&display=swap"
  rel="stylesheet"
/>

Configuration

Variable Default Description
PORT 3000 Port the proxy listens on
CACHE_DIR .cache Directory for processed 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

okfonts-0.2.0.tar.gz (3.9 kB view details)

Uploaded Source

File details

Details for the file okfonts-0.2.0.tar.gz.

File metadata

  • Download URL: okfonts-0.2.0.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.0 {"installer":{"name":"uv","version":"0.11.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"43","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for okfonts-0.2.0.tar.gz
Algorithm Hash digest
SHA256 8f76da2a6f64593844c73cb12b1b5ca0aba5ad67ce812a294a628d4d333a92bf
MD5 ae30e85979a41ab12e701bf8e06fb870
BLAKE2b-256 3eabf2bbe42d368f33b0233f461c02a8434e0a453f1193164a3197b5e0c0bb90

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