# Pixel Font Builder
[](https://www.python.org)
[](https://pypi.org/project/pixel-font-builder/)
A library that helps create pixel style fonts.
## Installation
```shell
pip install pixel-font-builder
```
## Usage
```python
import datetime
import shutil
from typing import Literal
from examples import build_dir
from pixel_font_builder import FontBuilder, WeightName, SerifStyle, SlantStyle, WidthStyle, Glyph, opentype
def _create_builder(outlines_style: Literal['SquareDot', 'CircleDot'] | None = None) -> FontBuilder:
builder = FontBuilder()
builder.font_metric.font_size = 12
builder.font_metric.horizontal_layout.ascent = 10
builder.font_metric.horizontal_layout.descent = -2
builder.font_metric.vertical_layout.ascent = 6
builder.font_metric.vertical_layout.descent = -6
builder.font_metric.x_height = 5
builder.font_metric.cap_height = 7
builder.meta_info.version = '1.0.0'
builder.meta_info.created_time = datetime.datetime.fromisoformat('2024-01-01T00:00:00Z')
builder.meta_info.modified_time = builder.meta_info.created_time
builder.meta_info.family_name = 'My Pixel'
if outlines_style is not None:
builder.meta_info.family_name = f'{builder.meta_info.family_name} {outlines_style}'
builder.meta_info.weight_name = WeightName.REGULAR
builder.meta_info.serif_style = SerifStyle.SANS_SERIF
builder.meta_info.slant_style = SlantStyle.NORMAL
builder.meta_info.width_style = WidthStyle.MONOSPACED
builder.meta_info.manufacturer = 'Pixel Font Studio'
builder.meta_info.designer = 'TakWolf'
builder.meta_info.description = 'A demo pixel font.'
builder.meta_info.copyright_info = 'Copyright (c) TakWolf'
builder.meta_info.license_info = 'This Font Software is licensed under the SIL Open Font License, Version 1.1.'
builder.meta_info.vendor_url = 'https://github.com/TakWolf/pixel-font-builder'
builder.meta_info.designer_url = 'https://takwolf.com'
builder.meta_info.license_url = 'https://openfontlicense.org'
builder.meta_info.sample_text = 'Hello World!'
builder.character_mapping.update({
ord('A'): 'CAP_LETTER_A',
})
builder.glyphs.append(Glyph(
name='.notdef',
horizontal_origin=(0, -2),
advance_width=8,
vertical_origin=(-4, 0),
advance_height=12,
bitmap=[
[1, 1, 1, 1, 1, 1, 1, 1],
[1, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 1],
[1, 1, 1, 1, 1, 1, 1, 1],
],
))
builder.glyphs.append(Glyph(
name='CAP_LETTER_A',
horizontal_origin=(0, -2),
advance_width=8,
vertical_origin=(-4, 0),
advance_height=12,
bitmap=[
[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],
],
))
if outlines_style == 'SquareDot':
builder.opentype_config.outlines_painter = opentype.SquareDotOutlinesPainter()
elif outlines_style == 'CircleDot':
builder.opentype_config.outlines_painter = opentype.CircleDotOutlinesPainter()
return builder
def main():
outputs_dir = build_dir.joinpath('create')
if outputs_dir.exists():
shutil.rmtree(outputs_dir)
outputs_dir.mkdir(parents=True)
builder = _create_builder()
builder.save_otf(outputs_dir.joinpath('my-pixel.otf'))
builder.save_otf(outputs_dir.joinpath('my-pixel.woff2'), flavor=opentype.Flavor.WOFF2)
builder.save_ttf(outputs_dir.joinpath('my-pixel.ttf'))
builder.save_bdf(outputs_dir.joinpath('my-pixel.bdf'))
builder.save_pcf(outputs_dir.joinpath('my-pixel.pcf'))
square_dot_builder = _create_builder('SquareDot')
square_dot_builder.save_otf(outputs_dir.joinpath('my-pixel-square_dot.otf'))
square_dot_builder.save_otf(outputs_dir.joinpath('my-pixel-square_dot.woff2'), flavor=opentype.Flavor.WOFF2)
square_dot_builder.save_ttf(outputs_dir.joinpath('my-pixel-square_dot.ttf'))
circle_dot_builder = _create_builder('CircleDot')
circle_dot_builder.save_otf(outputs_dir.joinpath('my-pixel-circle_dot.otf'))
circle_dot_builder.save_otf(outputs_dir.joinpath('my-pixel-circle_dot.woff2'), flavor=opentype.Flavor.WOFF2)
circle_dot_builder.save_ttf(outputs_dir.joinpath('my-pixel-circle_dot.ttf'))
if __name__ == '__main__':
main()
```
## Coordinate Systems
Use the same coordinate systems as OpenType.
### Horizontal Layout

### Vertical Layout

## Supported Output Formats
| Format | File Extension |
|---|---|
| [OpenType](https://learn.microsoft.com/en-us/typography/opentype/) | `.otf`, `.otc`, `.woff`, `.woff2` |
| [TrueType](https://learn.microsoft.com/en-us/typography/truetype/) | `.ttf`, `.ttc`, `.woff`, `.woff2` |
| [Glyph Bitmap Distribution Format](https://en.wikipedia.org/wiki/Glyph_Bitmap_Distribution_Format) | `.bdf` |
| [Portable Compiled Format](https://en.wikipedia.org/wiki/Portable_Compiled_Format) | `.pcf` |
## Dependencies
- [FontTools](https://github.com/fonttools/fonttools)
- [BdfFont](https://github.com/TakWolf/bdffont)
- [PcfFont](https://github.com/TakWolf/pcffont)
## References
- [FreeType Glyph Conventions - Glyph Metrics](https://freetype.org/freetype2/docs/glyphs/glyphs-3.html)
- [OpenType Feature File Specification](https://adobe-type-tools.github.io/afdko/OpenTypeFeatureFileSpecification.html)
## License
Under the [MIT license](LICENSE).
Raw data
{
"_id": null,
"home_page": null,
"name": "pixel-font-builder",
"maintainer": "TakWolf",
"docs_url": null,
"requires_python": ">=3.12",
"maintainer_email": null,
"keywords": "font, pixel",
"author": "TakWolf",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/14/ff/5f2363d38f396e32b8216724103d1bab44118fcf08cdce47cf7d3e1252eb/pixel_font_builder-0.0.31.tar.gz",
"platform": null,
"description": "# Pixel Font Builder\n\n[](https://www.python.org)\n[](https://pypi.org/project/pixel-font-builder/)\n\nA library that helps create pixel style fonts.\n\n## Installation\n\n```shell\npip install pixel-font-builder\n```\n\n## Usage\n\n```python\nimport datetime\nimport shutil\nfrom typing import Literal\n\nfrom examples import build_dir\nfrom pixel_font_builder import FontBuilder, WeightName, SerifStyle, SlantStyle, WidthStyle, Glyph, opentype\n\n\ndef _create_builder(outlines_style: Literal['SquareDot', 'CircleDot'] | None = None) -> FontBuilder:\n builder = FontBuilder()\n builder.font_metric.font_size = 12\n builder.font_metric.horizontal_layout.ascent = 10\n builder.font_metric.horizontal_layout.descent = -2\n builder.font_metric.vertical_layout.ascent = 6\n builder.font_metric.vertical_layout.descent = -6\n builder.font_metric.x_height = 5\n builder.font_metric.cap_height = 7\n\n builder.meta_info.version = '1.0.0'\n builder.meta_info.created_time = datetime.datetime.fromisoformat('2024-01-01T00:00:00Z')\n builder.meta_info.modified_time = builder.meta_info.created_time\n builder.meta_info.family_name = 'My Pixel'\n if outlines_style is not None:\n builder.meta_info.family_name = f'{builder.meta_info.family_name} {outlines_style}'\n builder.meta_info.weight_name = WeightName.REGULAR\n builder.meta_info.serif_style = SerifStyle.SANS_SERIF\n builder.meta_info.slant_style = SlantStyle.NORMAL\n builder.meta_info.width_style = WidthStyle.MONOSPACED\n builder.meta_info.manufacturer = 'Pixel Font Studio'\n builder.meta_info.designer = 'TakWolf'\n builder.meta_info.description = 'A demo pixel font.'\n builder.meta_info.copyright_info = 'Copyright (c) TakWolf'\n builder.meta_info.license_info = 'This Font Software is licensed under the SIL Open Font License, Version 1.1.'\n builder.meta_info.vendor_url = 'https://github.com/TakWolf/pixel-font-builder'\n builder.meta_info.designer_url = 'https://takwolf.com'\n builder.meta_info.license_url = 'https://openfontlicense.org'\n builder.meta_info.sample_text = 'Hello World!'\n\n builder.character_mapping.update({\n ord('A'): 'CAP_LETTER_A',\n })\n\n builder.glyphs.append(Glyph(\n name='.notdef',\n horizontal_origin=(0, -2),\n advance_width=8,\n vertical_origin=(-4, 0),\n advance_height=12,\n bitmap=[\n [1, 1, 1, 1, 1, 1, 1, 1],\n [1, 0, 0, 0, 0, 0, 0, 1],\n [1, 0, 0, 0, 0, 0, 0, 1],\n [1, 0, 0, 0, 0, 0, 0, 1],\n [1, 0, 0, 0, 0, 0, 0, 1],\n [1, 0, 0, 0, 0, 0, 0, 1],\n [1, 0, 0, 0, 0, 0, 0, 1],\n [1, 0, 0, 0, 0, 0, 0, 1],\n [1, 0, 0, 0, 0, 0, 0, 1],\n [1, 0, 0, 0, 0, 0, 0, 1],\n [1, 0, 0, 0, 0, 0, 0, 1],\n [1, 1, 1, 1, 1, 1, 1, 1],\n ],\n ))\n builder.glyphs.append(Glyph(\n name='CAP_LETTER_A',\n horizontal_origin=(0, -2),\n advance_width=8,\n vertical_origin=(-4, 0),\n advance_height=12,\n bitmap=[\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 if outlines_style == 'SquareDot':\n builder.opentype_config.outlines_painter = opentype.SquareDotOutlinesPainter()\n elif outlines_style == 'CircleDot':\n builder.opentype_config.outlines_painter = opentype.CircleDotOutlinesPainter()\n\n return builder\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 = _create_builder()\n builder.save_otf(outputs_dir.joinpath('my-pixel.otf'))\n builder.save_otf(outputs_dir.joinpath('my-pixel.woff2'), flavor=opentype.Flavor.WOFF2)\n builder.save_ttf(outputs_dir.joinpath('my-pixel.ttf'))\n builder.save_bdf(outputs_dir.joinpath('my-pixel.bdf'))\n builder.save_pcf(outputs_dir.joinpath('my-pixel.pcf'))\n\n square_dot_builder = _create_builder('SquareDot')\n square_dot_builder.save_otf(outputs_dir.joinpath('my-pixel-square_dot.otf'))\n square_dot_builder.save_otf(outputs_dir.joinpath('my-pixel-square_dot.woff2'), flavor=opentype.Flavor.WOFF2)\n square_dot_builder.save_ttf(outputs_dir.joinpath('my-pixel-square_dot.ttf'))\n\n circle_dot_builder = _create_builder('CircleDot')\n circle_dot_builder.save_otf(outputs_dir.joinpath('my-pixel-circle_dot.otf'))\n circle_dot_builder.save_otf(outputs_dir.joinpath('my-pixel-circle_dot.woff2'), flavor=opentype.Flavor.WOFF2)\n circle_dot_builder.save_ttf(outputs_dir.joinpath('my-pixel-circle_dot.ttf'))\n\n\nif __name__ == '__main__':\n main()\n```\n\n## Coordinate Systems\n\nUse the same coordinate systems as OpenType.\n\n### Horizontal Layout\n\n\n\n### Vertical Layout\n\n\n\n## Supported Output Formats\n\n| Format | File Extension |\n|---|---|\n| [OpenType](https://learn.microsoft.com/en-us/typography/opentype/) | `.otf`, `.otc`, `.woff`, `.woff2` |\n| [TrueType](https://learn.microsoft.com/en-us/typography/truetype/) | `.ttf`, `.ttc`, `.woff`, `.woff2` |\n| [Glyph Bitmap Distribution Format](https://en.wikipedia.org/wiki/Glyph_Bitmap_Distribution_Format) | `.bdf` |\n| [Portable Compiled Format](https://en.wikipedia.org/wiki/Portable_Compiled_Format) | `.pcf` |\n\n## Dependencies\n\n- [FontTools](https://github.com/fonttools/fonttools)\n- [BdfFont](https://github.com/TakWolf/bdffont)\n- [PcfFont](https://github.com/TakWolf/pcffont)\n\n## References\n\n- [FreeType Glyph Conventions - Glyph Metrics](https://freetype.org/freetype2/docs/glyphs/glyphs-3.html)\n- [OpenType Feature File Specification](https://adobe-type-tools.github.io/afdko/OpenTypeFeatureFileSpecification.html)\n\n## License\n\nUnder the [MIT license](LICENSE).\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "A library that helps create pixel style fonts.",
"version": "0.0.31",
"project_urls": {
"homepage": "https://github.com/TakWolf/pixel-font-builder",
"issues": "https://github.com/TakWolf/pixel-font-builder/issues",
"source": "https://github.com/TakWolf/pixel-font-builder"
},
"split_keywords": [
"font",
" pixel"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ca6a7f8cf6776bd92cc08bdc97ff02c005f5bb9449f13ac5e55ca4ee320f6294",
"md5": "60c33adf925bcadeefee80e22d2af811",
"sha256": "72aa3ece5330561f016ad96f22e3820425823a38bc4ddd860da10ad142591f18"
},
"downloads": -1,
"filename": "pixel_font_builder-0.0.31-py3-none-any.whl",
"has_sig": false,
"md5_digest": "60c33adf925bcadeefee80e22d2af811",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.12",
"size": 17114,
"upload_time": "2025-01-21T17:02:55",
"upload_time_iso_8601": "2025-01-21T17:02:55.406168Z",
"url": "https://files.pythonhosted.org/packages/ca/6a/7f8cf6776bd92cc08bdc97ff02c005f5bb9449f13ac5e55ca4ee320f6294/pixel_font_builder-0.0.31-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "14ff5f2363d38f396e32b8216724103d1bab44118fcf08cdce47cf7d3e1252eb",
"md5": "8738ace0334024c84768bd954de5f82d",
"sha256": "5d26d370b0a68c7181f4252bc3255f07835a0c39a315efce0d36d4fcfa23315b"
},
"downloads": -1,
"filename": "pixel_font_builder-0.0.31.tar.gz",
"has_sig": false,
"md5_digest": "8738ace0334024c84768bd954de5f82d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.12",
"size": 20155,
"upload_time": "2025-01-21T17:02:57",
"upload_time_iso_8601": "2025-01-21T17:02:57.677050Z",
"url": "https://files.pythonhosted.org/packages/14/ff/5f2363d38f396e32b8216724103d1bab44118fcf08cdce47cf7d3e1252eb/pixel_font_builder-0.0.31.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-21 17:02:57",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "TakWolf",
"github_project": "pixel-font-builder",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "fonttools",
"specs": [
[
"==",
"4.55.4"
]
]
},
{
"name": "bdffont",
"specs": [
[
"==",
"0.0.26"
]
]
},
{
"name": "pcffont",
"specs": [
[
"==",
"0.0.15"
]
]
},
{
"name": "pytest",
"specs": [
[
"==",
"8.3.4"
]
]
},
{
"name": "pypng",
"specs": [
[
"==",
"0.20220715.0"
]
]
}
],
"lcname": "pixel-font-builder"
}