A library for manipulating Portable Compiled Format (PCF) Fonts.
Project description
PcfFont
PcfFont is a library for manipulating Portable Compiled Format (PCF) Fonts.
Installation
pip install pcffont
Usage
import os
import shutil
from examples import assets_dir, build_dir
from pcffont import PcfFont
def main():
outputs_dir = os.path.join(build_dir, 'demo')
if os.path.exists(outputs_dir):
shutil.rmtree(outputs_dir)
os.makedirs(outputs_dir)
font = PcfFont.load(os.path.join(assets_dir, 'unifont', 'unifont-15.1.05.pcf'))
print(f'name: {font.properties.font}')
print(f'size: {font.properties.pixel_size}')
print(f'ascent: {font.accelerators.font_ascent}')
print(f'descent: {font.accelerators.font_descent}')
print()
for code_point, glyph_index in sorted(font.bdf_encodings.items()):
glyph_name = font.glyph_names[glyph_index]
metric = font.metrics[glyph_index]
bitmap = font.bitmaps[glyph_index]
print(f'char: {chr(code_point)} ({code_point:04X})')
print(f'glyph_name: {glyph_name}')
print(f'advance_width: {metric.character_width}')
print(f'offset: ({-metric.left_sided_bearing}, {-metric.character_descent})')
for bitmap_row in bitmap:
print(f'{''.join(map(str, bitmap_row)).replace('0', ' ').replace('1', '██')}*')
print()
font.save(os.path.join(outputs_dir, 'unifont-15.1.05.pcf'))
if __name__ == '__main__':
main()
Test Fonts
References
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
pcffont-0.0.2.tar.gz
(1.4 MB
view hashes)
Built Distribution
pcffont-0.0.2-py3-none-any.whl
(18.2 kB
view hashes)