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

IMEを追加 #63

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c4c1acc
add IME (prototype)
mikecat Aug 22, 2022
5a4fa6f
add cli and sti around SendMessage
mikecat Aug 22, 2022
b542275
ime: add arrows to hiragana conversion table
mikecat Aug 29, 2022
774b465
ime: improve hiragana conversion
mikecat Aug 29, 2022
069b713
tedit: recognize insertion from IME as edit
mikecat Aug 29, 2022
1ecc0f8
introduce layer priority
mikecat Aug 30, 2022
24ba66c
ime: improve member variables
mikecat Aug 30, 2022
8ad57b2
improve how IME looks
mikecat Aug 30, 2022
5f255d0
ime: improve enable/disable and window management
mikecat Aug 30, 2022
d923f21
add IME status indicator
mikecat Aug 30, 2022
7759e73
ime: improve input of っ and ん
mikecat Aug 31, 2022
4f1a790
ime: add Esc key support
mikecat Aug 31, 2022
a0cb3df
ime: support conversion of character types
mikecat Aug 31, 2022
c4c6aa9
recognize half-width katakana as half-width
mikecat Aug 31, 2022
0579539
use uint32_t instaed of char32_t for IME input message
mikecat Aug 31, 2022
4fa7534
ime: add conversion from character code
mikecat Sep 1, 2022
ab6967e
add system call to tell where the IME should be
mikecat Sep 1, 2022
1a8e8e5
ime: commit input when being disabled
mikecat Sep 9, 2022
9ba5738
ime: add converson candidate list
mikecat Sep 10, 2022
dbc65cb
IME: improve hiragana_map
mikecat Sep 25, 2022
635e68a
enable to select a candidate by inputting numbers
mikecat Oct 4, 2022
33865af
add dictionary for IME
mikecat Oct 4, 2022
1cb4e25
add conversion using dictionary
mikecat Oct 4, 2022
0f832ec
IME: fix candidate index drawing
mikecat Oct 5, 2022
c0b0652
IME: implement initial partition for conversion
mikecat Oct 5, 2022
3c17bb5
IME: add simple learning
mikecat Oct 5, 2022
5b462f4
use pre-increment instead of post-increment
mikecat Oct 5, 2022
6dd0311
add some marks to IME dictionary
mikecat Oct 5, 2022
7764af4
add comments
mikecat Oct 5, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions apps/syscall.asm
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,22 @@ Syscall%1:
ret
%endmacro

define_syscall LogString, 0x80000000
define_syscall PutString, 0x80000001
define_syscall Exit, 0x80000002
define_syscall OpenWindow, 0x80000003
define_syscall WinWriteString, 0x80000004
define_syscall WinFillRectangle, 0x80000005
define_syscall GetCurrentTick, 0x80000006
define_syscall WinRedraw, 0x80000007
define_syscall WinDrawLine, 0x80000008
define_syscall CloseWindow, 0x80000009
define_syscall ReadEvent, 0x8000000a
define_syscall CreateTimer, 0x8000000b
define_syscall OpenFile, 0x8000000c
define_syscall ReadFile, 0x8000000d
define_syscall DemandPages, 0x8000000e
define_syscall MapFile, 0x8000000f
define_syscall IsTerminal, 0x80000010
define_syscall LogString, 0x80000000
define_syscall PutString, 0x80000001
define_syscall Exit, 0x80000002
define_syscall OpenWindow, 0x80000003
define_syscall WinWriteString, 0x80000004
define_syscall WinFillRectangle, 0x80000005
define_syscall GetCurrentTick, 0x80000006
define_syscall WinRedraw, 0x80000007
define_syscall WinDrawLine, 0x80000008
define_syscall CloseWindow, 0x80000009
define_syscall ReadEvent, 0x8000000a
define_syscall CreateTimer, 0x8000000b
define_syscall OpenFile, 0x8000000c
define_syscall ReadFile, 0x8000000d
define_syscall DemandPages, 0x8000000e
define_syscall MapFile, 0x8000000f
define_syscall IsTerminal, 0x80000010
define_syscall SetPreferredIMEPos, 0x80000011
define_syscall UnsetPreferredIMEPos, 0x80000012
3 changes: 3 additions & 0 deletions apps/syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ struct SyscallResult SyscallDemandPages(size_t num_pages, int flags);
struct SyscallResult SyscallMapFile(int fd, size_t* file_size, int flags);
struct SyscallResult SyscallIsTerminal(int fd);

struct SyscallResult SyscallSetPreferredIMEPos(uint64_t layer_id_flags, int x, int y);
struct SyscallResult SyscallUnsetPreferredIMEPos(uint64_t layer_id_flags);

#ifdef __cplusplus
} // extern "C"
#endif
56 changes: 43 additions & 13 deletions apps/tedit/tedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ int DrawOneChar(uint64_t layer_id,
SyscallWinWriteString(layer_id, x, y, TEXT_COLOR, buf);
}
// TODO: 描画幅をより正確に判定する
return c < 0x80 ? 1 : 2;
return c < 0x80 || (0xff61 <= c && c <= 0xff9f) ? 1 : 2;
}

// [指定した文字の最初の位置, 指定した文字の幅] を返す
Expand Down Expand Up @@ -486,9 +486,19 @@ int main(int argc, char** argv) {
}
};

auto draw_cursor = [&, hwnd = hwnd](bool show, bool redraw) {
auto get_cursor_coord = [&]() -> std::tuple<int, int> {
int cx = X_OFFSET + X_PADDING + CHAR_WIDTH * cursor_x;
int cy = Y_OFFSET + Y_PADDING + CHAR_HEIGHT * (cursor_y - scroll_y);
return {cx, cy};
};

auto set_ime_position = [&, hwnd = hwnd]() {
auto [cx, cy] = get_cursor_coord();
SyscallSetPreferredIMEPos(hwnd, cx, cy);
};

auto draw_cursor = [&, hwnd = hwnd](bool show, bool redraw) {
auto [cx, cy] = get_cursor_coord();
if (show) {
// キャレットを出す
SyscallWinDrawLine(hwnd | LAYER_NO_REDRAW,
Expand Down Expand Up @@ -533,11 +543,28 @@ int main(int argc, char** argv) {
};
draw_lines(0, -1);
SyscallWinRedraw(hwnd);
set_ime_position();

SyscallCreateTimer(TIMER_ONESHOT_REL, CURSOR_TIMER_VALUE, CURSOR_TIMER_INTERVAL_MS);
int ret = 0;
bool exit_flag = false;

// カーソルの位置に文字cを挿入し、挿入後のカーソルのx座標を返す
auto insert_char = [&](uint32_t c) {
int idx = cursor_x == 0 ? 0 :
char_idx[cursor_y - scroll_y][cursor_x - 1] + 1;
data[cursor_y].insert(data[cursor_y].begin() + idx, c);
// 挿入後の行について、新しいカーソルの位置を求める
// タブ(など)の処理があり得るので、単に「一文字分」ではダメ
std::vector<int> new_char_idx;
DrawLine(new_char_idx, 0, 0, 0, width, tab_size,
data[cursor_y], false, true);
auto [s, cw] = GetCharRange(new_char_idx, cursor_x);
int new_cursor_x = cursor_x;
if (cursor_x + cw <= width) new_cursor_x += cw;
return new_cursor_x;
};

// ダイアログの各ボタンを押した時の動作
auto dialog_save_pressed = [&, hwnd = hwnd]() {
if (SaveFile(file_name, data)) {
Expand Down Expand Up @@ -623,6 +650,7 @@ int main(int argc, char** argv) {
cursor_x = start;
cursor_y = new_cursor_y;
if (cursor_on) draw_cursor(true, true);
set_ime_position();
}
}
}
Expand Down Expand Up @@ -702,17 +730,7 @@ int main(int argc, char** argv) {
edited = true;
} else {
// 文字の挿入
int idx = cursor_x == 0 ? 0 :
char_idx[cursor_y - scroll_y][cursor_x - 1] + 1;
int c = arg.keypush.ascii;
data[cursor_y].insert(data[cursor_y].begin() + idx, c);
// 挿入後の行について、新しいカーソルの位置を求める
// タブ(など)の処理があり得るので、単に「一文字分」ではダメ
std::vector<int> new_char_idx;
DrawLine(new_char_idx, 0, 0, 0, width, tab_size,
data[cursor_y], false, true);
auto [s, cw] = GetCharRange(new_char_idx, cursor_x);
if (cursor_x + cw <= width) new_cursor_x += cw;
new_cursor_x = insert_char(arg.keypush.ascii);
redraw_from = redraw_to = cursor_y - scroll_y;
edited = true;
}
Expand Down Expand Up @@ -843,6 +861,18 @@ int main(int argc, char** argv) {
cursor_y = new_cursor_y;
draw_lines(redraw_from, redraw_to);
SyscallWinRedraw(hwnd);
set_ime_position();
}
break;
case AppEvent::kCharInput:
{
if (cursor_on) draw_cursor(false, false);
cursor_x = insert_char(arg.charinput.ch);
edited = true;
int line_to_draw = cursor_y - scroll_y;
draw_lines(line_to_draw, line_to_draw);
SyscallWinRedraw(hwnd);
set_ime_position();
}
break;
}
Expand Down
2 changes: 1 addition & 1 deletion kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ TARGET = kernel.elf
OBJS = main.o graphics.o mouse.o font.o hankaku.o newlib_support.o console.o \
pci.o asmfunc.o libcxx_support.o logger.o interrupt.o segment.o paging.o memory_manager.o \
window.o layer.o timer.o frame_buffer.o acpi.o keyboard.o task.o terminal.o \
fat.o syscall.o file.o \
fat.o syscall.o file.o ime.o \
usb/memory.o usb/device.o usb/xhci/ring.o usb/xhci/trb.o usb/xhci/xhci.o \
usb/xhci/port.o usb/xhci/device.o usb/xhci/devmgr.o usb/xhci/registers.o \
usb/classdriver/base.o usb/classdriver/hid.o usb/classdriver/keyboard.o \
Expand Down
5 changes: 5 additions & 0 deletions kernel/app_event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct AppEvent {
kMouseButton,
kTimerTimeout,
kKeyPush,
kCharInput,
} type;

union {
Expand All @@ -37,6 +38,10 @@ struct AppEvent {
char ascii;
int press; // 1: press, 0: release
} keypush;

struct {
uint32_t ch;
} charinput;
} arg;
};

Expand Down
2 changes: 1 addition & 1 deletion kernel/font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ std::pair<char32_t, int> ConvertUTF8To32(const char* u8) {
}

bool IsHankaku(char32_t c) {
return c <= 0x7f;
return c <= 0x7f || (0xff61 <= c && c <= 0xff9f);
}

WithError<FT_Face> NewFTFace() {
Expand Down
Loading