pixel-font-builder


Namepixel-font-builder JSON
Version 0.0.28 PyPI version JSON
download
home_pageNone
SummaryA library that helps create pixel style fonts.
upload_time2024-08-28 03:39:22
maintainerTakWolf
docs_urlNone
authorTakWolf
requires_python>=3.11
licenseMIT License
keywords font pixel
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Pixel Font Builder

[![Python](https://img.shields.io/badge/python-3.11-brightgreen)](https://www.python.org)
[![PyPI](https://img.shields.io/pypi/v/pixel-font-builder)](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 examples import build_dir
from pixel_font_builder import FontBuilder, WeightName, SerifStyle, SlantStyle, WidthStyle, Glyph, opentype


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

    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'
    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],
        ],
    ))

    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-font.ttf'))
    builder.save_bdf(outputs_dir.joinpath('my-font.bdf'))
    builder.save_pcf(outputs_dir.joinpath('my-font.pcf'))


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

## Coordinate Systems

Use the same coordinate systems as OpenType.

### Horizontal Layout

![Horizontal Layout](https://freetype.org/freetype2/docs/glyphs/glyph-metrics-3.svg)

### Vertical Layout

![Vertical Layout](https://freetype.org/freetype2/docs/glyphs/glyph-metrics-4.svg)

## 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)
- [Brotli](https://github.com/google/brotli)
- [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.11",
    "maintainer_email": null,
    "keywords": "font, pixel",
    "author": "TakWolf",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/1c/f4/b92a388e8a6023c3d9a2f1d7f64a4f5d8c4f778fe4972c96071bdba30761/pixel_font_builder-0.0.28.tar.gz",
    "platform": null,
    "description": "# Pixel Font Builder\n\n[![Python](https://img.shields.io/badge/python-3.11-brightgreen)](https://www.python.org)\n[![PyPI](https://img.shields.io/pypi/v/pixel-font-builder)](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\n\nfrom examples import build_dir\nfrom pixel_font_builder import FontBuilder, WeightName, SerifStyle, SlantStyle, WidthStyle, Glyph, opentype\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 = 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    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    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-font.ttf'))\n    builder.save_bdf(outputs_dir.joinpath('my-font.bdf'))\n    builder.save_pcf(outputs_dir.joinpath('my-font.pcf'))\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![Horizontal Layout](https://freetype.org/freetype2/docs/glyphs/glyph-metrics-3.svg)\n\n### Vertical Layout\n\n![Vertical Layout](https://freetype.org/freetype2/docs/glyphs/glyph-metrics-4.svg)\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- [Brotli](https://github.com/google/brotli)\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.28",
    "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": "431a8e3c037843e2a73528fe712e47d169e13eda050759181e33f06073711eef",
                "md5": "6904aa5815537364547ea251169e14c2",
                "sha256": "65acb29b61a562e1f7083b4fa9088af77253adc2a49c6f59be4f3ffc852c9628"
            },
            "downloads": -1,
            "filename": "pixel_font_builder-0.0.28-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6904aa5815537364547ea251169e14c2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 13652,
            "upload_time": "2024-08-28T03:39:21",
            "upload_time_iso_8601": "2024-08-28T03:39:21.330179Z",
            "url": "https://files.pythonhosted.org/packages/43/1a/8e3c037843e2a73528fe712e47d169e13eda050759181e33f06073711eef/pixel_font_builder-0.0.28-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1cf4b92a388e8a6023c3d9a2f1d7f64a4f5d8c4f778fe4972c96071bdba30761",
                "md5": "4462da374e58417b473be93705fc3afc",
                "sha256": "d9d5a8b870257648cfaa7ffceeadbf6b8edc08551d7fc2b0eadb8c5064ff5c37"
            },
            "downloads": -1,
            "filename": "pixel_font_builder-0.0.28.tar.gz",
            "has_sig": false,
            "md5_digest": "4462da374e58417b473be93705fc3afc",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 18532,
            "upload_time": "2024-08-28T03:39:22",
            "upload_time_iso_8601": "2024-08-28T03:39:22.855303Z",
            "url": "https://files.pythonhosted.org/packages/1c/f4/b92a388e8a6023c3d9a2f1d7f64a4f5d8c4f778fe4972c96071bdba30761/pixel_font_builder-0.0.28.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-28 03:39:22",
    "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": [],
    "lcname": "pixel-font-builder"
}
        
Elapsed time: 0.98899s