Font indexing and querying support like fontconfig.
Project description
fontra
| |
Font indexing and querying support like fontconfig.
Features
- Font indexing and querying via display name
- Specifying custom font directories
- CLI for listing fonts
Installation
Via pip:
pip install fontra
For some advanced tools:
pip install fontra[tools]which currently enables you to:
- Extract a .ttc file to .ttf files
Usage
Command-line interface
fontra --help
--version
list
List available fonts.
--tree/[--table] | -t/[-T]
Whether to display a tree or a table.
--sort/[--no-sort] | -s/[-S]
Whether to output with sorted font names.
--localized/[--unlocalized] | -l/[-L]
Whether to show localized font names.
fontdirs
Show the font search directories.
show NAME...
Show the font information.
[--localized]/--unlocalized | -l/[-L]
Whether to lookup the localized index.
--fuzzy/[--exact] | -f/[-F]
Whether to fuzzy match.
--verbose/-v
Whether to show font path
unlocalize NAME
Convert a name into an unlocalized name.
unpack PATH
Unpack a TTC to TTF. (Requires fontra[tools] installed)
--output OUTPUT
Path to the output directory.
Font indexing and querying
>>> import fontra
>>> fontra.init_fontdb() # Initialize and search fonts
>>> fontra.all_fonts()
['Noto Sans Lisu', 'Noto Serif Tamil SemiCondensed', 'Noto Serif Georgian', 'Noto Sans Armenian', ...]
>>> fontra.get_font_styles("Arial")
['Regular', 'Italic', 'Bold', 'Bold Italic', 'Black']
>>> fontra.get_font("Arial", "Italic")
FontRef(path=PosixPath('/usr/share/fonts/TTF/ariali.ttf'), bank=0)
>>> fontra.has_font_family("Helvetica")
False
>>> fontra.has_font_style("Comic Sans MS", "Light")
False
>>> fontra.get_unlocalized_name("更紗ゴシック UI J")
'Sarasa UI J'
>>> fontra.get_localized_names("LXGW WenKai TC")
['霞鶩文楷 TC', '霞鹜文楷 TC']
>>> fontra.get_font("更纱黑体 SC", "SemiBold Italic")
FontRef(path=PosixPath('/usr/share/fonts/sarasa-gothic/Sarasa-SemiBoldItalic.ttc'), bank=1)
Custom font directories
>>> from pathlib import Path
>>> fontra.FONTDIR_CUSTOM.append(Path("~/.fonts"))
>>> fontra.update_custom_fontfiles_index()
>>> fontra.update_fontrefs_index()
>>> fontra.all_fonts()
[...]
From environment variable
PYFONTRA_CUSTOM_FONTDIRS=~/.fonts fontra
License
This project is under MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
fontra-0.5.0.tar.gz
(10.5 kB
view details)
Built Distribution
fontra-0.5.0-py3-none-any.whl
(11.2 kB
view details)
File details
Details for the file fontra-0.5.0.tar.gz
.
File metadata
- Download URL: fontra-0.5.0.tar.gz
- Upload date:
- Size: 10.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34779206161bd2733b72ec039b4360dc75e5d269beaa404325ca63ae4cc33da6 |
|
MD5 | fe3e4e6e01098a701ee621a0918df55e |
|
BLAKE2b-256 | 9af88e43adaa4a1946cddbddb77e0406c96c108532c1d2f216534a46a2fbf128 |
File details
Details for the file fontra-0.5.0-py3-none-any.whl
.
File metadata
- Download URL: fontra-0.5.0-py3-none-any.whl
- Upload date:
- Size: 11.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f09a80b0e1f437b63e05639daec50c5e30b431ffd807343c6eab089ecf14f698 |
|
MD5 | d85b4a613ca2b6719685a7d556e81978 |
|
BLAKE2b-256 | 6a502b617ced24ffd9672eb8a1e8016a87781d0fb6c39af61ab6f4ff06e01737 |