A library for manipulating '.bdf' format fonts.
Project description
BdfFont
BdfFont is a library for manipulating .bdf
format fonts.
Installation
pip install bdffont
Usage
Load
import os
from bdffont import BdfFont
from examples import assets_dir, outputs_dir
def main():
font = BdfFont.load(os.path.join(assets_dir, 'unifont', 'unifont-15.0.01.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.get_glyphs():
print(f'glyph: {glyph.name} - {glyph.code_point:04X}')
font.save(os.path.join(outputs_dir, 'unifont-15.0.01.bdf'), optimize_bitmap=True)
if __name__ == '__main__':
main()
Create
import os
from bdffont import BdfFont, BdfGlyph, xlfd
from examples import outputs_dir
def main():
font = BdfFont(
point_size=16,
resolution_xy=(75, 75),
bounding_box_size=(16, 16),
bounding_box_offset=(0, -2),
)
font.add_glyph(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 = 'TakWolf 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.code_point_to_glyph.values()]) / font.get_glyphs_count())
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()
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.13.tar.gz
(14.8 kB
view details)
Built Distribution
bdffont-0.0.13-py3-none-any.whl
(11.8 kB
view details)
File details
Details for the file bdffont-0.0.13.tar.gz
.
File metadata
- Download URL: bdffont-0.0.13.tar.gz
- Upload date:
- Size: 14.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9889412fd8267ee1548ad879e021ab75611ea0e564d86116de1bcd60793047c0 |
|
MD5 | 2bcb3727a40fde13866aa8023000d4ce |
|
BLAKE2b-256 | dd396453288d95b4fb051038440d10dbf5db5a3496e3b83ca53c27a26350aca2 |
Provenance
File details
Details for the file bdffont-0.0.13-py3-none-any.whl
.
File metadata
- Download URL: bdffont-0.0.13-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 819c6630c7ee5ab3cff31a23bd2253025ac23a840c631f1d953b9ad903f050ff |
|
MD5 | 79d33c12b40a2a7939d2cb90df371273 |
|
BLAKE2b-256 | 04af1fa9834ecd45bda8995d5bc30ce9c3c3a82520fc85eeb2b5925cd61fa6f6 |