Name | pcffont JSON |
Version |
0.0.15
JSON |
| download |
home_page | None |
Summary | A library for manipulating Portable Compiled Format (PCF) Fonts. |
upload_time | 2024-07-02 06:19:15 |
maintainer | TakWolf |
docs_url | None |
author | TakWolf |
requires_python | >=3.10 |
license | MIT License |
keywords |
font
pcf
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# PcfFont
[![Python](https://img.shields.io/badge/python-3.10-brightgreen)](https://www.python.org)
[![PyPI](https://img.shields.io/pypi/v/pcffont)](https://pypi.org/project/pcffont/)
PcfFont is a library for manipulating [Portable Compiled Format (PCF) Fonts](https://en.wikipedia.org/wiki/Portable_Compiled_Format).
## Installation
```shell
pip install pcffont
```
## Usage
### Load
```python
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
```python
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
- [GNU Unifont Glyphs](https://unifoundry.com/unifont/index.html)
- [Spleen](https://github.com/fcambus/spleen)
## References
- [FreeType font driver for PCF fonts](https://github.com/freetype/freetype/tree/master/src/pcf)
- [FontForge - The X11 PCF bitmap font file format](https://fontforge.org/docs/techref/pcf-format.html)
- [The X Font Library](https://www.x.org/releases/current/doc/libXfont/fontlib.html)
- [bdftopcf](https://gitlab.freedesktop.org/xorg/util/bdftopcf)
- [bdftopcf - docs](https://www.x.org/releases/current/doc/man/man1/bdftopcf.1.xhtml)
- [X Logical Font Description Conventions - X Consortium Standard](https://www.x.org/releases/current/doc/xorg-docs/xlfd/xlfd.html)
## License
Under the [MIT license](LICENSE).
Raw data
{
"_id": null,
"home_page": null,
"name": "pcffont",
"maintainer": "TakWolf",
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "font, pcf",
"author": "TakWolf",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/c6/d4/24f3164e0ff280325d39323658412042960445b36ee3409c12a441b5d744/pcffont-0.0.15.tar.gz",
"platform": null,
"description": "# PcfFont\n\n[![Python](https://img.shields.io/badge/python-3.10-brightgreen)](https://www.python.org)\n[![PyPI](https://img.shields.io/pypi/v/pcffont)](https://pypi.org/project/pcffont/)\n\nPcfFont is a library for manipulating [Portable Compiled Format (PCF) Fonts](https://en.wikipedia.org/wiki/Portable_Compiled_Format).\n\n## Installation\n\n```shell\npip install pcffont\n```\n\n## Usage\n\n### Load\n\n```python\nimport shutil\n\nfrom examples import assets_dir, build_dir\nfrom pcffont import PcfFont\n\n\ndef main():\n outputs_dir = build_dir.joinpath('load')\n if outputs_dir.exists():\n shutil.rmtree(outputs_dir)\n outputs_dir.mkdir(parents=True)\n\n font = PcfFont.load(assets_dir.joinpath('unifont', 'unifont-15.1.05.pcf'))\n print(f'name: {font.properties.font}')\n print(f'size: {font.properties.pixel_size}')\n print(f'ascent: {font.accelerators.font_ascent}')\n print(f'descent: {font.accelerators.font_descent}')\n print()\n for encoding, glyph_index in sorted(font.bdf_encodings.items()):\n glyph_name = font.glyph_names[glyph_index]\n metric = font.metrics[glyph_index]\n bitmap = font.bitmaps[glyph_index]\n print(f'char: {chr(encoding)} ({encoding:04X})')\n print(f'glyph_name: {glyph_name}')\n print(f'advance_width: {metric.character_width}')\n print(f'dimensions: {metric.dimensions}')\n print(f'origin: {metric.origin}')\n for bitmap_row in bitmap:\n text = ''.join(map(str, bitmap_row)).replace('0', ' ').replace('1', '\u2588\u2588')\n print(f'{text}*')\n print()\n font.save(outputs_dir.joinpath('unifont-15.1.05.pcf'))\n\n\nif __name__ == '__main__':\n main()\n```\n\n### Create\n\n```python\nimport shutil\n\nfrom examples import build_dir\nfrom pcffont import PcfFontBuilder, PcfGlyph\n\n\ndef main():\n outputs_dir = build_dir.joinpath('create')\n if outputs_dir.exists():\n shutil.rmtree(outputs_dir)\n outputs_dir.mkdir(parents=True)\n\n builder = PcfFontBuilder()\n builder.config.font_ascent = 14\n builder.config.font_descent = 2\n\n builder.glyphs.append(PcfGlyph(\n name='A',\n encoding=ord('A'),\n scalable_width=500,\n character_width=8,\n dimensions=(8, 16),\n origin=(0, -2),\n bitmap=[\n [0, 0, 0, 0, 0, 0, 0, 0],\n [0, 0, 0, 0, 0, 0, 0, 0],\n [0, 0, 0, 0, 0, 0, 0, 0],\n [0, 0, 0, 0, 0, 0, 0, 0],\n [0, 0, 0, 1, 1, 0, 0, 0],\n [0, 0, 1, 0, 0, 1, 0, 0],\n [0, 0, 1, 0, 0, 1, 0, 0],\n [0, 1, 0, 0, 0, 0, 1, 0],\n [0, 1, 0, 0, 0, 0, 1, 0],\n [0, 1, 1, 1, 1, 1, 1, 0],\n [0, 1, 0, 0, 0, 0, 1, 0],\n [0, 1, 0, 0, 0, 0, 1, 0],\n [0, 1, 0, 0, 0, 0, 1, 0],\n [0, 1, 0, 0, 0, 0, 1, 0],\n [0, 0, 0, 0, 0, 0, 0, 0],\n [0, 0, 0, 0, 0, 0, 0, 0],\n ],\n ))\n\n builder.properties.foundry = 'Pixel Font Studio'\n builder.properties.family_name = 'Demo Pixel'\n builder.properties.weight_name = 'Medium'\n builder.properties.slant = 'R'\n builder.properties.setwidth_name = 'Normal'\n builder.properties.add_style_name = 'Sans Serif'\n builder.properties.pixel_size = 16\n builder.properties.point_size = builder.properties.pixel_size * 10\n builder.properties.resolution_x = 75\n builder.properties.resolution_y = 75\n builder.properties.spacing = 'P'\n builder.properties.average_width = round(sum([glyph.character_width * 10 for glyph in builder.glyphs]) / len(builder.glyphs))\n builder.properties.charset_registry = 'ISO10646'\n builder.properties.charset_encoding = '1'\n builder.properties.generate_xlfd()\n\n builder.properties.x_height = 5\n builder.properties.cap_height = 7\n\n builder.properties.font_version = '1.0.0'\n builder.properties.copyright = 'Copyright (c) TakWolf'\n\n builder.save(outputs_dir.joinpath('my-font.pcf'))\n\n\nif __name__ == '__main__':\n main()\n```\n\n## Test Fonts\n\n- [GNU Unifont Glyphs](https://unifoundry.com/unifont/index.html)\n- [Spleen](https://github.com/fcambus/spleen)\n\n## References\n\n- [FreeType font driver for PCF fonts](https://github.com/freetype/freetype/tree/master/src/pcf)\n- [FontForge - The X11 PCF bitmap font file format](https://fontforge.org/docs/techref/pcf-format.html)\n- [The X Font Library](https://www.x.org/releases/current/doc/libXfont/fontlib.html)\n- [bdftopcf](https://gitlab.freedesktop.org/xorg/util/bdftopcf)\n- [bdftopcf - docs](https://www.x.org/releases/current/doc/man/man1/bdftopcf.1.xhtml)\n- [X Logical Font Description Conventions - X Consortium Standard](https://www.x.org/releases/current/doc/xorg-docs/xlfd/xlfd.html)\n\n## License\n\nUnder the [MIT license](LICENSE).\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "A library for manipulating Portable Compiled Format (PCF) Fonts.",
"version": "0.0.15",
"project_urls": {
"homepage": "https://github.com/TakWolf/pcffont",
"issues": "https://github.com/TakWolf/pcffont/issues",
"source": "https://github.com/TakWolf/pcffont"
},
"split_keywords": [
"font",
" pcf"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ee6210c2a3ff8047e2fa370ab6fdf5fd9a240c5f100c4a72a4528fae56ba8f2c",
"md5": "081956ce8e222dbe47ec1d8c1a0497e2",
"sha256": "3b91f32415dc5bef3a647091a24226bf81c785c99c1f819960c792f221b6dfa7"
},
"downloads": -1,
"filename": "pcffont-0.0.15-py3-none-any.whl",
"has_sig": false,
"md5_digest": "081956ce8e222dbe47ec1d8c1a0497e2",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 22638,
"upload_time": "2024-07-02T06:19:12",
"upload_time_iso_8601": "2024-07-02T06:19:12.121463Z",
"url": "https://files.pythonhosted.org/packages/ee/62/10c2a3ff8047e2fa370ab6fdf5fd9a240c5f100c4a72a4528fae56ba8f2c/pcffont-0.0.15-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "c6d424f3164e0ff280325d39323658412042960445b36ee3409c12a441b5d744",
"md5": "695d103473dcf46ed8c65a89a4892868",
"sha256": "b095a8a5d8d9d2f33406b74181ce9766c0c614deff342081aab0b26024614f73"
},
"downloads": -1,
"filename": "pcffont-0.0.15.tar.gz",
"has_sig": false,
"md5_digest": "695d103473dcf46ed8c65a89a4892868",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 2731147,
"upload_time": "2024-07-02T06:19:15",
"upload_time_iso_8601": "2024-07-02T06:19:15.534671Z",
"url": "https://files.pythonhosted.org/packages/c6/d4/24f3164e0ff280325d39323658412042960445b36ee3409c12a441b5d744/pcffont-0.0.15.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-02 06:19:15",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "TakWolf",
"github_project": "pcffont",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "pcffont"
}