Skip to main content

Python bindings for Fontconfig library

Project description

Python bindings for Fontconfig library

Requirement

Tested on

  • Python 2.7.2 (32-bit, 64-bit)

  • Python 3.2.2 (32-bit, 64-bit)

  • Python 3.3.2 (64-bit)

Installation

From PyPI:

>>> pip install Python-fontconfig

or

>>> easy_install Python-fontconfig

From GitHub:

>>> git clone git://github.com/Vayn/python-fontconfig.git
>>> cd python-fontconfig/
>>> python setup.py install

Building C source

>>> python setup.py build_ext -i

Testing

>>> cd test/
>>> python test.py

Usage

>>> import fontconfig
>>> fonts = fontconfig.query(family='ubuntu', lang='en')
>>> fonts
['/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-BI.ttf',
 '/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-L.ttf',
 '/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-LI.ttf',
 '/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-R.ttf',
 '/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-B.ttf',
 '/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-RI.ttf']
>>> font = fontconfig.FcFont(fonts[0])
>>> font
<FcFont: Ubuntu>
>>> font.
font.bestname           font.capability         font.fullname
font.slant              font.count_chars        font.get_languages
font.spacing            font.decorative         font.has_char
font.style              font.family             font.index
font.weight             font.file               font.outline
font.width              font.fontformat         font.print_pattern
font.foundry            font.scalable
>>> font.family
{'en': 'Ubuntu'}
>>> font.bestname
{'en': 'Ubuntu'}
>>> font.foundry
'unknown'
>>> font.fontformat
'TrueType'
>>> font.has_char('A')
True
>>> font.file
'/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-BI.ttf'
>>> fontconfig.fromName('Ubuntu')
<FcFont: Ubuntu>
>>> font = fontconfig.FcFont(font.file)
>>> font.family
{'en': 'Ubuntu'}

To get fonts from a .ttc (TrueType font collection) file:

>>> font = fontconfig.fromName('simsun')
>>> font.count, font.index, font.file, font
(3, 0, '/home/lilydjwg/.fonts/win/simsun.ttc', <FcFont: 宋体>)
>>> font = fontconfig.FcFont(font.file, 1)
>>> font.count, font.index, font.file, font
(3, 1, '/home/lilydjwg/.fonts/win/simsun.ttc', <FcFont: 新宋体>)
>>> fontconfig.query('新宋体', with_index=True)
[('/home/lilydjwg/.fonts/win/simsun.ttc', 1)]

License

This program is released under GPLv3 license, see LICENSE for more detail.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_fontconfig-0.6.2.post1.tar.gz (110.2 kB view details)

Uploaded Source

File details

Details for the file python_fontconfig-0.6.2.post1.tar.gz.

File metadata

  • Download URL: python_fontconfig-0.6.2.post1.tar.gz
  • Upload date:
  • Size: 110.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for python_fontconfig-0.6.2.post1.tar.gz
Algorithm Hash digest
SHA256 4837290305613710cf6c515db8923284da06e4f48a549d2fe8e2d4276aed3e73
MD5 3090bba2821bac22d02e07826106b368
BLAKE2b-256 205999db03443f584b6d14bb635ef9f849dae7966792471dee9bf50ae2308f07

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