pcffont


Namepcffont JSON
Version 0.0.23 PyPI version JSON
download
home_pageNone
SummaryA library for manipulating Portable Compiled Format (PCF) Fonts
upload_time2025-10-14 03:00:57
maintainerTakWolf
docs_urlNone
authorTakWolf
requires_python>=3.10
licenseNone
keywords pcf font
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # PcfFont.Python

[![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

### Create

```python
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

```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-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](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

[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": "pcf, font",
    "author": "TakWolf",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/eb/9e/e66e4ea701e54d02ba2f9cd4ad6e3a632b8e910719fbbfc74923e1ffc665/pcffont-0.0.23.tar.gz",
    "platform": null,
    "description": "# PcfFont.Python\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### Create\n\n```python\nimport shutil\nimport statistics\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=65,\n        scalable_width=500,\n        character_width=8,\n        dimensions=(8, 16),\n        offset=(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 = 'My Font'\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(statistics.fmean(glyph.character_width * 10 for glyph in 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 = 7\n    builder.properties.cap_height = 10\n    builder.properties.underline_position = -2\n    builder.properties.underline_thickness = 1\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### 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-17.0.01.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'offset: {metric.offset}')\n        for bitmap_row in bitmap:\n            text = ''.join('  ' if color == 0 else '\u2588\u2588' for color in bitmap_row)\n            print(f'{text}*')\n        print()\n    font.save(outputs_dir.joinpath('unifont-17.0.01.pcf'))\n\n\nif __name__ == '__main__':\n    main()\n```\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\n[MIT License](LICENSE)\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A library for manipulating Portable Compiled Format (PCF) Fonts",
    "version": "0.0.23",
    "project_urls": {
        "Homepage": "https://github.com/TakWolf/pcffont-python",
        "Issues": "https://github.com/TakWolf/pcffont-python/issues",
        "Source": "https://github.com/TakWolf/pcffont-python"
    },
    "split_keywords": [
        "pcf",
        " font"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "59b8e6bda5a6e374a9dc0010b2e0c974fc0f4e8bda1c8358a666c46fead66d9b",
                "md5": "2a7ee2e06d900e722cf86f9218037000",
                "sha256": "44c04cec2d97e86b0a2c049ad9177f1dc31843563a0bb05873b2bb65bf9a6558"
            },
            "downloads": -1,
            "filename": "pcffont-0.0.23-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2a7ee2e06d900e722cf86f9218037000",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 23006,
            "upload_time": "2025-10-14T03:00:56",
            "upload_time_iso_8601": "2025-10-14T03:00:56.674950Z",
            "url": "https://files.pythonhosted.org/packages/59/b8/e6bda5a6e374a9dc0010b2e0c974fc0f4e8bda1c8358a666c46fead66d9b/pcffont-0.0.23-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "eb9ee66e4ea701e54d02ba2f9cd4ad6e3a632b8e910719fbbfc74923e1ffc665",
                "md5": "0504538222681a20eb1adec55936711a",
                "sha256": "d509cd06cd25a86eac3b58a21361b1264f018310578aa161a3514a6de7a47068"
            },
            "downloads": -1,
            "filename": "pcffont-0.0.23.tar.gz",
            "has_sig": false,
            "md5_digest": "0504538222681a20eb1adec55936711a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 13832,
            "upload_time": "2025-10-14T03:00:57",
            "upload_time_iso_8601": "2025-10-14T03:00:57.556387Z",
            "url": "https://files.pythonhosted.org/packages/eb/9e/e66e4ea701e54d02ba2f9cd4ad6e3a632b8e910719fbbfc74923e1ffc665/pcffont-0.0.23.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-10-14 03:00:57",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "TakWolf",
    "github_project": "pcffont-python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pcffont"
}
        
Elapsed time: 0.86620s