Add functional dubeolsik standard layout

This commit is contained in:
Lee0701 2020-06-29 16:38:26 +09:00
parent 41c8563116
commit 603a5f2000
7 changed files with 280 additions and 2 deletions

View file

@ -49,6 +49,69 @@ class HangulCombiner : Combiner {
return createEventChainFromSequence(text, event) return createEventChainFromSequence(text, event)
} else { } else {
when(jamo) { when(jamo) {
is HangulJamo.Consonant -> {
val initial = jamo.toInitial()
val final = jamo.toFinal()
if(currentSyllable.final == null) {
if(currentSyllable.initial != null) {
val combination = COMBINATION_TABLE_DUBEOLSIK[currentSyllable.initial.codePoint to (initial?.codePoint ?: -1)]
if(combination != null) {
history += currentSyllable.copy(initial = HangulJamo.Initial(combination))
} else {
history += currentSyllable.copy(final = final)
}
} else {
history += currentSyllable.copy(final = final)
}
} else {
val pair = currentSyllable.final.codePoint to (final?.codePoint ?: -1)
val combination = COMBINATION_TABLE_DUBEOLSIK[pair]
if(combination != null) {
history += currentSyllable.copy(final = HangulJamo.Final(combination, combinationPair = pair))
} else {
composingWord.append(currentSyllable.string)
history.clear()
history += HangulSyllable(initial = initial)
}
}
}
is HangulJamo.Vowel -> {
val medial = jamo.toMedial()
if(currentSyllable.final == null) {
if(currentSyllable.medial != null) {
val combination = COMBINATION_TABLE_DUBEOLSIK[currentSyllable.medial.codePoint to (medial?.codePoint ?: -1)]
if(combination != null) {
history += currentSyllable.copy(medial = HangulJamo.Medial(combination))
} else {
composingWord.append(currentSyllable.string)
history.clear()
history += HangulSyllable(medial = medial)
}
} else {
history += currentSyllable.copy(medial = medial)
}
} else if(currentSyllable.final.combinationPair != null) {
val pair = currentSyllable.final.combinationPair
history.removeAt(history.lastIndex)
val final = HangulJamo.Final(pair.first)
history += currentSyllable.copy(final = final)
composingWord.append(syllable?.string ?: "")
history.clear()
val initial = HangulJamo.Final(pair.second).toConsonant()?.toInitial()
val newSyllable = HangulSyllable(initial = initial)
history += newSyllable
history += newSyllable.copy(medial = medial)
} else {
history.removeAt(history.lastIndex)
composingWord.append(syllable?.string ?: "")
history.clear()
val initial = currentSyllable.final.toConsonant()?.toInitial()
val newSyllable = HangulSyllable(initial = initial)
history += newSyllable
history += newSyllable.copy(medial = medial)
}
}
is HangulJamo.Initial -> { is HangulJamo.Initial -> {
if(currentSyllable.initial != null) { if(currentSyllable.initial != null) {
val combination = COMBINATION_TABLE_SEBEOLSIK[currentSyllable.initial.codePoint to jamo.codePoint] val combination = COMBINATION_TABLE_SEBEOLSIK[currentSyllable.initial.codePoint to jamo.codePoint]
@ -130,7 +193,7 @@ class HangulCombiner : Combiner {
return Vowel(codePoint.toInt()) return Vowel(codePoint.toInt())
} }
} }
data class Final(override val codePoint: Int) : HangulJamo() { data class Final(override val codePoint: Int, val combinationPair: Pair<Int, Int>? = null) : HangulJamo() {
override val modern: Boolean get() = codePoint in 0x11a8 .. 0x11c2 override val modern: Boolean get() = codePoint in 0x11a8 .. 0x11c2
val ordinal: Int get() = codePoint - 0x11a7 val ordinal: Int get() = codePoint - 0x11a7
fun toConsonant(): Consonant? { fun toConsonant(): Consonant? {
@ -170,6 +233,8 @@ class HangulCombiner : Combiner {
const val CONVERT_FINALS = "ᆨᆩᆪᆫᆬᆭᆮ\u0000ᆯᆰᆱᆲᆳᆴᆵᆶᆷᆸ\u0000ᆹᆺᆻᆼᆽ\u0000ᆾᆿᇀᇁᇂ" const val CONVERT_FINALS = "ᆨᆩᆪᆫᆬᆭᆮ\u0000ᆯᆰᆱᆲᆳᆴᆵᆶᆷᆸ\u0000ᆹᆺᆻᆼᆽ\u0000ᆾᆿᇀᇁᇂ"
fun of(codePoint: Int): HangulJamo { fun of(codePoint: Int): HangulJamo {
return when(codePoint) { return when(codePoint) {
in 0x3131 .. 0x314e -> Consonant(codePoint)
in 0x314f .. 0x3163 -> Vowel(codePoint)
in 0x1100 .. 0x115f -> Initial(codePoint) in 0x1100 .. 0x115f -> Initial(codePoint)
in 0x1160 .. 0x11a7 -> Medial(codePoint) in 0x1160 .. 0x11a7 -> Medial(codePoint)
in 0x11a8 .. 0x11ff -> Final(codePoint) in 0x11a8 .. 0x11ff -> Final(codePoint)

View file

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
**
** Copyright 2008, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
-->
<Keyboard
xmlns:latin="http://schemas.android.com/apk/res-auto"
>
<include
latin:keyboardLayout="@xml/rows_korean_dubeolsik_standard" />
</Keyboard>

View file

@ -24,7 +24,7 @@
latin:supportedScript="hangul" /> latin:supportedScript="hangul" />
<Element <Element
latin:elementName="alphabet" latin:elementName="alphabet"
latin:elementKeyboard="@xml/kbd_qwerty" latin:elementKeyboard="@xml/kbd_korean_dubeolsik_standard"
latin:enableProximityCharsCorrection="true" /> latin:enableProximityCharsCorrection="true" />
<Element <Element
latin:elementName="symbols" latin:elementName="symbols"

View file

@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
**
** Copyright 2012, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
-->
<merge xmlns:latin="http://schemas.android.com/apk/res-auto">
<Key
latin:keySpec="&#x3142;"
latin:keyHintLabel="&#x3143;"
latin:additionalMoreKeys="&#x3143;" />
<Key
latin:keySpec="&#x3148;"
latin:keyHintLabel="&#x3149;"
latin:additionalMoreKeys="&#x3149;" />
<Key
latin:keySpec="&#x3137;"
latin:keyHintLabel="&#x3138;"
latin:additionalMoreKeys="&#x3138;" />
<Key
latin:keySpec="&#x3131;"
latin:keyHintLabel="&#x3132;"
latin:additionalMoreKeys="&#x3132;" />
<Key
latin:keySpec="&#x3145;"
latin:keyHintLabel="&#x3146;"
latin:additionalMoreKeys="&#x3146;" />
<Key
latin:keySpec="&#x315b;" />
<Key
latin:keySpec="&#x3155;" />
<Key
latin:keySpec="&#x3151;" />
<Key
latin:keySpec="&#x3150;"
latin:keyHintLabel="&#x3152;"
latin:additionalMoreKeys="&#x3152;" />
<Key
latin:keySpec="&#x3154;"
latin:keyHintLabel="&#x3156;"
latin:additionalMoreKeys="&#x3156;" />
</merge>

View file

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
**
** Copyright 2012, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
-->
<merge xmlns:latin="http://schemas.android.com/apk/res-auto">
<Key
latin:keySpec="&#x3141;" />
<Key
latin:keySpec="&#x3134;" />
<Key
latin:keySpec="&#x3147;" />
<Key
latin:keySpec="&#x3139;" />
<Key
latin:keySpec="&#x314e;" />
<Key
latin:keySpec="&#x3157;" />
<Key
latin:keySpec="&#x3153;" />
<Key
latin:keySpec="&#x314f;" />
<Key
latin:keySpec="&#x3163;" />
</merge>

View file

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
**
** Copyright 2012, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
-->
<merge xmlns:latin="http://schemas.android.com/apk/res-auto">
<Key
latin:keySpec="&#x314b;" />
<Key
latin:keySpec="&#x314c;" />
<Key
latin:keySpec="&#x314a;" />
<Key
latin:keySpec="&#x314d;" />
<Key
latin:keySpec="&#x3160;" />
<Key
latin:keySpec="&#x315c;" />
<Key
latin:keySpec="&#x3161;" />
</merge>

View file

@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
**
** Copyright 2010, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
-->
<merge
xmlns:latin="http://schemas.android.com/apk/res-auto"
>
<include
latin:keyboardLayout="@xml/key_styles_common" />
<Row
latin:keyWidth="10%p"
>
<include
latin:keyboardLayout="@xml/rowkeys_korean_dubeolsik_standard_1" />
</Row>
<Row
latin:keyWidth="10%p"
>
<include
latin:keyboardLayout="@xml/rowkeys_korean_dubeolsik_standard_2"
latin:keyXPos="5%p" />
</Row>
<Row
latin:keyWidth="10%p"
>
<Key
latin:keyStyle="shiftKeyStyle"
latin:keyWidth="15%p"
latin:visualInsetsRight="1%p" />
<include
latin:keyboardLayout="@xml/rowkeys_korean_dubeolsik_standard_3" />
<Key
latin:keyStyle="deleteKeyStyle"
latin:keyWidth="fillRight"
latin:visualInsetsLeft="1%p" />
</Row>
<include
latin:keyboardLayout="@xml/row_qwerty4" />
</merge>