9front - general discussion about 9front
 help / color / mirror / Atom feed
* [9front] [PATCH] ktrans: fix Korean input
@ 2024-03-24 10:57 npmania
  2024-03-29 19:23 ` Jacob Moody
  0 siblings, 1 reply; 2+ messages in thread
From: npmania @ 2024-03-24 10:57 UTC (permalink / raw)
  To: 9front

Before applying the patch, /lib/ktrans/hangul.map file has to be
replaced with new one to work properly. The file was generated to
provide correct mapping between QWERTY and Dubeolsik layout. Due to
it's size, I have uploaded it on:
http://okturing.com/src/19014/body

This patch implements two specific behaviors of Dubeolsik layout.

dubeollkup function makes Jongseong(final consonant) to be treated as
Choseong(initial consonant) when possible. For example, QWERTY input
"zhem" in Dubeolsik has to be "코드", not "콛ㅡ" where switched
Jongseong is "ㄷ".

dubeolbksp function emits out syllable remaining after single
backspace. So when user presses backspace on "코드", the expected output
is "코ㄷ", still allowing user to edit latter syllable, rather than
"코" without dubeolbksp. This should only apply to last syllable
considering it's de facto in Dubeolsik implementations.

diff 57b4f2b8e4c5037f726d71c71479a4561ab03137 uncommitted
--- a/sys/man/1/ktrans
+++ b/sys/man/1/ktrans
@@ -167,8 +167,8 @@
 standard diacritic suffixes.
 .SS KOREAN
 Mapping is done by emulating a Dubeolsik layout, with each Latin
-character mapping to a single Jamo. Sequences of up to three Jamo
-are automatically converted to Hangul syllables.
+character mapping to a single Jamo. Sequences of Jamo are automatically
+converted to Hangul syllables.
 .SH EXAMPLES
 To type the following Japanese text:

--- a/sys/src/cmd/ktrans/main.c
+++ b/sys/src/cmd/ktrans/main.c
@@ -581,6 +581,59 @@
 }

 static void
+dubeolbksp(Str *line)
+{
+	Map lkup;
+
+	popstr(line);
+	/* lookup and emit remaining Jamo to output */
+	if(hmapget(hangul, line->b, &lkup) < 0)
+		return;
+	emitutf(output, lkup.kana, 0);
+}
+
+static void
+dubeollkup(Str *line)
+{
+	Map lkup;
+	char buf[UTFmax*2];
+	char *e2, *e1;
+
+	e1 = peekstr(line->p, line->b);
+	if(e1 != line->b){
+		e2 = peekstr(e1, line->b);
+		pushutf(buf, buf+sizeof buf, e2, utflen(e2));
+	}else
+		pushutf(buf, buf+sizeof buf, e1, utflen(e1));
+
+	if(hmapget(hangul, line->b, &lkup) < 0){
+		if(hmapget(hangul, buf, &lkup) < 0){
+			resetstr(line, nil);
+			line->p = pushutf(line->p, strend(line), e1, utflen(e1));
+			if(hmapget(hangul, line->b, &lkup) < 0)
+				return;
+		}else{
+			/* treat Jongseong as Choseong when it matches with new Jamo */
+			popstr(line);
+			popstr(line);
+			hmapget(hangul, line->b, &lkup);
+			emitutf(output, backspace, 2);
+			emitutf(output, lkup.kana, 0);
+
+			hmapget(hangul, buf, &lkup);
+			emitutf(output, lkup.kana, 0);
+			line->p = pushutf(line->b, strend(line), buf, utflen(buf));
+			return;
+		}
+	}
+	if(utflen(line->b) == 1)
+		emitutf(output, backspace, 1);
+	else
+		emitutf(output, backspace, 2);
+	emitutf(output, lkup.kana, 0);
+}
+
+static void
 keythread(void*)
 {
 	int lang;
@@ -645,6 +698,10 @@
 				resetstr(&line, nil);
 				continue;
 			} else if(r == '\b'){
+				if(lang == LangKO){
+					dubeolbksp(&line);
+					continue;
+				}
 				popstr(&line);
 				continue;
 			}
@@ -652,6 +709,9 @@
 			line.p = pushutf(line.p, strend(&line), p, 1);
 			if(lang == LangVN){
 				telexlkup(&line);
+				continue;
+			}else if(lang == LangKO){
+				dubeollkup(&line);
 				continue;
 			}
 			if(maplkup(lang, line.b, &lkup) < 0){
--- a/sys/src/cmd/ktrans/test.c
+++ b/sys/src/cmd/ktrans/test.c
@@ -43,6 +43,9 @@
 	"\fddaua", L"đâu",
 	"\fhoir", L"hỏi",
 	"\fgi\fof", L"giò",
+
+	"\f\x13gpffhdnjfemsms wlruqwksw\bgdk, wha tlstjsgks rj djqtdj?",
+	L"헬로월드는 지겹잖아, 좀 신선한 거 없어?",
 };

 char*

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [9front] [PATCH] ktrans: fix Korean input
  2024-03-24 10:57 [9front] [PATCH] ktrans: fix Korean input npmania
@ 2024-03-29 19:23 ` Jacob Moody
  0 siblings, 0 replies; 2+ messages in thread
From: Jacob Moody @ 2024-03-29 19:23 UTC (permalink / raw)
  To: 9front

On 3/24/24 05:57, npmania wrote:
> Before applying the patch, /lib/ktrans/hangul.map file has to be
> replaced with new one to work properly. The file was generated to
> provide correct mapping between QWERTY and Dubeolsik layout. Due to
> it's size, I have uploaded it on:
> http://okturing.com/src/19014/body
> 
> This patch implements two specific behaviors of Dubeolsik layout.
> 
> dubeollkup function makes Jongseong(final consonant) to be treated as
> Choseong(initial consonant) when possible. For example, QWERTY input
> "zhem" in Dubeolsik has to be "코드", not "콛ㅡ" where switched
> Jongseong is "ㄷ".
> 
> dubeolbksp function emits out syllable remaining after single
> backspace. So when user presses backspace on "코드", the expected output
> is "코ㄷ", still allowing user to edit latter syllable, rather than
> "코" without dubeolbksp. This should only apply to last syllable
> considering it's de facto in Dubeolsik implementations.

Absolutely fantastic work, thank you so much for taking the time
to help fix this. I very much appreciate the new test cases.

I will apply this very soon, I have a collection of other ktrans
work I am hacking on currently.

Thank you,
moody


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-03-29 19:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-24 10:57 [9front] [PATCH] ktrans: fix Korean input npmania
2024-03-29 19:23 ` Jacob Moody

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).