Skip to content

Commit dc87d9c

Browse files
committed
Port font editor to SDL2
Port font editor from X11 to SDL2, improving portability, cross-platform support, and maintainability. Window creation now uses SDL_CreateWindow, replacing X11 XCreateWindow. Event handling is migrated to SDL2 SDL_PollEvent, streamlining the capture of keyboard and mouse inputs. Rendering is updated to leverage SDL_Renderer and SDL_Surface, replacing X11 rendering functions. Key event behaviors have been refined for better usability. Pressing SDLK_ESCAPE or clicking the window close button (SDL_QUIT) now exits the application. To address a formatting issue with clang-format, the function delete() has been renamed to delete_first_cmd(), avoiding conflicts with the C++ keyword delete. File reading has also been simplified using fopen for improved clarity. The README has been expanded with a background on twin-fedit, key bindings, a quick start guide, and a demo GIF to help users get started. Close #7
1 parent a2becfd commit dc87d9c

File tree

5 files changed

+299
-173
lines changed

5 files changed

+299
-173
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: 81 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,93 @@
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+
<p align="center">
6+
<img src="./assets/demo.gif" />
7+
</p>
58

69
## Build Dependency
710
```shell
8-
sudo apt-get install libx11-dev libcairo2-dev
11+
sudo apt-get install libsdl2-dev libcairo2-dev
912
```
1013

1114
## Usage
1215
```shell
1316
make
14-
./twin-fedit < nchars
17+
./twin-fedit nchars
18+
```
19+
20+
## Background
21+
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.
22+
23+
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
24+
```
25+
/* 0x31 '1' offset 666 */
26+
0, 10, 42, 0, 2, 3,
27+
0, 10, /* snap_x */
28+
-21, -15, 0, /* snap_y */
29+
'm', 0, -34,
30+
'c', 4, -35, 8, -38, 10, -42,
31+
'l', 10, 0,
32+
'e',
1533
```
1634

17-
(press 'q' to next character)
35+
The first line to 4-th line are used to draw the glyph.
36+
37+
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
38+
39+
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.
40+
41+
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.
42+
43+
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.
44+
45+
The character `e` is an abbreviation for `end`.
46+
47+
According to the steps outlined above for drawing glyph `1`, it can be split into the following steps:
48+
49+
1. `'m' 0,-34`: Move to `0,-34` and plot a point at `0,-34`.
50+
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`.
51+
3. `'l' 10,0`: Starting from `10,-42` and ending at `10,0`, draw a straight line.
52+
4. `'e'`: End the drawing of glyph `1`.
53+
54+
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.
55+
56+
## Quick Guide
57+
For each glyph, there are the following shortcut keys used for editing the glyph.
58+
59+
| Key | Functionality |
60+
| --- | --- |
61+
| ESC | Exit program |
62+
| left mouse button | Select a point as the first operation for that glyph |
63+
| right mouse button | Select a point as the last operation for that glyph |
64+
| d | Delete selected point|
65+
| f | Replace a line with a spline |
66+
| q | Switch to next character |
67+
| s | Split a spline into two splines by start point and end point |
68+
| u | Undo the last operation |
69+
70+
71+
To move a point
72+
1. Select a point by left mouse button,
73+
2. Use arrow keys to move the selected point.
74+
75+
To move a control point
76+
1. Select a point with two control points by left mouse button,
77+
2. Use arrow keys to move the first control point,
78+
3. Keep pressing shift key and use arrow keys to move the second control point.
79+
80+
To split a spline or line
81+
1. Select two point by left and right mouse button,
82+
2. Use s key to split the line or spline into two segments.
83+
84+
To replace the line or spline by another spline
85+
1. Select two point by left and right mouse button as start and end of the another spline,
86+
2. Use f key to replace the line or spline with another spline.
87+
88+
To delete a point
89+
1. Select a point by left mouse button,
90+
2. Use d key to delete the selected point.
91+
92+
To undo any operations above
93+
1. Use u key.

tools/font-edit/assets/demo.gif

329 KB
Loading

0 commit comments

Comments
 (0)