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
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-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 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'origin: {metric.origin}')
for bitmap_row in bitmap:
text = ''.join(map(str, bitmap_row)).replace('0', ' ').replace('1', '██')
print(f'{text}*')
print()
font.save(outputs_dir.joinpath('unifont-15.1.05.pcf'))
if __name__ == '__main__':
main()
Create
import shutil
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=ord('A'),
scalable_width=500,
character_width=8,
dimensions=(8, 16),
origin=(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 = 'Demo Pixel'
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(sum([glyph.character_width * 10 for glyph in builder.glyphs]) / len(builder.glyphs))
builder.properties.charset_registry = 'ISO10646'
builder.properties.charset_encoding = '1'
builder.properties.generate_xlfd()
builder.properties.x_height = 5
builder.properties.cap_height = 7
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()
Test Fonts
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
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.15.tar.gz
(2.7 MB
view details)
Built Distribution
pcffont-0.0.15-py3-none-any.whl
(22.6 kB
view details)
File details
Details for the file pcffont-0.0.15.tar.gz
.
File metadata
- Download URL: pcffont-0.0.15.tar.gz
- Upload date:
- Size: 2.7 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b095a8a5d8d9d2f33406b74181ce9766c0c614deff342081aab0b26024614f73 |
|
MD5 | 695d103473dcf46ed8c65a89a4892868 |
|
BLAKE2b-256 | c6d424f3164e0ff280325d39323658412042960445b36ee3409c12a441b5d744 |
File details
Details for the file pcffont-0.0.15-py3-none-any.whl
.
File metadata
- Download URL: pcffont-0.0.15-py3-none-any.whl
- Upload date:
- Size: 22.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b91f32415dc5bef3a647091a24226bf81c785c99c1f819960c792f221b6dfa7 |
|
MD5 | 081956ce8e222dbe47ec1d8c1a0497e2 |
|
BLAKE2b-256 | ee6210c2a3ff8047e2fa370ab6fdf5fd9a240c5f100c4a72a4528fae56ba8f2c |