Package for finding and installing fonts for Unicode scripts.
Project description
fontfinder
Overview
fontfinder is a Python package for finding and installing fonts for Unicode scripts. It's useful
when generating documents that must specify a font family and will be viewed across multiple platforms.
For now, fontfinder
mostly locates fonts in the Google Noto font collection.
Font enumeration and installation is currently supported on macOS (using CoreText) and Windows (using DirectWrite).
Most functionality is provided by instantiating the FontFinder
class.
Docs
See multiscript.app/fontfinder
Examples
>>> from fontfinder import FontFinder
>>> ff = FontFinder()
>>> text = 'الشمس (رمزها: ☉) هي النجم المركزي للمجموعة الشمسية.' # From Arabic Wikipedia article about the Sun
>>> ff.analyse(text)
TextInfo(main_script='Arabic', script_variant='', emoji_count=1, script_count=Counter({'Arabic': 39, 'Common': 12}))
>>> known_families = ff.find_families(text) # Available font families for the given text
>>> print(known_families)
['Noto Kufi Arabic', 'Noto Naskh Arabic', 'Noto Naskh Arabic UI', 'Noto Sans Arabic']
>>> preferred_family = ff.find_family(text) # Selects a single preferred font family for the text
>>> print(preferred_family)
Noto Naskh Arabic
>>> print(ff.installed_families(preferred_family)) # The font family is not yet installed
[]
>>> family_fonts = ff.find_family_fonts(preferred_family)
>>> print([font_info.postscript_name for font_info in family_fonts]) # The individual fonts in the family
['NotoNaskhArabic-Bold', 'NotoNaskhArabic-Medium', 'NotoNaskhArabic-Regular', 'NotoNaskhArabic-SemiBold']
>>> from tempfile import TemporaryDirectory
>>> tempdir = TemporaryDirectory()
>>> fonts_for_download = ff.find_family_fonts_to_download(preferred_family) # The indiv fonts that can be downloaded
>>> fonts_for_install = ff.download_fonts(fonts_for_download, tempdir.name) # The downloaded fonts
>>> ff.install_fonts(fonts_for_install) # Actually install each individual font
>>> print(ff.installed_families(preferred_family)) # The font family is now installed
['Noto Naskh Arabic']
>>> ff.uninstall_fonts(fonts_for_install) # Uninstall each individual font
>>> print(ff.installed_families(preferred_family)) # The font family is once again not installed
[]
>>> tempdir.cleanup()
Attribution
Parts of this library are derived from code in the FindSystemFontsFilename library by moi15moi (https://github.com/moi15moi/FindSystemFontsFilename/), under the MIT Licence.
See ACKNOWLEDGEMENTS for more detail.
Installation
pip install fontfinder
Build Instructions
Use these instructions if you’re building from the source. fontfinder
has been developed on Python 3.10, but should
work on other versions as well.
git clone https://github.com/multiscript/fontfinder/
cd fontfinder
python3 -m venv venv
(Create a virtual environment.)- On Windows:
python -m venv venv
- On Windows:
source venv/bin/activate
(Activate the virtual environment.)- In Windows cmd.exe:
venv\Scripts\\activate.bat
- In Windows powershell:
.\\venv\Scripts\Activate.ps1
You may first need to runSet-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
- In Windows cmd.exe:
- For development work...
pip install -e .
(Creates an editable local install)
- ...or to build the package:
pip install build
python -m build
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
File details
Details for the file fontfinder-0.15.0.tar.gz
.
File metadata
- Download URL: fontfinder-0.15.0.tar.gz
- Upload date:
- Size: 208.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54ffc582af30501bb0f7b9e7298e52d6af6116d56db45a1634ec215aaba3f21b |
|
MD5 | 4296170714f9b664674f9fdf5daeb8c1 |
|
BLAKE2b-256 | 62c508dc136448fa0caac1f10a4a3eea4a46649d6319a758bbdf10bbb03a7823 |
File details
Details for the file fontfinder-0.15.0-py3-none-any.whl
.
File metadata
- Download URL: fontfinder-0.15.0-py3-none-any.whl
- Upload date:
- Size: 198.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ba7acb95f44ffb072bbbed19fc31518f7b372348633c8584904024c6d448938 |
|
MD5 | f63e0304b7c97e3d7d56887effa3c608 |
|
BLAKE2b-256 | 9d786535cd336a57458f12555668fe6824a1aed7a521a5629b81978e89077dc8 |