Compare commits

...

3 Commits

Author SHA1 Message Date
Jules Aguillon
3591881b14 Disable combining diacritics on some keys
Disable combining diacritics on digit, latin punctuations and currency
symbols
2024-07-14 23:37:41 +02:00
Jules Aguillon
4c0c1fa13b Combining diacritic for accent double aigu 2024-07-13 12:13:25 +02:00
Jules Aguillon
9a44ecf4e2 Apply combining diacritic for accent aigu
Any characters that were not affected by the compose or the dead char
mappings are now outputted with a combining diacritic when enabling the
accent aigu.
2024-07-13 12:10:04 +02:00
4 changed files with 50 additions and 42 deletions

View File

@ -11,15 +11,5 @@
"u": "ú", "u": "ú",
"y": "ý", "y": "ý",
"z": "ź", "z": "ź",
"ü": "ǘ", "ü": "ǘ"
"j": "j\u0301",
"у": "у\u0301",
"е": "е\u0301",
"а": "а\u0301",
"о": "о\u0301",
"и": "и\u0301",
"ы": "ы\u0301",
"э": "э\u0301",
"ю": "ю\u0301",
"я": "я\u0301"
} }

View File

@ -1,10 +1,5 @@
{ {
"o": "ő", "o": "ő",
"u": "ű", "u": "ű",
" ": "˝", " ": "˝"
"a": "a\u030b",
"e": "e\u030b",
"i": "i\u030b",
"m": "m\u030b",
"y": "y\u030b"
} }

View File

@ -2,6 +2,7 @@ package juloo.keyboard2;
import android.view.KeyCharacterMap; import android.view.KeyCharacterMap;
import android.view.KeyEvent; import android.view.KeyEvent;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
public final class KeyModifier public final class KeyModifier
@ -58,7 +59,7 @@ public final class KeyModifier
case GESTURE: return apply_gesture(k); case GESTURE: return apply_gesture(k);
case SHIFT: return apply_shift(k); case SHIFT: return apply_shift(k);
case GRAVE: return apply_compose_or_dead_char(k, ComposeKeyData.accent_grave, '\u02CB'); case GRAVE: return apply_compose_or_dead_char(k, ComposeKeyData.accent_grave, '\u02CB');
case AIGU: return apply_compose_or_dead_char(k, ComposeKeyData.accent_aigu, '\u00B4'); case AIGU: return apply_diacritics(k, ComposeKeyData.accent_aigu, '\u00B4', '\u0301');
case CIRCONFLEXE: return apply_compose_or_dead_char(k, ComposeKeyData.accent_circonflexe, '\u02C6'); case CIRCONFLEXE: return apply_compose_or_dead_char(k, ComposeKeyData.accent_circonflexe, '\u02C6');
case TILDE: return apply_compose_or_dead_char(k, ComposeKeyData.accent_tilde, '\u02DC'); case TILDE: return apply_compose_or_dead_char(k, ComposeKeyData.accent_tilde, '\u02DC');
case CEDILLE: return apply_compose_or_dead_char(k, ComposeKeyData.accent_cedille, '\u00B8'); case CEDILLE: return apply_compose_or_dead_char(k, ComposeKeyData.accent_cedille, '\u00B8');
@ -69,7 +70,7 @@ public final class KeyModifier
case OGONEK: return apply_compose_or_dead_char(k, ComposeKeyData.accent_ogonek, '\u02DB'); case OGONEK: return apply_compose_or_dead_char(k, ComposeKeyData.accent_ogonek, '\u02DB');
case DOT_ABOVE: return apply_compose_or_dead_char(k, ComposeKeyData.accent_dot_above, '\u02D9'); case DOT_ABOVE: return apply_compose_or_dead_char(k, ComposeKeyData.accent_dot_above, '\u02D9');
case BREVE: return apply_dead_char(k, '\u02D8'); case BREVE: return apply_dead_char(k, '\u02D8');
case DOUBLE_AIGU: return apply_compose(k, ComposeKeyData.accent_double_aigu); case DOUBLE_AIGU: return apply_diacritics(k, ComposeKeyData.accent_double_aigu, '\0', '\u030b');
case ORDINAL: return apply_compose(k, ComposeKeyData.accent_ordinal); case ORDINAL: return apply_compose(k, ComposeKeyData.accent_ordinal);
case SUPERSCRIPT: return apply_compose(k, ComposeKeyData.accent_superscript); case SUPERSCRIPT: return apply_compose(k, ComposeKeyData.accent_superscript);
case SUBSCRIPT: return apply_compose(k, ComposeKeyData.accent_subscript); case SUBSCRIPT: return apply_compose(k, ComposeKeyData.accent_subscript);
@ -131,45 +132,53 @@ public final class KeyModifier
return k; return k;
} }
/** Apply the given compose state or fallback to the dead_char. */ /** Apply the following mapping, in this order, and stop at the first that
private static KeyValue apply_compose_or_dead_char(KeyValue k, int state, char dead_char) changes the key.
- The compose state, unless it is [0].
- The dead char, unless it is ['\0'].
- The combining diacritic, unless it is ['\0'].
This is not done if the initial key matches [combining_disabled]. */
private static KeyValue apply_diacritics(KeyValue k, int state, char dead_char, char combining)
{ {
switch (k.getKind()) switch (k.getKind())
{ {
case Char: case Char:
char c = k.getChar(); char c = k.getChar();
if (state != 0)
{
KeyValue r = ComposeKey.apply(state, c); KeyValue r = ComposeKey.apply(state, c);
if (r != null) if (r != null)
return r; return r;
} }
return apply_dead_char(k, dead_char); if (dead_char != '\0')
}
private static KeyValue apply_compose(KeyValue k, int state)
{ {
switch (k.getKind())
{
case Char:
KeyValue r = ComposeKey.apply(state, k.getChar());
if (r != null)
return r;
}
return k;
}
private static KeyValue apply_dead_char(KeyValue k, char dead_char)
{
switch (k.getKind())
{
case Char:
char c = k.getChar();
char modified = (char)KeyCharacterMap.getDeadChar(dead_char, c); char modified = (char)KeyCharacterMap.getDeadChar(dead_char, c);
if (modified != 0 && modified != c) if (modified != 0 && modified != c)
return KeyValue.makeStringKey(String.valueOf(modified)); return KeyValue.makeStringKey(String.valueOf(modified));
} }
if (combining != '\0' && !combining_disabled(c))
return KeyValue.makeStringKey(new String(new char[]{ c, combining }));
break;
}
return k; return k;
} }
private static KeyValue apply_compose(KeyValue k, int state)
{
return apply_diacritics(k, state, '\0', '\0');
}
private static KeyValue apply_dead_char(KeyValue k, char dead_char)
{
return apply_diacritics(k, 0, dead_char, '\0');
}
private static KeyValue apply_compose_or_dead_char(KeyValue k, int state, char dead_char)
{
return apply_diacritics(k, state, dead_char, '\0');
}
private static KeyValue apply_shift(KeyValue k) private static KeyValue apply_shift(KeyValue k)
{ {
if (_modmap != null) if (_modmap != null)
@ -806,4 +815,18 @@ public final class KeyModifier
} }
return KeyValue.makeHangulFinal(precomposed, final_idx); return KeyValue.makeHangulFinal(precomposed, final_idx);
} }
/** Characters for which combining diacritics should not be appeneded. */
private static final char[] combining_disabled_chars =
"0123456789@`!\"#$%&'()*:+;[{,<\\|-=]}.>^~/?_ \t\n¡¿«»“”—¬‰≈°…·¦¶‡∙€£₹¥¢₽₱₴₿".toCharArray();
static
{
Arrays.sort(combining_disabled_chars);
}
private static boolean combining_disabled(char c)
{
return (Arrays.binarySearch(combining_disabled_chars, c) >= 0);
}
} }