M10: keep Hangul first in a Korean UI when Thai is also needed

samples() reversed the whole script list for a Korean UI, which put the
Bengali and Thai entries ahead of Hangul. Swap Hangul and Kana instead,
so the order is Hangul, Han, Kana, then Bengali and Thai. A test covers
the mixed case.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cs5R9irCMt9rwfhpkwxvSn
This commit is contained in:
watchakorn-18k
2026-10-24 22:09:09 +07:00
co-authored by Claude Sonnet 5.5
parent f0764be987
commit 42c7f89543
+5 -1
View File
@@ -124,7 +124,7 @@ fn samples(need: u8, ui: u8) -> Vec<(char, Vec<&'static str>)> {
(THAI, ('ก', THAI_FONTS.to_vec())),
];
match ui {
HANGUL => v.reverse(),
HANGUL => v.swap(0, 2),
HAN => v.swap(0, 1),
BENGALI | THAI => {
if let Some(pos) = v.iter().position(|(bit, _)| *bit == ui) {
@@ -157,6 +157,7 @@ pub fn faces(need: u8, lang: &str, have: &dyn Fn(char) -> bool) -> Vec<Arc<Face>
mod tests {
use super::*;
/// Each script is found in text and tied to its UI language code.
#[test]
fn scripts_and_languages() {
assert_eq!(scripts("Frame 1"), 0);
@@ -185,6 +186,7 @@ mod tests {
assert!(shows("en", true) && shows("tr", true));
}
/// The UI language's script leads the fallback order; the others follow.
#[test]
fn the_ui_language_script_comes_first() {
let order = |need, ui| samples(need, ui).into_iter().map(|(c, _)| c).collect::<String>();
@@ -196,6 +198,8 @@ mod tests {
assert_eq!(order(HANGUL, 0), "한");
assert_eq!(order(THAI, 0), "ก");
assert_eq!(order(THAI | KANA, language("th")), "กあ");
// A Korean UI draws Hangul in a Korean face before the Thai or Bengali ones.
assert_eq!(order(KANA | HAN | HANGUL | BENGALI | THAI, HANGUL), "한漢あঅก");
// Han without kana outside a Japanese or Korean UI reads as Chinese.
assert_eq!(order(HAN, 0), "们");
assert_eq!(first_face(HAN, 0), Some("Noto Sans CJK SC"));