Skip to main content

A library for manipulating '.bdf' format fonts.

Project description

BdfFont

Python PyPI

BdfFont is a library for manipulating .bdf format fonts.

Installation

pip install bdffont

Usage

Load

import os

from bdffont import BdfFont
from examples import assets_dir, outputs_dir


def main():
    font = BdfFont.load(os.path.join(assets_dir, 'unifont-15.0.01.bdf'))
    print(f'name: {font.name}')
    print(f'size: {font.point_size}')
    print(f'ascent: {font.properties.font_ascent}')
    print(f'descent: {font.properties.font_descent}')
    for glyph in font.get_orderly_glyphs():
        print(f'glyph: {glyph.name} - {glyph.code_point:04X}')
    font.save(os.path.join(outputs_dir, 'unifont-15.0.01.bdf'), optimize_bitmap=True)


if __name__ == '__main__':
    main()

Create

import os

from bdffont import BdfFont, BdfGlyph, xlfd
from examples import outputs_dir


def main():
    font = BdfFont(
        point_size=16,
        resolution_xy=(75, 75),
        bounding_box_size=(16, 16),
        bounding_box_offset=(0, -2),
    )

    font.add_glyph(BdfGlyph(
        name='A',
        code_point=ord('A'),
        scalable_width=(500, 0),
        device_width=(8, 0),
        bounding_box_size=(8, 16),
        bounding_box_offset=(0, -2),
        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],
        ],
    ))

    font.properties.foundry = 'TakWolf Studio'
    font.properties.family_name = 'Demo Pixel'
    font.properties.add_style_name = xlfd.AddStyleName.SANS_SERIF
    font.properties.pixel_size = 16
    font.properties.point_size = 160
    font.properties.spacing = xlfd.Spacing.PROPORTIONAL
    font.properties.average_width = round(sum([glyph.scalable_width_x for glyph in font.code_point_to_glyph.values()]) / font.get_glyphs_count())
    font.setup_missing_xlfd_properties()

    font.properties.default_char = -1
    font.properties.font_ascent = 14
    font.properties.font_descent = 2
    font.properties.x_height = 5
    font.properties.cap_height = 7

    font.properties.font_version = '1.0.0'
    font.properties.copyright = 'Copyright (c) TakWolf'

    font.generate_xlfd_font_name()

    font.save(os.path.join(outputs_dir, 'my-font.bdf'), optimize_bitmap=True)


if __name__ == '__main__':
    main()

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

bdffont-0.0.11.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

bdffont-0.0.11-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file bdffont-0.0.11.tar.gz.

File metadata

  • Download URL: bdffont-0.0.11.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for bdffont-0.0.11.tar.gz
Algorithm Hash digest
SHA256 0fcc1bd54203d5d2b469da7485d80c97a43b0982491693cf9052c0d8b78eae0c
MD5 cf31533505602a236d7f13feba099028
BLAKE2b-256 37357a0c240d417d2a081736551a233261628dc1dfc820ca632de666a4f96286

See more details on using hashes here.

Provenance

File details

Details for the file bdffont-0.0.11-py3-none-any.whl.

File metadata

  • Download URL: bdffont-0.0.11-py3-none-any.whl
  • Upload date:
  • Size: 11.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for bdffont-0.0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 0b5680c0d2ec13b7c33fa44f38ef8463ed4ec897b8754c894f6e8755f9c59344
MD5 8484d1978062354a162cdeb0c0a03fa9
BLAKE2b-256 637551151650331b623b9037d6c1e8d28add605b30413c3d4b79a995c1881929

See more details on using hashes here.

Provenance

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