Skip to main content

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.

  1. git clone https://github.com/multiscript/fontfinder/
  2. cd fontfinder
  3. python3 -m venv venv (Create a virtual environment.)
    • On Windows: python -m venv venv
  4. 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 run Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
  5. For development work...
    • pip install -e . (Creates an editable local install)
  6. ...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

fontfinder-0.16.0.tar.gz (218.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fontfinder-0.16.0-py3-none-any.whl (216.8 kB view details)

Uploaded Python 3

File details

Details for the file fontfinder-0.16.0.tar.gz.

File metadata

  • Download URL: fontfinder-0.16.0.tar.gz
  • Upload date:
  • Size: 218.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.6

File hashes

Hashes for fontfinder-0.16.0.tar.gz
Algorithm Hash digest
SHA256 e2e74a7a1cecb12076c1c89c4bd19b104189d726d6fb944fe799876274f85e57
MD5 4c2da5e61f6118a712ddb784e4b88d64
BLAKE2b-256 c9fa83df9b5177da50e1554bfe2f2f94c0961adaad20792447655df0f81e9003

See more details on using hashes here.

File details

Details for the file fontfinder-0.16.0-py3-none-any.whl.

File metadata

  • Download URL: fontfinder-0.16.0-py3-none-any.whl
  • Upload date:
  • Size: 216.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.6

File hashes

Hashes for fontfinder-0.16.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f13d02fb8a51b68882fba607c6f2265e29d5459eb31074bbc92997d7bc959e08
MD5 cd727660f0f88bc02ac9ee6aa22cda68
BLAKE2b-256 506795e99551074801c28f58698c046dfb0d4538ffbac97562f2a9cbd49d90f1

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