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.10.tar.gz
(14.8 kB
view details)
Built Distribution
bdffont-0.0.10-py3-none-any.whl
(11.9 kB
view details)
File details
Details for the file bdffont-0.0.10.tar.gz
.
File metadata
- Download URL: bdffont-0.0.10.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 | 5943399e2d5e8b46767c5b810efb0e819f1390fca883bf1ca4840003897bc4e7 |
|
MD5 | 39159fe8ff4f60844589952e7b1318c1 |
|
BLAKE2b-256 | 152889fe5708c41c32cddad1e28682b6702ee1c7c8a4323c79ef78ff38974675 |
Provenance
File details
Details for the file bdffont-0.0.10-py3-none-any.whl
.
File metadata
- Download URL: bdffont-0.0.10-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 | b46de2eea046d5d3feb01d64eca70e64b5a95913406223d371420a48fa665867 |
|
MD5 | fffe6d4b57faaaeb75cfcfa9598c1bb1 |
|
BLAKE2b-256 | 8db6a64ba3cf825f0bc864d3637982414187794f7523a1877130d34fc460d875 |