Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Disable subpixel shifting for y axis on Windows (#38440)
localcc8bac1bee7a6e
diff --git a/crates/gpui/src/platform/linux/text_system.rs b/crates/gpui/src/platform/linux/text_system.rsindex f66a2e71d49..3f045f9406f 100644--- a/crates/gpui/src/platform/linux/text_system.rs+++ b/crates/gpui/src/platform/linux/text_system.rs@@ -1,6 +1,6 @@use crate::{Bounds, DevicePixels, Font, FontFeatures, FontId, FontMetrics, FontRun, FontStyle, FontWeight,- GlyphId, LineLayout, Pixels, PlatformTextSystem, Point, RenderGlyphParams, SUBPIXEL_VARIANTS,+ GlyphId, LineLayout, Pixels, PlatformTextSystem, Point, RenderGlyphParams, SUBPIXEL_VARIANTS_X,ShapedGlyph, ShapedRun, SharedString, Size, point, size,};use anyhow::{Context as _, Ok, Result};@@ -276,7 +276,7 @@ impl CosmicTextSystemState {let font = &self.loaded_fonts[params.font_id.0].font;let subpixel_shift = params.subpixel_variant- .map(|v| v as f32 / (SUBPIXEL_VARIANTS as f32 * params.scale_factor));+ .map(|v| v as f32 / (SUBPIXEL_VARIANTS_X as f32 * params.scale_factor));let image = self.swash_cache.get_image(@@ -311,7 +311,7 @@ impl CosmicTextSystemState {let font = &self.loaded_fonts[params.font_id.0].font;let subpixel_shift = params.subpixel_variant- .map(|v| v as f32 / (SUBPIXEL_VARIANTS as f32 * params.scale_factor));+ .map(|v| v as f32 / (SUBPIXEL_VARIANTS_X as f32 * params.scale_factor));let mut image = self.swash_cache.get_image(diff --git a/crates/gpui/src/platform/mac/text_system.rs b/crates/gpui/src/platform/mac/text_system.rsindex 7f765fbaac8..67ece1f153f 100644--- a/crates/gpui/src/platform/mac/text_system.rs+++ b/crates/gpui/src/platform/mac/text_system.rs@@ -1,7 +1,7 @@use crate::{Bounds, DevicePixels, Font, FontFallbacks, FontFeatures, FontId, FontMetrics, FontRun,FontStyle, FontWeight, GlyphId, LineLayout, Pixels, PlatformTextSystem, Point,- RenderGlyphParams, Result, SUBPIXEL_VARIANTS, ShapedGlyph, ShapedRun, SharedString, Size,+ RenderGlyphParams, Result, SUBPIXEL_VARIANTS_X, ShapedGlyph, ShapedRun, SharedString, Size,point, px, size, swap_rgba_pa_to_bgra,};use anyhow::anyhow;@@ -395,7 +395,7 @@ impl MacTextSystemState {let subpixel_shift = params.subpixel_variant- .map(|v| v as f32 / SUBPIXEL_VARIANTS as f32);+ .map(|v| v as f32 / SUBPIXEL_VARIANTS_X as f32);cx.set_allows_font_smoothing(true);cx.set_text_drawing_mode(CGTextDrawingMode::CGTextFill);cx.set_gray_fill_color(0.0, 1.0);diff --git a/crates/gpui/src/platform/windows/direct_write.rs b/crates/gpui/src/platform/windows/direct_write.rsindex df3161bf079..e187fc4b091 100644--- a/crates/gpui/src/platform/windows/direct_write.rs+++ b/crates/gpui/src/platform/windows/direct_write.rs@@ -723,11 +723,10 @@ impl DirectWriteState {dx: 0.0,dy: 0.0,};- let subpixel_shift = params- .subpixel_variant- .map(|v| v as f32 / SUBPIXEL_VARIANTS as f32);- let baseline_origin_x = subpixel_shift.x / params.scale_factor;- let baseline_origin_y = subpixel_shift.y / params.scale_factor;+ let baseline_origin_x =+ params.subpixel_variant.x as f32 / SUBPIXEL_VARIANTS_X as f32 / params.scale_factor;+ let baseline_origin_y =+ params.subpixel_variant.y as f32 / SUBPIXEL_VARIANTS_Y as f32 / params.scale_factor;let mut rendering_mode = DWRITE_RENDERING_MODE1::default();let mut grid_fit_mode = DWRITE_GRID_FIT_MODE::default();@@ -859,7 +858,7 @@ impl DirectWriteState {let bitmap_size = glyph_bounds.size;let subpixel_shift = params.subpixel_variant- .map(|v| v as f32 / SUBPIXEL_VARIANTS as f32);+ .map(|v| v as f32 / SUBPIXEL_VARIANTS_X as f32);let baseline_origin_x = subpixel_shift.x / params.scale_factor;let baseline_origin_y = subpixel_shift.y / params.scale_factor;diff --git a/crates/gpui/src/text_system.rs b/crates/gpui/src/text_system.rsindex 4d4087f45d4..efa4ad032a6 100644--- a/crates/gpui/src/text_system.rs+++ b/crates/gpui/src/text_system.rs@@ -41,7 +41,13 @@ pub struct FontId(pub usize);#[derive(Hash, PartialEq, Eq, Clone, Copy, Debug)]pub struct FontFamilyId(pub usize);-pub(crate) const SUBPIXEL_VARIANTS: u8 = 4;+pub(crate) const SUBPIXEL_VARIANTS_X: u8 = 4;++pub(crate) const SUBPIXEL_VARIANTS_Y: u8 = if cfg!(target_os = "windows") {+ 1+} else {+ SUBPIXEL_VARIANTS_X+};/// The GPUI text rendering sub system.pub struct TextSystem {diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rsindex 307197acca7..d9bf27dca12 100644--- a/crates/gpui/src/window.rs+++ b/crates/gpui/src/window.rs@@ -11,8 +11,8 @@ use crate::{MouseMoveEvent, MouseUpEvent, Path, Pixels, PlatformAtlas, PlatformDisplay, PlatformInput,PlatformInputHandler, PlatformWindow, Point, PolychromeSprite, PromptButton, PromptLevel, Quad,Render, RenderGlyphParams, RenderImage, RenderImageParams, RenderSvgParams, Replay, ResizeEdge,- SMOOTH_SVG_SCALE_FACTOR, SUBPIXEL_VARIANTS, ScaledPixels, Scene, Shadow, SharedString, Size,- StrikethroughStyle, Style, SubscriberSet, Subscription, SystemWindowTab,+ SMOOTH_SVG_SCALE_FACTOR, SUBPIXEL_VARIANTS_X, SUBPIXEL_VARIANTS_Y, ScaledPixels, Scene, Shadow,+ SharedString, Size, StrikethroughStyle, Style, SubscriberSet, Subscription, SystemWindowTab,SystemWindowTabController, TabHandles, TaffyLayoutEngine, Task, TextStyle, TextStyleRefinement,TransformationMatrix, Underline, UnderlineStyle, WindowAppearance, WindowBackgroundAppearance,WindowBounds, WindowControls, WindowDecorations, WindowOptions, WindowParams, WindowTextSystem,@@ -2944,9 +2944,10 @@ impl Window {let element_opacity = self.element_opacity();let scale_factor = self.scale_factor();let glyph_origin = origin.scale(scale_factor);+let subpixel_variant = Point {- x: (glyph_origin.x.0.fract() * SUBPIXEL_VARIANTS as f32).floor() as u8,- y: (glyph_origin.y.0.fract() * SUBPIXEL_VARIANTS as f32).floor() as u8,+ x: (glyph_origin.x.0.fract() * SUBPIXEL_VARIANTS_X as f32).floor() as u8,+ y: (glyph_origin.y.0.fract() * SUBPIXEL_VARIANTS_Y as f32).floor() as u8,};let params = RenderGlyphParams {font_id,