Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port font editor to SDL2 #59

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Port font editor to SDL2 #59

wants to merge 1 commit into from

Conversation

jouae
Copy link
Collaborator

@jouae jouae commented Oct 9, 2024

Replace X11 with SDL2 to improve the portability and cross-platform support

Migrated window creation from X11's XCreateWindow to SDL_CreateWindow.

Replaced X11 event handling with SDL2’s event loop (SDL_PollEvent) to capture input events such as keyboard and mouse interactions.

Updated rendering to use SDL_Renderer and SDL_Surface, replacing X11's rendering functions.

  • Modified 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.
  • Features not fully implemented yet:
  1. SDLK_s, SDLK_u, SDLK_f, SDLK_d, SDLK_DOWN: Handling logic for stripe drawing operations.
  2. SDL_WINDOWEVENT, SDL_MOUSEBUTTONDOWN.

@jserv jserv requested a review from weihsinyeh October 9, 2024 12:20
tools/font-edit/twin-fedit.c Outdated Show resolved Hide resolved
tools/font-edit/twin-fedit.c Outdated Show resolved Hide resolved
tools/font-edit/twin-fedit.h Outdated Show resolved Hide resolved
tools/font-edit/twin-fedit.c Outdated Show resolved Hide resolved
tools/font-edit/twin-fedit.c Outdated Show resolved Hide resolved
tools/font-edit/twin-fedit.c Show resolved Hide resolved
tools/font-edit/twin-fedit.c Outdated Show resolved Hide resolved
jserv

This comment was marked as outdated.

@jserv
Copy link
Contributor

jserv commented Nov 23, 2024

You don't have to write the message Resolved in <commit> literally. Instead, simply click the button "Resolve conversation" once you have confirmed.

tools/font-edit/twin-fedit.c Outdated Show resolved Hide resolved
tools/font-edit/twin-fedit.c Outdated Show resolved Hide resolved
tools/font-edit/twin-fedit.c Outdated Show resolved Hide resolved
tools/font-edit/twin-fedit.c Outdated Show resolved Hide resolved
tools/font-edit/twin-fedit.c Outdated Show resolved Hide resolved
@jouae jouae force-pushed the font-edit branch 2 times, most recently from 54d876b to dd01a82 Compare November 23, 2024 19:15
tools/font-edit/README.md Outdated Show resolved Hide resolved
tools/font-edit/README.md Outdated Show resolved Hide resolved
tools/font-edit/README.md Outdated Show resolved Hide resolved
tools/font-edit/twin-fedit.c Outdated Show resolved Hide resolved
Copy link
Collaborator

@weihsinyeh weihsinyeh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can I control the second control point, pt[1], when I press pt[2]? I can currently only control the first control point, pt[0].

@jouae
Copy link
Collaborator Author

jouae commented Nov 24, 2024

How can I control the second control point, pt[1], when I press pt[2]? I can currently only control the first control point, pt[0].

@weihsinyeh

Sorry, this function is not supported now.

I'm trying to figure out how to let the second control point be moved by user.

tools/font-edit/README.md Outdated Show resolved Hide resolved
tools/font-edit/README.md Outdated Show resolved Hide resolved
tools/font-edit/twin-fedit.c Outdated Show resolved Hide resolved
@jouae
Copy link
Collaborator Author

jouae commented Nov 25, 2024

How can I control the second control point, pt[1], when I press pt[2]? I can currently only control the first control point, pt[0].

@weihsinyeh

I figure out how to control second point. Press shift and arrow key at same time to move the control point.

static void tweak_spline(char_t *c, cmd_t *first, int p2, double dx, double dy)
{
    int i = p2 ? 1 : 0;

    push(c);
    first->pt[i].x += dx;
    first->pt[i].y += dy;
}

This p2 is used to determine whether to move the second control point.

@jserv
Copy link
Contributor

jserv commented Nov 25, 2024

static void tweak_spline(char_t *c, cmd_t *first, int p2, double dx, double dy)
{
    int i = p2 ? 1 : 0;

The statement int i = p2 ? 1 : 0 can be replaced with int i = !!p2, which is shorter and elegant.

@jouae jouae force-pushed the font-edit branch 2 times, most recently from b10cff1 to ada8e48 Compare November 25, 2024 12:17
tools/font-edit/README.md Outdated Show resolved Hide resolved
tools/font-edit/twin-fedit.c Outdated Show resolved Hide resolved
tools/font-edit/README.md Outdated Show resolved Hide resolved
tools/font-edit/README.md Outdated Show resolved Hide resolved
tools/font-edit/README.md Outdated Show resolved Hide resolved
tools/font-edit/README.md Outdated Show resolved Hide resolved
tools/font-edit/README.md Outdated Show resolved Hide resolved
tools/font-edit/README.md Outdated Show resolved Hide resolved
{
char_t *c;

if (!init(argc, argv))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dump the usage before calling exit.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+    char_t *c;
+
+   /*
+    * Use the following command to start twin-fedit:

Don't do that. Dump the message.

What kind of usage should I dump here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can simply change the behavior of this font editor, allowing read a file from given filename (argv[1]). Thus, you can check argument count and the existence of file to proceed.

Replace X11 with SDL2 to improve the portability and cross-platform support

Migrated window creation from X11's `XCreateWindow` to `SDL_CreateWindow`.

Replaced X11 event handling with SDL2’s event loop (`SDL_PollEvent`)
to capture input events such as keyboard and mouse interactions.

Updated rendering to use `SDL_Renderer` and `SDL_Surface`,
replacing X11's rendering functions.

* Modified 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 ()`.

* 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
char_t *c;

/*
* Use the following command to start twin-fedit:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't do that. Dump the message.


XClearArea(dpy, win, 0, 0, 0, 0, True);
for (;;) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to merge the outer and inner loop. That is, use one while statement.

## Background
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.

The Hershey vector fonts set of `twin-fedit` is [`nchars`](./nchars), for example, the interpolation points and operations used to draw the font `1` are as follows
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop ./

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 is not "font". Instead, it is a glyph.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants