slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
17.51k stars 600 forks source link

Subpixel font rendering #5748

Open Enyium opened 3 months ago

Enyium commented 3 months ago

No renderer I tried (at least software, FemtoVG and Skia) rendered text on Windows 10 with ClearType, that is, utilizing the R, G, B hardware subpixels of the monitor. I have it turned on in my system (confirmed by screenshots with orange and blue sides on letters) and @tronical called the way Skia renders text the one and true way of doing it in another issue. ChatGPT with GPT-4o claimed that Skia is able to render using ClearType, but the text rendered with it in my Slint window only uses shades of gray.

tkkcc commented 3 months ago

same as me, i think anti-aliasing is broken with FemtoVG and winit-skia backend, for both win and linux. But winit-software and qt backend have normal smoothing, you can try

$env:SLINT_BACKEND='winit-software'; cargo run --release
tronical commented 3 months ago

I think that's a valid bug report. If I understand correctly, we're not setting the lcd config on the skia surface, and we should probably also set SK_FONT_HOST_USE_SYSTEM_SETTINGS when compiling skia to read the correct gramma correction values from the system.

Enyium commented 3 months ago

You added issue labels specifying this as a Windows bug. But I have no idea whether it works on the other OSs. macOS has subpixel font antialiasing; and with Linux, there are apparently also ways to render text like this.

tronical commented 2 months ago

It's true that while macOS does support sub pixel anti-aliasing, it's not enabled by default. That said, AFAICS Skia uses glyphs rendered by CoreText that are LCD optimised.

On Linux, I don't see Skia supporting LCD filtering, i.e. I don't see it forwarding any filter setting to FreeType.

Setting the LCD config on the skia surface is a cross-platform matter, but we need to find a way to get the correct setting there. Unless... there isn't a way and we should just set it to kRGB_H_SkPixelGeometry?

Enyium commented 2 months ago

If, after using Skia in a way that activates ClearType, ClearType in Slint windows can't be deactivated anymore by changing the system setting, Slint should read the system setting SPI_GETFONTSMOOTHINGTYPE (there's also the ClearType-related SPI_GETFONTSMOOTHINGORIENTATION and SPI_GETFONTSMOOTHINGCONTRAST), and possibly also SPI_GETFONTSMOOTHING. It would need to be tested how Slint behaves after the change.

bu5hm4nn commented 1 month ago

Bump. Fonts look ugly for me on macOS.