PcfFont - Python
A library for handling 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.config.default_char = 0xFFFE
builder.glyphs.append(PcfGlyph(
name='.notdef',
encodings={0xFFFE},
scalable_width=500,
character_width=8,
dimensions=(8, 16),
offset=(0, -2),
bitmap=[
[1, 1, 1, 1, 1, 1, 1, 1],
[1, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 1],
[1, 1, 1, 1, 1, 1, 1, 1],
],
))
builder.glyphs.append(PcfGlyph(
name='LATIN_CAPITAL_LETTER_A',
encodings={0x0041},
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.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 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 pixel == 0 else '██' for pixel in bitmap_row)
print(f'{text}*')
print()
font.save(outputs_dir.joinpath('unifont-17.0.05.pcf'))
if __name__ == '__main__':
main()
References
- libXfont - X font handling library for server & utilities
- Debian - X Consortium - lib/font/bitmap
- FreeType font driver for PCF fonts
- bdftopcf
- FontForge - The X11 PCF bitmap font file format
- The X Font Library
- X Logical Font Description Conventions - X Consortium Standard
License
Metadata
Release files for pcffont 0.0.34
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pcffont-0.0.34.tar.gz | 17.0 kB | Without provenance | Details for pcffont-0.0.34.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pcffont-0.0.34-py3-none-any.whl | Python 3 | none | any | Details for pcffont-0.0.34-py3-none-any.whl |
Total release size: 43.9 kB
Release files / pcffont-0.0.34.tar.gz
| Download URL | pcffont-0.0.34.tar.gz |
|---|---|
| Size | 17.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
77de4ddd257b03bbd0a2925381650cef39b2acd3cb474815c41057834667e046
|
|
BLAKE2b-256 checksum How to use checksums |
f43f7d67ed6d68a10bc3bba79737d54561743b375b254f8f12faab586f8da516
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.9 {"installer":{"name":"uv","version":"0.12.9","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}
|
Release files / pcffont-0.0.34-py3-none-any.whl
| Download URL | pcffont-0.0.34-py3-none-any.whl |
|---|---|
| Size | 26.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3c1c46a4b8ce8f6b6f63e464633c8886299855310b04939fba544f2ecea08ffb
|
|
BLAKE2b-256 checksum How to use checksums |
6ecc6a9fdbdffcaa2fd0d5c545f1b531966b5eb4981cab74e0e806792ca4c059
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.9 {"installer":{"name":"uv","version":"0.12.9","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}
|
Security for pcffont 0.0.34
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.