pcffont


Namepcffont JSON
Version 0.0.8 PyPI version JSON
download
home_pageNone
SummaryA library for manipulating Portable Compiled Format (PCF) Fonts.
upload_time2024-05-07 10:38:55
maintainerTakWolf
docs_urlNone
authorTakWolf
requires_python>=3.10
licenseMIT 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 os
import shutil

from examples import assets_dir, build_dir
from pcffont import PcfFont


def main():
    outputs_dir = os.path.join(build_dir, 'load')
    if os.path.exists(outputs_dir):
        shutil.rmtree(outputs_dir)
    os.makedirs(outputs_dir)

    font = PcfFont.load(os.path.join(assets_dir, '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 code_point, 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(code_point)} ({code_point: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(os.path.join(outputs_dir, 'unifont-15.1.05.pcf'))


if __name__ == '__main__':
    main()
```

### Create

```python
import os
import shutil

from examples import build_dir
from pcffont import PcfFontBuilder, PcfGlyph


def main():
    outputs_dir = os.path.join(build_dir, 'create')
    if os.path.exists(outputs_dir):
        shutil.rmtree(outputs_dir)
    os.makedirs(outputs_dir)

    builder = PcfFontBuilder()
    builder.configs.font_ascent = 14
    builder.configs.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'

    font = builder.build()
    font.save(os.path.join(outputs_dir, '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/92/35/03862ad6dd7b59fd56a2b6550361d86db7575145d828ac85b1bfa29d722d/pcffont-0.0.8.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 os\nimport shutil\n\nfrom examples import assets_dir, build_dir\nfrom pcffont import PcfFont\n\n\ndef main():\n    outputs_dir = os.path.join(build_dir, 'load')\n    if os.path.exists(outputs_dir):\n        shutil.rmtree(outputs_dir)\n    os.makedirs(outputs_dir)\n\n    font = PcfFont.load(os.path.join(assets_dir, '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 code_point, 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(code_point)} ({code_point: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(os.path.join(outputs_dir, 'unifont-15.1.05.pcf'))\n\n\nif __name__ == '__main__':\n    main()\n```\n\n### Create\n\n```python\nimport os\nimport shutil\n\nfrom examples import build_dir\nfrom pcffont import PcfFontBuilder, PcfGlyph\n\n\ndef main():\n    outputs_dir = os.path.join(build_dir, 'create')\n    if os.path.exists(outputs_dir):\n        shutil.rmtree(outputs_dir)\n    os.makedirs(outputs_dir)\n\n    builder = PcfFontBuilder()\n    builder.configs.font_ascent = 14\n    builder.configs.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    font = builder.build()\n    font.save(os.path.join(outputs_dir, '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.8",
    "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": "eacc27a9369a95dc3c93e88b44da1b37c408caa303ebbea8d1ff980db9572999",
                "md5": "5a25779a2e9f47fc7ca472f42add43b7",
                "sha256": "33f764f64c718e07b907936ffc4259e2d2c3c372a4efad9b750582672603d88b"
            },
            "downloads": -1,
            "filename": "pcffont-0.0.8-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5a25779a2e9f47fc7ca472f42add43b7",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 22274,
            "upload_time": "2024-05-07T10:38:54",
            "upload_time_iso_8601": "2024-05-07T10:38:54.046572Z",
            "url": "https://files.pythonhosted.org/packages/ea/cc/27a9369a95dc3c93e88b44da1b37c408caa303ebbea8d1ff980db9572999/pcffont-0.0.8-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "923503862ad6dd7b59fd56a2b6550361d86db7575145d828ac85b1bfa29d722d",
                "md5": "61d7853333a31657b62995fd4c20b840",
                "sha256": "467f17ecf7a40eb6e8abd58f001a980152447f0151d504186e28beb8faa0676b"
            },
            "downloads": -1,
            "filename": "pcffont-0.0.8.tar.gz",
            "has_sig": false,
            "md5_digest": "61d7853333a31657b62995fd4c20b840",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 2730951,
            "upload_time": "2024-05-07T10:38:55",
            "upload_time_iso_8601": "2024-05-07T10:38:55.940154Z",
            "url": "https://files.pythonhosted.org/packages/92/35/03862ad6dd7b59fd56a2b6550361d86db7575145d828ac85b1bfa29d722d/pcffont-0.0.8.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-07 10:38:55",
    "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"
}
        
Elapsed time: 0.29534s