Skip to main content

A library that helps create pixel style fonts.

Project description

Pixel Font Builder

Python PyPI

A library that helps create pixel style fonts.

Installation

pip install pixel-font-builder

Usage

import os
import shutil

from examples import build_dir
from pixel_font_builder import FontBuilder, StyleName, SerifMode, WidthMode, Glyph, opentype


def main():
    outputs_dir = os.path.join(build_dir, 'create')
    if os.path.exists(outputs_dir):
        shutil.rmtree(outputs_dir)
    os.makedirs(outputs_dir)

    builder = FontBuilder(12)

    builder.meta_info.version = '1.0.0'
    builder.meta_info.family_name = 'My Pixel'
    builder.meta_info.style_name = StyleName.REGULAR
    builder.meta_info.serif_mode = SerifMode.SANS_SERIF
    builder.meta_info.width_mode = WidthMode.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.horizontal_header.ascent = 10
    builder.horizontal_header.descent = -2

    builder.vertical_header.ascent = 6
    builder.vertical_header.descent = -6

    builder.os2_configs.x_height = 5
    builder.os2_configs.cap_height = 7

    builder.character_mapping.update({
        ord('A'): 'CAP_LETTER_A',
    })

    builder.glyphs.append(Glyph(
        name='.notdef',
        advance_width=8,
        advance_height=12,
        horizontal_origin=(0, -2),
        vertical_origin_y=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, 1, 1, 1, 1, 1, 1, 1],
        ],
    ))
    builder.glyphs.append(Glyph(
        name='CAP_LETTER_A',
        advance_width=8,
        advance_height=12,
        horizontal_origin=(0, -2),
        vertical_origin_y=0,
        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(os.path.join(outputs_dir, 'my-pixel.otf'))
    builder.save_otf(os.path.join(outputs_dir, 'my-pixel.woff2'), flavor=opentype.Flavor.WOFF2)
    builder.save_ttf(os.path.join(outputs_dir, 'my-font.ttf'))
    builder.save_bdf(os.path.join(outputs_dir, 'my-font.bdf'))
    builder.save_pcf(os.path.join(outputs_dir, 'my-font.pcf'))


if __name__ == '__main__':
    main()

Dependencies

References

License

Under the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pixel_font_builder-0.0.22.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

pixel_font_builder-0.0.22-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file pixel_font_builder-0.0.22.tar.gz.

File metadata

  • Download URL: pixel_font_builder-0.0.22.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for pixel_font_builder-0.0.22.tar.gz
Algorithm Hash digest
SHA256 807a28670dd6a1edd6845c61d871e3f48911692810477dfb6e77b583fa34df6d
MD5 8804998ebb824f4e9db219ba51b3e22c
BLAKE2b-256 2483b406e813cc95169d69bd3ee6a61f870cd288d72625f35297a24e9721e5a6

See more details on using hashes here.

File details

Details for the file pixel_font_builder-0.0.22-py3-none-any.whl.

File metadata

File hashes

Hashes for pixel_font_builder-0.0.22-py3-none-any.whl
Algorithm Hash digest
SHA256 0de5e38b115c68d1ae04db73ed99d5b95a3c9222a4d96ebba22aae4a8f61ef3a
MD5 0bff7448b912f470f4db8569b01dbb52
BLAKE2b-256 4adf71243ec95c97d213f9f891c0646bc5cf83e6423d781ad229d9dacdeef198

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page