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, WeightName, SerifStyle, SlantStyle, WidthStyle, Glyph, 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_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 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',
        horizontal_offset=(0, -2),
        advance_width=8,
        vertical_offset=(-4, 0),
        advance_height=16,
        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',
        horizontal_offset=(0, -2),
        advance_width=8,
        vertical_offset=(-4, 0),
        advance_height=16,
        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],
        ],
    ))

    builder.character_mapping[0x0041] = 'LATIN_CAPITAL_LETTER_A'

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


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

Dependencies

References

License

MIT License

Metadata

Release files for pixel-font-builder 0.0.62

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.62
File Size Uploaded Provenance Actions
pixel_font_builder-0.0.62.tar.gz 27.3 kB Without provenance Details for pixel_font_builder-0.0.62.tar.gz

Built distribution (wheel)

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

Total release size: 69.0 kB

Release files / pixel_font_builder-0.0.62.tar.gz

Download URL pixel_font_builder-0.0.62.tar.gz
Size 27.3 kB
Tags Source
SHA-256 checksum
How to use checksums
858d152264377767c9a4792141e0a9a13a2ce0064a5e1234578950af33317966
BLAKE2b-256 checksum
How to use checksums
7be0c8384a9bc48dbf30595e0be744ebd232900776c61bb8ddc3278ab90f5d8e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

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

Download URL pixel_font_builder-0.0.62-py3-none-any.whl
Size 41.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
61a028aa5915ea2b2565098fd64a3f8c0b1b52d7c70880768a78fa388cf8ca95
BLAKE2b-256 checksum
How to use checksums
fd2dec99ada45456e0ffd7989fec6d84d28d56daac3586c07573ed81bbc6a790
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for pixel-font-builder 0.0.62

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.62 This release

2 release files No 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