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.1.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.1-py3-none-any.whl (216.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fontfinder-0.16.1.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.1.tar.gz
Algorithm Hash digest
SHA256 02bcbcdc140784c62115d8b09409bfdfe00f746b5c02267c5c67269a24b185d0
MD5 e877d0ae92cc2fe3074e4baa30f611b2
BLAKE2b-256 96792a9f4ff9ff120e33de499b06270b70236b1df5cde916d1a7de72e094818d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fontfinder-0.16.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4d4c055a95a0ac20b388cbcb80032c3520d5b262f0d5f24d62c4c9af13e22ee5
MD5 4bd923eb861d87705086918b6b364872
BLAKE2b-256 45551b29056e796d3dc2c474d92fca0dd285f831169ecb0ee154dee07f681bb4

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