Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
gpui: Do not render ligatures between different styled text runs (#43080)
Kirill Bulatov97b429953eb6
diff --git a/crates/gpui/src/platform/mac/text_system.rs b/crates/gpui/src/platform/mac/text_system.rsindex 92135a2c96e..3faf4e6491e 100644--- a/crates/gpui/src/platform/mac/text_system.rs+++ b/crates/gpui/src/platform/mac/text_system.rs@@ -435,6 +435,7 @@ impl MacTextSystemState {{let mut text = text;+ let mut break_ligature = true;for run in font_runs {let text_run;(text_run, text) = text.split_at(run.len);@@ -444,7 +445,8 @@ impl MacTextSystemState {string.replace_str(&CFString::new(text_run), CFRange::init(utf16_start, 0));let utf16_end = string.char_len();- let cf_range = CFRange::init(utf16_start, utf16_end - utf16_start);+ let length = utf16_end - utf16_start;+ let cf_range = CFRange::init(utf16_start, length);let font = &self.fonts[run.font_id.0];let font_metrics = font.metrics();@@ -452,6 +454,11 @@ impl MacTextSystemState {max_ascent = max_ascent.max(font_metrics.ascent * font_scale);max_descent = max_descent.max(-font_metrics.descent * font_scale);+ let font_size = if break_ligature {+ px(font_size.0.next_up())+ } else {+ font_size+ };unsafe {string.set_attribute(cf_range,@@ -459,6 +466,7 @@ impl MacTextSystemState {&font.native_font().clone_with_font_size(font_size.into()),);}+ break_ligature = !break_ligature;}}// Retrieve the glyphs from the shaped line, converting UTF16 offsets to UTF8 offsets.diff --git a/crates/gpui/src/platform/windows/direct_write.rs b/crates/gpui/src/platform/windows/direct_write.rsindex cb22948898f..84539633c9e 100644--- a/crates/gpui/src/platform/windows/direct_write.rs+++ b/crates/gpui/src/platform/windows/direct_write.rs@@ -608,6 +608,7 @@ impl DirectWriteState {let mut first_run = true;let mut ascent = Pixels::default();let mut descent = Pixels::default();+ let mut break_ligatures = false;for run in font_runs {if first_run {first_run = false;@@ -616,6 +617,7 @@ impl DirectWriteState {text_layout.GetLineMetrics(Some(&mut metrics), &mut line_count as _)?;ascent = px(metrics[0].baseline);descent = px(metrics[0].height - metrics[0].baseline);+ break_ligatures = !break_ligatures;continue;}let font_info = &self.fonts[run.font_id.0];@@ -636,10 +638,17 @@ impl DirectWriteState {text_layout.SetFontCollection(collection, text_range)?;text_layout.SetFontFamilyName(&HSTRING::from(&font_info.font_family), text_range)?;- text_layout.SetFontSize(font_size.0, text_range)?;+ let font_size = if break_ligatures {+ font_size.0.next_up()+ } else {+ font_size.0+ };+ text_layout.SetFontSize(font_size, text_range)?;text_layout.SetFontStyle(font_info.font_face.GetStyle(), text_range)?;text_layout.SetFontWeight(font_info.font_face.GetWeight(), text_range)?;text_layout.SetTypography(&font_info.features, text_range)?;++ break_ligatures = !break_ligatures;}let mut runs = Vec::new();