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-vector-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

Freezing apps

Freetype implements a hook for PyInstaller to help simplify the freezing process (it e.g. ensures that the freetype DLL is included). This hook requires PyInstaller version 4+.

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.4.0.zip (832.5 kB view details)

Uploaded Source

Built Distributions

freetype_py-2.4.0-py3-none-win_amd64.whl (790.5 kB view details)

Uploaded Python 3 Windows x86-64

freetype_py-2.4.0-py3-none-musllinux_1_1_x86_64.whl (1.1 MB view details)

Uploaded Python 3 musllinux: musl 1.1+ x86-64

freetype_py-2.4.0-py3-none-musllinux_1_1_aarch64.whl (1.1 MB view details)

Uploaded Python 3 musllinux: musl 1.1+ ARM64

freetype_py-2.4.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.0 MB view details)

Uploaded Python 3 manylinux: glibc 2.17+ ARM64

freetype_py-2.4.0-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.0 MB view details)

Uploaded Python 3 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

freetype_py-2.4.0-py3-none-macosx_10_9_universal2.whl (1.8 MB view details)

Uploaded Python 3 macOS 10.9+ universal2 (ARM64, x86-64)

File details

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

File metadata

  • Download URL: freetype-py-2.4.0.zip
  • Upload date:
  • Size: 832.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for freetype-py-2.4.0.zip
Algorithm Hash digest
SHA256 8ad81195d2f8f339aba61700cebfbd77defad149c51f59b75a2a5e37833ae12e
MD5 c63b1ee876bf97be9d2be49745e10be7
BLAKE2b-256 a76d66c222fae5dc5fd13fd840ab75feb49f78963f560a56e134c85f1236a94c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for freetype_py-2.4.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 a2620788d4f0c00bd75fee2dfca61635ab0da856131598c96e2355d5257f70e5
MD5 f73821c84168ed1aff2b74fe36608256
BLAKE2b-256 b4f54b8bb492464247236bd3dabd7734b3ea49adc63cf2e53160e830ebccb39d

See more details on using hashes here.

File details

Details for the file freetype_py-2.4.0-py3-none-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for freetype_py-2.4.0-py3-none-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 9614f68876e9c62e821dfa811dd6160e00279d9d98cf60118cb264be48da1472
MD5 6a4ef6843f4e8e3714e9d36df6ba19e4
BLAKE2b-256 64c0731aef7ab5a996ea1cccb5096fd95a6be5cc3ec82299808daa9164fe5042

See more details on using hashes here.

File details

Details for the file freetype_py-2.4.0-py3-none-musllinux_1_1_aarch64.whl.

File metadata

File hashes

Hashes for freetype_py-2.4.0-py3-none-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 c6276d92ac401c8ce02ea391fc854de413b01a8d835fb394ee5eb6f04fc947f5
MD5 af336406174a0ebc781b1fed7318824f
BLAKE2b-256 57fe90f718b3e8d83c477b9d96e7c9737236818294ab00509eb27b2935b2adc7

See more details on using hashes here.

File details

Details for the file freetype_py-2.4.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for freetype_py-2.4.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c9a3abc277f5f6d21575c0093c0c6139c161bf05b91aa6258505ab27c5001c5e
MD5 b87da6ceb33dd618fb8423a7e522d649
BLAKE2b-256 8545f0200e64029aa0474ba4dc3e325d32c023c6607d6d8e5bc278aa27c570d3

See more details on using hashes here.

File details

Details for the file freetype_py-2.4.0-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for freetype_py-2.4.0-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 ce931f581d5038c4fea1f3d314254e0264e92441a5fdaef6817fe77b7bb888d3
MD5 6058eb7804b5c510648fb76eacb7cdb1
BLAKE2b-256 5f3476cfe866e482745ea8c9956b0be6198fd72d08d2be77b71596afdb8cd89f

See more details on using hashes here.

File details

Details for the file freetype_py-2.4.0-py3-none-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for freetype_py-2.4.0-py3-none-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 3e0f5a91bc812f42d98a92137e86bac4ed037a29e43dafdb76d716d5732189e8
MD5 47730540d88e75d548d6d75f7deba93f
BLAKE2b-256 7c77faec42d1ffac2b970f606860a5bb083d606f1c673a5c57ab26382c8efec1

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