A library for manipulating Portable Compiled Format (PCF) Fonts
Project description
PcfFont.Python
PcfFont is a library for manipulating Portable Compiled Format (PCF) Fonts.
Installation
pip install pcffont
Usage
Create
import shutil
import statistics
from examples import build_dir
from pcffont import PcfFontBuilder, PcfGlyph
def main():
outputs_dir = build_dir.joinpath('create')
if outputs_dir.exists():
shutil.rmtree(outputs_dir)
outputs_dir.mkdir(parents=True)
builder = PcfFontBuilder()
builder.config.font_ascent = 14
builder.config.font_descent = 2
builder.glyphs.append(PcfGlyph(
name='A',
encoding=65,
scalable_width=500,
character_width=8,
dimensions=(8, 16),
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],
],
))
builder.properties.foundry = 'Pixel Font Studio'
builder.properties.family_name = 'My Font'
builder.properties.weight_name = 'Medium'
builder.properties.slant = 'R'
builder.properties.setwidth_name = 'Normal'
builder.properties.add_style_name = 'Sans Serif'
builder.properties.pixel_size = 16
builder.properties.point_size = builder.properties.pixel_size * 10
builder.properties.resolution_x = 75
builder.properties.resolution_y = 75
builder.properties.spacing = 'P'
builder.properties.average_width = round(statistics.fmean(glyph.character_width * 10 for glyph in builder.glyphs))
builder.properties.charset_registry = 'ISO10646'
builder.properties.charset_encoding = '1'
builder.properties.generate_xlfd()
builder.properties.x_height = 7
builder.properties.cap_height = 10
builder.properties.underline_position = -2
builder.properties.underline_thickness = 1
builder.properties.font_version = '1.0.0'
builder.properties.copyright = 'Copyright (c) TakWolf'
builder.save(outputs_dir.joinpath('my-font.pcf'))
if __name__ == '__main__':
main()
Load
import shutil
from examples import assets_dir, build_dir
from pcffont import PcfFont
def main():
outputs_dir = build_dir.joinpath('load')
if outputs_dir.exists():
shutil.rmtree(outputs_dir)
outputs_dir.mkdir(parents=True)
font = PcfFont.load(assets_dir.joinpath('unifont', 'unifont-17.0.01.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 encoding, 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(encoding)} ({encoding:04X})')
print(f'glyph_name: {glyph_name}')
print(f'advance_width: {metric.character_width}')
print(f'dimensions: {metric.dimensions}')
print(f'offset: {metric.offset}')
for bitmap_row in bitmap:
text = ''.join(' ' if color == 0 else '██' for color in bitmap_row)
print(f'{text}*')
print()
font.save(outputs_dir.joinpath('unifont-17.0.01.pcf'))
if __name__ == '__main__':
main()
References
- FreeType font driver for PCF fonts
- FontForge - The X11 PCF bitmap font file format
- The X Font Library
- bdftopcf
- bdftopcf - docs
- X Logical Font Description Conventions - X Consortium Standard
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.22.tar.gz
(13.7 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
pcffont-0.0.22-py3-none-any.whl
(23.0 kB
view details)
File details
Details for the file pcffont-0.0.22.tar.gz.
File metadata
- Download URL: pcffont-0.0.22.tar.gz
- Upload date:
- Size: 13.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c91b188d38115a19996b9fe78e191cc6495bf0b954007f1bdb4839d24f108f98
|
|
| MD5 |
bade52120116b8fde2fbe8f64d326727
|
|
| BLAKE2b-256 |
268571bd7e098ff9b2da55e80f3edaa63c64e8914948583567c0dc0d75941a30
|
File details
Details for the file pcffont-0.0.22-py3-none-any.whl.
File metadata
- Download URL: pcffont-0.0.22-py3-none-any.whl
- Upload date:
- Size: 23.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e6114dfd251ec8223173c61e8d2ad9ea565068023af34fc58b9ef5b948270a4
|
|
| MD5 |
e050e04944301f82567e2415f8670b98
|
|
| BLAKE2b-256 |
0120ebda948edb11dd35f9651cdaff44b68ef4f47114420faf3a8100eabfb4de
|