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 shutil
from examples import build_dir
from pixel_font_builder import FontBuilder, WeightName, SerifStyle, SlantStyle, WidthStyle, Glyph, opentype
def main():
outputs_dir = build_dir.joinpath('create')
if outputs_dir.exists():
shutil.rmtree(outputs_dir)
outputs_dir.mkdir(parents=True)
builder = FontBuilder()
builder.font_metric.font_size = 12
builder.font_metric.horizontal_layout.ascent = 10
builder.font_metric.horizontal_layout.descent = -2
builder.font_metric.vertical_layout.ascent = 6
builder.font_metric.vertical_layout.descent = -6
builder.font_metric.x_height = 5
builder.font_metric.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_style = WidthStyle.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',
horizontal_origin=(0, -2),
advance_width=8,
vertical_origin=(-4, 0),
advance_height=12,
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',
horizontal_origin=(0, -2),
advance_width=8,
vertical_origin=(-4, 0),
advance_height=12,
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(outputs_dir.joinpath('my-pixel.otf'))
builder.save_otf(outputs_dir.joinpath('my-pixel.woff2'), flavor=opentype.Flavor.WOFF2)
builder.save_ttf(outputs_dir.joinpath('my-font.ttf'))
builder.save_bdf(outputs_dir.joinpath('my-font.bdf'))
builder.save_pcf(outputs_dir.joinpath('my-font.pcf'))
if __name__ == '__main__':
main()
Coordinate Systems
Use the same coordinate systems as OpenType.
Horizontal Layout
Vertical Layout
Supported Output Formats
Format | File Extension |
---|---|
OpenType | .otf , .otc , .woff , .woff2 |
TrueType | .ttf , .ttc , .woff , .woff2 |
Glyph Bitmap Distribution Format | .bdf |
Portable Compiled Format | .pcf |
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.28.tar.gz
(18.5 kB
view details)
Built Distribution
File details
Details for the file pixel_font_builder-0.0.28.tar.gz
.
File metadata
- Download URL: pixel_font_builder-0.0.28.tar.gz
- Upload date:
- Size: 18.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9d5a8b870257648cfaa7ffceeadbf6b8edc08551d7fc2b0eadb8c5064ff5c37 |
|
MD5 | 4462da374e58417b473be93705fc3afc |
|
BLAKE2b-256 | 1cf4b92a388e8a6023c3d9a2f1d7f64a4f5d8c4f778fe4972c96071bdba30761 |
File details
Details for the file pixel_font_builder-0.0.28-py3-none-any.whl
.
File metadata
- Download URL: pixel_font_builder-0.0.28-py3-none-any.whl
- Upload date:
- Size: 13.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65acb29b61a562e1f7083b4fa9088af77253adc2a49c6f59be4f3ffc852c9628 |
|
MD5 | 6904aa5815537364547ea251169e14c2 |
|
BLAKE2b-256 | 431a8e3c037843e2a73528fe712e47d169e13eda050759181e33f06073711eef |