A library that helps create pixel style fonts.
Project description
Pixel Font Builder
A library that helps create pixel style fonts.
Installation
pip install pixel-font-builder
Usage
import datetime
import os
import shutil
from examples import build_dir
from pixel_font_builder import FontBuilder, WeightName, SerifStyle, SlantStyle, 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()
builder.font_metrics.font_size = 12
builder.font_metrics.horizontal_layout.ascent = 10
builder.font_metrics.horizontal_layout.descent = -2
builder.font_metrics.vertical_layout.ascent = 6
builder.font_metrics.vertical_layout.descent = -6
builder.font_metrics.x_height = 5
builder.font_metrics.cap_height = 7
builder.meta_info.version = '1.0.0'
builder.meta_info.created_time = datetime.datetime.fromisoformat('2024-01-01T00:00:00Z')
builder.meta_info.modified_time = builder.meta_info.created_time
builder.meta_info.family_name = 'My Pixel'
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_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.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
Release history Release notifications | RSS feed
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.23.tar.gz
(18.2 kB
view details)
Built Distribution
File details
Details for the file pixel_font_builder-0.0.23.tar.gz
.
File metadata
- Download URL: pixel_font_builder-0.0.23.tar.gz
- Upload date:
- Size: 18.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24c5f64e05ed7d3e7a5e524a17b316cf80e291e7913c66e00ac619d8cbd58ace |
|
MD5 | b416887be680129c2d7df5963a0243f5 |
|
BLAKE2b-256 | f88d26c2f47ad8a1234523d1dabf602668c43465f6aa43b1d0f4fac1ab73f4da |
File details
Details for the file pixel_font_builder-0.0.23-py3-none-any.whl
.
File metadata
- Download URL: pixel_font_builder-0.0.23-py3-none-any.whl
- Upload date:
- Size: 13.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e8ffc473bc7e0d110da7061d08f9ecee92b47afd7e7bf3082bef0e55d79ebbc3 |
|
MD5 | 50fdc0d8b96654bb7a65c54eae6986c3 |
|
BLAKE2b-256 | 523f76b562d536600f89497f7f380a7b3b5858b0a6370275ef09e7af6e707c4c |