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-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_orderly_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.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.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.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],
],
))
glyph_widths = [glyph.scalable_width_x for glyph in font.get_orderly_glyphs()]
font.properties.average_width = round(sum(glyph_widths) / font.get_glyphs_count())
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.9.tar.gz
(14.8 kB
view details)
Built Distribution
bdffont-0.0.9-py3-none-any.whl
(11.9 kB
view details)
File details
Details for the file bdffont-0.0.9.tar.gz
.
File metadata
- Download URL: bdffont-0.0.9.tar.gz
- Upload date:
- Size: 14.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8c5b8340885275e3e30c74486e666c201e81e2699e194fe5d4df215aa625cb3 |
|
MD5 | bc4fdb6e309193c78824b45c5feeb4fc |
|
BLAKE2b-256 | cb1da43b84db5c4d3d9bdecfbaa4cbf25995eedcd5543266587876372fb4e338 |
Provenance
File details
Details for the file bdffont-0.0.9-py3-none-any.whl
.
File metadata
- Download URL: bdffont-0.0.9-py3-none-any.whl
- Upload date:
- Size: 11.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e5ba7c22d08b19e589f2749ecd9cc3a203d2ef7644ec22b3b3bcb7fc857f369 |
|
MD5 | d4ef5590b707a05a7f34c8660534165d |
|
BLAKE2b-256 | 31a7ef25d3f303acc3567af88377442b05f3100da19679ceab013664764d5f9a |