Skip to main content

Query Windows fonts by name

Project description

windows-fonts

Enumerate and discover fonts on Windows

Why this module exists

Most (all?) python modules that render text to an image (matplotlib, PIL/Pillow etc) need to take a filename on Windows, but happily take a font name on other platforms, which is a) annoying from a cross-platform standpoint, and b) requires a bit of "faff" for the user to discover the font file for a given font.

Synopsis

>>> from windows_fonts import FontCollection, Weight
>>> fonts = FontCollection()

>>> # Get the first variant (light/regular/bold etc) for a named family
>>> family = fonts['Arial']

>>> variant = family[0]
>>> variant
<FontVariant family=<FontFamily name="Arial">, style=Style.NORMAL weight=Weight.REGULAR>
>>> print(variant.filename, variant.weight, variant.style)
C:\WINDOWS\FONTS\ARIAL.TTF Weight.REGULAR Style.NORMAL

# Find the "closest" variant for a given family
>>> variant = family.get_best_variant(weight=Weight.BOLD)  # Or `style=Style.ITALIC, or both
>>> variant
<FontVariant family=<FontFamily name="Arial">, style=Style.NORMAL weight=Weight.BOLD>

# Or to find all "matching" variants in priority order:
>>> for variant  in family.get_matching_variants(weight=Weight.BOLD):
...    variant
...
<FontVariant family=<FontFamily name="Arial">, style=Style.NORMAL weight=Weight.BOLD>
<FontVariant family=<FontFamily name="Arial">, style=Style.NORMAL weight=Weight.BLACK>
<FontVariant family=<FontFamily name="Arial">, style=Style.NORMAL weight=Weight.BOLD>
<FontVariant family=<FontFamily name="Arial">, style=Style.ITALIIC weight=Weight.BOLD>
<FontVariant family=<FontFamily name="Arial">, style=Style.ITALIIC weight=Weight.BOLD>
<FontVariant family=<FontFamily name="Arial">, style=Style.NORMAL weight=Weight.BOLD>
<FontVariant family=<FontFamily name="Arial">, style=Style.NORMAL weight=Weight.BOLD>
<FontVariant family=<FontFamily name="Arial">, style=Style.ITALIIC weight=Weight.BOLD>
<FontVariant family=<FontFamily name="Arial">, style=Style.ITALIIC weight=Weight.BOLD>

Requirements

Python >= 3.7 Windows Vista and up

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

windows_fonts-1.0.0a1.tar.gz (16.1 kB view hashes)

Uploaded Source

Built Distributions

windows_fonts-1.0.0a1-cp311-none-win_amd64.whl (166.0 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

windows_fonts-1.0.0a1-cp310-none-win_amd64.whl (166.0 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

windows_fonts-1.0.0a1-cp39-none-win_amd64.whl (166.3 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

windows_fonts-1.0.0a1-cp38-none-win_amd64.whl (166.5 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

windows_fonts-1.0.0a1-cp37-none-win_amd64.whl (166.5 kB view hashes)

Uploaded CPython 3.7 Windows x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page