fonts: allow harfbuzz to guess the script
Our default meant that harfbuzz wouldn't engage preprocessing steps that normalized the text to NFC. With this change we now correctly normalize and render certain compositions that were totally borked previously. refs: https://github.com/wez/wezterm/issues/1573 refs: https://github.com/wez/wezterm/issues/1474
This commit is contained in:
1 parent
85a6b178cf
commit
7ccce20544
6 files changed
+44
-1
No files matched your search
Generated
+1
@@ -4910,6 +4910,7 @@ dependencies = [
|
||||
"serde",
|
||||
"terminfo",
|
||||
"termwiz",
|
||||
"unicode-normalization",
|
||||
"unicode-segmentation",
|
||||
"unicode-width",
|
||||
"url",
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -187,7 +187,12 @@ impl HarfbuzzShaper {
|
||||
presentation: Option<Presentation>,
|
||||
) -> anyhow::Result<Vec<GlyphInfo>> {
|
||||
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.
|
||||
// <https://github.com/wez/wezterm/issues/1474> and
|
||||
// <https://github.com/wez/wezterm/issues/1573>
|
||||
// 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);
|
||||
|
||||
Reference in new issue
Block a user