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 name=Regular, 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 name=Bold, 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 name=Bold, family=<FontFamily name="Arial">, style=Style.NORMAL weight=Weight.BOLD>
<FontVariant name=Bold, family=<FontFamily name="Arial">, style=Style.NORMAL weight=Weight.BOLD>
<FontVariant name=Black, family=<FontFamily name="Arial">, style=Style.NORMAL weight=Weight.BLACK>
<FontVariant name=Narrow Bold, family=<FontFamily name="Arial">, style=Style.NORMAL weight=Weight.BOLD>
<FontVariant name=Narrow Bold, family=<FontFamily name="Arial">, style=Style.NORMAL weight=Weight.BOLD>
<FontVariant name=Bold Italic, family=<FontFamily name="Arial">, style=Style.ITALIIC weight=Weight.BOLD>
<FontVariant name=Italic Bold, family=<FontFamily name="Arial">, style=Style.ITALIIC weight=Weight.BOLD>
<FontVariant name=Narrow Bold Italic, family=<FontFamily name="Arial">, style=Style.ITALIIC weight=Weight.BOLD>
<FontVariant name=Narrow Italic Bold, family=<FontFamily name="Arial">, style=Style.ITALIIC weight=Weight.BOLD>

Find a specific Font Variant

Some font families are aggregated, for instance Arial and Arial Narrow both are placed under the "Arial" family by the Win32 APIs. But if you want to be able to directly get to the Arial Narrow font files you need to use the top-level get_matching_variants function:

>>> get_matching_variants(win32_family_names="Arial Narrow")
[<FontVariant name=Narrow, family=<FontFamily name="Arial">, style=Style.NORMAL weight=Weight.REGULAR>,
 <FontVariant name=Narrow Italic, family=<FontFamily name="Arial">, style=Style.ITALIIC weight=Weight.REGULAR>,
 <FontVariant name=Narrow Bold, family=<FontFamily name="Arial">, style=Style.NORMAL weight=Weight.BOLD>,
 <FontVariant name=Narrow Bold Italic, family=<FontFamily name="Arial">, style=Style.ITALIIC weight=Weight.BOLD>]

Or if you know the full name already:

>>> get_matching_variants(full_name="Arial Narrow Bold Italic")
[<FontVariant name=Narrow Bold Italic, family=<FontFamily name="Arial">, style=Style.ITALIIC weight=Weight.BOLD>]

Get information about a Font Variant

.information is a dict-like object. The some keys will not be available on every font.

>>> info = variant.information
>>> import pprint
>>> pprint.pprint(dict(info))
{'copyright': '© 2008 The Monotype Corporation. All Rights Reserved.',
 'description': ...,
 'designer': 'Robin Nicholas, Patricia Saunders',
 'full_name': 'Arial Narrow Italic',
 'license_description': ...,
 'manufacturer': 'The Monotype Corporation',
 'postscript_name': 'ArialNarrow-Italic',
 'preferred_family_names': 'Arial',
 'preferred_subfamily_names': 'Narrow Italic',
 'trademark': 'Arial is a trademark of The Monotype Corporation in the United '
              'States and/or other countries.',
 'typographic_subfamily_names': 'Narrow Italic',
 'typographic_family_names': 'Arial',
 'versions': 'Version 2.40',
 'win32_family_names': 'Arial Narrow',
 'win32_subfamily_names': 'Italic'}

Requirements

Python >= 3.7
Windows Vista and up
Some functions or methods need Windows 10 (get_matching_variants top-level function, and FontFamily.get_matching_variants when called with width, slant, optical_size, or italic parameters).

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.0.tar.gz (22.1 kB view details)

Uploaded Source

Built Distributions

windows_fonts-1.0.0-cp311-none-win_amd64.whl (197.8 kB view details)

Uploaded CPython 3.11 Windows x86-64

windows_fonts-1.0.0-cp310-none-win_amd64.whl (197.8 kB view details)

Uploaded CPython 3.10 Windows x86-64

windows_fonts-1.0.0-cp39-none-win_amd64.whl (198.1 kB view details)

Uploaded CPython 3.9 Windows x86-64

windows_fonts-1.0.0-cp38-none-win_amd64.whl (197.6 kB view details)

Uploaded CPython 3.8 Windows x86-64

windows_fonts-1.0.0-cp37-none-win_amd64.whl (197.7 kB view details)

Uploaded CPython 3.7 Windows x86-64

File details

Details for the file windows_fonts-1.0.0.tar.gz.

File metadata

  • Download URL: windows_fonts-1.0.0.tar.gz
  • Upload date:
  • Size: 22.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for windows_fonts-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b87e8ee54936fd9a46b9d23f84011e076044c15febf40a902ffb289a89f1b26f
MD5 098bff3a1a3df3ece66b3318d065bc5a
BLAKE2b-256 ba575d66d0b9464582993ef54b810e63de482134b1cc7223a9edf10dab9dc301

See more details on using hashes here.

File details

Details for the file windows_fonts-1.0.0-cp311-none-win_amd64.whl.

File metadata

File hashes

Hashes for windows_fonts-1.0.0-cp311-none-win_amd64.whl
Algorithm Hash digest
SHA256 2426cda4cb5839166f74e7bb78cc20c66546873667fbbd7a78be0b365d1536db
MD5 adc5bc2f2d134e23bff6594f2f276277
BLAKE2b-256 ffd6641de124bdc73eda758ceec30440c7a6c830d675821d9bd6c343bcf817bd

See more details on using hashes here.

File details

Details for the file windows_fonts-1.0.0-cp310-none-win_amd64.whl.

File metadata

File hashes

Hashes for windows_fonts-1.0.0-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 05a20d9ebe29fd993eba1b9f9489b5978631c7a28e6cb47ccfa315940ebfa3a0
MD5 a0a3c36d68702ea005acf8b883b65bc2
BLAKE2b-256 b866097e1b715d49687cd38ab94710d8ddb6546a59f6c2beafe5dc68d436d9a3

See more details on using hashes here.

File details

Details for the file windows_fonts-1.0.0-cp39-none-win_amd64.whl.

File metadata

File hashes

Hashes for windows_fonts-1.0.0-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 2b7c5f76525b15e2c1139062dd4bf4693bc2ce72e4d3f9a08c6a178e0026a603
MD5 72a4877d8ab237e5d29961ff1bfd3a0c
BLAKE2b-256 f009cead05bc9411acf702cbca4ba389e1387fcfeddaae1d436e2d8ff8504759

See more details on using hashes here.

File details

Details for the file windows_fonts-1.0.0-cp38-none-win_amd64.whl.

File metadata

File hashes

Hashes for windows_fonts-1.0.0-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 51585401b3677204ea84bc1db2b46439960cd9fb7fda32b9b95fbb41823113c8
MD5 0f9f7e869d37e04067b09815afd8466e
BLAKE2b-256 ad323b14e6b3994daebe813afce062d451898dbc1f923e475026b3b4a97afeb3

See more details on using hashes here.

File details

Details for the file windows_fonts-1.0.0-cp37-none-win_amd64.whl.

File metadata

File hashes

Hashes for windows_fonts-1.0.0-cp37-none-win_amd64.whl
Algorithm Hash digest
SHA256 ff8fd5d351d32ad03f44b20e990833fcef9411d76035961822b80c7053f81848
MD5 41f3541a89e885946a9181a60ac9b221
BLAKE2b-256 0ea8fd8af2430b56e6dc6416b106e71462499925c87992d21780b9429d898629

See more details on using hashes here.

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