Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Anti-aliased text in X11

I'm experimenting with Xlib to gain a deeper understanding of how Linux GUI programs work. I've written a simple program that display "Hello, world" in a window, but it looks rather anachronistic since the text is not anti-aliased.

What is the best way to display anti-aliased text in X11? How is anti-aliasing implemented in GTK, Qt, and other toolkits?

like image 926
Jay Conrod Avatar asked Dec 11 '09 00:12

Jay Conrod


3 Answers

The X protocol's text-rendering facilities do not support anti-aliasing and aren't used much these days. (I think the reason is that the X font protocol doesn't have any place for an alpha channel.)

GTK and Qt render text in the client using the FreeType library, getting a pixmap with an alpha channel as the result. If the X server supports the RENDER extension, the client can send that pixmap to the server to have it blended onto the display using its alpha channel. If the X server doesn't support RENDER, the client has to retrieve the region of the screen where the text is to be displayed (taking a small screenshot, basically), do the alpha blending client-side, and send the resulting opaque pixmap back to the X server to be displayed.

like image 86
Wyzard Avatar answered Nov 14 '22 18:11

Wyzard


FreeType is at the wrong level of the stack. It will only allow you to draw glyphs at certain places. Typically you need at least a font selection mechanism (supplied by Fontconfig) and a shaping engine (supplied by Pango or Qt).

Both Pango and Qt use a forked version of an abandoned FreeType layout engine, but this is being reconciled into the HarfBuzz project.

See also this post by Behdad Esfahbod: Pango vs HarfBuzz, and this longer and more comprehensive document: State of Text Rendering.

like image 36
Adam Goode Avatar answered Nov 14 '22 18:11

Adam Goode


FreeType. GTK+ uses Pango, and Qt has its own text layout library, but both of them use FreeType in the end, and several apps (for example XTerm with antialiased fonts enabled) use FreeType through the lower-level libXft library which comes with Xorg.

like image 4
hobbs Avatar answered Nov 14 '22 18:11

hobbs