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 build_dir, outputs_dir
from examples.utils import fs_util
from pixel_font_builder import FontBuilder, Glyph, StyleName, SerifMode, WidthMode, opentype

logging.basicConfig(level=logging.DEBUG)


def main():
    fs_util.delete_dir(build_dir)
    fs_util.make_dirs_if_not_exists(outputs_dir)

    font_builder = FontBuilder(
        size=12,
        ascent=10,
        descent=-2,
        x_height=5,
        cap_height=7,
    )

    font_builder.character_mapping = {
        ord('A'): 'CAP_LETTER_A',
    }

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

    font_builder.meta_infos.version = '1.0.0'
    font_builder.meta_infos.family_name = 'Demo Pixel'
    font_builder.meta_infos.style_name = StyleName.REGULAR
    font_builder.meta_infos.serif_mode = SerifMode.SANS_SERIF
    font_builder.meta_infos.width_mode = WidthMode.MONOSPACED
    font_builder.meta_infos.manufacturer = 'TakWolf Studio'
    font_builder.meta_infos.designer = 'TakWolf'
    font_builder.meta_infos.description = 'A demo pixel font.'
    font_builder.meta_infos.copyright_info = 'Copyright (c) TakWolf'
    font_builder.meta_infos.license_info = 'This Font Software is licensed under the SIL Open Font License, Version 1.1.'
    font_builder.meta_infos.vendor_url = 'https://github.com/TakWolf/pixel-font-builder'
    font_builder.meta_infos.designer_url = 'https://takwolf.com'
    font_builder.meta_infos.license_url = 'https://scripts.sil.org/OFL'

    font_builder.save_otf(os.path.join(outputs_dir, 'demo.otf'))
    font_builder.save_otf(os.path.join(outputs_dir, 'demo.woff2'), flavor=opentype.Flavor.WOFF2)
    font_builder.save_ttf(os.path.join(outputs_dir, 'demo.ttf'))
    font_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.1.tar.gz (9.4 kB view hashes)

Uploaded Source

Built Distribution

pixel_font_builder-0.0.1-py3-none-any.whl (9.9 kB view hashes)

Uploaded Python 3

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