{"id":20457548,"url":"https://github.com/takwolf/pcffont","last_synced_at":"2025-03-05T10:44:09.000Z","repository":{"id":232770733,"uuid":"784224498","full_name":"TakWolf/pcffont","owner":"TakWolf","description":"PcfFont is a library for manipulating Portable Compiled Format (PCF) Fonts.","archived":false,"fork":false,"pushed_at":"2025-01-22T15:20:03.000Z","size":5632,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-31T09:37:33.080Z","etag":null,"topics":["bitmap-font","bitmap-fonts","font","fonts","pcf"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/pcffont/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TakWolf.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-09T12:39:05.000Z","updated_at":"2025-01-22T15:20:07.000Z","dependencies_parsed_at":"2024-04-15T10:46:31.819Z","dependency_job_id":"21676fa0-fcd6-442c-ae5d-a98f88dccbaf","html_url":"https://github.com/TakWolf/pcffont","commit_stats":null,"previous_names":["takwolf/pcffont"],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TakWolf%2Fpcffont","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TakWolf%2Fpcffont/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TakWolf%2Fpcffont/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TakWolf%2Fpcffont/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TakWolf","download_url":"https://codeload.github.com/TakWolf/pcffont/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242013523,"owners_count":20057865,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bitmap-font","bitmap-fonts","font","fonts","pcf"],"created_at":"2024-11-15T12:07:47.235Z","updated_at":"2025-03-05T10:44:08.945Z","avatar_url":"https://github.com/TakWolf.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 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-16.0.02.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('  ' if alpha == 0 else '██' for alpha in bitmap_row)\n            print(f'{text}*')\n        print()\n    font.save(outputs_dir.joinpath('unifont-16.0.02.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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftakwolf%2Fpcffont","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftakwolf%2Fpcffont","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftakwolf%2Fpcffont/lists"}