Skip to content

Commit

Permalink
rewrite README
Browse files Browse the repository at this point in the history
tomchen committed Dec 25, 2020
1 parent b543a5f commit aa3dd9e
Showing 1 changed file with 46 additions and 18 deletions.
64 changes: 46 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -2,26 +2,54 @@

[![PyPI package](https://img.shields.io/badge/pip%20install-bdfparser-brightgreen)](https://pypi.org/project/example-pypi-package/) [![Actions Status](https://github.com/tomchen/bdfparser/workflows/Test/badge.svg)](https://github.com/tomchen/bdfparser/actions) [![License](https://img.shields.io/github/license/tomchen/bdfparser)](https://github.com/tomchen/bdfparser/blob/master/LICENSE)

BDF (Glyph Bitmap Distribution) format bitmap font file parser library in Python. It has 3 classes `Font`, `Glyph` and `Bitmap` providing more than 30 enriched API methods (functions) for parsing BDF fonts, getting their meta information, rendering text in any writing direction, adding special effects and manipulating bitmap images. It works seamlessly with PIL / Pillow and NumPy. It also has [**detailed documentation / tutorials / API reference**](https://tomchen.org/bdfparser_py/ "BDF Parser Python library's documentation / tutorials / API reference") that I strongly recommend you read.
BDF (Glyph Bitmap Distribution; [Wikipedia](https://en.wikipedia.org/wiki/Glyph_Bitmap_Distribution_Format); [Spec](https://font.tomchen.org/bdf_spec/)) format bitmap font file parser library in Python. It has [`Font`](https://font.tomchen.org/bdfparser_py/font), [`Glyph`](https://font.tomchen.org/bdfparser_py/glyph) and [`Bitmap`](https://font.tomchen.org/bdfparser_py/bitmap) classes providing more than 30 enriched API methods of parsing BDF fonts, getting their meta information, rendering text in any writing direction, adding special effects and manipulating bitmap images. It works seamlessly with [PIL / Pillow](https://pillow.readthedocs.io/en/stable/) and [NumPy](https://numpy.org/).

## Other tools
* [Example .bdf fonts](https://github.com/tomchen/bdfparser/tree/master/example_fonts/bdf):
* GNU Unifont ([Wikipedia article](https://en.wikipedia.org/wiki/GNU_Unifont); [Homepage](https://unifoundry.com/unifont/index.html)): Unicode font (intended to support "all" common languages)
* M+ FONTS ([Wikipedia article](https://en.wikipedia.org/wiki/M%2B_FONTS); [Homepage](https://mplus-fonts.osdn.jp/about-en.html)): Japanese font
* HanWangYanKai 王漢宗自由字型顏體 ([Chinese Wikipedia article](https://zh.wikipedia.org/wiki/%E7%8E%8B%E6%BC%A2%E5%AE%97%E8%87%AA%E7%94%B1%E5%AD%97%E5%9E%8B); [download .ttf](https://github.com/hepochen/fonts/raw/master/gpl-cjk-fonts/wang/wt064.ttf)): Traditional Chinese font
* See also some typical but non-free, fair-used Chinese fonts in [another repo](https://github.com/might-and-magic/fnt-generator#other-tools)
* [otf2bdf](https://github.com/tomchen/bdfparser/tree/master/tools/otf2bdf): OpenType to BDF Converter. Just an archive. Not written by me.
Below I'll show you some quick examples, but it is still strongly recommended you go to [**BDF Parser Python Library's official website to read the detailed documentation / tutorials / API reference**](https://font.tomchen.org/bdfparser_py/).

## Projects that use this library
Install bdfparser library with [pip](https://pip.pypa.io/en/stable/installing/#do-i-need-to-install-pip):

[FNT Generator](https://github.com/might-and-magic/fnt-generator): Might and Magic 6 7 8 and Heroes 3 font File Generator in Python. Another project of mine
```bash
pip install bdfparser
```

## License
Then:

* Python code is written by me (Tom CHEN) and is released under the MIT License.
* [otf2bdf](https://github.com/tomchen/bdfparser/tree/master/tools/otf2bdf): see its page.
* Example .bdf fonts:
* GNU Unifont: [GNU General Public License v2](https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html), by Roman Czyborra, Paul Hardy, part of the GNU Project
* M+ FONTS: [a free license](https://mplus-fonts.osdn.jp/about-en.html#license), designed by Coji Morishita
* HanWangYanKai 王漢宗自由字型顏體: [GNU General Public License v2](https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html), by 王漢宗
* Other fonts are proprietary, and are used non-commercially and fairly
```python
from bdfparser import Font
font = Font('tests/fonts/unifont-13.0.04.bdf')
print(f"This font's global size is "
f"{font.headers['fbbx']} x {font.headers['fbby']} (pixel), "
f"it contains {len(font)} glyphs.")

# =================================

ac = font.glyph("a").draw().crop(6, 8, 1, 2).concat(
font.glyph("c").draw().crop(6, 8, 1, 2)
).shadow()
ac_8x8 = ac * 8
from PIL import Image
im_ac = Image.frombytes('RGBA',
(ac_8x8.width(), ac_8x8.height()),
ac_8x8.tobytes('RGBA'))
im_ac.save("ac.png", "PNG")

# =================================

hello = font.draw('Hello!', direction='rl').glow()
print(hello)
import numpy
import matplotlib.pyplot as plt
nparr = numpy.array(hello.todata(2))
plt.imshow(nparr, 'Blues')
plt.show()

# =================================

font_preview = font.drawall()
im_ac = Image.frombytes('1',
(font_preview.width(), font_preview.height()),
font_preview.tobytes('1'))
im_ac.save("font_preview.png", "PNG")
```

You probably understand what I did in these examples. If you don't, go to [bdfparser's documentation website](https://font.tomchen.org/bdfparser_py/).

0 comments on commit aa3dd9e

Please sign in to comment.