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 logging
import os

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

logging.basicConfig(level=logging.DEBUG)


def main():
    builder = FontBuilder(
        size=12,
        ascent=10,
        descent=-2,
        x_height=5,
        cap_height=7,
    )

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

    builder.add_glyph(Glyph(
        name='.notdef',
        advance_width=8,
        offset=(0, -2),
        data=[
            [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.add_glyph(Glyph(
        name='CAP_LETTER_A',
        advance_width=8,
        offset=(0, -2),
        data=[
            [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.meta_infos.version = '1.0.0'
    builder.meta_infos.family_name = 'Demo Pixel'
    builder.meta_infos.style_name = StyleName.REGULAR
    builder.meta_infos.serif_mode = SerifMode.SANS_SERIF
    builder.meta_infos.width_mode = WidthMode.MONOSPACED
    builder.meta_infos.manufacturer = 'TakWolf Studio'
    builder.meta_infos.designer = 'TakWolf'
    builder.meta_infos.description = 'A demo pixel font.'
    builder.meta_infos.copyright_info = 'Copyright (c) TakWolf'
    builder.meta_infos.license_info = 'This Font Software is licensed under the SIL Open Font License, Version 1.1.'
    builder.meta_infos.vendor_url = 'https://github.com/TakWolf/pixel-font-builder'
    builder.meta_infos.designer_url = 'https://takwolf.com'
    builder.meta_infos.license_url = 'https://scripts.sil.org/OFL'
    builder.meta_infos.sample_text = 'Hello World!'

    builder.save_otf(os.path.join(outputs_dir, 'demo.otf'))
    builder.save_otf(os.path.join(outputs_dir, 'demo.woff2'), flavor=opentype.Flavor.WOFF2)
    builder.save_ttf(os.path.join(outputs_dir, 'demo.ttf'))
    builder.save_bdf(os.path.join(outputs_dir, 'demo.bdf'))


if __name__ == '__main__':
    main()

Dependencies

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.8.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

pixel_font_builder-0.0.8-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file pixel-font-builder-0.0.8.tar.gz.

File metadata

  • Download URL: pixel-font-builder-0.0.8.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for pixel-font-builder-0.0.8.tar.gz
Algorithm Hash digest
SHA256 67263dad21971786955720ba85cb8b5ffac1daf047c4eebaecacfa29c455b5f4
MD5 0bd3a0ded9efc1562aada205c65fcffa
BLAKE2b-256 79ade5074cef3451521cb8b859d7f8e55bc7e0b814fc84479c02b995ced8b444

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pixel_font_builder-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 e7a07338128be0b6f3035442752a48ff3800f72a6274d377a15b781baf405327
MD5 ccd3d6d54d698a0153dec538f2c7640d
BLAKE2b-256 0b6565c789cc548c69f50a6b18044dc7314f102e90ae7f3649abf776513baf11

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