A library for parsing Bits'N'Picas native save format files ('.kbits' and '.kbitx')
Project description
KbitFont - Python
KbitFont is a library for parsing Bits'N'Picas native save format files (.kbits and .kbitx).
Installation
pip install kbitfont
Usage
Create
import shutil
from examples import build_dir
from kbitfont import KbitFont, KbitGlyph
def main():
outputs_dir = build_dir.joinpath('create')
if outputs_dir.exists():
shutil.rmtree(outputs_dir)
outputs_dir.mkdir(parents=True)
font = KbitFont()
font.props.em_ascent = 14
font.props.em_descent = 2
font.props.line_ascent = 14
font.props.line_descent = 2
font.props.x_height = 7
font.props.cap_height = 10
font.names.version = '1.0.0'
font.names.family = 'My Font'
font.names.style = 'Regular'
font.names.manufacturer = 'Pixel Font Studio'
font.names.designer = 'TakWolf'
font.names.description = 'A pixel font'
font.names.copyright = 'Copyright (c) TakWolf'
font.names.license_description = 'This Font Software is licensed under the SIL Open Font License, Version 1.1'
font.names.vendor_url = 'https://github.com/TakWolf/kbitfont-python'
font.names.designer_url = 'https://takwolf.com'
font.names.license_url = 'https://openfontlicense.org'
font.named_glyphs['.notdef'] = KbitGlyph(
x=0,
y=14,
advance=8,
bitmap=[
[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF],
[0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF],
[0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF],
[0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF],
[0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF],
[0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF],
[0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF],
[0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF],
[0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF],
[0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF],
[0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF],
[0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF],
[0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF],
[0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF],
[0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF],
[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF],
],
)
font.characters[65] = KbitGlyph(
x=0,
y=14,
advance=8,
bitmap=[
[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
[0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00],
[0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00],
[0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00],
[0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00],
[0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00],
[0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00],
[0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00],
[0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00],
[0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00],
[0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00],
[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
],
)
font.save_kbits(outputs_dir.joinpath('my-font.kbits'))
font.save_kbitx(outputs_dir.joinpath('my-font.kbitx'))
if __name__ == '__main__':
main()
Load Kbits
import shutil
from examples import assets_dir, build_dir
from kbitfont import KbitFont
def main():
outputs_dir = build_dir.joinpath('load_kbits')
if outputs_dir.exists():
shutil.rmtree(outputs_dir)
outputs_dir.mkdir(parents=True)
font = KbitFont.load_kbits(assets_dir.joinpath('macintosh', 'Athens.kbits'))
print(f'name: {font.names.family}')
print(f'size: {font.props.em_height}')
print(f'ascent: {font.props.line_ascent}')
print(f'descent: {font.props.line_descent}')
print()
for code_point, glyph in sorted(font.characters.items()):
print(f'char: {chr(code_point)} ({code_point:04X})')
print(f'xy: {(glyph.x, glyph.y)}')
print(f'dimensions: {glyph.dimensions}')
print(f'advance: {glyph.advance}')
for bitmap_row in glyph.bitmap:
text = ''.join(' ' if color <= 127 else '██' for color in bitmap_row)
print(f'{text}*')
print()
font.save_kbits(outputs_dir.joinpath('Athens.kbits'))
if __name__ == '__main__':
main()
Load Kbitx
import shutil
from examples import assets_dir, build_dir
from kbitfont import KbitFont
def main():
outputs_dir = build_dir.joinpath('load_kbitx')
if outputs_dir.exists():
shutil.rmtree(outputs_dir)
outputs_dir.mkdir(parents=True)
font = KbitFont.load_kbitx(assets_dir.joinpath('macintosh', 'Athens.kbitx'))
print(f'name: {font.names.family}')
print(f'size: {font.props.em_height}')
print(f'ascent: {font.props.line_ascent}')
print(f'descent: {font.props.line_descent}')
print()
for code_point, glyph in sorted(font.characters.items()):
print(f'char: {chr(code_point)} ({code_point:04X})')
print(f'xy: {(glyph.x, glyph.y)}')
print(f'dimensions: {glyph.dimensions}')
print(f'advance: {glyph.advance}')
for bitmap_row in glyph.bitmap:
text = ''.join(' ' if color <= 127 else '██' for color in bitmap_row)
print(f'{text}*')
print()
font.save_kbitx(outputs_dir.joinpath('Athens.kbitx'))
if __name__ == '__main__':
main()
Specifications
Font Struct
Kbits
Kbitx
Dependencies
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
kbitfont-0.0.10.tar.gz
(9.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
kbitfont-0.0.10-py3-none-any.whl
(12.7 kB
view details)
File details
Details for the file kbitfont-0.0.10.tar.gz.
File metadata
- Download URL: kbitfont-0.0.10.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e0d69bfc52f9012ad23201cff4284d6af3f838e992851412ca0bc56ed8f82819
|
|
| MD5 |
1147fe8d0d96c69882dce25752e1c2f8
|
|
| BLAKE2b-256 |
9d37c20251f0774618582ebd2b8e846a6efa92a6bf364311ace42c02f975f649
|
File details
Details for the file kbitfont-0.0.10-py3-none-any.whl.
File metadata
- Download URL: kbitfont-0.0.10-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7fdea90b315335f48abe37c704034e9b9d48eda4287144ba17d492a876f3572
|
|
| MD5 |
1d677db30f72b3d098954bd4807a1c67
|
|
| BLAKE2b-256 |
832e80a0c2ac0366e2c3485a1cf0f8bc22fd96b4c1843ea4b4ddccfb211bf0e9
|