zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
46.64k stars 2.65k forks source link

no font anti-aliasing #14169

Closed ciaran-matthew-dunne closed 2 weeks ago

ciaran-matthew-dunne commented 1 month ago

Check for existing issues

Describe the bug / provide steps to reproduce it

Run Zed Dev 0.142.0, and Zed Preview 0.144.0. The UI and buffer fonts in 0.142.0 look nice and smooth. Observe the UI and buffer fonts in 0.144.0, which are sharp and not anti-aliased.

Environment

(text looks pretty and anti-aliased in UI and buffer) Zed: v0.142.0 (Zed Dev 3ee3c6a3bd77370de952831b1f99b7dc026b2b95) OS: Linux Wayland ubuntu 24.04 Memory: 31 GiB Architecture: x86_64

(ugly text in UI and buffer no anti-aliasing) Zed: v0.144.0 (Zed Preview) OS: Linux Wayland ubuntu 24.04 Memory: 31 GiB Architecture: x86_64

If applicable, add mockups / screenshots to help explain present your vision of the feature

Zed Preview 0.144.0 Screenshot from 2024-07-11 10-54-15

Zed Dev 0.142.0 Screenshot from 2024-07-11 10-53-23

If applicable, attach your Zed.log file to this issue.

Zed.log

2024-07-11T10:56:03+02:00 [INFO] ========== starting zed ==========
2024-07-11T10:56:03+02:00 [INFO] Opening main db
2024-07-11T10:56:03+02:00 [INFO] perform;
2024-07-11T10:56:03+02:00 [INFO] read_command;
2024-07-11T10:56:03+02:00 [INFO] read_command;
2024-07-11T10:56:03+02:00 [INFO] socket reader;
2024-07-11T10:56:03+02:00 [INFO] new;
2024-07-11T10:56:03+02:00 [INFO] Using git binary path: None
2024-07-11T10:56:03+02:00 [INFO] keep_updated;
2024-07-11T10:56:03+02:00 [INFO] extensions updated. loading 5, reloading 0, unloading 0
2024-07-11T10:56:03+02:00 [INFO] activate is not implemented on Linux, ignoring the call
2024-07-11T10:56:03+02:00 [INFO] Opening main db
2024-07-11T10:56:03+02:00 [INFO] perform;
2024-07-11T10:56:03+02:00 [INFO] read_command;
2024-07-11T10:56:03+02:00 [INFO] read_command;
2024-07-11T10:56:03+02:00 [INFO] socket reader;
2024-07-11T10:56:03+02:00 [INFO] set environment variables from shell:/bin/bash, path:/home/ciaran/.opam/smtcoqcapi/bin:/home/ciaran/.local/bin:/home/ciaran/.opam/smtcoqcapi/bin:/home/ciaran/.cargo/bin:/home/ciaran/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin
2024-07-11T10:56:03+02:00 [INFO] Enabling Vulkan Portability
2024-07-11T10:56:03+02:00 [INFO] Enabling color space support
2024-07-11T10:56:03+02:00 [INFO] Adapter "NVIDIA RTX A1000 6GB Laptop GPU"
2024-07-11T10:56:03+02:00 [INFO] Ray tracing is supported
2024-07-11T10:56:03+02:00 [INFO] Using surface present mode MAILBOX
2024-07-11T10:56:03+02:00 [WARN] Unable to forbid exclusive full screen
2024-07-11T10:56:03+02:00 [INFO] Creating a descriptor pool for at most 16 sets
2024-07-11T10:56:03+02:00 [INFO] Creating a descriptor pool for at most 16 sets
2024-07-11T10:56:03+02:00 [INFO] Initializing Blade pipelines for surface SurfaceInfo { format: Bgra8UnormSrgb, alpha: PreMultiplied }
2024-07-11T10:56:03+02:00 [INFO] Opening main db
2024-07-11T10:56:03+02:00 [INFO] Using surface present mode MAILBOX
2024-07-11T10:56:03+02:00 [WARN] Unable to forbid exclusive full screen
2024-07-11T10:56:03+02:00 [INFO] Opening main db
2024-07-11T10:56:03+02:00 [ERROR] No path stored for this editor
2024-07-11T10:56:04+02:00 [INFO] Node runtime install_if_needed
2024-07-11T10:56:04+02:00 [INFO] starting language server. binary path: "/home/ciaran/.local/share/zed/node/node-v18.15.0-linux-x64/bin/node", working directory: "/", args: ["/home/ciaran/.local/share/zed/copilot/copilot-v0.5.0/dist/agent.js", "--stdio"]
2024-07-11T10:56:04+02:00 [INFO] Language server with id 0 sent unhandled notification LogMessage:
{
  "level": 0,
  "message": "[DEBUG] [agent] [2024-07-11T08:56:04.763Z] Agent service starting",
  "metadataStr": "[DEBUG] [agent] [2024-07-11T08:56:04.763Z]",
  "extra": [
    "Agent service starting"
  ]
}
2024-07-11T10:56:04+02:00 [INFO] Language server with id 0 sent unhandled notification client/registerCapability:
{
  "registrations": [
    {
      "id": "26df1674-92c6-408e-864a-d1cf948c52b1",
      "method": "workspace/didChangeWorkspaceFolders",
      "registerOptions": {}
    }
  ]
}
2024-07-11T10:56:04+02:00 [INFO] Language server with id 0 sent unhandled notification LogMessage:
{
  "level": 0,
  "message": "[DEBUG] [agent] [2024-07-11T08:56:04.774Z] Telemetry initialized",
  "metadataStr": "[DEBUG] [agent] [2024-07-11T08:56:04.774Z]",
  "extra": [
    "Telemetry initialized"
  ]
}
2024-07-11T10:56:06+02:00 [INFO] Creating a descriptor pool for at most 16 sets
2024-07-11T10:56:06+02:00 [INFO] Creating a descriptor pool for at most 16 sets
2024-07-11T10:56:06+02:00 [INFO] Creating a descriptor pool for at most 256 sets
2024-07-11T10:56:06+02:00 [INFO] Creating a descriptor pool for at most 256 sets
vgnh commented 1 month ago

+1 on this..

I was wondering why the text seemed too thin in Zed..

Weirdly enough, this is not a problem on my other laptop running Fedora Linux 40 with Wayland. The fonts look right on that one.

(Subpixel antialiasing for fonts is enabled on both the Fedora and the Ubuntu machines.)

Environment

Zed: v0.144.3 OS: Linux Wayland Ubuntu 22.04.4 LTS Architecture: x86_64 Font used: JetBrains Mono

cmedamine commented 1 month ago

same issue 🐛🐛:

Environment

Zed: v0.146.5
OS: Linux X11 Kubuntu 22.04.4 LTS
Architecture: x86_64
Font used: Zed Mono
afontenot commented 1 month ago

Specifically the issue is not "anti-aliasing" per se, Zed does support grayscale anti-aliasing. If you look closely at your two screenshots you'll see that neither of them show subpixel (rgb) anti-aliasing (there's no color fringe). But that is relatively normal these days if somewhat controversial, e.g. GTK4 doesn't do subpixel anti-aliasing.

The issue is hard to assess in the screenshots because the two screenshots show completely different fonts, but I also see issues and I believe it's the lack of subpixel positioning. In Zed, the same glyph at a particular size always appears to have the same alignment to the pixel grid. GTK4, QT5/6, the major browsers, and most software built on Pango support subpixel positioning, and they look a lot better than Linux programs from 15 years ago as a result.

Here's a 10x zoomed screenshot I took of the menu:

zed_issue

Observe that the characters I've highlighted have been shifted by one pixel increments, and have the same anti-aliasing. You can also see issues with the rendering that are easily visible to the naked eye, e.g. that the three dots in the ellipses are not evenly spaced.

Edit: you can see where the code enables subpixel positioning for the rendering system on macOS here, and there appears to be a todo note about it left in the Linux rendering code here. On the other hand there is apparently discussion about moving the layout engine to Harfbuzz which might impact this issue: https://github.com/zed-industries/zed/issues/13951

Edit: it looks like cosmic-text supports subpixel rendering, so the broken rendering shown in my screenshot is very likely a bug in Zed.

afontenot commented 2 weeks ago

Wow the rendering looks a million times better to me, thanks @apricotbucket28! I came up with the same code myself, but I missed the .trunc(), I guess that's needed because of the y-hinting cosmic_text does?


To anyone whose font rendering issues aren't fixed with the next release:

apricotbucket28 commented 2 weeks ago

but I missed the .trunc(), I guess that's needed because of the y-hinting cosmic_text does?

I actually attempted to implement this a while back, but I ran into an issue where glyphs where being cut off in the y axis. When looking at this again, I noticed that the LayoutGlyph::physical function in cosmic-text was doing a .trunc() - and you're right that it's because of the y-hinting 😄

There seems to be a bit more context in the PR that implemented this: https://github.com/pop-os/cosmic-text/pull/143#discussion_r1234743616

afontenot commented 2 weeks ago

I ran into an issue where glyphs where being cut off in the y axis

Exactly where I gave up! Thanks again.