Skip to main content

Freetype python bindings

Project description

FreeType (high-level Python API)

Freetype Python provides bindings for the FreeType library. Only the high-level API is bound.

Documentation available at: http://freetype-py.readthedocs.org/en/latest/

Installation

From PyPI, recommended: pip install freetype-py. This will install the library with a bundled FreeType binary, so you’re ready to go on Windows, macOS and Linux (all with 32 and 64 bit x86 architecture support).

Do note: if you specify the –no-binary paramater to pip, or use a different architecture for which we don’t pre-compile binaries, the package will default to using an external FreeType library. Specify the environment variable FREETYPEPY_BUNDLE_FT=1 before calling pip to compile a binary yourself.

Installation with compiling FreeType from source

If you don’t want to or can’t use the pre-built binaries, build FreeType yourself: export FREETYPEPY_BUNDLE_FT=yesplease && pip install .. This will download and compile FreeType with Harfbuzz support as specified in setup-build-freetype.py. Set the environment variable PYTHON_ARCH to 32 or 64 to explicitly set an architecture, default is whatever your host machine uses. On macOS, we will always build a universal 32 and 64 bit Intel binary.

  • Windows: You need CMake and a C and C++ compiler, e.g. the Visual Code Community 2017 distribution with the desktop C++ workload.

  • macOS: You need CMake and the XCode tools (full IDE not necessary)

  • Linux: You need CMake, gcc and g++. For building a 32 bit library on a 64 bit machine, you need gcc-multilib and g++-multilib (Debian) or glibc-devel.i686 and libstdc++-devel.i686 (Fedora).

Installation with an external FreeType library (the default)

Install just the pure Python library and let it find a system-wide installed FreeType at runtime.

Mac users

Freetype should be already installed on your system. If not, either install it using homebrew or compile it and place the library binary file in ‘/usr/local/lib’.

Linux users

Freetype should be already installed on your system. If not, either install relevant package from your package manager or compile from sources and place the library binary file in ‘/usr/local/lib’.

Window users

There are no official Freetype binary releases available, but they offer some links to precompiled Windows DLLs. Please see the FreeType Downloads page for links. You can also compile the FreeType library from source yourself.

If you are using freetype-py on Windows with a 32-Bit version of Python, you need the 32-Bit version of the Freetype binary. The same applies for a 64-Bit version of Python.

Because of the way Windows searches for dll files, make sure the resulting file is named ‘freetype.dll’ (and not something like Freetype245.dll). Windows expects the library in one of the directories listed in the $PATH environment variable. As it is not recommended to place the dll in a Windows system folder, you can choose one of the following ways to solve this:

  • Place library in a folder of your choice and edit the $PATH user environment variable

  • Place library in a folder of your choice and edit the $PATH system environment variable

  • For development purpose, place the library in the working directory of the application

  • Place the library in one of the existing directories listed in $PATH

To get a complete list of all the directories in the $PATH environment variable (user and system), open a command promt and type

echo %PATH%

Usage example

import freetype
face = freetype.Face("Vera.ttf")
face.set_char_size( 48*64 )
face.load_char('S')
bitmap = face.glyph.bitmap
print bitmap.buffer

Screenshots

Screenshot below comes from the wordle.py example. No clever tricks here, just brute force.

https://raw.githubusercontent.com/rougier/freetype-py/master/doc/_static/wordle.png

Screenshots below comes from the glyph-vector.py and glyph-vectopr-2.py examples showing how to access a glyph outline information and use it to draw the glyph. Rendering (with Bézier curves) is done using matplotlib.

https://raw.githubusercontent.com/rougier/freetype-py/master/doc/_static/S.png https://raw.githubusercontent.com/rougier/freetype-py/master/doc/_static/G.png

Screenshot below comes from the glyph-color.py showing how to draw and combine a glyph outline with the regular glyph.

https://raw.githubusercontent.com/rougier/freetype-py/master/doc/_static/outline.png

The screenshot below comes from the hello-world.py example showing how to draw text in a bitmap (that has been zoomed in to show antialiasing).

https://raw.githubusercontent.com/rougier/freetype-py/master/doc/_static/hello-world.png

The screenshot below comes from the agg-trick.py example showing an implementation of ideas from the Texts Rasterization Exposures by Maxim Shemarev.

https://raw.githubusercontent.com/rougier/freetype-py/master/doc/_static/agg-trick.png

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

freetype-py-2.2.0.zip (827.5 kB view details)

Uploaded Source

Built Distributions

freetype_py-2.2.0-py3-none-win_amd64.whl (708.9 kB view details)

Uploaded Python 3 Windows x86-64

freetype_py-2.2.0-py3-none-manylinux1_x86_64.whl (890.4 kB view details)

Uploaded Python 3

freetype_py-2.2.0-py3-none-macosx_10_9_x86_64.whl (852.6 kB view details)

Uploaded Python 3 macOS 10.9+ x86-64

File details

Details for the file freetype-py-2.2.0.zip.

File metadata

  • Download URL: freetype-py-2.2.0.zip
  • Upload date:
  • Size: 827.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.10

File hashes

Hashes for freetype-py-2.2.0.zip
Algorithm Hash digest
SHA256 cf43716bc5246cd54a64b2238b942e8dc80b79eda92f814c720286fa6fab387a
MD5 82e1d9905a37f4ee2fdabe00ea17f15d
BLAKE2b-256 e816d7fee48fd6ac1234af8ae4f1d664a6c8f0748e138a6ce676c194923f2104

See more details on using hashes here.

File details

Details for the file freetype_py-2.2.0-py3-none-win_amd64.whl.

File metadata

  • Download URL: freetype_py-2.2.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 708.9 kB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.8

File hashes

Hashes for freetype_py-2.2.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 719a639040484a063b99421d104e3911a860d2e034b67769ae438bc1d4aa6e1f
MD5 60a097960f9ed5feaeca8a710a7bc335
BLAKE2b-256 3990e820daead8c1f36f4b7323644bb8203a31bace207a01fc1839fa4bd77d80

See more details on using hashes here.

File details

Details for the file freetype_py-2.2.0-py3-none-manylinux1_x86_64.whl.

File metadata

  • Download URL: freetype_py-2.2.0-py3-none-manylinux1_x86_64.whl
  • Upload date:
  • Size: 890.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.10

File hashes

Hashes for freetype_py-2.2.0-py3-none-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 ede78730db61dc17c4524412aa3fccf038ede65400aa49b9e0a73a7e839a91a2
MD5 a00c123dd53885d3c249009f5b4dacdf
BLAKE2b-256 40b556751e13f8b4a42f52c1b85ecce1446f83245190d820b42748eb8574ae43

See more details on using hashes here.

File details

Details for the file freetype_py-2.2.0-py3-none-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: freetype_py-2.2.0-py3-none-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 852.6 kB
  • Tags: Python 3, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.11

File hashes

Hashes for freetype_py-2.2.0-py3-none-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 8059ebad562d465555fa556739906a2429381ba6206989afe2b7c8c87fad19d8
MD5 afcd7c991eecbee99084ec930f49ec80
BLAKE2b-256 7de01ef978a7df66ee92abb8e5f08c77da55c4cb8c49c1852c3e53892d51eede

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