Skip to main content

Pixel Font Builder

Python PyPI

A library that helps create pixel style fonts.

Installation

pip install pixel-font-builder

Usage

import shutil
from datetime import datetime

from examples import BUILD_DIR
from pixel_font_builder import FontBuilder, Weight, SerifStyle, Spacing, Slant, Glyph, MonoRaster, ColorRaster, opentype


def main() -> None:
    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 = 16
    builder.font_metric.horizontal_layout.ascent = 14
    builder.font_metric.horizontal_layout.descent = -2
    builder.font_metric.vertical_layout.ascent = 8
    builder.font_metric.vertical_layout.descent = -8
    builder.font_metric.x_height = 7
    builder.font_metric.cap_height = 10
    builder.font_metric.underline_position = -2
    builder.font_metric.underline_thickness = 1
    builder.font_metric.strikeout_position = 6
    builder.font_metric.strikeout_thickness = 1

    builder.meta_info.version = '1.0.0'
    builder.meta_info.created_time = datetime.fromisoformat('2024-01-01T00:00:00Z')
    builder.meta_info.modified_time = builder.meta_info.created_time
    builder.meta_info.family_name = 'My Font'
    builder.meta_info.weight = Weight.REGULAR
    builder.meta_info.serif_style = SerifStyle.SANS_SERIF
    builder.meta_info.spacing = Spacing.MONOSPACED
    builder.meta_info.slant = Slant.UPRIGHT
    builder.meta_info.manufacturer = 'TakWolf'
    builder.meta_info.designer = 'TakWolf'
    builder.meta_info.description = 'A 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.glyphs.append(Glyph(
        name='.notdef',
        advance_width=8,
        advance_height=16,
        mono_raster=MonoRaster(
            horizontal_offset=(0, -2),
            vertical_offset=(-4, 0),
            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, 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='LATIN_CAPITAL_LETTER_A',
        advance_width=8,
        advance_height=16,
        mono_raster=MonoRaster(
            horizontal_offset=(0, -2),
            vertical_offset=(-4, 0),
            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],
            ],
        ),
    ))

    heart_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, 1, 1, 0, 1, 1, 0, 0],
        [1, 1, 1, 1, 1, 1, 1, 0],
        [1, 1, 1, 1, 1, 1, 1, 0],
        [1, 1, 1, 1, 1, 1, 1, 0],
        [0, 1, 1, 1, 1, 1, 0, 0],
        [0, 1, 1, 1, 1, 1, 0, 0],
        [0, 0, 1, 1, 1, 0, 0, 0],
        [0, 0, 0, 1, 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, 0],
    ]
    builder.glyphs.append(Glyph(
        name='HEAVY_BLACK_HEART',
        advance_width=8,
        advance_height=16,
        mono_raster=MonoRaster(
            horizontal_offset=(0, -2),
            vertical_offset=(-4, 0),
            bitmap=heart_bitmap,
        ),
        color_raster=ColorRaster(
            horizontal_offset=(0, -2),
            vertical_offset=(-4, 0),
            bitmap=[
                [
                    (255, 0, 0, 255) if pixel != 0 else (0, 0, 0, 0)
                    for pixel in bitmap_row
                ]
                for bitmap_row in heart_bitmap
            ],
        ),
    ))

    builder.character_mapping[0x0041] = 'LATIN_CAPITAL_LETTER_A'
    builder.character_mapping[0x2764] = 'HEAVY_BLACK_HEART'

    builder.save_otf(outputs_dir.joinpath('my-font.otf'))
    builder.save_otf_woff(outputs_dir.joinpath('my-font.otf.woff'))
    builder.save_otf_woff2(outputs_dir.joinpath('my-font.otf.woff2'))
    builder.save_ttf(outputs_dir.joinpath('my-font.ttf'))
    builder.save_ttf_woff(outputs_dir.joinpath('my-font.ttf.woff'))
    builder.save_ttf_woff2(outputs_dir.joinpath('my-font.ttf.woff2'))
    builder.save_ms_bitmap_ttf(outputs_dir.joinpath('my-font.ms-bitmap.ttf'))
    builder.save_otb(outputs_dir.joinpath('my-font.otb'))
    builder.save_dfont(outputs_dir.joinpath('my-font.dfont'))
    builder.save_bdf(outputs_dir.joinpath('my-font.bdf'))
    builder.save_pcf(outputs_dir.joinpath('my-font.pcf'))

    builder.meta_info.family_name = 'My Font SquareDot'
    builder.opentype_config.outline_painter = opentype.SquareDotOutlinePainter()
    
    builder.save_otf(outputs_dir.joinpath('my-font-square-dot.otf'))
    builder.save_otf_woff(outputs_dir.joinpath('my-font-square-dot.otf.woff'))
    builder.save_otf_woff2(outputs_dir.joinpath('my-font-square-dot.otf.woff2'))
    builder.save_ttf(outputs_dir.joinpath('my-font-square-dot.ttf'))
    builder.save_ttf_woff(outputs_dir.joinpath('my-font-square-dot.ttf.woff'))
    builder.save_ttf_woff2(outputs_dir.joinpath('my-font-square-dot.ttf.woff2'))

    builder.meta_info.family_name = 'My Font CircleDot'
    builder.opentype_config.outline_painter = opentype.CircleDotOutlinePainter()
    
    builder.save_otf(outputs_dir.joinpath('my-font-circle-dot.otf'))
    builder.save_otf_woff(outputs_dir.joinpath('my-font-circle-dot.otf.woff'))
    builder.save_otf_woff2(outputs_dir.joinpath('my-font-circle-dot.otf.woff2'))
    builder.save_ttf(outputs_dir.joinpath('my-font-circle-dot.ttf'))
    builder.save_ttf_woff(outputs_dir.joinpath('my-font-circle-dot.ttf.woff'))
    builder.save_ttf_woff2(outputs_dir.joinpath('my-font-circle-dot.ttf.woff2'))

    builder.opentype_config.outline_painter = opentype.Config.DEFAULT_OUTLINE_PAINTER

    builder.meta_info.family_name = 'My Font Color COLR'
    builder.opentype_config.color_table_formats = {
        opentype.ColorTableFormat.COLR,
    }

    builder.save_otf(outputs_dir.joinpath('my-font.colr.otf'))
    builder.save_otf_woff(outputs_dir.joinpath('my-font.colr.otf.woff'))
    builder.save_otf_woff2(outputs_dir.joinpath('my-font.colr.otf.woff2'))
    builder.save_ttf(outputs_dir.joinpath('my-font.colr.ttf'))
    builder.save_ttf_woff(outputs_dir.joinpath('my-font.colr.ttf.woff'))
    builder.save_ttf_woff2(outputs_dir.joinpath('my-font.colr.ttf.woff2'))

    builder.meta_info.family_name = 'My Font Color CBDT'
    builder.opentype_config.color_table_formats = {
        opentype.ColorTableFormat.CBDT,
    }

    builder.save_otf(outputs_dir.joinpath('my-font.cbdt.otf'))
    builder.save_otf_woff(outputs_dir.joinpath('my-font.cbdt.otf.woff'))
    builder.save_otf_woff2(outputs_dir.joinpath('my-font.cbdt.otf.woff2'))
    builder.save_ttf(outputs_dir.joinpath('my-font.cbdt.ttf'))
    builder.save_ttf_woff(outputs_dir.joinpath('my-font.cbdt.ttf.woff'))
    builder.save_ttf_woff2(outputs_dir.joinpath('my-font.cbdt.ttf.woff2'))

    builder.meta_info.family_name = 'My Font Color SBIX'
    builder.opentype_config.color_table_formats = {
        opentype.ColorTableFormat.SBIX,
    }

    builder.save_otf(outputs_dir.joinpath('my-font.sbix.otf'))
    builder.save_otf_woff(outputs_dir.joinpath('my-font.sbix.otf.woff'))
    builder.save_otf_woff2(outputs_dir.joinpath('my-font.sbix.otf.woff2'))
    builder.save_ttf(outputs_dir.joinpath('my-font.sbix.ttf'))
    builder.save_ttf_woff(outputs_dir.joinpath('my-font.sbix.ttf.woff'))
    builder.save_ttf_woff2(outputs_dir.joinpath('my-font.sbix.ttf.woff2'))

    builder.meta_info.family_name = 'My Font Color All'
    builder.opentype_config.color_table_formats = {
        opentype.ColorTableFormat.COLR,
        opentype.ColorTableFormat.CBDT,
        opentype.ColorTableFormat.SBIX,
    }

    builder.save_otf(outputs_dir.joinpath('my-font.color-all.otf'))
    builder.save_otf_woff(outputs_dir.joinpath('my-font.color-all.otf.woff'))
    builder.save_otf_woff2(outputs_dir.joinpath('my-font.color-all.otf.woff2'))
    builder.save_ttf(outputs_dir.joinpath('my-font.color-all.ttf'))
    builder.save_ttf_woff(outputs_dir.joinpath('my-font.color-all.ttf.woff'))
    builder.save_ttf_woff2(outputs_dir.joinpath('my-font.color-all.ttf.woff2'))


if __name__ == '__main__':
    main()

Coordinate Systems

Use the same coordinate systems as OpenType.

Horizontal Layout

Horizontal Layout

Vertical Layout

Vertical Layout

Supported Output Formats

Format File Extension
OpenType .otf, .otc
TrueType .ttf, .ttc
WOFF File Format 1.0 .otf.woff, .ttf.woff
WOFF File Format 2.0 .otf.woff2, .ttf.woff2
Microsoft Bitmap Only SFNT .ms-bitmap.ttf
X11 OpenType Bitmap .otb
Macintosh Datafork TrueType .dfont
Glyph Bitmap Distribution Format .bdf
Portable Compiled Format .pcf

Supported Color Table Formats

Dependencies

References

License

MIT License

Metadata

Release files for pixel-font-builder 0.0.65

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pixel-font-builder 0.0.65
File Size Uploaded Provenance Actions
pixel_font_builder-0.0.65.tar.gz 34.0 kB With provenance Details for pixel_font_builder-0.0.65.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pixel-font-builder 0.0.65
File Interpreter ABI Platform Actions
pixel_font_builder-0.0.65-py3-none-any.whl Python 3 none any Details for pixel_font_builder-0.0.65-py3-none-any.whl

Total release size: 84.5 kB

Release files / pixel_font_builder-0.0.65.tar.gz

Download URL pixel_font_builder-0.0.65.tar.gz
Size 34.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f7085674989d2921062606da4749732e6ad96bc48656ff1c3d288d3688beec2e
BLAKE2b-256 checksum
How to use checksums
00777ac29a8f6cdfc6394bc62f9b479dc09ee67894cd35911786812cd59fa42c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Release files / pixel_font_builder-0.0.65-py3-none-any.whl

Download URL pixel_font_builder-0.0.65-py3-none-any.whl
Size 50.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ca2c644dff43cfeaf9cf7d942c4335bf19744d50b7f1699e9b7d3871cf8e5908
BLAKE2b-256 checksum
How to use checksums
9c0fe9144b46841d47281794eb6776a771f81de89181dd5b271414bce4e26137
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Security for pixel-font-builder 0.0.65

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pixel_font_builder-0.0.65.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.65 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page