Skip to content

Commit 3c63548

Browse files
committed
Port font editor to SDL2
Replace X11 with SDL2 to improve the portability and cross-platform support Migrate window creation from X11's `XCreateWindow` to `SDL_CreateWindow`. Replace X11 event handling with SDL2’s event loop (`SDL_PollEvent`) to capture input events such as keyboard and mouse interactions. Update rendering to use `SDL_Renderer` and `SDL_Surface`, replacing X11's rendering functions. * Modify some key event logic: 1. SDLK_ESCAPE: ESC now exits the program. 2. SDL_QUIT: Clicking the "X" on the window exits the program. * Unchanged key event logic: 1. SDLK_q: Switches to the next font. * Rename delete function: 1. Rename delete() to delete_first_cmd() to avoid `clang-format` misinterpreting `delete()` as the C++ the keyword, which cauese an extra space to be added when running `clang-format`, turning `delete()` to `delete ()`. * Modify the file reading method: 1. use fopen read the filename to improve readability. * Add instructions and descriptions in the READMD. 1. Add the background of twin-fedit 2. Add Key bindings 3. Add a quick guide 4. Add demo GIF of twin-fedit
1 parent 35ddf50 commit 3c63548

File tree

5 files changed

+300
-172
lines changed

5 files changed

+300
-172
lines changed

tools/font-edit/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
TARGET = twin-fedit
22

3-
CFLAGS = $(shell pkg-config --cflags cairo x11) -g -Wall
4-
LIBS = $(shell pkg-config --libs cairo x11)
3+
CFLAGS = $(shell pkg-config --cflags cairo) $(shell sdl2-config --cflags) -g -Wall
4+
LIBS = $(shell pkg-config --libs cairo) $(shell sdl2-config --libs)
55

66
OBJS = \
77
twin-fedit.o \

tools/font-edit/README.md

Lines changed: 82 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
# twin-fedit
22
`twin-fedit` is a tool allowing users to edit specific scalable fonts
3-
which are expected to fit the requirements of embedded systems with larger
4-
screens.
3+
which are expected to fit the requirements of embedded systems with larger screens.
4+
5+
The fonts that can be modified using a font editor provide the self-defined font used in [twin.h](/include/twin.h).
6+
7+
<p align="center">
8+
<img src="./assets/demo.gif" />
9+
</p>
510

611
## Build Dependency
712
```shell
8-
sudo apt-get install libx11-dev libcairo2-dev
13+
sudo apt-get install libsdl2-dev libcairo2-dev
914
```
1015

1116
## Usage
@@ -14,4 +19,77 @@ make
1419
./twin-fedit < nchars
1520
```
1621

17-
(press 'q' to next character)
22+
## Background
23+
The glyphs in `twin-fedit` is originated from [Hershey vector fonts](https://en.wikipedia.org/wiki/Hershey_fonts), which were created by Dr. A. V. Hershey while working at the U. S. National Bureau of Standards.
24+
25+
The Hershey vector fonts set of `twin-fedit` is [`nchars`](nchars), for example, the interpolation points and operations used to draw the glyph `1` are as follows
26+
```
27+
/* 0x31 '1' offset 666 */
28+
0, 10, 42, 0, 2, 3,
29+
0, 10, /* snap_x */
30+
-21, -15, 0, /* snap_y */
31+
'm', 0, -34,
32+
'c', 4, -35, 8, -38, 10, -42,
33+
'l', 10, 0,
34+
'e',
35+
```
36+
37+
The first line to 4-th line are used to draw the glyph. For more detail, see [font.c](/src/font.c).
38+
39+
The first line of is the header that contains the information of the character `1`, `0x31` is the ASCII code of `1` and offset `666` is the
40+
41+
The character `m` is an abbreviation for `move to`, and the values following `m` represent the x and y positions to move to in the drawing window's coordinate system, respectively.
42+
43+
The character `c` is an abbreviation for `curve to`, and the values following `c` represent three x-y coordinate points used to draw a cubic Bézier curve, in the order of the first control point, the second control point, and the endpoint.
44+
45+
The character `l` is an abbreviation for `line to`, and the values following `l` represent the x and y positions to move to, relative to the position from the previous operation, in the drawing window's coordinate system, respectively.
46+
47+
The character `e` is an abbreviation for `end`.
48+
49+
According to the steps outlined above for drawing glyph `1`, it can be split into the following steps:
50+
51+
1. `'m' 0,-34`: Move to `0,-34` and plot a point at `0,-34`.
52+
2. `'c' 4, -35, 8, -38, 10, -42`: Starting from `0,-34` and ending at `10,-42`, draw a curve using Bézier curve with the first control point at `4,-35` and the second control point at `8,-38`.
53+
3. `'l' 10,0`: Starting from `10,-42` and ending at `10,0`, draw a straight line.
54+
4. `'e'`: End the drawing of glyph `1`.
55+
56+
Each point seen in `twin-fedit` corresponds to an operation. By selecting a point in `twin-fedit`, you can modify the coordinates to edit any glyph.
57+
58+
## Quick Guide
59+
For each glyph, there are the following shortcut keys used for editing the glyph.
60+
61+
| Key | Functionality |
62+
| --- | --- |
63+
| ESC | Exit program |
64+
| left mouse button | Select a point as the first operation for that glyph |
65+
| right mouse button | Select a point as the last operation for that glyph |
66+
| d | Delete selected point|
67+
| f | Replace a line with a spline |
68+
| q | Switch to next character |
69+
| s | Split a spline into two splines by start point and end point |
70+
| u | Undo the last operation |
71+
72+
73+
To move a point
74+
1. Select a point by left mouse button,
75+
2. Use arrow keys to move the selected point.
76+
77+
To move a control point
78+
1. Select a point with two control points by left mouse button,
79+
2. Use arrow keys to move the first control point,
80+
3. Keep press shift key and use arrow keys to move the second control point.
81+
82+
To split a spline or line
83+
1. Select two point by left and right mouse button,
84+
2. Use s key to split the line or spline into two segments.
85+
86+
To replace the line or spline by another spline
87+
1. Select two point by left and right mouse button as start and end of the another spline,
88+
2. Use f key to replace the line or spline with another spline.
89+
90+
To delete a point
91+
1. Select a point by left mouse button,
92+
2. Use d key to delete the selected point.
93+
94+
To undo any operations above
95+
1. Use u key.

tools/font-edit/assets/demo.gif

329 KB
Loading

0 commit comments

Comments
 (0)