fontsplitta is a command-line tool that splits web fonts and generates CSS.
Project description
fontsplitta
fontsplitta is a command-line tool that splits web fonts and generates CSS.
It creates web fonts that are divided into specific Unicode ranges, similar to Google Fonts.
By properly splitting large fonts such as Japanese fonts, it aims to reduce transfer size and improve user experience.
Installation
Install from Homebrew (macOS):
brew install shunirr/fontsplitta/fontsplitta
Install from PyPI:
pip install fontsplitta
Or, you can download executables from releases:
Development
This project uses uv for Python project management.
To set up the development environment:
# Install uv (if not already installed)
curl -LsSf https://astral.sh/uv/install.sh | sh
# Clone the repository
git clone https://github.com/shunirr/fontsplitta.git
cd fontsplitta
# Create virtual environment and install dependencies
uv sync
# Install with dev dependencies
uv sync --extra dev
# Activate the virtual environment
source .venv/bin/activate
# Run fontsplitta in development mode
fontsplitta --help
To build the project:
# Build distributions
uv build
# Build standalone executable with PyInstaller
uv run pyinstaller --onefile fontsplitta/__main__.py -n fontsplitta
Getting Started
Firstly, generate an unicode_ranges.txt using Google Fonts' CSS:
fontsplitta get-unicode-ranges-from-google-fonts
Secondly, split fonts and generate CSS:
fontsplitta split FONT_FILE
Using a custom CSS template file
If you want to modify the output CSS, you can create a new template file:
@font-face {
font-family: "${font_family}";
font-style: ${font_style};
font-weight: ${font_weight};
src: url(http://localhost:8080/output/${font_filename}) format("${font_format}");
unicode-range: ${unicode_range};
}
Basically, you should use your environment's hostname in the src section.
And then,
fontsplitta split FONT_FILE --css_template=YOUR_CSS_TEMPLATE
You can use below variables:
font_family... The font-family name extracted from the original font filefont_style... The font style, always returnsnormalfont_weight... The font weight extracted from the original font filefont_filename... The split font filenamefont_format... The format of the output font, such aswofforwoff2unicode_range... The unicode ranges specified inunicode_ranges.txt
Using custom unicode ranges
If you want to use custom unicode ranges, you can use the --unicode_ranges_file option:
fontsplitta split FONT_FILE --unicode_ranges_file=YOUR_UNICODE_RANGES_FILE
You can generate the unicode ranges using your web page contents.
Test with local web server
fontsplitta test-server
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fontsplitta-0.1.6.tar.gz.
File metadata
- Download URL: fontsplitta-0.1.6.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
859e4195a5e1d607a6c24c0218c3f1cec683091a6d44db10f787d69fc5f4596d
|
|
| MD5 |
f5bd5d97542a5d42fbe6f3169054db45
|
|
| BLAKE2b-256 |
e1c8ae37794be68627858a9568dd52b39aec146919b22dbe6b69f32ca806e57e
|
File details
Details for the file fontsplitta-0.1.6-py3-none-any.whl.
File metadata
- Download URL: fontsplitta-0.1.6-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d018b6b19cf929270bd63685d4b7b2c97359f323dd54c0b6f04add9dcc45fc6
|
|
| MD5 |
210368b410e43ae455d1fed1f8bb99bf
|
|
| BLAKE2b-256 |
dca8a51af7b22e6e7d9b3dd2d69799d25f334b5b09e7f6e8103b354de08bfba8
|