https://github.com/takwolf/pixel-font-builder
A library that helps create pixel style fonts.
https://github.com/takwolf/pixel-font-builder
font fonts pixel-font pixel-fonts
Last synced: about 1 month ago
JSON representation
A library that helps create pixel style fonts.
- Host: GitHub
- URL: https://github.com/takwolf/pixel-font-builder
- Owner: TakWolf
- License: mit
- Created: 2023-05-08T14:05:55.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-06-11T07:46:46.000Z (11 months ago)
- Last Synced: 2024-06-13T12:04:13.148Z (11 months ago)
- Topics: font, fonts, pixel-font, pixel-fonts
- Language: Python
- Homepage: https://pypi.org/project/pixel-font-builder/
- Size: 262 KB
- Stars: 9
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Pixel Font Builder
[](https://www.python.org)
[](https://pypi.org/project/pixel-font-builder/)A library that helps create pixel style fonts.
## Installation
```shell
pip install pixel-font-builder
```## Usage
```python
import datetime
import shutilfrom examples import build_dir
from pixel_font_builder import FontBuilder, WeightName, SerifStyle, SlantStyle, WidthStyle, Glyph, opentypedef 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 = 16
builder.font_metric.horizontal_layout.ascent = 14
builder.font_metric.horizontal_layout.descent = -2
builder.font_metric.vertical_layout.ascent = 8
builder.font_metric.vertical_layout.descent = -8
builder.font_metric.x_height = 7
builder.font_metric.cap_height = 10builder.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 Font'
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 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.character_mapping.update({
65: 'CAP_LETTER_A',
})builder.glyphs.append(Glyph(
name='.notdef',
horizontal_offset=(0, -2),
advance_width=8,
vertical_offset=(-4, 0),
advance_height=16,
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, 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_offset=(0, -2),
advance_width=8,
vertical_offset=(-4, 0),
advance_height=16,
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],
],
))builder.save_otf(outputs_dir.joinpath('my-font.otf'))
builder.save_otf(outputs_dir.joinpath('my-font.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'))builder.meta_info.family_name = 'My Font SquareDot'
builder.opentype_config.outlines_painter = opentype.SquareDotOutlinesPainter()
builder.save_otf(outputs_dir.joinpath('my-font-square_dot.otf'))
builder.save_otf(outputs_dir.joinpath('my-font-square_dot.woff2'), flavor=opentype.Flavor.WOFF2)
builder.save_ttf(outputs_dir.joinpath('my-font-square_dot.ttf'))builder.meta_info.family_name = 'My Font CircleDot'
builder.opentype_config.outlines_painter = opentype.CircleDotOutlinesPainter()
builder.save_otf(outputs_dir.joinpath('my-font-circle_dot.otf'))
builder.save_otf(outputs_dir.joinpath('my-font-circle_dot.woff2'), flavor=opentype.Flavor.WOFF2)
builder.save_ttf(outputs_dir.joinpath('my-font-circle_dot.ttf'))if __name__ == '__main__':
main()
```## Coordinate Systems
Use the same coordinate systems as OpenType.
### Horizontal Layout

### Vertical Layout

## Supported Output Formats
| Format | File Extension |
|---|---|
| [OpenType](https://learn.microsoft.com/en-us/typography/opentype/) | `.otf`, `.otc`, `.woff`, `.woff2` |
| [TrueType](https://learn.microsoft.com/en-us/typography/truetype/) | `.ttf`, `.ttc`, `.woff`, `.woff2` |
| [Glyph Bitmap Distribution Format](https://en.wikipedia.org/wiki/Glyph_Bitmap_Distribution_Format) | `.bdf` |
| [Portable Compiled Format](https://en.wikipedia.org/wiki/Portable_Compiled_Format) | `.pcf` |## Dependencies
- [FontTools](https://github.com/fonttools/fonttools)
- [BdfFont.Python](https://github.com/TakWolf/bdffont-python)
- [PcfFont.Python](https://github.com/TakWolf/pcffont-python)## References
- [FreeType Glyph Conventions - Glyph Metrics](https://freetype.org/freetype2/docs/glyphs/glyphs-3.html)
- [OpenType Feature File Specification](https://adobe-type-tools.github.io/afdko/OpenTypeFeatureFileSpecification.html)## License
[MIT License](LICENSE)