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 os
import shutil
from bdffont import BdfFont
from examples import assets_dir, build_dir
def main():
outputs_dir = os.path.join(build_dir, 'load')
if os.path.exists(outputs_dir):
shutil.rmtree(outputs_dir)
os.makedirs(outputs_dir)
font = BdfFont.load(os.path.join(assets_dir, '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}')
for glyph in font.glyphs:
print(f'glyph: {glyph.name} - {glyph.code_point:04X} {chr(glyph.code_point)} {glyph.bounding_box}')
for bitmap_row in glyph.bitmap:
print(''.join(map(str, bitmap_row)).replace('0', '__').replace('1', '**'))
print()
font.save(os.path.join(outputs_dir, 'unifont-15.0.01.bdf'), optimize_bitmap=True)
if __name__ == '__main__':
main()
Create
import os
import shutil
from bdffont import BdfFont, BdfGlyph, xlfd
from examples import build_dir
def main():
outputs_dir = os.path.join(build_dir, 'create')
if os.path.exists(outputs_dir):
shutil.rmtree(outputs_dir)
os.makedirs(outputs_dir)
font = BdfFont(
point_size=16,
resolution_xy=(75, 75),
bounding_box_size=(16, 16),
bounding_box_offset=(0, -2),
)
font.glyphs.append(BdfGlyph(
name='A',
code_point=ord('A'),
scalable_width=(500, 0),
device_width=(8, 0),
bounding_box_size=(8, 16),
bounding_box_offset=(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.add_style_name = xlfd.AddStyleName.SANS_SERIF
font.properties.pixel_size = 16
font.properties.point_size = 160
font.properties.spacing = xlfd.Spacing.PROPORTIONAL
font.properties.average_width = round(sum([glyph.device_width_x * 10 for glyph in font.glyphs]) / len(font.glyphs))
font.setup_missing_xlfd_properties()
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.generate_xlfd_font_name()
font.save(os.path.join(outputs_dir, 'my-font.bdf'), optimize_bitmap=True)
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
- ArchWiki - X Logical Font Description
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.19.tar.gz
(1.9 MB
view details)
Built Distribution
bdffont-0.0.19-py3-none-any.whl
(11.6 kB
view details)
File details
Details for the file bdffont-0.0.19.tar.gz
.
File metadata
- Download URL: bdffont-0.0.19.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 | 990b81ccb06c96bc56d30114822a84830db54365e616d499fc2d231c8bcf77c4 |
|
MD5 | ee5e03daf662448fbc7218155f090f4d |
|
BLAKE2b-256 | c14b3671ae18faca2af8a823a3f29e3d6cad1eb324b6d1c19b0de4be91bda400 |
Provenance
File details
Details for the file bdffont-0.0.19-py3-none-any.whl
.
File metadata
- Download URL: bdffont-0.0.19-py3-none-any.whl
- Upload date:
- Size: 11.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 | e02ef22b09117fbfcc6fddb4b3d8b1bc737ecfc6f9d556aa27858ea0e01d7d11 |
|
MD5 | 5a346ca6ca53469ead9d3063f033f6d5 |
|
BLAKE2b-256 | 2ab577e917353f78ac2539e6fb0369fffd81d60e263efbe5e05c8395b0ef696b |