bdffont


Namebdffont JSON
Version 0.0.34 PyPI version JSON
download
home_pageNone
SummaryA library for manipulating Glyph Bitmap Distribution Format (BDF) Fonts
upload_time2025-10-14 02:53:41
maintainerTakWolf
docs_urlNone
authorTakWolf
requires_python>=3.10
licenseNone
keywords bdf font
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # BdfFont.Python

[![Python](https://img.shields.io/badge/python-3.10-brightgreen)](https://www.python.org)
[![PyPI](https://img.shields.io/pypi/v/bdffont)](https://pypi.org/project/bdffont/)

BdfFont is a library for manipulating [Glyph Bitmap Distribution Format (BDF) Fonts](https://en.wikipedia.org/wiki/Glyph_Bitmap_Distribution_Format).

## Installation

```shell
pip install bdffont
```

## Usage

### Create

```python
import shutil
import statistics

from bdffont import BdfFont, BdfGlyph
from examples import build_dir


def main():
    outputs_dir = build_dir.joinpath('create')
    if outputs_dir.exists():
        shutil.rmtree(outputs_dir)
    outputs_dir.mkdir(parents=True)

    font = BdfFont(
        point_size=16,
        resolution=(75, 75),
        bounding_box=(16, 16, 0, -2),
    )

    font.glyphs.append(BdfGlyph(
        name='A',
        encoding=65,
        scalable_width=(500, 0),
        device_width=(8, 0),
        bounding_box=(8, 16, 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],
        ],
    ))

    font.properties.foundry = 'Pixel Font Studio'
    font.properties.family_name = 'My Font'
    font.properties.weight_name = 'Medium'
    font.properties.slant = 'R'
    font.properties.setwidth_name = 'Normal'
    font.properties.add_style_name = 'Sans Serif'
    font.properties.pixel_size = font.point_size
    font.properties.point_size = font.point_size * 10
    font.properties.resolution_x = font.resolution_x
    font.properties.resolution_y = font.resolution_y
    font.properties.spacing = 'P'
    font.properties.average_width = round(statistics.fmean(glyph.device_width_x * 10 for glyph in font.glyphs))
    font.properties.charset_registry = 'ISO10646'
    font.properties.charset_encoding = '1'
    font.generate_name_as_xlfd()

    font.properties.default_char = -1
    font.properties.font_ascent = 14
    font.properties.font_descent = 2
    font.properties.x_height = 7
    font.properties.cap_height = 10
    font.properties.underline_position = -2
    font.properties.underline_thickness = 1

    font.properties.font_version = '1.0.0'
    font.properties.copyright = 'Copyright (c) TakWolf'

    font.save(outputs_dir.joinpath('my-font.bdf'))


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

### Load

```python
import shutil

from bdffont import BdfFont
from examples import assets_dir, build_dir


def main():
    outputs_dir = build_dir.joinpath('load')
    if outputs_dir.exists():
        shutil.rmtree(outputs_dir)
    outputs_dir.mkdir(parents=True)

    font = BdfFont.load(assets_dir.joinpath('unifont', 'unifont-17.0.01.bdf'))
    print(f'name: {font.name}')
    print(f'size: {font.point_size}')
    print(f'ascent: {font.properties.font_ascent}')
    print(f'descent: {font.properties.font_descent}')
    print()
    for glyph in font.glyphs:
        print(f'char: {chr(glyph.encoding)} ({glyph.encoding:04X})')
        print(f'glyph_name: {glyph.name}')
        print(f'advance_width: {glyph.device_width_x}')
        print(f'dimensions: {glyph.dimensions}')
        print(f'offset: {glyph.offset}')
        for bitmap_row in glyph.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.bdf'))


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

## References

- [X11 - Bitmap Distribution Format - Version 2.1](https://www.x.org/docs/BDF/bdf.pdf)
- [Adobe - Glyph Bitmap Distribution Format (BDF) Specification - Version 2.2](https://adobe-type-tools.github.io/font-tech-notes/pdfs/5005.BDF_Spec.pdf)
- [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": "bdffont",
    "maintainer": "TakWolf",
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "bdf, font",
    "author": "TakWolf",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/de/53/057ffa4c8bbd52341ab06b06e2f31c1a21e3eef468084a22fbd4a473542a/bdffont-0.0.34.tar.gz",
    "platform": null,
    "description": "# BdfFont.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/bdffont)](https://pypi.org/project/bdffont/)\n\nBdfFont is a library for manipulating [Glyph Bitmap Distribution Format (BDF) Fonts](https://en.wikipedia.org/wiki/Glyph_Bitmap_Distribution_Format).\n\n## Installation\n\n```shell\npip install bdffont\n```\n\n## Usage\n\n### Create\n\n```python\nimport shutil\nimport statistics\n\nfrom bdffont import BdfFont, BdfGlyph\nfrom examples import build_dir\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    font = BdfFont(\n        point_size=16,\n        resolution=(75, 75),\n        bounding_box=(16, 16, 0, -2),\n    )\n\n    font.glyphs.append(BdfGlyph(\n        name='A',\n        encoding=65,\n        scalable_width=(500, 0),\n        device_width=(8, 0),\n        bounding_box=(8, 16, 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    font.properties.foundry = 'Pixel Font Studio'\n    font.properties.family_name = 'My Font'\n    font.properties.weight_name = 'Medium'\n    font.properties.slant = 'R'\n    font.properties.setwidth_name = 'Normal'\n    font.properties.add_style_name = 'Sans Serif'\n    font.properties.pixel_size = font.point_size\n    font.properties.point_size = font.point_size * 10\n    font.properties.resolution_x = font.resolution_x\n    font.properties.resolution_y = font.resolution_y\n    font.properties.spacing = 'P'\n    font.properties.average_width = round(statistics.fmean(glyph.device_width_x * 10 for glyph in font.glyphs))\n    font.properties.charset_registry = 'ISO10646'\n    font.properties.charset_encoding = '1'\n    font.generate_name_as_xlfd()\n\n    font.properties.default_char = -1\n    font.properties.font_ascent = 14\n    font.properties.font_descent = 2\n    font.properties.x_height = 7\n    font.properties.cap_height = 10\n    font.properties.underline_position = -2\n    font.properties.underline_thickness = 1\n\n    font.properties.font_version = '1.0.0'\n    font.properties.copyright = 'Copyright (c) TakWolf'\n\n    font.save(outputs_dir.joinpath('my-font.bdf'))\n\n\nif __name__ == '__main__':\n    main()\n```\n\n### Load\n\n```python\nimport shutil\n\nfrom bdffont import BdfFont\nfrom examples import assets_dir, build_dir\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 = BdfFont.load(assets_dir.joinpath('unifont', 'unifont-17.0.01.bdf'))\n    print(f'name: {font.name}')\n    print(f'size: {font.point_size}')\n    print(f'ascent: {font.properties.font_ascent}')\n    print(f'descent: {font.properties.font_descent}')\n    print()\n    for glyph in font.glyphs:\n        print(f'char: {chr(glyph.encoding)} ({glyph.encoding:04X})')\n        print(f'glyph_name: {glyph.name}')\n        print(f'advance_width: {glyph.device_width_x}')\n        print(f'dimensions: {glyph.dimensions}')\n        print(f'offset: {glyph.offset}')\n        for bitmap_row in glyph.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.bdf'))\n\n\nif __name__ == '__main__':\n    main()\n```\n\n## References\n\n- [X11 - Bitmap Distribution Format - Version 2.1](https://www.x.org/docs/BDF/bdf.pdf)\n- [Adobe - Glyph Bitmap Distribution Format (BDF) Specification - Version 2.2](https://adobe-type-tools.github.io/font-tech-notes/pdfs/5005.BDF_Spec.pdf)\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 Glyph Bitmap Distribution Format (BDF) Fonts",
    "version": "0.0.34",
    "project_urls": {
        "Homepage": "https://github.com/TakWolf/bdffont-python",
        "Issues": "https://github.com/TakWolf/bdffont-python/issues",
        "Source": "https://github.com/TakWolf/bdffont-python"
    },
    "split_keywords": [
        "bdf",
        " font"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "2ca3a3d0f178b70d507922db093dd314c7bb379a0f9bd68757dbcdcda5e7ce1d",
                "md5": "d189cd193c62aad0822092b46637aeee",
                "sha256": "e467995ace2a07e053c1e4684ab0a4cfd31cb24b7b14f997bc4539a130aeebe9"
            },
            "downloads": -1,
            "filename": "bdffont-0.0.34-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d189cd193c62aad0822092b46637aeee",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 10256,
            "upload_time": "2025-10-14T02:53:40",
            "upload_time_iso_8601": "2025-10-14T02:53:40.736198Z",
            "url": "https://files.pythonhosted.org/packages/2c/a3/a3d0f178b70d507922db093dd314c7bb379a0f9bd68757dbcdcda5e7ce1d/bdffont-0.0.34-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "de53057ffa4c8bbd52341ab06b06e2f31c1a21e3eef468084a22fbd4a473542a",
                "md5": "d01a56e3b021ea9553df2c5a6c3d0331",
                "sha256": "d33eb88c4f3d4e320f80e132d3c84d751e5ff1979d5e051f179af889f6e07fab"
            },
            "downloads": -1,
            "filename": "bdffont-0.0.34.tar.gz",
            "has_sig": false,
            "md5_digest": "d01a56e3b021ea9553df2c5a6c3d0331",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 8156,
            "upload_time": "2025-10-14T02:53:41",
            "upload_time_iso_8601": "2025-10-14T02:53:41.567160Z",
            "url": "https://files.pythonhosted.org/packages/de/53/057ffa4c8bbd52341ab06b06e2f31c1a21e3eef468084a22fbd4a473542a/bdffont-0.0.34.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-10-14 02:53:41",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "TakWolf",
    "github_project": "bdffont-python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "bdffont"
}
        
Elapsed time: 1.85987s