Skip to content

Commit c923107

Browse files
committed
Add c_to_python_font.py.
1 parent eebd730 commit c923107

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

icon_fonts/README.md

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Icon Fonts
2+
3+
It is possible to display icons by incorporating their images in a font file.
4+
There are `.ttf` and `.otf` files available which can be converted to Python
5+
using `font_to_py.py`. I have not had much success with these. I also wanted
6+
to create my own icons. I also experimented with using a font editor to modify
7+
an existing font. I found the font editor unintuitive and hard to use.
8+
9+
The solution offered here uses the Linux `bitmap` editor plus a utility to
10+
convert a set of its output files to a Python font file. The image below shows
11+
typical usage.
12+
13+
![Image](./icon_font.jpg)
14+
15+
# The bitmap editor
16+
17+
This is documented in the man pages, but it is easy and intuitive to use. To
18+
generate (say) 19x19 icons, issue
19+
```bash
20+
$ bitmap -size 19x19
21+
```
22+
Save each bitmap under a different name: I use a `.c` extension as they are C
23+
source files.
24+
25+
You need to create an additional icon to provide the output under error
26+
conditions, i.e. if an attempt is made to display a glyph not in the font.
27+
28+
# The file list
29+
30+
Create a text file listing the bitmap filenames, one filename per line. The
31+
icon to be used as the default (error) image should be first. Subsequent icons
32+
will be assigned to characters "A", "B", "C"...
33+
34+
# Creating the Python font
35+
36+
Assuming a file list `my_file_list.txt`, the following will create
37+
`my_font.py`. It requires Python 3.8 or later. The `font_to_py.py` file should
38+
be in the same directory.
39+
40+
```bash
41+
$ ./c_to_python_font.py my_file_list.txt my_font.py
42+
```
43+
44+
# Using the font
45+
46+
The following will print `icon[2]` where `icon[0]` is the default and `icon[1]`
47+
is associated with "A".
48+
```python
49+
# Instantiate the ssd display object
50+
import my_font
51+
import CWriter
52+
wri = CWriter(ssd, my_font)
53+
wri.printstring("B")
54+
```

0 commit comments

Comments
 (0)