Skip to main content

BDF (Glyph Bitmap Distribution Format) Bitmap Font File Parser in Python

Project description

BDF Parser Python library

PyPI package version number Actions Status codecov License

BDF (Glyph Bitmap Distribution; Wikipedia; Spec) format bitmap font file parser library in Python. It has Font, Glyph and Bitmap classes providing more than 30 chainable API methods of parsing BDF fonts, getting their meta information, rendering text in any writing direction, adding special effects and manipulating bitmap images. It works seamlessly with PIL / Pillow and NumPy, and has detailed documentation / tutorials / API reference.

BDF Parser TypeScript (JavaScript) library (documentation; GitHub page; npm page; npm i bdfparser) is a port of BDF Parser Python library (documentation; GitHub page; PyPI page; pip install bdfparser). Both are written by Tom Chen and under the MIT License.

The BDF Parser TypeScript (JavaScript) library has a Live Demo & Editor you can try.

Below I'll show you some quick examples, but it is still strongly recommended you go to BDF Parser Python Library's official website to read the detailed documentation / tutorials / API reference.

Install bdfparser Python library with pip:

pip install bdfparser

Then:

from bdfparser import Font
font = Font('tests/fonts/unifont-13.0.04.bdf')
print(f"This font's global size is "
      f"{font.headers['fbbx']} x {font.headers['fbby']} (pixel), "
      f"it contains {len(font)} glyphs.")

# =================================

ac = font.glyph("a").draw().crop(6, 8, 1, 2).concat(
    font.glyph("c").draw().crop(6, 8, 1, 2)
    ).shadow()
ac_8x8 = ac * 8

from PIL import Image
im_ac = Image.frombytes('RGBA',
                        (ac_8x8.width(), ac_8x8.height()),
                        ac_8x8.tobytes('RGBA'))
im_ac.save("ac.png", "PNG")

# =================================

hello = font.draw('Hello!', direction='rl').glow()
print(hello)

import numpy
import matplotlib.pyplot as plt
nparr = numpy.array(hello.todata(2))
plt.imshow(nparr, 'Blues')
plt.show()

# =================================

font_preview = font.drawall()
im_ac = Image.frombytes('1',
                        (font_preview.width(), font_preview.height()),
                        font_preview.tobytes('1'))
im_ac.save("font_preview.png", "PNG")

You probably understand what I did in these examples. Whether you do or not, go to bdfparser's documentation website.



BDF Parser Live Demo & Code Editor

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

bdfparser-2.2.0.tar.gz (14.6 kB view details)

Uploaded Source

Built Distribution

bdfparser-2.2.0-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file bdfparser-2.2.0.tar.gz.

File metadata

  • Download URL: bdfparser-2.2.0.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

File hashes

Hashes for bdfparser-2.2.0.tar.gz
Algorithm Hash digest
SHA256 75cebd7c2f1ed5e5d0985763b255726a9538c602c7c5ca8639707aec54a58683
MD5 614854b2fae1abb929f0701f2506d893
BLAKE2b-256 e3b78e2a9b806450254f1ae0d4e18e4d8612cf7561fb87a5a8395e369b3bf4b9

See more details on using hashes here.

File details

Details for the file bdfparser-2.2.0-py3-none-any.whl.

File metadata

  • Download URL: bdfparser-2.2.0-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

File hashes

Hashes for bdfparser-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 62ceed3b90b1fca050fcb414e70cc5b1f4551d57b088f9e7417678563eebf135
MD5 45c5fca5dd88ebe05219ed61503e8384
BLAKE2b-256 2f00846b41165fd31b5668fe89bdbda9f44099d9df8760c3865404336af094a3

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