A library for manipulating Glyph Bitmap Distribution Format (BDF) Fonts.
Project description
BdfFont
BdfFont is a library for manipulating Glyph Bitmap Distribution Format (BDF) Fonts.
Installation
pip install bdffont
Usage
Load
import shutil
from bdffont import BdfFont
from examples import assets_dir, build_dir
def main():
outputs_dir = build_dir.joinpath('load')
if outputs_dir.exists():
shutil.rmtree(outputs_dir)
outputs_dir.mkdir(parents=True)
font = BdfFont.load(assets_dir.joinpath('unifont', 'unifont-15.1.05.bdf'))
print(f'name: {font.name}')
print(f'size: {font.point_size}')
print(f'ascent: {font.properties.font_ascent}')
print(f'descent: {font.properties.font_descent}')
print()
for glyph in font.glyphs:
print(f'char: {chr(glyph.encoding)} ({glyph.encoding:04X})')
print(f'glyph_name: {glyph.name}')
print(f'advance_width: {glyph.device_width_x}')
print(f'dimensions: {glyph.dimensions}')
print(f'origin: {glyph.origin}')
for bitmap_row in glyph.bitmap:
text = ''.join(map(str, bitmap_row)).replace('0', ' ').replace('1', '██')
print(f'{text}*')
print()
font.save(outputs_dir.joinpath('unifont-15.0.01.bdf'))
if __name__ == '__main__':
main()
Create
import shutil
from bdffont import BdfFont, BdfGlyph
from examples import build_dir
def main():
outputs_dir = build_dir.joinpath('create')
if outputs_dir.exists():
shutil.rmtree(outputs_dir)
outputs_dir.mkdir(parents=True)
font = BdfFont(
point_size=16,
resolution=(75, 75),
bounding_box=(16, 16, 0, -2),
)
font.glyphs.append(BdfGlyph(
name='A',
encoding=ord('A'),
scalable_width=(500, 0),
device_width=(8, 0),
bounding_box=(8, 16, 0, -2),
bitmap=[
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 1, 0, 0, 0],
[0, 0, 1, 0, 0, 1, 0, 0],
[0, 0, 1, 0, 0, 1, 0, 0],
[0, 1, 0, 0, 0, 0, 1, 0],
[0, 1, 0, 0, 0, 0, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 0, 0, 0, 0, 1, 0],
[0, 1, 0, 0, 0, 0, 1, 0],
[0, 1, 0, 0, 0, 0, 1, 0],
[0, 1, 0, 0, 0, 0, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
],
))
font.properties.foundry = 'Pixel Font Studio'
font.properties.family_name = 'Demo Pixel'
font.properties.weight_name = 'Medium'
font.properties.slant = 'R'
font.properties.setwidth_name = 'Normal'
font.properties.add_style_name = 'Sans Serif'
font.properties.pixel_size = font.point_size
font.properties.point_size = font.point_size * 10
font.properties.resolution_x = font.resolution_x
font.properties.resolution_y = font.resolution_y
font.properties.spacing = 'P'
font.properties.average_width = round(sum([glyph.device_width_x * 10 for glyph in font.glyphs]) / len(font.glyphs))
font.properties.charset_registry = 'ISO10646'
font.properties.charset_encoding = '1'
font.generate_name_as_xlfd()
font.properties.default_char = -1
font.properties.font_ascent = 14
font.properties.font_descent = 2
font.properties.x_height = 5
font.properties.cap_height = 7
font.properties.font_version = '1.0.0'
font.properties.copyright = 'Copyright (c) TakWolf'
font.save(outputs_dir.joinpath('my-font.bdf'))
if __name__ == '__main__':
main()
Test Fonts
References
- X11 - Bitmap Distribution Format - Version 2.1
- Adobe - Glyph Bitmap Distribution Format (BDF) Specification - Version 2.2
- X Logical Font Description Conventions - X Consortium Standard
License
Under the MIT license.
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
bdffont-0.0.25.tar.gz
(1.9 MB
view details)
Built Distribution
bdffont-0.0.25-py3-none-any.whl
(10.6 kB
view details)
File details
Details for the file bdffont-0.0.25.tar.gz
.
File metadata
- Download URL: bdffont-0.0.25.tar.gz
- Upload date:
- Size: 1.9 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 210d7ca2ca4e0a0fe2c93d13b3e0707db16a501cfbd566abedcdca325ff7cfe6 |
|
MD5 | 863582ea483ef4d1bfc8d1dec8130a1e |
|
BLAKE2b-256 | 594eec262930eda2fa19f1acb6ee75a5fd3488b3162f43e51d2942392e77752d |
Provenance
File details
Details for the file bdffont-0.0.25-py3-none-any.whl
.
File metadata
- Download URL: bdffont-0.0.25-py3-none-any.whl
- Upload date:
- Size: 10.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d39e7856be1e18b5bb2b8fa714a123e2fe6d758f6ff69852124b3b37b54e8771 |
|
MD5 | 28870adf796d588dfdc3597302b79e4b |
|
BLAKE2b-256 | 839f083003192ba364e601729e0a71ddb53083b3d5b5c398879413aa1459510c |