diff --git a/Cargo.lock b/Cargo.lock index aeaae3c9f..755269d57 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4910,6 +4910,7 @@ dependencies = [ "serde", "terminfo", "termwiz", + "unicode-normalization", "unicode-segmentation", "unicode-width", "url", diff --git a/docs/changelog.md b/docs/changelog.md index 7bd3b8bf4..d2006ae89 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -53,6 +53,7 @@ As features stabilize some brief notes about them will accumulate here. * Multiplexer sessions now propagate user vars [#1528](https://github.com/wez/wezterm/issues/1528) * Config reloads on the multiplexer server didn't cause the palette to update on the client [#1526](https://github.com/wez/wezterm/issues/1528) * [ScrollToTop](config/lua/keyassignment/ScrollToTop.md) could get confused when there were multiple prompts on the same line [#1121](https://github.com/wez/wezterm/issues/1121) +* Hangul text in NFD was not always correctly composed when shaping fonts. [#1573](https://github.com/wez/wezterm/issues/1573) ### 20220101-133340-7edc5b5a diff --git a/term/Cargo.toml b/term/Cargo.toml index 0c702ac37..cceb4642b 100644 --- a/term/Cargo.toml +++ b/term/Cargo.toml @@ -35,6 +35,7 @@ url = "2" pretty_assertions = "0.6" pretty_env_logger = "0.4" k9 = "0.11.0" +unicode-normalization = "0.1" [dependencies.termwiz] version = "0.15" diff --git a/term/src/test/mod.rs b/term/src/test/mod.rs index 20387e53b..c784643c3 100644 --- a/term/src/test/mod.rs +++ b/term/src/test/mod.rs @@ -1081,6 +1081,30 @@ fn test_emoji_with_modifier() { ); } +#[test] +fn test_1573() { + let sequence = "\u{1112}\u{1161}\u{11ab}"; + + let mut term = TestTerm::new(2, 5, 0); + term.print(sequence); + term.print("\r\n"); + + assert_all_contents( + &term, + file!(), + line!(), + &[&format!("{} ", sequence), " "], + ); + + use unicode_normalization::UnicodeNormalization; + let recomposed: String = sequence.nfc().collect(); + assert_eq!(recomposed, "\u{d55c}"); + + use unicode_segmentation::UnicodeSegmentation; + let graphemes: Vec<_> = sequence.graphemes(true).collect(); + assert_eq!(graphemes, vec![sequence]); +} + #[test] fn test_hyperlinks() { let mut term = TestTerm::new(3, 5, 0); diff --git a/termwiz/src/cell.rs b/termwiz/src/cell.rs index 93a83a60c..73cd37a50 100644 --- a/termwiz/src/cell.rs +++ b/termwiz/src/cell.rs @@ -1099,4 +1099,15 @@ mod test { vec![raised_fist.to_string()] ); } + + #[test] + fn issue_1573() { + let sequence = "\u{1112}\u{1161}\u{11ab}"; + assert_eq!(unicode_column_width(sequence, None), 2); + assert_eq!(grapheme_column_width(sequence, None), 2); + + let sequence2 = std::str::from_utf8(b"\xe1\x84\x92\xe1\x85\xa1\xe1\x86\xab").unwrap(); + assert_eq!(unicode_column_width(sequence2, None), 2); + assert_eq!(grapheme_column_width(sequence2, None), 2); + } } diff --git a/wezterm-font/src/shaper/harfbuzz.rs b/wezterm-font/src/shaper/harfbuzz.rs index 1a47f87c0..af298ba8b 100644 --- a/wezterm-font/src/shaper/harfbuzz.rs +++ b/wezterm-font/src/shaper/harfbuzz.rs @@ -187,7 +187,12 @@ impl HarfbuzzShaper { presentation: Option, ) -> anyhow::Result> { let mut buf = harfbuzz::Buffer::new()?; - buf.set_script(harfbuzz::hb_script_t::HB_SCRIPT_LATIN); + // We deliberately omit setting the script and leave it to harfbuzz + // to infer from the buffer contents so that it can correctly + // enable appropriate preprocessing for eg: Hangul. + // and + // + // buf.set_script(harfbuzz::hb_script_t::HB_SCRIPT_LATIN); buf.set_direction(harfbuzz::hb_direction_t::HB_DIRECTION_LTR); buf.set_language(self.lang); buf.add_str(s);