A library for parsing Bits'N'Picas native save format files ('.kbits' and '.kbitx')
Project description
KbitFont
KbitFont is a library for parsing Bits'N'Picas native save format files (.kbits and .kbitx).
Installation
pip install kbitfont
Usage
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 alpha <= 127 else '██' for alpha 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 alpha <= 127 else '██' for alpha in bitmap_row)
print(f'{text}*')
print()
font.save_kbitx(outputs_dir.joinpath('Athens.kbitx'))
if __name__ == '__main__':
main()
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'
font.names.designer_url = 'https://takwolf.com'
font.names.license_url = 'https://openfontlicense.org'
font.characters[ord('A')] = 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.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.save_kbits(outputs_dir.joinpath('my-font.kbits'))
font.save_kbitx(outputs_dir.joinpath('my-font.kbitx'))
if __name__ == '__main__':
main()
Specifications
Font Struct
Kbits
Kbitx
Dependencies
License
Under the MIT license.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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
File details
Details for the file kbitfont-0.0.1.tar.gz.
File metadata
- Download URL: kbitfont-0.0.1.tar.gz
- Upload date:
- Size: 116.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ff6ea5c055204ca6534f11b0f864fe1e539b487997ed0e66cb91d417e5a7234
|
|
| MD5 |
0b5e2ea4ea91849029e6f019f6883607
|
|
| BLAKE2b-256 |
2eac8336c9b67594428a0a6397b5d57e68dac92a6d4dc807f6388b400d6c4726
|
Provenance
The following attestation bundles were made for kbitfont-0.0.1.tar.gz:
Publisher:
publish.yml on TakWolf/kbitfont
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kbitfont-0.0.1.tar.gz -
Subject digest:
0ff6ea5c055204ca6534f11b0f864fe1e539b487997ed0e66cb91d417e5a7234 - Sigstore transparency entry: 179435431
- Sigstore integration time:
-
Permalink:
TakWolf/kbitfont@08da55f0d1fa82e608e9030ca0a99baeca601c42 -
Branch / Tag:
refs/tags/0.0.1 - Owner: https://github.com/TakWolf
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@08da55f0d1fa82e608e9030ca0a99baeca601c42 -
Trigger Event:
release
-
Statement type:
File details
Details for the file kbitfont-0.0.1-py3-none-any.whl.
File metadata
- Download URL: kbitfont-0.0.1-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c00d4deabcddb53c04bc6debabdc06e09dfabd46ca0141fdfd6e142e747f9be0
|
|
| MD5 |
9b4a370144b215eebb2860601917c85f
|
|
| BLAKE2b-256 |
b5087190f6ec8b3b8550966389df4693ce7e77e846227036dc3e23273912c2bc
|
Provenance
The following attestation bundles were made for kbitfont-0.0.1-py3-none-any.whl:
Publisher:
publish.yml on TakWolf/kbitfont
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kbitfont-0.0.1-py3-none-any.whl -
Subject digest:
c00d4deabcddb53c04bc6debabdc06e09dfabd46ca0141fdfd6e142e747f9be0 - Sigstore transparency entry: 179435433
- Sigstore integration time:
-
Permalink:
TakWolf/kbitfont@08da55f0d1fa82e608e9030ca0a99baeca601c42 -
Branch / Tag:
refs/tags/0.0.1 - Owner: https://github.com/TakWolf
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@08da55f0d1fa82e608e9030ca0a99baeca601c42 -
Trigger Event:
release
-
Statement type: