BDF (Glyph Bitmap Distribution Format) Bitmap Font File Parser in Python
Project description
BDF Parser
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 enriched 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.
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 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bdfparser-2.1.0.tar.gz.
File metadata
- Download URL: bdfparser-2.1.0.tar.gz
- Upload date:
- Size: 13.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.9.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
20b768dc29203294ed601d8a102c41f4d5e0063c5ffc8374f81dba8d6218012f
|
|
| MD5 |
bd43e6b32e1e5a6d8e20955a4daf1181
|
|
| BLAKE2b-256 |
541c509dd2e0cb99ed6c2aa8af34474bbb87d4a12b06d67ec3f0b184869dd685
|
File details
Details for the file bdfparser-2.1.0-py3-none-any.whl.
File metadata
- Download URL: bdfparser-2.1.0-py3-none-any.whl
- Upload date:
- Size: 12.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.9.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed370f2e0e852749587dd24a2ed2be53758ed3d2d058be6882f8caacabfc3ee6
|
|
| MD5 |
270ca2690bc981c808e5c393ec7837cd
|
|
| BLAKE2b-256 |
b2122b1b9713e111f1d5f149659ef6ce2bc275f880b41568142611cf48c8822f
|