Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.futo.inputmethod.event.combiners.wylie;

public class EwtsConverter {
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you might have left it blank accidentally

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I committed all changes now

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.futo.inputmethod.event.combiners.wylie

import android.text.TextUtils
import org.futo.inputmethod.event.Combiner
import org.futo.inputmethod.event.Event
import org.futo.inputmethod.latin.common.Constants
import java.util.ArrayList

/**
* Combiner that converts Extended Wylie transliteration to Tibetan script
* Useful for Tibetan and Dzongkha languages
* Uses the ewts-converter library: https://github.com/buda-base/ewts-converter
*/
class WylieCombiner: Combiner {
private val buffer = StringBuilder() //Holds a single syllable (as divided by "tsheg"s)
private val ewtsConverter = EwtsConverter()

private fun isWylie(char: Char): Boolean {
return char.code <= 0x7f &&
(char.isLetter() ||
char in listOf('\'', '+', '-', '.', '~', '`', '&', '?') )
} //ASCII uppercase and lowercase letters, and a few other characters used in Wylie.

override fun processEvent(previousEvents: ArrayList<Event>?, event: Event?): Event {
if (event == null) return Event.createNotHandledEvent()
val keypress = event.mCodePoint.toChar()

if (!isWylie(keypress)) {
if (!TextUtils.isEmpty(buffer)) {
if (event.mKeyCode == Constants.CODE_DELETE) {
return if (buffer.length == 1) {
reset()
Event.createHardwareKeypressEvent(0x20, Constants.CODE_SPACE,
event, event.isKeyRepeat)
// for some reason, this is needed, otherwise if there is only one letter
// in the buffer it won't be deleted
}
else {
buffer.setLength(buffer.length - 1)
Event.createConsumedEvent(event)
}
}
}
return event
}

buffer.append(keypress)
return Event.createConsumedEvent(event)
}

override fun getCombiningStateFeedback(): CharSequence {
return ewtsConverter.toUnicode(buffer.toString())
}

override fun reset() {
buffer.setLength(0)
}
}
4 changes: 3 additions & 1 deletion java/src/org/futo/inputmethod/v2keyboard/CombinerKind.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import org.futo.inputmethod.event.Combiner
import org.futo.inputmethod.event.DeadKeyCombiner
import org.futo.inputmethod.event.combiners.DeadKeyPreCombiner
import org.futo.inputmethod.event.combiners.KoreanCombiner
import org.futo.inputmethod.event.combiners.WylieCombiner

enum class CombinerKind(val factory: () -> Combiner) {
DeadKey({ DeadKeyCombiner() }),
DeadKeyPreCombiner({ DeadKeyPreCombiner() }),
Korean({ KoreanCombiner() }),
KoreanCombineInitials({ KoreanCombiner(combineInitials = true) })
KoreanCombineInitials({ KoreanCombiner(combineInitials = true) }),
Wylie({ WylieCombiner() })
}