bdffont


Namebdffont JSON
Version 0.0.25 PyPI version JSON
download
home_pageNone
SummaryA library for manipulating Glyph Bitmap Distribution Format (BDF) Fonts.
upload_time2024-05-15 17:42:44
maintainerTakWolf
docs_urlNone
authorTakWolf
requires_python>=3.10
licenseMIT License
keywords bdf font
VCS
bugtrack_url
requirements pytest
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # BdfFont

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

### 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-15.1.05.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'origin: {glyph.origin}')
        for bitmap_row in glyph.bitmap:
            text = ''.join(map(str, bitmap_row)).replace('0', '  ').replace('1', '██')
            print(f'{text}*')
        print()
    font.save(outputs_dir.joinpath('unifont-15.0.01.bdf'))


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

### Create

```python
import shutil

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=ord('A'),
        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 = 'Demo Pixel'
    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(sum([glyph.device_width_x * 10 for glyph in font.glyphs]) / len(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 = 5
    font.properties.cap_height = 7

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

## Test Fonts

- [GNU Unifont Glyphs](https://unifoundry.com/unifont/index.html)
- [Galmuri](https://github.com/quiple/galmuri)
- [美咲フォント / Misaki](https://littlelimit.net/misaki.htm)

## 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

Under the [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/59/4e/ec262930eda2fa19f1acb6ee75a5fd3488b3162f43e51d2942392e77752d/bdffont-0.0.25.tar.gz",
    "platform": null,
    "description": "# BdfFont\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### 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-15.1.05.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'origin: {glyph.origin}')\n        for bitmap_row in glyph.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.0.01.bdf'))\n\n\nif __name__ == '__main__':\n    main()\n```\n\n### Create\n\n```python\nimport shutil\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=ord('A'),\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 = 'Demo Pixel'\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(sum([glyph.device_width_x * 10 for glyph in font.glyphs]) / len(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 = 5\n    font.properties.cap_height = 7\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## Test Fonts\n\n- [GNU Unifont Glyphs](https://unifoundry.com/unifont/index.html)\n- [Galmuri](https://github.com/quiple/galmuri)\n- [\u7f8e\u54b2\u30d5\u30a9\u30f3\u30c8 / Misaki](https://littlelimit.net/misaki.htm)\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\nUnder the [MIT license](LICENSE).\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "A library for manipulating Glyph Bitmap Distribution Format (BDF) Fonts.",
    "version": "0.0.25",
    "project_urls": {
        "homepage": "https://github.com/TakWolf/bdffont",
        "issues": "https://github.com/TakWolf/bdffont/issues",
        "source": "https://github.com/TakWolf/bdffont"
    },
    "split_keywords": [
        "bdf",
        " font"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "839f083003192ba364e601729e0a71ddb53083b3d5b5c398879413aa1459510c",
                "md5": "28870adf796d588dfdc3597302b79e4b",
                "sha256": "d39e7856be1e18b5bb2b8fa714a123e2fe6d758f6ff69852124b3b37b54e8771"
            },
            "downloads": -1,
            "filename": "bdffont-0.0.25-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "28870adf796d588dfdc3597302b79e4b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 10642,
            "upload_time": "2024-05-15T17:42:42",
            "upload_time_iso_8601": "2024-05-15T17:42:42.302811Z",
            "url": "https://files.pythonhosted.org/packages/83/9f/083003192ba364e601729e0a71ddb53083b3d5b5c398879413aa1459510c/bdffont-0.0.25-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "594eec262930eda2fa19f1acb6ee75a5fd3488b3162f43e51d2942392e77752d",
                "md5": "863582ea483ef4d1bfc8d1dec8130a1e",
                "sha256": "210d7ca2ca4e0a0fe2c93d13b3e0707db16a501cfbd566abedcdca325ff7cfe6"
            },
            "downloads": -1,
            "filename": "bdffont-0.0.25.tar.gz",
            "has_sig": false,
            "md5_digest": "863582ea483ef4d1bfc8d1dec8130a1e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 1850322,
            "upload_time": "2024-05-15T17:42:44",
            "upload_time_iso_8601": "2024-05-15T17:42:44.241963Z",
            "url": "https://files.pythonhosted.org/packages/59/4e/ec262930eda2fa19f1acb6ee75a5fd3488b3162f43e51d2942392e77752d/bdffont-0.0.25.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-15 17:42:44",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "TakWolf",
    "github_project": "bdffont",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "pytest",
            "specs": [
                [
                    "==",
                    "8.2.0"
                ]
            ]
        }
    ],
    "lcname": "bdffont"
}
        
Elapsed time: 0.27684s